source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/LexicalAnalyzer_TypeDef.cpp@ 648

Last change on this file since 648 was 637, checked in by dai_9181, 16 years ago

リンカの依存関係解決モジュールを製作中

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