source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Procedure.cpp

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 6.4 KB
Line 
1#include "stdafx.h"
2#include <jenga/include/jenga.h>
3#include <abdev/ab_common/include/ab_common.h>
4
5
6void Procedure::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
7{
8 RelationalObjectModuleItem::ResetRelationalObjectModuleIndex( relationTable );
9
10 if( !this->sourceCodePosition.IsNothing() )
11 {
12 this->sourceCodePosition.SetRelationalObjectModuleIndex( relationTable[this->sourceCodePosition.GetRelationalObjectModuleIndex()] );
13 }
14}
15
16bool Procedure::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
17{
18 foreach( Parameter *pParameter, params )
19 {
20 pParameter->Resolve( resolver, resolveErrors );
21 }
22
23 returnType.Resolve( resolver, resolveErrors );
24
25 return true;
26}
27
28
29void UserProc::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
30{
31 Procedure::ResetRelationalObjectModuleIndex( relationTable );
32
33 this->GetNativeCode().ResetRelationalObjectModuleIndex( relationTable );
34}
35
36int id_base = 0;
37
38UserProc::UserProc( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces, Kind kind, bool isMacro, bool isCdecl, bool isExport )
39 : Procedure( symbol, kind, isCdecl )
40 , importedNamespaces( importedNamespaces )
41 , pParentClass( NULL )
42 , pInterface( NULL )
43 , pMethod( NULL )
44 , isMacro( isMacro )
45 , secondParmNum( 0 )
46 , realSecondParmNum( 1 )
47 , isExport( isExport )
48 , isAutoGenerationSystem( false )
49 , isAutoGeneration( false )
50 , isCompiled( false )
51 , beginOpAddress( 0 )
52 , endOpAddress( 0 )
53 , id( id_base ++ )
54{
55}
56
57UserProc::UserProc( const UserProc &userProc, const CClass *pParentClass )
58 : Procedure( userProc )
59 , _paramStr( userProc._paramStr )
60 , importedNamespaces( userProc.importedNamespaces )
61 , pParentClass( pParentClass )
62 , pInterface( NULL )
63 , pMethod( NULL )
64 , isMacro( userProc.isMacro )
65 , secondParmNum( userProc.secondParmNum )
66 , realParams( userProc.realParams )
67 , realSecondParmNum( userProc.realSecondParmNum )
68 , isExport( userProc.isExport )
69 , isAutoGenerationSystem( userProc.isAutoGenerationSystem )
70 , isAutoGeneration( userProc.isAutoGeneration )
71 , isCompiled( false )
72 , beginOpAddress( 0 )
73 , endOpAddress( 0 )
74 , localVars( Variables() )
75 , id( id_base ++ )
76 , nativeCode( NativeCode() )
77{
78}
79
80UserProc::UserProc()
81{
82}
83
84UserProc::~UserProc()
85{
86 foreach( Parameter *pParam, realParams ){
87 delete pParam;
88 }
89}
90
91bool UserProc::IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const
92{
93 if( this->GetName() == pUserProc->GetName() // 名前空間及び名前が等しい
94 && this->Params().Equals( actualTypeParametersForThisProc, pUserProc->Params() ) ) // パラメータが等しい
95 {
96 if( this->returnType.Equals( pUserProc->returnType ) )
97 {
98 // 戻り値が等しい
99 return true;
100 }
101 else if( this->returnType.IsCovariant( pUserProc->returnType ) )
102 {
103 // 戻り値が共変
104 return true;
105 }
106 else if( this->returnType.IsTypeParameter() )
107 {
108 // 型パラメータだったとき
109
110 if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].Equals( pUserProc->returnType ) )
111 {
112 // 戻り値が等しい
113 return true;
114 }
115 else if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].IsCovariant( pUserProc->returnType ) )
116 {
117 // 戻り値が共変
118 return true;
119 }
120 }
121 }
122 return false;
123}
124
125
126std::string UserProc::GetFullName() const
127{
128 if( HasParentClass() ){
129 return GetParentClass().GetName() + "." + GetName();
130 }
131
132 return GetName();
133}
134bool UserProc::IsCastOperator() const
135{
136 if( GetName()[0] == 1 && GetName()[1] == ESC_OPERATOR && GetName()[2] == CALC_AS )
137 {
138 return true;
139 }
140 return false;
141}
142bool UserProc::IsSystem() const
143{
144 // "_System_" を名前の先頭に含む関数
145 if( memcmp( this->GetName().c_str(), "_System_", 8 ) == 0 )
146 {
147 return true;
148 }
149
150 // "_System_" を名前の先頭に含むクラスのメソッド
151 if( this->HasParentClass() )
152 {
153 if( memcmp( this->GetParentClass().GetName().c_str(), "_System_", 8 ) == 0 )
154 {
155 return true;
156 }
157 }
158
159 return false;
160}
161const NamespaceScopes &UserProc::GetNamespaceScopes() const
162{
163 if( HasParentClass() )
164 {
165 return GetParentClassPtr()->GetNamespaceScopes();
166 }
167 return Symbol::GetNamespaceScopes();
168}
169const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const
170{
171 if( pParentClass )
172 {
173 return pParentClass->GetImportedNamespaces();
174 }
175 return importedNamespaces;
176}
177bool UserProc::IsVirtual() const
178{
179 if( pMethod == NULL ){
180 return false;
181 }
182 return ( pMethod->IsVirtual() != 0 );
183}
184const CMethod &UserProc::GetMethod() const
185{
186 if( !HasParentClass() )
187 {
188 Jenga::Throw( "グローバル関数に対してUserProc::GetMethodメソッドが呼ばれた" );
189 }
190 return *pMethod;
191}
192
193bool UserProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
194{
195 Procedure::Resolve( resolver, resolveErrors );
196
197 if( this->pParentClass )
198 {
199 if( this->pParentClass->IsNeedResolve() )
200 {
201 const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pParentClass );
202 if( pTempClass )
203 {
204 this->pParentClass = pTempClass;
205 }
206 else
207 {
208 resolveErrors.Add( ResolveError( this->pParentClass->GetRelationalObjectModuleIndex(), this->pParentClass->GetFullName() ) );
209 }
210 }
211 }
212
213 if( pInterface )
214 {
215 const_cast<Interface *>(pInterface)->Resolve( resolver, resolveErrors );
216 }
217
218 if( pMethod )
219 {
220 pMethod->Resolve( resolver, resolveErrors );
221 }
222
223 foreach( Parameter *pParameter, realParams )
224 {
225 pParameter->Resolve( resolver, resolveErrors );
226 }
227
228 foreach( Variable *pLocalVar, localVars )
229 {
230 pLocalVar->Resolve( resolver, resolveErrors );
231 }
232
233 nativeCode.Resolve( resolver, resolveErrors );
234 return true;
235}
236
237const UserProc *UserProc::pGlobalProc = NULL;
238
239
240void UserProcs::EnumGlobalProcs( const char *simpleName, const Symbol &localSymbol, std::vector<const UserProc *> &subs )
241{
242 ///////////////////////////
243 // グローバル関数を検索
244 ///////////////////////////
245
246 // ハッシュ値を取得
247 foreach (auto pUserProc, GetHashArrayElement( simpleName ))
248 {
249 if( pUserProc->IsGlobalProcedure() ){
250 if( pUserProc->IsEqualSymbol( localSymbol ) ){
251 subs.push_back( pUserProc );
252 }
253 }
254 }
255}
256
257bool DllProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
258{
259 Procedure::Resolve( resolver, resolveErrors );
260 return true;
261}
262
263bool ProcPointer::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
264{
265 Procedure::Resolve( resolver, resolveErrors );
266 return true;
267}
268
269void ProcPointers::Clear()
270{
271 ProcPointers &procPointers = *this;
272 foreach( ProcPointer *pProcPointer, procPointers ){
273 delete pProcPointer;
274 }
275 this->clear();
276}
Note: See TracBrowser for help on using the repository browser.