1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include <Delegate.h>
|
---|
4 |
|
---|
5 | Delegate::Delegate( const NamespaceScopes &namespaceScopes, const std::string &name, Procedure::Kind procKind, const char *paramStr, const Type &returnType, int nowLine )
|
---|
6 | : Procedure( namespaceScopes, name, procKind, false )
|
---|
7 | {
|
---|
8 | this->returnType = returnType;
|
---|
9 | params.Analyze( paramStr, nowLine );
|
---|
10 | }
|
---|
11 |
|
---|
12 | void Delegates::Collect( const BasicSource &source )
|
---|
13 | {
|
---|
14 | int i2;
|
---|
15 | char temporary[VN_SIZE];
|
---|
16 |
|
---|
17 | // 名前空間管理
|
---|
18 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
19 | namespaceScopes.clear();
|
---|
20 |
|
---|
21 | // Importsされた名前空間の管理
|
---|
22 | NamespaceScopesCollection &importedNamespaces = compiler.GetNamespaceSupporter().GetImportedNamespaces();
|
---|
23 | importedNamespaces.clear();
|
---|
24 |
|
---|
25 | for( int i=0; i<source.GetLength(); i++ )
|
---|
26 | {
|
---|
27 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
28 | for(i+=2,i2=0;;i2++,i++){
|
---|
29 | if( IsCommandDelimitation( source[i] ) ){
|
---|
30 | temporary[i2]=0;
|
---|
31 | break;
|
---|
32 | }
|
---|
33 | temporary[i2]=source[i];
|
---|
34 | }
|
---|
35 | namespaceScopes.push_back( temporary );
|
---|
36 |
|
---|
37 | continue;
|
---|
38 | }
|
---|
39 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
40 | if( namespaceScopes.size() <= 0 ){
|
---|
41 | SetError(12, "End Namespace", i );
|
---|
42 | }
|
---|
43 | else{
|
---|
44 | namespaceScopes.pop_back();
|
---|
45 | }
|
---|
46 |
|
---|
47 | i += 2;
|
---|
48 | continue;
|
---|
49 | }
|
---|
50 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
51 | for(i+=2,i2=0;;i2++,i++){
|
---|
52 | if( IsCommandDelimitation( source[i] ) ){
|
---|
53 | temporary[i2]=0;
|
---|
54 | break;
|
---|
55 | }
|
---|
56 | temporary[i2]=source[i];
|
---|
57 | }
|
---|
58 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
59 | {
|
---|
60 | SetError(64,temporary,i );
|
---|
61 | }
|
---|
62 |
|
---|
63 | continue;
|
---|
64 | }
|
---|
65 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED ){
|
---|
66 | importedNamespaces.clear();
|
---|
67 | continue;
|
---|
68 | }
|
---|
69 |
|
---|
70 | else if( source[i] == 1 && source[i+1] == ESC_DELEGATE )
|
---|
71 | {
|
---|
72 | int nowLine = i;
|
---|
73 |
|
---|
74 | i += 2;
|
---|
75 | if( !( source[i] == 1 && ( source[i+1] == ESC_SUB || source[i+1] == ESC_FUNCTION ) ) )
|
---|
76 | {
|
---|
77 | SetError(1,NULL,i);
|
---|
78 | continue;
|
---|
79 | }
|
---|
80 |
|
---|
81 | Procedure::Kind procKind = Procedure::Sub;
|
---|
82 | if( source[i+1] == ESC_FUNCTION )
|
---|
83 | {
|
---|
84 | procKind = Procedure::Function;
|
---|
85 | }
|
---|
86 | i += 2;
|
---|
87 |
|
---|
88 | // 名前
|
---|
89 | char name[VN_SIZE];
|
---|
90 | GetIdentifierToken( name, source.GetBuffer(), i );
|
---|
91 |
|
---|
92 | char paramStr[8192];
|
---|
93 | i += GetStringInPare( paramStr, source.GetBuffer() + i );
|
---|
94 |
|
---|
95 | // 戻り値
|
---|
96 | Type returnType;
|
---|
97 | if( source[i] == 1 && source[i+1] == ESC_AS )
|
---|
98 | {
|
---|
99 | i += 2;
|
---|
100 | char typeName[VN_SIZE];
|
---|
101 | GetCommandToken( typeName, source.GetBuffer(), i );
|
---|
102 | compiler.StringToType( typeName, returnType );
|
---|
103 | }
|
---|
104 |
|
---|
105 | this->Put( new Delegate( namespaceScopes, name, procKind, paramStr, returnType, nowLine ) );
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | void Delegates::GenerateSourceCode( std::string &destSource )
|
---|
111 | {
|
---|
112 | destSource = "";
|
---|
113 |
|
---|
114 | SourceTemplate sourceTemplate( "\\SubOperation\\templates\\delegate_class.tab" );
|
---|
115 |
|
---|
116 | this->Iterator_Reset();
|
---|
117 | while( this->Iterator_HasNext() )
|
---|
118 | {
|
---|
119 | const Delegate &dg = *this->Iterator_GetNext();
|
---|
120 |
|
---|
121 | std::map<std::string,std::string> values;
|
---|
122 | values.insert( std::map<std::string,std::string>::value_type( "name", dg.GetName() ) );
|
---|
123 | values.insert( std::map<std::string,std::string>::value_type( "params", "" ) );
|
---|
124 | destSource += sourceTemplate.GetResult( values );
|
---|
125 | }
|
---|
126 | }
|
---|