1 | #include "common.h"
|
---|
2 |
|
---|
3 |
|
---|
4 | TypeDef::TypeDef( const string &newName, const string &baseName ):
|
---|
5 | newName( newName ),
|
---|
6 | baseName( baseName )
|
---|
7 | {
|
---|
8 | if( !Type::StringToType( baseName, baseType ) ){
|
---|
9 | SetError(3, baseName, cp );
|
---|
10 | return;
|
---|
11 | }
|
---|
12 | }
|
---|
13 | TypeDef::~TypeDef(){
|
---|
14 | }
|
---|
15 |
|
---|
16 |
|
---|
17 | TypeDefCollection::TypeDefCollection(){
|
---|
18 | }
|
---|
19 | TypeDefCollection::~TypeDefCollection(){
|
---|
20 | }
|
---|
21 | void TypeDefCollection::Add( const string &newName, const string &baseName ){
|
---|
22 | TypeDef typeDef( newName, baseName );
|
---|
23 | this->push_back( typeDef );
|
---|
24 |
|
---|
25 |
|
---|
26 | /*
|
---|
27 | TODO: 消す1
|
---|
28 | ////////////////////////
|
---|
29 | // 循環参照をチェック
|
---|
30 | ////////////////////////
|
---|
31 |
|
---|
32 | int i;
|
---|
33 | string tempName = newName;
|
---|
34 |
|
---|
35 | while(1){
|
---|
36 | i=GetIndex( tempName );
|
---|
37 | if(i==-1) break;
|
---|
38 |
|
---|
39 | if( (*this)[i].baseName == newName ){
|
---|
40 | //循環エラー
|
---|
41 | extern int cp;
|
---|
42 | SetError(124,NULL,cp);
|
---|
43 |
|
---|
44 | //不明な型として、Long型を指定しておく
|
---|
45 | (*this)[i].baseName = "Long";
|
---|
46 |
|
---|
47 | break;
|
---|
48 | }
|
---|
49 |
|
---|
50 | tempName = (*this)[i].baseName;
|
---|
51 | }*/
|
---|
52 | }
|
---|
53 | int TypeDefCollection::GetIndex( const string &typeName ) const{
|
---|
54 | int max = (int)(*this).size();
|
---|
55 | for( int i=0; i<max; i++ ){
|
---|
56 | if( (*this)[i].newName == typeName ){
|
---|
57 | return i;
|
---|
58 | }
|
---|
59 | }
|
---|
60 | return -1;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void TypeDefCollection::Add( const string &expression, int nowLine ){
|
---|
64 | int i;
|
---|
65 | char temporary[VN_SIZE];
|
---|
66 |
|
---|
67 | for(i=0;;i++){
|
---|
68 | if(expression[i]=='='||expression[i]=='\0'){
|
---|
69 | temporary[i]=0;
|
---|
70 | break;
|
---|
71 | }
|
---|
72 | temporary[i]=expression[i];
|
---|
73 | }
|
---|
74 |
|
---|
75 | if(expression[i]!='='){
|
---|
76 | SetError(10,"TypeDef",nowLine);
|
---|
77 | return;
|
---|
78 | }
|
---|
79 |
|
---|
80 | const char *pTemp=expression.c_str()+i+1;
|
---|
81 |
|
---|
82 | //識別文字のエラーチェック(新しい型)
|
---|
83 | i=0;
|
---|
84 | for(;;i++){
|
---|
85 | if(temporary[i]=='\0') break;
|
---|
86 | if(!IsVariableChar(temporary[i])){
|
---|
87 | SetError(10,"TypeDef",nowLine);
|
---|
88 | return;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | //識別文字のエラーチェック(コピー元の型)
|
---|
93 | if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
|
---|
94 | //関数ポインタ
|
---|
95 | if(pTemp[3]!='('){
|
---|
96 | SetError(10,"TypeDef",nowLine);
|
---|
97 | return;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | else{
|
---|
101 | i=0;
|
---|
102 | while(pTemp[i]=='*') i++;
|
---|
103 | for(;;i++){
|
---|
104 | if(pTemp[i]=='\0') break;
|
---|
105 | if(!IsVariableChar(pTemp[i])){
|
---|
106 | SetError(10,"TypeDef",nowLine);
|
---|
107 | return;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | //識別子が重複している場合はエラーにする
|
---|
113 | if(lstrcmp(temporary,pTemp)==0){
|
---|
114 | SetError(1,NULL,nowLine);
|
---|
115 | return;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 |
|
---|
120 | //////////////////////////
|
---|
121 | // TypeDef情報を追加
|
---|
122 | //////////////////////////
|
---|
123 |
|
---|
124 | //エラー用
|
---|
125 | extern int cp;
|
---|
126 | cp = nowLine;
|
---|
127 |
|
---|
128 | House::typeDefs.Add(temporary,pTemp);
|
---|
129 | }
|
---|
130 |
|
---|
131 | void TypeDefCollection::Init(){
|
---|
132 | // 初期化
|
---|
133 | clear();
|
---|
134 |
|
---|
135 | int i=-1;
|
---|
136 | while(1){
|
---|
137 | i++;
|
---|
138 |
|
---|
139 | extern char *basbuf;
|
---|
140 | if( basbuf[i]==1 ){
|
---|
141 | char temporary[VN_SIZE];
|
---|
142 | if(basbuf[i+1]==ESC_TYPEDEF){
|
---|
143 | int i2 = 0;
|
---|
144 | for(i+=2;;i2++,i++){
|
---|
145 | if(basbuf[i]=='\n'){
|
---|
146 | temporary[i2]=0;
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | temporary[i2]=basbuf[i];
|
---|
150 | if(basbuf[i]=='\0') break;
|
---|
151 | }
|
---|
152 | Add(temporary,i);
|
---|
153 |
|
---|
154 | continue;
|
---|
155 | }
|
---|
156 | else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
|
---|
157 | int i2 = 0;
|
---|
158 | for(i+=4;;i2++,i++){
|
---|
159 | if(!IsVariableChar(basbuf[i])){
|
---|
160 | temporary[i2]=0;
|
---|
161 | break;
|
---|
162 | }
|
---|
163 | temporary[i2]=basbuf[i];
|
---|
164 | if(basbuf[i]=='\0') break;
|
---|
165 | }
|
---|
166 | House::typeDefs.Add(temporary,"Long");
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | //次の行
|
---|
171 | for(;;i++){
|
---|
172 | if(IsCommandDelimitation(basbuf[i])) break;
|
---|
173 | }
|
---|
174 | if(basbuf[i]=='\0') break;
|
---|
175 | }
|
---|
176 | }
|
---|