source: dev/trunk/abdev/BasicCompiler_Common/Object.cpp@ 277

Last change on this file since 277 was 276, checked in by dai_9181, 17 years ago
File size: 2.9 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4
5#include "../BasicCompiler_Common/common.h"
6
7#ifdef _AMD64_
8#include "../BasicCompiler64/opcode.h"
9#else
10#include "../BasicCompiler32/opcode.h"
11#endif
12
13extern HANDLE hHeap;
14
15void CallConstructor( const char *ObjectName,const Subscripts &subscripts,const Type &type,const char *Parameter){
16 if( !type.IsObject() ){
17 return;
18 }
19
20 /////////////////////////////////////
21 // クラスオブジェクトの場合
22 // ※コンストラクタの呼び出し
23 /////////////////////////////////////
24
25 const UserProc *pUserProc = GetMethodHash(ObjectName,type.GetClass().GetName().c_str(),Parameter);
26 if(!pUserProc){
27 if(Parameter[0]) SetError(113,type.GetClass().GetName().c_str(),cp);
28 return;
29 }
30
31
32 char temporary[VN_SIZE];
33
34 if( subscripts.size() > 0 ){
35 int ss[MAX_ARRAYDIM];
36 memset(ss,0,MAX_ARRAYDIM*sizeof(int));
37 while(1){
38 int i3;
39 for(i3=0; i3<(int)subscripts.size(); i3++){
40 if(ss[i3]>subscripts[i3]){
41 ss[i3]=0;
42 ss[i3+1]++;
43 }
44 else break;
45 }
46 if( i3 == subscripts.size() )
47 {
48 break;
49 }
50 sprintf(temporary,"%s[%d",ObjectName,ss[0]);
51 for(i3=1; i3<(int)subscripts.size(); i3++){
52 sprintf(temporary+lstrlen(temporary),",%d",ss[i3]);
53 }
54 lstrcat(temporary,"]");
55
56 Type dummyType;
57 sprintf(temporary+lstrlen(temporary),".%s",type.GetClass().GetName().c_str());
58 CallProc( PROC_DEFAULT,
59 pUserProc,
60 temporary,
61 Parameter,
62 dummyType );
63
64 ss[0]++;
65 }
66 }
67 else{
68 Type dummyType;
69 sprintf(temporary,"%s.%s",ObjectName,type.GetClass().GetName().c_str());
70 CallProc( PROC_DEFAULT,
71 pUserProc,
72 temporary,
73 Parameter,
74 dummyType );
75 }
76}
77
78bool Operator_New( const char *expression, const Type &baseType, Type &resultType ){
79 char CreateParameter[VN_SIZE],objectSizeStr[VN_SIZE];
80 int i,i2;
81
82 i=0;
83
84 if(expression[0]=='['){
85 i=GetStringInBracket(objectSizeStr,expression);
86
87 SlideString(objectSizeStr+1,-1);
88 objectSizeStr[i-2]=0;
89 }
90 else objectSizeStr[0]=0;
91
92 char typeName[VN_SIZE];
93 for(i2=0;;i++,i2++){
94 if(expression[i]=='('){
95 typeName[i2]=0;
96
97 //コンストラクタに渡すパラメータを取得
98 i2=GetStringInPare(CreateParameter,expression+i);
99 RemoveStringPare(CreateParameter);
100 i+=i2;
101 if(expression[i]!='\0'){
102 SetError(42,NULL,cp);
103 return false;
104 }
105 break;
106 }
107 typeName[i2]=expression[i];
108 if(expression[i]=='\0'){
109 CreateParameter[0]=0;
110 break;
111 }
112 }
113
114 if( !compiler.StringToType( typeName, resultType ) ){
115 SetError(3,typeName,cp);
116 return false;
117 }
118
119 if( !resultType.IsObject() ){
120 ////////////////////////
121 // 通常のデータ型の場合
122 ////////////////////////
123
124 SetError(121,NULL,cp);
125 return false;
126 }
127
128 Operator_New( resultType.GetClass(), objectSizeStr, CreateParameter, baseType );
129
130 if( !baseType.IsObject() ){
131 // オブジェクトポインタ向け
132 resultType.SetBasicType( DEF_PTR_OBJECT );
133 }
134
135 return true;
136}
Note: See TracBrowser for help on using the repository browser.