source: dev/ProjectEditor/EndPairCommandComplement.cpp@ 5

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