Changeset 525 in dev for trunk/ab5.0/abdev/BasicCompiler_Common/src/Delegate.cpp
- Timestamp:
- May 1, 2008, 11:46:43 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/abdev/BasicCompiler_Common/src/Delegate.cpp
r523 r525 42 42 return false; 43 43 } 44 45 void Delegates::Collect( const BasicSource &source )46 {47 int i2;48 char temporary[VN_SIZE];49 50 // 名前空間管理51 NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();52 namespaceScopes.clear();53 54 // Importsされた名前空間の管理55 NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();56 importedNamespaces.clear();57 58 for( int i=0; i<source.GetLength(); i++ )59 {60 if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){61 for(i+=2,i2=0;;i2++,i++){62 if( IsCommandDelimitation( source[i] ) ){63 temporary[i2]=0;64 break;65 }66 temporary[i2]=source[i];67 }68 namespaceScopes.push_back( temporary );69 70 continue;71 }72 else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){73 if( namespaceScopes.size() <= 0 ){74 compiler.errorMessenger.Output(12, "End Namespace", i );75 }76 else{77 namespaceScopes.pop_back();78 }79 80 i += 2;81 continue;82 }83 else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){84 for(i+=2,i2=0;;i2++,i++){85 if( IsCommandDelimitation( source[i] ) ){86 temporary[i2]=0;87 break;88 }89 temporary[i2]=source[i];90 }91 if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )92 {93 compiler.errorMessenger.Output(64,temporary,i );94 }95 96 continue;97 }98 else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){99 importedNamespaces.clear();100 continue;101 }102 103 else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )104 {105 int nowLine = i;106 107 i += 2;108 if( !( source[i] == 1 && ( source[i+1] == ESC_SUB || source[i+1] == ESC_FUNCTION ) ) )109 {110 compiler.errorMessenger.Output(1,NULL,i);111 continue;112 }113 114 Procedure::Kind procKind = Procedure::Sub;115 if( source[i+1] == ESC_FUNCTION )116 {117 procKind = Procedure::Function;118 }119 i += 2;120 121 // 名前122 char name[VN_SIZE];123 GetIdentifierToken( name, source.GetBuffer(), i );124 125 if( source[i] != '(' )126 {127 compiler.errorMessenger.Output(1,NULL,nowLine);128 continue;129 }130 131 // パラメータ文字列132 char paramStr[8192];133 i += GetStringInPare( paramStr, source.GetBuffer() + i, true );134 135 // 戻り値の型の文字列136 char returnTypeName[VN_SIZE] = "";137 if( source[i] == 1 && source[i+1] == ESC_AS )138 {139 i += 2;140 GetCommandToken( returnTypeName, source.GetBuffer(), i );141 142 if( procKind != Procedure::Function )143 {144 compiler.errorMessenger.Output(38,name,nowLine);145 }146 }147 else148 {149 if( procKind == Procedure::Function )150 {151 compiler.errorMessenger.Output(-104,name,nowLine);152 lstrcpy( returnTypeName, "Double" );153 }154 }155 156 this->Put( new Delegate( namespaceScopes, importedNamespaces, name, procKind, paramStr, returnTypeName, nowLine ) );157 }158 }159 }160 161 void Delegates::GenerateSourceCode( std::string &destSource )162 {163 destSource = "";164 165 SourceTemplate sourceTemplate( ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\templates\\delegate_class.tab" );166 167 this->Iterator_Reset();168 while( this->Iterator_HasNext() )169 {170 const Delegate &dg = *this->Iterator_GetNext();171 172 if( !dg.isTargetObjectModule )173 {174 // 静的リンクライブラリの場合は飛ばす(既にインスタンスが定義済みであるため)175 continue;176 }177 178 std::map<std::string,std::string> values;179 180 if( dg.GetNamespaceScopes().size() )181 {182 std::string namespaceScopesCommandStr = "";183 std::string endNamespaceScopesCommandStr = "";184 BOOST_FOREACH( const std::string &namespaceStr, dg.GetNamespaceScopes() )185 {186 if( namespaceScopesCommandStr.size() )187 {188 namespaceScopesCommandStr += ":";189 endNamespaceScopesCommandStr += ":";190 }191 namespaceScopesCommandStr += "Namespace " + namespaceStr;192 endNamespaceScopesCommandStr += "End Namespace";193 }194 195 values.insert( std::map<std::string,std::string>::value_type(196 "#namespace_begin#",197 namespaceScopesCommandStr198 ) );199 values.insert( std::map<std::string,std::string>::value_type(200 "#namespace_end#",201 endNamespaceScopesCommandStr202 ) );203 }204 else205 {206 values.insert( std::map<std::string,std::string>::value_type( "#namespace_begin#", "" ) );207 values.insert( std::map<std::string,std::string>::value_type( "#namespace_end#", "" ) );208 }209 210 values.insert( std::map<std::string,std::string>::value_type( "#name#", dg.GetName() ) );211 212 if( dg.IsFunction() )213 {214 values.insert( std::map<std::string,std::string>::value_type(215 "#call_method_begin#",216 (std::string)"Function Call(" + dg.paramStr + ") As " + dg.returnTypeName217 ) );218 219 values.insert( std::map<std::string,std::string>::value_type(220 "#call_method_end#",221 "End Function"222 ) );223 224 values.insert( std::map<std::string,std::string>::value_type( "#result#", "Call=" ) );225 }226 else227 {228 values.insert( std::map<std::string,std::string>::value_type(229 "#call_method_begin#",230 (std::string)"Sub Call(" + dg.paramStr + ")"231 ) );232 233 values.insert( std::map<std::string,std::string>::value_type(234 "#call_method_end#",235 "End Sub"236 ) );237 238 values.insert( std::map<std::string,std::string>::value_type( "#result#", "" ) );239 }240 241 values.insert( std::map<std::string,std::string>::value_type( "#params#", dg.paramStr ) );242 243 destSource += sourceTemplate.GetResult( values );244 }245 /*246 std::ofstream ofs( ( Jenga::Common::Environment::GetAppDir() + "\\generated_delegate_code.log" ).c_str() );247 ofs << destSource;248 ofs.close();249 */250 }251 252 void Delegates::RefleshParameterAndReturnType()253 {254 this->Iterator_Reset();255 while( this->Iterator_HasNext() )256 {257 Delegate &dg = *this->Iterator_GetNext();258 dg.RefleshParameterAndReturnType();259 }260 }
Note:
See TracChangeset
for help on using the changeset viewer.