1 | #include "stdafx.h"
|
---|
2 | #include <abdev/ab_common/include/ab_common.h>
|
---|
3 | #include "LexicalAnalyzer.h"
|
---|
4 | #include "Compiler.h"
|
---|
5 | #include "StrOperation.h"
|
---|
6 |
|
---|
7 | using namespace ActiveBasic::Compiler;
|
---|
8 |
|
---|
9 | void LexicalAnalyzer::AddTypeDef( TypeDefCollection &typeDefs, const NamespaceScopes &namespaceScopes, const std::string &expression, int nowLine )
|
---|
10 | {
|
---|
11 | int i;
|
---|
12 | char temporary[VN_SIZE];
|
---|
13 |
|
---|
14 | for(i=0;;i++){
|
---|
15 | if(expression[i]=='='||expression[i]=='\0'){
|
---|
16 | temporary[i]=0;
|
---|
17 | break;
|
---|
18 | }
|
---|
19 | temporary[i]=expression[i];
|
---|
20 | }
|
---|
21 |
|
---|
22 | if(expression[i]!='='){
|
---|
23 | compiler.errorMessenger.Output(10,"TypeDef",nowLine);
|
---|
24 | return;
|
---|
25 | }
|
---|
26 |
|
---|
27 | const char *pTemp=expression.c_str()+i+1;
|
---|
28 |
|
---|
29 | //識別文字のエラーチェック(新しい型)
|
---|
30 | i=0;
|
---|
31 | for(;;i++){
|
---|
32 | if(temporary[i]=='\0') break;
|
---|
33 | if( !( IsVariableChar( temporary[i], true) ) ){
|
---|
34 | compiler.errorMessenger.Output(10,"TypeDef",nowLine);
|
---|
35 | return;
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | //識別文字のエラーチェック(コピー元の型)
|
---|
40 | if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
|
---|
41 | //関数ポインタ
|
---|
42 | if(pTemp[3]!='('){
|
---|
43 | compiler.errorMessenger.Output(10,"TypeDef",nowLine);
|
---|
44 | return;
|
---|
45 | }
|
---|
46 | }
|
---|
47 | else{
|
---|
48 | i=0;
|
---|
49 | while(pTemp[i]=='*') i++;
|
---|
50 | for(;;i++){
|
---|
51 | if(pTemp[i]=='\0') break;
|
---|
52 | if( !( IsVariableChar( pTemp[i], true) ) )
|
---|
53 | {
|
---|
54 | compiler.errorMessenger.Output(10,"TypeDef",nowLine);
|
---|
55 | return;
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | //識別子が重複している場合はエラーにする
|
---|
61 | if(lstrcmp(temporary,pTemp)==0){
|
---|
62 | compiler.errorMessenger.Output(1,NULL,nowLine);
|
---|
63 | return;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | //////////////////////////
|
---|
69 | // TypeDef情報を追加
|
---|
70 | //////////////////////////
|
---|
71 |
|
---|
72 | Type baseType;
|
---|
73 | if( !compiler.StringToType( pTemp, baseType ) )
|
---|
74 | {
|
---|
75 | compiler.errorMessenger.Output(3, pTemp, nowLine );
|
---|
76 | return;
|
---|
77 | }
|
---|
78 |
|
---|
79 | typeDefs.push_back(
|
---|
80 | TypeDef(
|
---|
81 | Symbol( namespaceScopes, temporary ),
|
---|
82 | pTemp,
|
---|
83 | baseType
|
---|
84 | )
|
---|
85 | );
|
---|
86 | }
|
---|
87 | void LexicalAnalyzer::CollectTypeDefs( const char *source, TypeDefCollection &typeDefs )
|
---|
88 | {
|
---|
89 | // 名前空間管理
|
---|
90 | NamespaceScopes &namespaceScopes = compiler.GetNamespaceSupporter().GetLivingNamespaceScopes();
|
---|
91 | namespaceScopes.clear();
|
---|
92 |
|
---|
93 | // Imports情報のクリア
|
---|
94 | compiler.GetNamespaceSupporter().ClearImportedNamespaces();
|
---|
95 |
|
---|
96 | int i=-1, i2;
|
---|
97 | char temporary[VN_SIZE];
|
---|
98 | while(1){
|
---|
99 |
|
---|
100 | i++;
|
---|
101 |
|
---|
102 | if( source[i] == 1 && source[i+1] == ESC_NAMESPACE ){
|
---|
103 | for(i+=2,i2=0;;i2++,i++){
|
---|
104 | if( IsCommandDelimitation( source[i] ) ){
|
---|
105 | temporary[i2]=0;
|
---|
106 | break;
|
---|
107 | }
|
---|
108 | temporary[i2]=source[i];
|
---|
109 | }
|
---|
110 | namespaceScopes.push_back( temporary );
|
---|
111 |
|
---|
112 | continue;
|
---|
113 | }
|
---|
114 | else if( source[i] == 1 && source[i+1] == ESC_ENDNAMESPACE ){
|
---|
115 | if( namespaceScopes.size() <= 0 ){
|
---|
116 | compiler.errorMessenger.Output(12, "End Namespace", i );
|
---|
117 | }
|
---|
118 | else{
|
---|
119 | namespaceScopes.pop_back();
|
---|
120 | }
|
---|
121 |
|
---|
122 | i += 2;
|
---|
123 | continue;
|
---|
124 | }
|
---|
125 | else if( source[i] == 1 && source[i+1] == ESC_IMPORTS ){
|
---|
126 | for(i+=2,i2=0;;i2++,i++){
|
---|
127 | if( IsCommandDelimitation( source[i] ) ){
|
---|
128 | temporary[i2]=0;
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | temporary[i2]=source[i];
|
---|
132 | }
|
---|
133 | if( !compiler.GetNamespaceSupporter().ImportsNamespace( temporary ) )
|
---|
134 | {
|
---|
135 | compiler.errorMessenger.Output(64,temporary,i );
|
---|
136 | }
|
---|
137 |
|
---|
138 | continue;
|
---|
139 | }
|
---|
140 | else if( source[i] == 1 && source[i+1] == ESC_CLEARNAMESPACEIMPORTED )
|
---|
141 | {
|
---|
142 | // Imports情報のクリア
|
---|
143 | compiler.GetNamespaceSupporter().ClearImportedNamespaces();
|
---|
144 | continue;
|
---|
145 | }
|
---|
146 |
|
---|
147 | if( source[i]==1 ){
|
---|
148 | char temporary[VN_SIZE];
|
---|
149 | if(source[i+1]==ESC_TYPEDEF){
|
---|
150 | int i2 = 0;
|
---|
151 | for(i+=2;;i2++,i++){
|
---|
152 | if(source[i]=='\n'){
|
---|
153 | temporary[i2]=0;
|
---|
154 | break;
|
---|
155 | }
|
---|
156 | temporary[i2]=source[i];
|
---|
157 | if(source[i]=='\0') break;
|
---|
158 | }
|
---|
159 | AddTypeDef( typeDefs, namespaceScopes, temporary, i );
|
---|
160 |
|
---|
161 | continue;
|
---|
162 | }
|
---|
163 | else if( source[i+1] == ESC_CONST && source[i+2] == 1 && source[i+3] == ESC_ENUM ){
|
---|
164 | int i2 = 0;
|
---|
165 | for(i+=4;;i2++,i++){
|
---|
166 | if(!IsVariableChar(source[i])){
|
---|
167 | temporary[i2]=0;
|
---|
168 | break;
|
---|
169 | }
|
---|
170 | temporary[i2]=source[i];
|
---|
171 | if(source[i]=='\0') break;
|
---|
172 | }
|
---|
173 |
|
---|
174 | Type baseType;
|
---|
175 | if( !compiler.StringToType( "Long", baseType ) )
|
---|
176 | {
|
---|
177 | throw;
|
---|
178 | }
|
---|
179 |
|
---|
180 | typeDefs.push_back(
|
---|
181 | TypeDef(
|
---|
182 | Symbol( namespaceScopes, temporary ),
|
---|
183 | "Long",
|
---|
184 | baseType
|
---|
185 | )
|
---|
186 | );
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | //次の行
|
---|
191 | for(;;i++){
|
---|
192 | if(IsCommandDelimitation(source[i])) break;
|
---|
193 | }
|
---|
194 | if(source[i]=='\0') break;
|
---|
195 | }
|
---|
196 | }
|
---|