[322] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
| 3 | #include <Delegate.h>
|
---|
| 4 |
|
---|
[422] | 5 | void Delegate::RefleshParameterAndReturnType()
|
---|
[322] | 6 | {
|
---|
[422] | 7 | // パラメータを解析
|
---|
| 8 | params.Analyze( paramStr.c_str(), sourceIndex );
|
---|
[339] | 9 |
|
---|
[422] | 10 | // 動的パラメータを作る
|
---|
[339] | 11 | dynamicParams = params;
|
---|
| 12 | dynamicParams.insert( dynamicParams.begin(), new Parameter( "_System_LocalThis", Type( DEF_PTR_VOID ) ) );
|
---|
[422] | 13 |
|
---|
| 14 | if( IsFunction() )
|
---|
| 15 | {
|
---|
| 16 | // 戻り値を取得
|
---|
| 17 | if( !compiler.StringToType( returnTypeName, returnType ) )
|
---|
| 18 | {
|
---|
| 19 | SetError(3,returnTypeName,sourceIndex);
|
---|
| 20 | }
|
---|
| 21 | }
|
---|
[322] | 22 | }
|
---|
| 23 |
|
---|
| 24 | void Delegates::Collect( const BasicSource &source )
|
---|
| 25 | {
|
---|
| 26 | int i2;
|
---|
| 27 | char temporary[VN_SIZE];
|
---|
| 28 |
|
---|
| 29 | // 名前空間管理
|
---|
| 30 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
| 31 | namespaceScopes.clear();
|
---|
| 32 |
|
---|
| 33 | // Importsされた名前空間の管理
|
---|
| 34 | NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
| 35 | importedNamespaces.clear();
|
---|
| 36 |
|
---|
| 37 | for( int i=0; i<source.GetLength(); i++ )
|
---|
| 38 | {
|
---|
| 39 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
| 40 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 41 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 42 | temporary[i2]=0;
|
---|
| 43 | break;
|
---|
| 44 | }
|
---|
| 45 | temporary[i2]=source[i];
|
---|
| 46 | }
|
---|
| 47 | namespaceScopes.push_back( temporary );
|
---|
| 48 |
|
---|
| 49 | continue;
|
---|
| 50 | }
|
---|
| 51 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
| 52 | if( namespaceScopes.size() <= 0 ){
|
---|
| 53 | SetError(12, "End Namespace", i );
|
---|
| 54 | }
|
---|
| 55 | else{
|
---|
| 56 | namespaceScopes.pop_back();
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | i += 2;
|
---|
| 60 | continue;
|
---|
| 61 | }
|
---|
| 62 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
| 63 | for(i+=2,i2=0;;i2++,i++){
|
---|
| 64 | if( IsCommandDelimitation( source[i] ) ){
|
---|
| 65 | temporary[i2]=0;
|
---|
| 66 | break;
|
---|
| 67 | }
|
---|
| 68 | temporary[i2]=source[i];
|
---|
| 69 | }
|
---|
| 70 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
| 71 | {
|
---|
| 72 | SetError(64,temporary,i );
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | continue;
|
---|
| 76 | }
|
---|
| 77 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
| 78 | importedNamespaces.clear();
|
---|
| 79 | continue;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
|
---|
| 83 | {
|
---|
| 84 | int nowLine = i;
|
---|
| 85 |
|
---|
| 86 | i += 2;
|
---|
| 87 | if( !( source[i] == 1 && ( source[i+1] == ESC_SUB || source[i+1] == ESC_FUNCTION ) ) )
|
---|
| 88 | {
|
---|
| 89 | SetError(1,NULL,i);
|
---|
| 90 | continue;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | Procedure::Kind procKind = Procedure::Sub;
|
---|
| 94 | if( source[i+1] == ESC_FUNCTION )
|
---|
| 95 | {
|
---|
| 96 | procKind = Procedure::Function;
|
---|
| 97 | }
|
---|
| 98 | i += 2;
|
---|
| 99 |
|
---|
| 100 | // 名前
|
---|
| 101 | char name[VN_SIZE];
|
---|
| 102 | GetIdentifierToken( name, source.GetBuffer(), i );
|
---|
| 103 |
|
---|
[422] | 104 | if( source[i] != '(' )
|
---|
| 105 | {
|
---|
| 106 | SetError(1,NULL,nowLine);
|
---|
| 107 | continue;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | // パラメータ文字列
|
---|
[322] | 111 | char paramStr[8192];
|
---|
[422] | 112 | i += GetStringInPare( paramStr, source.GetBuffer() + i, true );
|
---|
[322] | 113 |
|
---|
[422] | 114 | // 戻り値の型の文字列
|
---|
| 115 | char returnTypeName[VN_SIZE] = "";
|
---|
[322] | 116 | if( source[i] == 1 && source[i+1] == ESC_AS )
|
---|
| 117 | {
|
---|
| 118 | i += 2;
|
---|
[422] | 119 | GetCommandToken( returnTypeName, source.GetBuffer(), i );
|
---|
| 120 |
|
---|
| 121 | if( procKind != Procedure::Function )
|
---|
| 122 | {
|
---|
| 123 | SetError(38,name,nowLine);
|
---|
| 124 | }
|
---|
[322] | 125 | }
|
---|
[422] | 126 | else
|
---|
| 127 | {
|
---|
| 128 | if( procKind == Procedure::Function )
|
---|
| 129 | {
|
---|
| 130 | SetError(-104,name,nowLine);
|
---|
| 131 | lstrcpy( returnTypeName, "Double" );
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
[322] | 134 |
|
---|
[422] | 135 | this->Put( new Delegate( namespaceScopes, name, procKind, paramStr, returnTypeName, nowLine ) );
|
---|
[322] | 136 | }
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | void Delegates::GenerateSourceCode( std::string &destSource )
|
---|
| 141 | {
|
---|
| 142 | destSource = "";
|
---|
| 143 |
|
---|
| 144 | SourceTemplate sourceTemplate( "\\SubOperation\\templates\\delegate_class.tab" );
|
---|
| 145 |
|
---|
| 146 | this->Iterator_Reset();
|
---|
| 147 | while( this->Iterator_HasNext() )
|
---|
| 148 | {
|
---|
| 149 | const Delegate &dg = *this->Iterator_GetNext();
|
---|
| 150 |
|
---|
| 151 | std::map<std::string,std::string> values;
|
---|
[325] | 152 |
|
---|
| 153 | if( dg.GetNamespaceScopes().size() )
|
---|
| 154 | {
|
---|
| 155 | std::string namespaceScopesCommandStr = "";
|
---|
| 156 | std::string endNamespaceScopesCommandStr = "";
|
---|
| 157 | BOOST_FOREACH( const std::string &namespaceStr, dg.GetNamespaceScopes() )
|
---|
| 158 | {
|
---|
| 159 | if( namespaceScopesCommandStr.size() )
|
---|
| 160 | {
|
---|
| 161 | namespaceScopesCommandStr += ":";
|
---|
| 162 | endNamespaceScopesCommandStr += ":";
|
---|
| 163 | }
|
---|
| 164 | namespaceScopesCommandStr += "Namespace " + namespaceStr;
|
---|
| 165 | endNamespaceScopesCommandStr += "End Namespace";
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 169 | "#namespace_begin#",
|
---|
| 170 | namespaceScopesCommandStr
|
---|
| 171 | ) );
|
---|
| 172 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 173 | "#namespace_end#",
|
---|
| 174 | endNamespaceScopesCommandStr
|
---|
| 175 | ) );
|
---|
| 176 | }
|
---|
| 177 | else
|
---|
| 178 | {
|
---|
| 179 | values.insert( std::map<std::string,std::string>::value_type( "#namespace_begin#", "" ) );
|
---|
| 180 | values.insert( std::map<std::string,std::string>::value_type( "#namespace_end#", "" ) );
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | values.insert( std::map<std::string,std::string>::value_type( "#name#", dg.GetName() ) );
|
---|
| 184 |
|
---|
| 185 | if( dg.IsFunction() )
|
---|
| 186 | {
|
---|
| 187 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 188 | "#call_method_begin#",
|
---|
[422] | 189 | (string)"Function Call(" + dg.paramStr + ") As " + dg.returnTypeName
|
---|
[325] | 190 | ) );
|
---|
| 191 |
|
---|
| 192 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 193 | "#call_method_end#",
|
---|
| 194 | "End Function"
|
---|
| 195 | ) );
|
---|
| 196 |
|
---|
| 197 | values.insert( std::map<std::string,std::string>::value_type( "#result#", "Call=" ) );
|
---|
| 198 | }
|
---|
| 199 | else
|
---|
| 200 | {
|
---|
| 201 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 202 | "#call_method_begin#",
|
---|
[422] | 203 | (string)"Sub Call(" + dg.paramStr + ")"
|
---|
[325] | 204 | ) );
|
---|
| 205 |
|
---|
| 206 | values.insert( std::map<std::string,std::string>::value_type(
|
---|
| 207 | "#call_method_end#",
|
---|
| 208 | "End Sub"
|
---|
| 209 | ) );
|
---|
| 210 |
|
---|
| 211 | values.insert( std::map<std::string,std::string>::value_type( "#result#", "" ) );
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[422] | 214 | values.insert( std::map<std::string,std::string>::value_type( "#params#", dg.paramStr ) );
|
---|
[325] | 215 |
|
---|
[322] | 216 | destSource += sourceTemplate.GetResult( values );
|
---|
| 217 | }
|
---|
[335] | 218 | /*
|
---|
| 219 | ofstream ofs( ( Jenga::Common::Environment::GetAppDir() + "\\generated_delegate_code.log" ).c_str() );
|
---|
| 220 | ofs << destSource;
|
---|
| 221 | ofs.close();
|
---|
| 222 | */
|
---|
[322] | 223 | }
|
---|
[422] | 224 |
|
---|
| 225 | void Delegates::RefleshParameterAndReturnType()
|
---|
| 226 | {
|
---|
| 227 | this->Iterator_Reset();
|
---|
| 228 | while( this->Iterator_HasNext() )
|
---|
| 229 | {
|
---|
| 230 | Delegate &dg = *this->Iterator_GetNext();
|
---|
| 231 | dg.RefleshParameterAndReturnType();
|
---|
| 232 | }
|
---|
| 233 | }
|
---|