source: dev/trunk/ab5.0/abdev/ProjectEditor/EndPairCommandComplement.cpp@ 451

Last change on this file since 451 was 380, checked in by dai_9181, 17 years ago

Foreachに対応。
ジェネリクスインターフェイスに対応。

File size: 12.2 KB
Line 
1#include "common.h"
2
3///////////////////////////////////////////////////////////////////
4// ここから、ペアステートメント補完を行うための関数郡
5///////////////////////////////////////////////////////////////////
6
7int GetStartCommandId_FromBuffer(char *buffer){
8 int i;
9 char temporary[VN_SIZE];
10
11 for(i=0;;i++){
12 if(!IsVariableChar(buffer[i])){
13 temporary[i]=0;
14 break;
15 }
16 temporary[i]=buffer[i];
17 }
18
19 if(lstrcmpi(temporary,"If")==0){
20 //If文の場合はブロック形式の有無を判定
21
22 int IsStr=0;
23 for(;;i++){
24 if(buffer[i]=='\"') IsStr^=1;
25 if((buffer[i]=='\''||IsCommandDelimitation(buffer,i))&&IsStr==0){
26 i--;
27 break;
28 }
29 }
30
31 while(buffer[i]==' '||buffer[i]=='\t') i--;
32
33 if(memicmp(buffer+i-3,"Then",4)==0){
34 //ブロック形式のIf
35 return COM_IF;
36 }
37 else{
38 //一行のみのIf
39 return 0;
40 }
41 }
42
43 if(lstrcmpi(temporary,"Virtual")==0||
44 lstrcmpi(temporary,"Override")==0||
45 lstrcmpi(temporary,"Static")==0){
46 if(temporary[0]=='s'||temporary[0]=='S')
47 i=7;
48 else if(temporary[0]=='v'||temporary[0]=='V')
49 i=8;
50 else i=9;
51
52 while(buffer[i]==' '||buffer[i]=='\t') i++;
53
54 int i2;
55 for(i2=0;;i++,i2++){
56 if(!IsVariableChar(buffer[i])){
57 temporary[i2]=0;
58 break;
59 }
60 temporary[i2]=buffer[i];
61 }
62
63 if(lstrcmpi(temporary,"Function")==0) return COM_FUNCTION;
64 if(lstrcmpi(temporary,"Sub")==0) return COM_SUB;
65 return 0;
66 }
67
68 if(lstrcmpi(temporary,"Class")==0) return COM_CLASS;
69 if(lstrcmpi(temporary,"Interface")==0) return COM_INTERFACE;
70 if(lstrcmpi(temporary,"Do")==0) return COM_DO;
71 if(lstrcmpi(temporary,"Enum")==0) return COM_ENUM;
72 if(lstrcmpi(temporary,"For")==0) return COM_FOR;
73 if(lstrcmpi(temporary,"Foreach")==0) return COM_FOR;
74 if(lstrcmpi(temporary,"Function")==0) return COM_FUNCTION;
75 if(lstrcmpi(temporary,"Namespace")==0) return COM_NAMESPACE;
76 if(lstrcmpi(temporary,"Select")==0) return COM_SELECT;
77 if(lstrcmpi(temporary,"Sub")==0) return COM_SUB;
78 if(lstrcmpi(temporary,"Try")==0) return COM_TRY;
79 if(lstrcmpi(temporary,"Type")==0) return COM_TYPE;
80 if(lstrcmpi(temporary,"While")==0) return COM_WHILE;
81 if(lstrcmpi(temporary,"With")==0) return COM_WITH;
82
83 return 0;
84}
85int GetEndCommandId_FromBuffer(char *buffer){
86 int i,i2;
87 char temporary[VN_SIZE];
88
89 for(i=0,i2=0;;i++,i2++){
90 if(!IsVariableChar(buffer[i])){
91 temporary[i2]=0;
92
93 if(lstrcmpi(temporary,"End")==0&&
94 (buffer[i]==' '||buffer[i]=='\t')){
95 while(buffer[i]==' '||buffer[i]=='\t') i++;
96 i--;
97 i2--;
98 continue;
99 }
100
101 break;
102 }
103 temporary[i2]=buffer[i];
104 }
105
106 if(lstrcmpi(temporary,"EndClass")==0) return COM_CLASS;
107 if(lstrcmpi(temporary,"EndInterface")==0) return COM_INTERFACE;
108 if(lstrcmpi(temporary,"Loop")==0) return COM_DO;
109 if(lstrcmpi(temporary,"EndEnum")==0) return COM_ENUM;
110 if(lstrcmpi(temporary,"Next")==0) return COM_FOR;
111 if(lstrcmpi(temporary,"EndFunction")==0) return COM_FUNCTION;
112 if(lstrcmpi(temporary,"EndIf")==0) return COM_IF;
113 if(lstrcmpi(temporary,"EndNamespace")==0) return COM_NAMESPACE;
114 if(lstrcmpi(temporary,"EndSelect")==0) return COM_SELECT;
115 if(lstrcmpi(temporary,"EndSub")==0) return COM_SUB;
116 if(lstrcmpi(temporary,"EndTry")==0) return COM_TRY;
117 if(lstrcmpi(temporary,"EndType")==0) return COM_TYPE;
118 if(lstrcmpi(temporary,"Wend")==0) return COM_WHILE;
119 if(lstrcmpi(temporary,"EndWith")==0) return COM_WITH;
120
121 return 0;
122}
123void GetNameOfEndCommand(int CmdId,char *buffer){
124 switch(CmdId){
125 case COM_CLASS:
126 lstrcpy(buffer,"End Class");
127 break;
128 case COM_INTERFACE:
129 lstrcpy(buffer,"End Interface");
130 break;
131 case COM_DO:
132 lstrcpy(buffer,"Loop");
133 break;
134 case COM_ENUM:
135 lstrcpy(buffer,"End Enum");
136 break;
137 case COM_FOR:
138 lstrcpy(buffer,"Next");
139 break;
140 case COM_FUNCTION:
141 lstrcpy(buffer,"End Function");
142 break;
143 case COM_IF:
144 lstrcpy(buffer,"End If");
145 break;
146 case COM_NAMESPACE:
147 lstrcpy(buffer,"End Namespace");
148 break;
149 case COM_SELECT:
150 lstrcpy(buffer,"End Select");
151 break;
152 case COM_SUB:
153 lstrcpy(buffer,"End Sub");
154 break;
155 case COM_TRY:
156 lstrcpy(buffer,"End Try");
157 break;
158 case COM_TYPE:
159 lstrcpy(buffer,"End Type");
160 break;
161 case COM_WHILE:
162 lstrcpy(buffer,"Wend");
163 break;
164 case COM_WITH:
165 lstrcpy(buffer,"End With");
166 break;
167 }
168}
169BOOL IsIntoStringQuotes(char *buffer,int i){
170 int i2;
171
172 i2=i;
173 while(i2&&buffer[i2]!='\n') i2--;
174 if(i2==-1) i2=0;
175 if(buffer[i2]=='\n') i2++;
176
177 int IsStr=0;
178 for(;i2<i;i2++){
179 if(buffer[i2]=='\"') IsStr^=1;
180 }
181 return IsStr;
182}
183BOOL GetEndPairCommandInfo(char *buffer,int p){
184 int i,i2,i3,CmdId;
185 char epcName[32];
186 char indent[255],LineNum;
187
188 int stack[255];
189 int sp;
190
191 CmdId=0;
192 LineNum=0;
193 sp=-1;
194
195 i=p;
196
197 //入力中の行を除く
198 for(i--;i>=0;i--){
199 i2=IsCommandDelimitation(buffer,i);
200 if(i2) break;
201 }
202
203 while(1){
204
205 //i2に一行前の先頭位置を格納
206 for(i--;i>=0;i--){
207 i2=IsCommandDelimitation(buffer,i);
208 if(i2){
209 if(IsIntoStringQuotes(buffer,i)){
210 //文字列中の場合
211 continue;
212 }
213
214 if(i2==1) i2=i+1;
215 else{
216 i2=i+2;
217 LineNum++;
218
219 if(LineNum>pobj_nv->BackNum_PairStatementComplement){
220 //設定された行数を超えた場合
221 return 0;
222 }
223 }
224
225 break;
226 }
227 }
228 if(i==-1) i2=i+1;
229
230 //インデント文字列をindentにコピー
231 for(i3=0;;i2++,i3++){
232 if(buffer[i2]!='\t'){
233 indent[i3]=0;
234 break;
235 }
236 indent[i3]=buffer[i2];
237 }
238
239 //空白文字を飛び越す
240 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
241
242 //終了コマンドを取得(End Class、End Sub、Next、Wendなど…)
243 i3=GetEndCommandId_FromBuffer(buffer+i2);
244 if(i3){
245 sp++;
246 stack[sp]=i3;
247 }
248
249 //開始コマンドを取得(Class、Sub、For、Whileなど…)
250 i3=GetStartCommandId_FromBuffer(buffer+i2);
251 if(i3){
252 if(sp==-1){
253 CmdId=i3;
254 break;
255 }
256
257 if(stack[sp]!=i3) return 0;
258 sp--;
259 }
260
261 if(i<=0) break;
262 }
263
264 if(!CmdId) return 0;
265
266 extern HANDLE hHeap;
267 extern COMPLEMENT_WINDOW_INFO ComplementWndInfo;
268 if(CmdId==COM_IF){
269 //Else、ElseIf、End Ifをリストに追加
270
271 ///////////////////////
272 // 補完情報
273 ///////////////////////
274
275 ComplementWndInfo.pMemberInfo=(MEMBERINFO *)HeapAlloc(hHeap,0,sizeof(MEMBERINFO)*2);
276 ComplementWndInfo.MemberNum=2;
277
278 ComplementWndInfo.pMemberInfo[0].pName=(char *)HeapAlloc(hHeap,0,5);
279 lstrcpy(ComplementWndInfo.pMemberInfo[0].pName,"Else");
280 ComplementWndInfo.pMemberInfo[0].dwProc=0;
281 ComplementWndInfo.pMemberInfo[0].dwAccess=ACCESS_PAIRCOMMAND;
282
283 ComplementWndInfo.pMemberInfo[1].pName=(char *)HeapAlloc(hHeap,0,7);
284 lstrcpy(ComplementWndInfo.pMemberInfo[1].pName,"End If");
285 ComplementWndInfo.pMemberInfo[1].dwProc=0;
286 ComplementWndInfo.pMemberInfo[1].dwAccess=ACCESS_PAIRCOMMAND;
287 }
288 else if(CmdId==COM_CLASS){
289 ComplementWndInfo.pMemberInfo=(MEMBERINFO *)HeapAlloc(hHeap,0,sizeof(MEMBERINFO)*4);
290 ComplementWndInfo.MemberNum=4;
291
292 ComplementWndInfo.pMemberInfo[0].pName=(char *)HeapAlloc(hHeap,0,10);
293 lstrcpy(ComplementWndInfo.pMemberInfo[0].pName,"End Class");
294 ComplementWndInfo.pMemberInfo[0].dwProc=0;
295 ComplementWndInfo.pMemberInfo[0].dwAccess=ACCESS_PAIRCOMMAND;
296
297 ComplementWndInfo.pMemberInfo[1].pName=(char *)HeapAlloc(hHeap,0,8);
298 lstrcpy(ComplementWndInfo.pMemberInfo[1].pName,"Private");
299 ComplementWndInfo.pMemberInfo[1].dwProc=0;
300 ComplementWndInfo.pMemberInfo[1].dwAccess=ACCESS_PAIRCOMMAND;
301
302 ComplementWndInfo.pMemberInfo[2].pName=(char *)HeapAlloc(hHeap,0,10);
303 lstrcpy(ComplementWndInfo.pMemberInfo[2].pName,"Protected");
304 ComplementWndInfo.pMemberInfo[2].dwProc=0;
305 ComplementWndInfo.pMemberInfo[2].dwAccess=ACCESS_PAIRCOMMAND;
306
307 ComplementWndInfo.pMemberInfo[3].pName=(char *)HeapAlloc(hHeap,0,7);
308 lstrcpy(ComplementWndInfo.pMemberInfo[3].pName,"Public");
309 ComplementWndInfo.pMemberInfo[3].dwProc=0;
310 ComplementWndInfo.pMemberInfo[3].dwAccess=ACCESS_PAIRCOMMAND;
311 }
312 else if(CmdId==COM_SELECT){
313 ComplementWndInfo.pMemberInfo=(MEMBERINFO *)HeapAlloc(hHeap,0,sizeof(MEMBERINFO)*4);
314 ComplementWndInfo.MemberNum=2;
315
316 ComplementWndInfo.pMemberInfo[0].pName=(char *)HeapAlloc(hHeap,0,10);
317 lstrcpy(ComplementWndInfo.pMemberInfo[0].pName,"End Select");
318 ComplementWndInfo.pMemberInfo[0].dwProc=0;
319 ComplementWndInfo.pMemberInfo[0].dwAccess=ACCESS_PAIRCOMMAND;
320
321 ComplementWndInfo.pMemberInfo[1].pName=(char *)HeapAlloc(hHeap,0,8);
322 lstrcpy(ComplementWndInfo.pMemberInfo[1].pName,"Case");
323 ComplementWndInfo.pMemberInfo[1].dwProc=0;
324 ComplementWndInfo.pMemberInfo[1].dwAccess=ACCESS_PAIRCOMMAND;
325 }
326 else if(CmdId==COM_TRY){
327 ComplementWndInfo.pMemberInfo=(MEMBERINFO *)HeapAlloc(hHeap,0,sizeof(MEMBERINFO)*4);
328 ComplementWndInfo.MemberNum=3;
329
330 ComplementWndInfo.pMemberInfo[0].pName=(char *)HeapAlloc(hHeap,0,10);
331 lstrcpy(ComplementWndInfo.pMemberInfo[0].pName,"End Try");
332 ComplementWndInfo.pMemberInfo[0].dwProc=0;
333 ComplementWndInfo.pMemberInfo[0].dwAccess=ACCESS_PAIRCOMMAND;
334
335 ComplementWndInfo.pMemberInfo[1].pName=(char *)HeapAlloc(hHeap,0,10);
336 lstrcpy(ComplementWndInfo.pMemberInfo[1].pName,"Catch");
337 ComplementWndInfo.pMemberInfo[1].dwProc=0;
338 ComplementWndInfo.pMemberInfo[1].dwAccess=ACCESS_PAIRCOMMAND;
339
340 ComplementWndInfo.pMemberInfo[2].pName=(char *)HeapAlloc(hHeap,0,8);
341 lstrcpy(ComplementWndInfo.pMemberInfo[2].pName,"Finally");
342 ComplementWndInfo.pMemberInfo[2].dwProc=0;
343 ComplementWndInfo.pMemberInfo[2].dwAccess=ACCESS_PAIRCOMMAND;
344 }
345 else{
346 //その他のコマンド
347
348 //エンドペアステートメントの名前を取得
349 GetNameOfEndCommand(CmdId,epcName);
350
351
352 ///////////////////////
353 // 補完情報
354 ///////////////////////
355
356 ComplementWndInfo.pMemberInfo=(MEMBERINFO *)HeapAlloc(hHeap,0,sizeof(MEMBERINFO));
357 ComplementWndInfo.MemberNum=1;
358
359 ComplementWndInfo.pMemberInfo[0].pName=(char *)HeapAlloc(hHeap,0,lstrlen(epcName)+1);
360 lstrcpy(ComplementWndInfo.pMemberInfo[0].pName,epcName);
361
362 ComplementWndInfo.pMemberInfo[0].dwProc=0;
363 ComplementWndInfo.pMemberInfo[0].dwAccess=ACCESS_PAIRCOMMAND;
364 }
365 lstrcpy(ComplementWndInfo.szIndent,indent);
366
367
368 return 1;
369}
370BOOL IsNeedNewIndentCommand(char *name){
371 if(lstrcmpi(name,"Case")==0) return 1;
372 return 0;
373}
374
375
376
377///////////////////////////////////////////////
378// Withで構成されるオブジェクト識別子を取得
379///////////////////////////////////////////////
380
381void GetWithObjectVariable(char *buffer,int p,char *pObjectVar){
382 int i,i2,i3,i4,CmdId;
383 char LineNum;
384 char temporary[VN_SIZE];
385
386 int stack[255];
387 int sp;
388
389 CmdId=0;
390 LineNum=0;
391 sp=-1;
392 pObjectVar[0]=0;
393
394 i=p;
395
396 //入力中の行を除く
397 for(i--;i>=0;i--){
398 i2=IsCommandDelimitation(buffer,i);
399 if(i2) break;
400 }
401
402 while(1){
403
404 //i2に一行前の先頭位置を格納
405 for(i--;i>=0;i--){
406 i2=IsCommandDelimitation(buffer,i);
407 if(i2){
408 if(i2==1) i2=i+1;
409 else{
410 i2=i+2;
411 LineNum++;
412
413 if(LineNum>pobj_nv->BackNum_PairStatementComplement){
414 //設定された行数を超えた場合
415 return;
416 }
417 }
418
419 break;
420 }
421 }
422 if(i==-1) i2=i+1;
423
424 //インデントを飛び越す
425 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
426
427 //終了コマンドを取得(End Class、End Sub、Next、Wendなど…)
428 CmdId=GetEndCommandId_FromBuffer(buffer+i2);
429 if(CmdId){
430 sp++;
431 stack[sp]=CmdId;
432 }
433
434 //開始コマンドを取得(Class、Sub、For、Whileなど…)
435 CmdId=GetStartCommandId_FromBuffer(buffer+i2);
436 if(CmdId){
437 if(sp==-1){
438 if(CmdId==COM_WITH){
439 //オブジェクト識別子を付加
440 i2+=5;
441 while(buffer[i2]==' '||buffer[i2]=='\t') i2++;
442
443 for(i3=0;;i2++,i3++){
444 if(buffer[i2]=='-'&&buffer[i2+1]=='>'){
445 temporary[i3++]=buffer[i2++];
446 temporary[i3]=buffer[i2];
447 continue;
448 }
449 if(buffer[i2]=='['){
450 i4=GetStringInBracket(temporary+i3,buffer+i2);
451 i2+=i4-1;
452 i3+=i4-1;
453 continue;
454 }
455 if(buffer[i2]=='('){
456 i4=GetStringInPare(temporary+i3,buffer+i2);
457 i2+=i4-1;
458 i3+=i4-1;
459 continue;
460 }
461 if(!(IsVariableChar(buffer[i2])||buffer[i2]=='.')){
462 temporary[i3]=0;
463 break;
464 }
465 temporary[i3]=buffer[i2];
466 }
467 lstrcat(temporary,pObjectVar);
468 lstrcpy(pObjectVar,temporary);
469 }
470 }
471 else{
472 if(stack[sp]!=CmdId){
473 pObjectVar[0]=0;
474 break;
475 }
476 sp--;
477 }
478 }
479
480 if(i<=0) break;
481 }
482}
Note: See TracBrowser for help on using the repository browser.