source: dev/trunk/abdev/BasicCompiler_Common/src/Parameter.cpp@ 324

Last change on this file since 324 was 322, checked in by dai_9181, 17 years ago

コンパイラ組み込みテンプレートエンジンを実装。
静的リンクライブラリ、デバッグ情報の内部形式をテキストからバイナリに変更した。

File size: 3.2 KB
Line 
1#include "stdafx.h"
2
3
4bool Parameters::Analyze( const char *sourceOfParams, int nowLine )
5{
6 int i2,i3,sw;
7 char temporary[8192],temp2[VN_SIZE];
8
9 //パラメータ
10 int i = 0;
11 if(sourceOfParams[i]!='('){
12 SetError(1,NULL,nowLine);
13 return 0;
14 }
15 i++;
16 while(1){
17 if(sourceOfParams[i]==')') break;
18
19 //ByRef
20 bool isRef;
21 if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYVAL){
22 isRef = false;
23 i+=2;
24 }
25 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_BYREF){
26 isRef = true;
27 i+=2;
28 }
29 else isRef = false;
30
31 //パラメータ名
32 bool isArray = false;
33 Subscripts subscripts;
34 char name[VN_SIZE];
35 sw=0;
36 for(i2=0;;i++,i2++){
37 if(sourceOfParams[i]=='('){
38 if(!sw) sw=1;
39
40 i3=GetStringInPare(name+i2,sourceOfParams+i);
41 i2+=i3-1;
42 i+=i3-1;
43 continue;
44 }
45 if(sourceOfParams[i]=='['){
46 if(!sw) sw=1;
47
48 i3=GetStringInBracket(name+i2,sourceOfParams+i);
49 i2+=i3-1;
50 i+=i3-1;
51 continue;
52 }
53 if(!IsVariableChar(sourceOfParams[i])){
54 name[i2]=0;
55 break;
56 }
57 name[i2]=sourceOfParams[i];
58 }
59 if(sw){
60 //配列パラメータ
61 if( isRef == false )
62 {
63 SetError(29,NULL,nowLine);
64 }
65 isArray = true;
66
67 if((name[i2-2]=='('&&name[i2-1]==')')||
68 (name[i2-2]=='['&&name[i2-1]==']'))
69 {
70 subscripts.push_back( LONG_MAX );
71
72 name[i2-2]=0;
73 }
74 else{
75 GetArrange(name,temp2,subscripts);
76 lstrcpy(name,temp2);
77 }
78
79 i2=lstrlen(name);
80 }
81
82 Type type( DEF_NON );
83 char initValue[8192] = "";
84 if( sourceOfParams[i] == '=' ){
85 i++;
86 i = GetOneParameter( sourceOfParams, i, initValue );
87
88 // TODO: エラー用 fix me!!!
89 //cp = nowLine;
90
91 NumOpe_GetType( initValue, GetStringTypeInfo(), type );
92
93 if( IS_LITERAL(type.GetIndex()) )
94 {
95 type.SetIndex( -1 );
96 }
97 }
98 else if(sourceOfParams[i]==1&&sourceOfParams[i+1]==ESC_AS){
99 // As指定
100 i+=2;
101
102 i2=0;
103 while(sourceOfParams[i]=='*'){
104 temporary[i2]=sourceOfParams[i];
105 i++;
106 i2++;
107 }
108 for(;;i++,i2++){
109 if(!IsVariableChar(sourceOfParams[i])){
110 if(sourceOfParams[i]==1&&(sourceOfParams[i+1]==ESC_FUNCTION||sourceOfParams[i+1]==ESC_SUB)){
111 temporary[i2++]=sourceOfParams[i++];
112 temporary[i2]=sourceOfParams[i];
113 continue;
114 }
115 temporary[i2]=0;
116 break;
117 }
118 temporary[i2]=sourceOfParams[i];
119 }
120
121 compiler.StringToType( temporary, type );
122
123 if( type.IsNull() ){
124 SetError(3,temporary,nowLine);
125 type.SetBasicType( DEF_PTR_VOID );
126 }
127
128 if( type.IsObject() ){
129 if( type.GetClass().IsBlittableType() ){
130 // Blittable型のときは基本型として扱う
131 type = type.GetClass().GetBlittableType();
132 }
133 }
134 }
135 else{
136 type.SetBasicType( Type::GetBasicTypeFromSimpleName(temporary) );
137 SetError(-103,temporary,nowLine);
138 }
139
140 Parameter *pParam = new Parameter( name, type, isRef, initValue );
141 if( isArray ){
142 pParam->SetArray( subscripts );
143 }
144
145 //パラメータを追加
146 this->push_back( pParam );
147
148 if(sourceOfParams[i]==','){
149 i++;
150 continue;
151 }
152 else if(sourceOfParams[i]==')') continue;
153 else{
154 SetError(1,NULL,nowLine);
155 break;
156 }
157 }
158
159 return true;
160}
Note: See TracBrowser for help on using the repository browser.