source: dev/trunk/abdev/ProjectEditor/EndPairCommandComplement.cpp@ 274

Last change on this file since 274 was 118, checked in by dai_9181, 18 years ago

Namespace名前空間のコード補間機能に対応。

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