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 | int TypeDefCollection::GetIndex( const string &typeName ) const{
|
---|
26 | int max = (int)(*this).size();
|
---|
27 | for( int i=0; i<max; i++ ){
|
---|
28 | if( (*this)[i].newName == typeName ){
|
---|
29 | return i;
|
---|
30 | }
|
---|
31 | }
|
---|
32 | return -1;
|
---|
33 | }
|
---|
34 |
|
---|
35 | void TypeDefCollection::Add( const string &expression, int nowLine ){
|
---|
36 | int i;
|
---|
37 | char temporary[VN_SIZE];
|
---|
38 |
|
---|
39 | for(i=0;;i++){
|
---|
40 | if(expression[i]=='='||expression[i]=='\0'){
|
---|
41 | temporary[i]=0;
|
---|
42 | break;
|
---|
43 | }
|
---|
44 | temporary[i]=expression[i];
|
---|
45 | }
|
---|
46 |
|
---|
47 | if(expression[i]!='='){
|
---|
48 | SetError(10,"TypeDef",nowLine);
|
---|
49 | return;
|
---|
50 | }
|
---|
51 |
|
---|
52 | const char *pTemp=expression.c_str()+i+1;
|
---|
53 |
|
---|
54 | //識別文字のエラーチェック(新しい型)
|
---|
55 | i=0;
|
---|
56 | for(;;i++){
|
---|
57 | if(temporary[i]=='\0') break;
|
---|
58 | if(!IsVariableChar(temporary[i])){
|
---|
59 | SetError(10,"TypeDef",nowLine);
|
---|
60 | return;
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | //識別文字のエラーチェック(コピー元の型)
|
---|
65 | if(pTemp[0]=='*'&&pTemp[1]==1&&(pTemp[2]==ESC_FUNCTION||pTemp[2]==ESC_SUB)){
|
---|
66 | //関数ポインタ
|
---|
67 | if(pTemp[3]!='('){
|
---|
68 | SetError(10,"TypeDef",nowLine);
|
---|
69 | return;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | else{
|
---|
73 | i=0;
|
---|
74 | while(pTemp[i]=='*') i++;
|
---|
75 | for(;;i++){
|
---|
76 | if(pTemp[i]=='\0') break;
|
---|
77 | if(!IsVariableChar(pTemp[i])){
|
---|
78 | SetError(10,"TypeDef",nowLine);
|
---|
79 | return;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | //識別子が重複している場合はエラーにする
|
---|
85 | if(lstrcmp(temporary,pTemp)==0){
|
---|
86 | SetError(1,NULL,nowLine);
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 |
|
---|
92 | //////////////////////////
|
---|
93 | // TypeDef情報を追加
|
---|
94 | //////////////////////////
|
---|
95 |
|
---|
96 | //エラー用
|
---|
97 | extern int cp;
|
---|
98 | cp = nowLine;
|
---|
99 |
|
---|
100 | Smoothie::Meta::typeDefs.Add(temporary,pTemp);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void TypeDefCollection::Init(){
|
---|
104 | // 初期化
|
---|
105 | clear();
|
---|
106 |
|
---|
107 | int i=-1;
|
---|
108 | while(1){
|
---|
109 | i++;
|
---|
110 |
|
---|
111 | extern char *basbuf;
|
---|
112 | if( basbuf[i]==1 ){
|
---|
113 | char temporary[VN_SIZE];
|
---|
114 | if(basbuf[i+1]==ESC_TYPEDEF){
|
---|
115 | int i2 = 0;
|
---|
116 | for(i+=2;;i2++,i++){
|
---|
117 | if(basbuf[i]=='\n'){
|
---|
118 | temporary[i2]=0;
|
---|
119 | break;
|
---|
120 | }
|
---|
121 | temporary[i2]=basbuf[i];
|
---|
122 | if(basbuf[i]=='\0') break;
|
---|
123 | }
|
---|
124 | Add(temporary,i);
|
---|
125 |
|
---|
126 | continue;
|
---|
127 | }
|
---|
128 | else if( basbuf[i+1] == ESC_CONST && basbuf[i+2] == 1 && basbuf[i+3] == ESC_ENUM ){
|
---|
129 | int i2 = 0;
|
---|
130 | for(i+=4;;i2++,i++){
|
---|
131 | if(!IsVariableChar(basbuf[i])){
|
---|
132 | temporary[i2]=0;
|
---|
133 | break;
|
---|
134 | }
|
---|
135 | temporary[i2]=basbuf[i];
|
---|
136 | if(basbuf[i]=='\0') break;
|
---|
137 | }
|
---|
138 | Smoothie::Meta::typeDefs.Add(temporary,"Long");
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | //次の行
|
---|
143 | for(;;i++){
|
---|
144 | if(IsCommandDelimitation(basbuf[i])) break;
|
---|
145 | }
|
---|
146 | if(basbuf[i]=='\0') break;
|
---|
147 | }
|
---|
148 | }
|
---|