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

Last change on this file since 640 was 640, checked in by dai_9181, 16 years ago

静的リンクリンカの依存関係解決モジュールを製作中

File size: 6.3 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 BOOST_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 , isSystem( 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 , isSystem( userProc.isSystem )
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 BOOST_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}
140const NamespaceScopes &UserProc::GetNamespaceScopes() const
141{
142 if( HasParentClass() )
143 {
144 return GetParentClassPtr()->GetNamespaceScopes();
145 }
146 return Symbol::GetNamespaceScopes();
147}
148const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const
149{
150 if( pParentClass )
151 {
152 return pParentClass->GetImportedNamespaces();
153 }
154 return importedNamespaces;
155}
156bool UserProc::IsVirtual() const
157{
158 if( pMethod == NULL ){
159 return false;
160 }
161 return ( pMethod->IsVirtual() != 0 );
162}
163const CMethod &UserProc::GetMethod() const
164{
165 if( !HasParentClass() )
166 {
167 Jenga::Throw( "グローバル関数に対してUserProc::GetMethodメソッドが呼ばれた" );
168 }
169 return *pMethod;
170}
171
172bool UserProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
173{
174 Procedure::Resolve( resolver, resolveErrors );
175
176 if( this->pParentClass )
177 {
178 if( this->pParentClass->IsNeedResolve() )
179 {
180 const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pParentClass );
181 if( pTempClass )
182 {
183 this->pParentClass = pTempClass;
184 }
185 else
186 {
187 resolveErrors.Add( ResolveError( this->pParentClass->GetRelationalObjectModuleIndex(), this->pParentClass->GetFullName() ) );
188 }
189 }
190 }
191
192 if( pInterface )
193 {
194 const_cast<Interface *>(pInterface)->Resolve( resolver, resolveErrors );
195 }
196
197 if( pMethod )
198 {
199 pMethod->Resolve( resolver, resolveErrors );
200 }
201
202 BOOST_FOREACH( Parameter *pParameter, realParams )
203 {
204 pParameter->Resolve( resolver, resolveErrors );
205 }
206
207 BOOST_FOREACH( Variable *pLocalVar, localVars )
208 {
209 pLocalVar->Resolve( resolver, resolveErrors );
210 }
211
212 nativeCode.Resolve( resolver, resolveErrors );
213 return true;
214}
215
216const UserProc *UserProc::pGlobalProc = NULL;
217
218
219void UserProcs::EnumGlobalProcs( const char *simpleName, const Symbol &localSymbol, std::vector<const UserProc *> &subs )
220{
221 ///////////////////////////
222 // グローバル関数を検索
223 ///////////////////////////
224
225 // ハッシュ値を取得
226 UserProc *pUserProc = GetHashArrayElement( simpleName );
227 while(pUserProc){
228 if( pUserProc->IsGlobalProcedure() ){
229 if( pUserProc->IsEqualSymbol( localSymbol ) ){
230 subs.push_back( pUserProc );
231 }
232 }
233
234 pUserProc=pUserProc->GetChainNext();
235 }
236}
237
238bool DllProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
239{
240 Procedure::Resolve( resolver, resolveErrors );
241 return true;
242}
243
244bool ProcPointer::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
245{
246 Procedure::Resolve( resolver, resolveErrors );
247 return true;
248}
249
250void ProcPointers::Clear()
251{
252 ProcPointers &procPointers = *this;
253 BOOST_FOREACH( ProcPointer *pProcPointer, procPointers ){
254 delete pProcPointer;
255 }
256 this->clear();
257}
Note: See TracBrowser for help on using the repository browser.