[506] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | using namespace ActiveBasic::Compiler;
|
---|
| 4 |
|
---|
[531] | 5 | LexicalAnalyzer::SourceTemplate::SourceTemplate( const std::string &filePath )
|
---|
| 6 | {
|
---|
| 7 | Jenga::Common::File file = Jenga::Common::File( GetApplicationBaseFullPath( filePath ) );
|
---|
| 8 | source = file.Read();
|
---|
| 9 | }
|
---|
| 10 | std::string LexicalAnalyzer::SourceTemplate::GetResult( const std::map<std::string,std::string> &values )
|
---|
| 11 | {
|
---|
| 12 | std::string result = source;
|
---|
| 13 |
|
---|
| 14 | std::map<std::string,std::string>::const_iterator it = values.begin();
|
---|
| 15 | while( it != values.end() )
|
---|
| 16 | {
|
---|
| 17 | while( true )
|
---|
| 18 | {
|
---|
| 19 | std::string::size_type index = result.find( it->first );
|
---|
| 20 | if( index == std::string::npos )
|
---|
| 21 | {
|
---|
| 22 | break;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | result = result.substr( 0, index ) + it->second + result.substr( index + it->first.length() );
|
---|
| 26 | }
|
---|
| 27 | it++;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | return result;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 |
|
---|
[506] | 34 | bool LexicalAnalyzer::CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection )
|
---|
| 35 | {
|
---|
| 36 | int i, i2;
|
---|
| 37 | char temporary[1024];
|
---|
| 38 |
|
---|
| 39 | bool isSuccessful = true;
|
---|
| 40 |
|
---|
| 41 | // 名前空間管理
|
---|
| 42 | NamespaceScopes namespaceScopes;
|
---|
| 43 |
|
---|
| 44 | for(i=0;;i++){
|
---|
| 45 | if(source[i]=='\0') break;
|
---|
| 46 |
|
---|
| 47 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 48 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 49 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 50 | temporary[i2]=0;
|
---|
| 51 | break;
|
---|
| 52 | }
|
---|
| 53 | temporary[i2]=source[i];
|
---|
| 54 | }
|
---|
| 55 | namespaceScopes.push_back( temporary );
|
---|
| 56 |
|
---|
| 57 | if( !namespaceScopesCollection.IsExist( namespaceScopes ) ){
|
---|
| 58 | namespaceScopesCollection.push_back( namespaceScopes );
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | continue;
|
---|
| 62 | }
|
---|
| 63 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 64 | if( namespaceScopes.size() <= 0 ){
|
---|
| 65 | compiler.errorMessenger.Output( 12, "End Namespace", i );
|
---|
| 66 | isSuccessful = false;
|
---|
| 67 | }
|
---|
| 68 | else{
|
---|
| 69 | namespaceScopes.pop_back();
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | i += 2;
|
---|
| 73 | continue;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | if( namespaceScopes.size() > 0 ){
|
---|
| 78 | compiler.errorMessenger.Output( 63, NULL, cp );
|
---|
| 79 | isSuccessful = false;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | return isSuccessful;
|
---|
| 83 | }
|
---|
[508] | 84 |
|
---|
| 85 | Symbol LexicalAnalyzer::FullNameToSymbol( const char *fullName )
|
---|
| 86 | {
|
---|
| 87 | char areaName[VN_SIZE] = ""; //オブジェクト変数
|
---|
| 88 | char nestName[VN_SIZE] = ""; //入れ子メンバ
|
---|
| 89 | bool isNest = SplitMemberName( fullName, areaName, nestName );
|
---|
| 90 |
|
---|
| 91 | return Symbol( NamespaceScopes( areaName ), nestName );
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | Symbol LexicalAnalyzer::FullNameToSymbol( const std::string &fullName )
|
---|
| 95 | {
|
---|
| 96 | return FullNameToSymbol( fullName.c_str() );
|
---|
| 97 | }
|
---|