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

Last change on this file since 779 was 750, checked in by イグトランス (egtra), 16 years ago

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

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