source: dev/trunk/abdev/BasicCompiler_Common/OldStatement.cpp@ 191

Last change on this file since 191 was 97, checked in by dai_9181, 18 years ago

関数の戻り値オブジェクトのメンバ・メソッドを一時オブジェクトを介さずに参照できるようにした。

File size: 7.1 KB
Line 
1#include "common.h"
2
3#ifdef _AMD64_
4#include "../BasicCompiler64/opcode.h"
5#else
6#include "../BasicCompiler32/opcode.h"
7#endif
8
9void Opcode_Input(const char *Parameter){
10 extern int cp;
11 int i2,i3,i4,i5;
12 BOOL bFile;
13 char temporary[VN_SIZE],temp2[VN_SIZE],buffer[VN_SIZE];
14
15 if(Parameter[0]=='#'){
16 bFile=1;
17 for(i2=0,i3=1;;i2++,i3++){
18 buffer[i2]=Parameter[i3];
19 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
20 }
21 buffer[i2+1]=0;
22 i2=i3+1;
23 }
24 else{
25 bFile=0;
26 i2=0;
27 buffer[0]=0;
28
29 //表示用文字列パラメータをセット
30 if(Parameter[0]=='\"'){
31 buffer[0]='\"';
32 for(i2=1;;i2++){
33 if(Parameter[i2]=='\"'){
34 buffer[i2]=0;
35 break;
36 }
37 buffer[i2]=Parameter[i2];
38 }
39 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
40 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
41 else SetError(10,"Input",cp);
42 i2+=2;
43 }
44 else if((Parameter[0]=='e'||Parameter[0]=='E')&&
45 (Parameter[1]=='x'||Parameter[1]=='X')&&
46 Parameter[2]=='\"'){
47 memcpy(buffer,Parameter,3);
48 for(i2=3;;i2++){
49 if(Parameter[i2]=='\"'){
50 buffer[i2]=0;
51 break;
52 }
53 buffer[i2]=Parameter[i2];
54 }
55 if(Parameter[i2+1]==';') lstrcpy(buffer+i2,"? \"");
56 else if(Parameter[i2+1]==',') lstrcpy(buffer+i2,"\"");
57 else SetError(10,"Input",cp);
58 i2+=2;
59 }
60 else{
61 lstrcpy(buffer,"\"? \"");
62 i2=0;
63 }
64 }
65
66 //変数ポインタ、変数のタイプをセット
67 i4=0;
68 while(1){
69 for(i3=0;;i2++,i3++){
70 if(Parameter[i2]=='('){
71 i5=GetStringInPare(temporary+i3,Parameter+i2);
72 i2+=i5-1;
73 i3+=i5-1;
74 }
75 if(Parameter[i2]=='['){
76 i5=GetStringInBracket(temporary+i3,Parameter+i2);
77 i2+=i5-1;
78 i3+=i5-1;
79 }
80 if(Parameter[i2]==','){
81 temporary[i3]=0;
82 i2++;
83 break;
84 }
85 temporary[i3]=Parameter[i2];
86 if(Parameter[i2]=='\0') break;
87 }
88 if(temporary[0]=='\0'){
89 SetError(10,"Input",cp);
90 return;
91 }
92
93 Type varType;
94 if( !GetVarType(temporary, varType, 1) ){
95 return;
96 }
97
98 sprintf(temp2,"_System_InputDataPtr[%d]=VarPtr(%s)",i4,temporary);
99 OpcodeCalc(temp2);
100
101 if(varType.IsLong()) varType.SetBasicType( DEF_DWORD );
102 else if(varType.IsInteger()) varType.SetBasicType( DEF_WORD );
103 else if(varType.IsObject()){
104 varType.SetBasicType( DEF_OBJECT );
105 if( varType.IsStringClass() ){
106 varType.SetBasicType( DEF_STRING );
107 }
108 }
109 sprintf(temp2,"_System_InputDataType[%d]=%d",i4,varType.GetBasicType());
110 OpcodeCalc(temp2);
111
112 i4++;
113 if(Parameter[i2]=='\0') break;
114 }
115 sprintf(temp2,"_System_InputDataPtr[%d]=0",i4);
116 OpcodeCalc(temp2);
117
118 UserProc *pUserProc;
119 if(bFile) pUserProc=GetSubHash("INPUT_FromFile");
120 else pUserProc=GetSubHash("INPUT_FromPrompt");
121 if(!pUserProc){
122 SetError(3,"Input",cp);
123 return;
124 }
125 Opcode_CallProc(buffer,pUserProc,0,"",0);
126}
127void Opcode_PrintUsing(const char *Parameter,char *buffer,BOOL bFile){
128 extern int cp;
129 int i2,i3,i4,i5;
130 char temporary[VN_SIZE],temp2[8192];
131 BOOL bReturnLine;
132
133 char parms[8192];
134 lstrcpy( parms, Parameter );
135
136 i2=lstrlen(parms);
137 if(parms[i2-1]==';'){
138 bReturnLine=0;
139 parms[i2-1]=0;
140 }
141 else bReturnLine=1;
142
143 i3=lstrlen(buffer);
144 for(i2=0;;i2++,i3++){
145 if(parms[i2]==';'){
146 buffer[i3]=0;
147 break;
148 }
149 buffer[i3]=parms[i2];
150 if(parms[i2]=='\0') break;
151 }
152 if(parms[i2]==';') i2++;
153
154 if(bReturnLine) lstrcat(buffer,"+Ex\"\\r\\n\"");
155
156 //データポインタ、データのタイプをセット
157 i4=0;
158 while(1){
159 for(i3=0;;i2++,i3++){
160 if(parms[i2]=='\"'){
161 temporary[i3]=parms[i2];
162 for(i2++,i3++;;i2++,i3++){
163 temporary[i3]=parms[i2];
164 if(parms[i2]=='\"') break;
165 }
166 continue;
167 }
168 if(parms[i2]=='('){
169 i5=GetStringInPare(temporary+i3,parms+i2);
170 i2+=i5-1;
171 i3+=i5-1;
172 continue;
173 }
174 if(parms[i2]=='['){
175 i5=GetStringInBracket(temporary+i3,parms+i2);
176 i2+=i5-1;
177 i3+=i5-1;
178 continue;
179 }
180 if(parms[i2]==','){
181 temporary[i3]=0;
182 i2++;
183 break;
184 }
185 temporary[i3]=parms[i2];
186 if(parms[i2]=='\0') break;
187 }
188 if(temporary[0]=='\0'){
189 SetError(10,"Print",cp);
190 return;
191 }
192
193 int iResult;
194 iResult=IsStrCalculation(temporary);
195
196 if(iResult==1){
197 //文字列
198 sprintf(temp2,"_System_UsingStrData[%d]=%s",i4,temporary);
199 OpcodeCalc(temp2);
200
201 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_STRING);
202 OpcodeCalc(temp2);
203 }
204 else if(iResult==0){
205 //数値
206 sprintf(temp2,"_System_UsingDblData[%d]=%s",i4,temporary);
207 OpcodeCalc(temp2);
208
209 sprintf(temp2,"_System_UsingDataType[%d]=%d",i4,DEF_DOUBLE);
210 OpcodeCalc(temp2);
211 }
212 //else if(iResult==-1) エラー
213
214 i4++;
215 if(parms[i2]=='\0') break;
216 }
217 sprintf(temp2,"_System_UsingDataType[%d]=-1",i4);
218 OpcodeCalc(temp2);
219
220 UserProc *pUserProc;
221 if(bFile) pUserProc=GetSubHash("PRINTUSING_ToFile");
222 else pUserProc=GetSubHash("PRINTUSING_ToPrompt");
223 if(!pUserProc){
224 SetError(3,"Print",cp);
225 return;
226 }
227 Opcode_CallProc(buffer,pUserProc,0,"",0);
228}
229void Opcode_Print(const char *Parameter,BOOL bWrite){
230 int i2,i3,i4,sw;
231 char temporary[VN_SIZE],buffer[VN_SIZE];
232 BOOL bFile;
233
234 if(Parameter[0]=='#'){
235 bFile=1;
236 for(i2=0,i3=1;;i2++,i3++){
237 buffer[i2]=Parameter[i3];
238 if(Parameter[i3]==','||Parameter[i3]=='\0') break;
239 }
240 buffer[i2+1]=0;
241 if(Parameter[i3]==',') i3++;
242 i2=i3;
243 }
244 else{
245 bFile=0;
246 i2=0;
247 buffer[0]=0;
248 }
249 if(Parameter[i2]==1&&Parameter[i2+1]==ESC_USING){
250 Opcode_PrintUsing(Parameter+i2+2,buffer,bFile);
251 return;
252 }
253
254 lstrcat(buffer,"_System_DummyStr+");
255
256 sw=1;
257 while(1){
258 for(i3=0;;i2++,i3++){
259 if(Parameter[i2]=='\"'){
260 temporary[i3]=Parameter[i2];
261 for(i2++,i3++;;i2++,i3++){
262 temporary[i3]=Parameter[i2];
263 if(Parameter[i2]=='\"') break;
264 }
265 continue;
266 }
267 if(Parameter[i2]=='('){
268 i4=GetStringInPare(temporary+i3,Parameter+i2);
269 i2+=i4-1;
270 i3+=i4-1;
271 continue;
272 }
273 if(Parameter[i2]=='['){
274 i4=GetStringInBracket(temporary+i3,Parameter+i2);
275 i2+=i4-1;
276 i3+=i4-1;
277 continue;
278 }
279 if(Parameter[i2]==','||Parameter[i2]==';'){
280 temporary[i3]=0;
281 break;
282 }
283 temporary[i3]=Parameter[i2];
284 if(Parameter[i2]=='\0') break;
285 }
286
287 if(temporary[0]=='\0') lstrcat(buffer,"\"\"");
288 else{
289 int iResult;
290 iResult=IsStrCalculation(temporary);
291 if(iResult==-1){
292 //エラー
293 lstrcat(buffer,"\"\"");
294 }
295 else if(iResult){
296 //文字列
297 lstrcat(buffer,temporary);
298 }
299 else{
300 //数値
301 sprintf(buffer+lstrlen(buffer),"Str$(%s)",temporary);
302 }
303 }
304
305 if(Parameter[i2]==','){
306 if(bWrite) lstrcat(buffer,"+\",\"+");
307 else lstrcat(buffer,"+\"\t\"+");
308 }
309 else if(Parameter[i2]==';'){
310 if(Parameter[i2+1]=='\0'){
311 sw=0;
312 break;
313 }
314 if(bWrite) lstrcat(buffer,"+\",\"+");
315 else lstrcat(buffer,"+\" \"+");
316 }
317 else if(Parameter[i2]=='\0') break;
318
319 i2++;
320 }
321
322 if(sw) lstrcat(buffer,"+Ex\"\\r\\n\"");
323
324 UserProc *pUserProc;
325 if(bFile) pUserProc=GetSubHash("PRINT_ToFile");
326 else pUserProc=GetSubHash("PRINT_ToPrompt");
327 if(!pUserProc){
328 SetError(3,"Print",cp);
329 return;
330 }
331 Opcode_CallProc(buffer,pUserProc,0,"",0);
332}
Note: See TracBrowser for help on using the repository browser.