source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/OldStatement.cpp@ 765

Last change on this file since 765 was 485, checked in by dai_9181, 17 years ago

プロジェクトのリネームが完了

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