source: dev/branches/egtra/ab5.0/abdev/ab_common/src/Lexical/Meta.cpp@ 820

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

Typeクラスを単体テスト可能な状態へ

File size: 6.6 KB
RevLine 
[270]1#include "stdafx.h"
2
[272]3void Meta::Clear()
4{
5 // 名前空間
6 namespaceScopesCollection.clear();
7
8 // 関数・メソッド
9 userProcs.Clear();
10
11 // DLL関数
12 dllProcs.Clear();
13
14 // クラス
15 classesImpl.Clear();
16
17 // グローバル変数
18 globalVars.Clear();
19
20 // グローバル定数
21 globalConsts.Clear();
22
23 // グローバル定数マクロ
24 globalConstMacros.Clear();
25
26 // blittable型
27 blittableTypes.clear();
28
29 // TypeDef
30 typeDefs.clear();
31
32 // 関数ポインタ
33 procPointers.Clear();
34}
35
[636]36void Meta::StaticLink( Meta &meta, long dataSectionBaseOffset, const std::vector<int> &relationTable )
[270]37{
38 // 名前空間
[820]39 foreach (NamespaceScopes const &namespaceScopes, meta.namespaceScopesCollection)
[270]40 {
41 if( !this->namespaceScopesCollection.IsExist( namespaceScopes ) )
42 {
43 this->namespaceScopesCollection.push_back( namespaceScopes );
44 }
45 }
46
47 // 関数・メソッド
[803]48 foreach (auto pUserProc, meta.GetUserProcs())
[270]49 {
[637]50 if( pUserProc->IsExternal() )
51 {
52 // 外部参照の場合は取り込まない
53 continue;
54 }
[273]55
[637]56 pUserProc->ResetRelationalObjectModuleIndex( relationTable );
57
[273]58 pUserProc->GetNativeCode().ResetDataSectionBaseOffset( dataSectionBaseOffset );
59
[270]60 this->userProcs.Put( pUserProc );
61 }
62 meta.GetUserProcs().PullOutAll();
63
64 // DLL関数
[803]65 foreach (auto pDllProc, meta.GetDllProcs())
[270]66 {
[637]67 if( pDllProc->IsExternal() )
68 {
69 // 外部参照の場合は取り込まない
70 continue;
71 }
72
73 pDllProc->ResetRelationalObjectModuleIndex( relationTable );
[270]74 this->dllProcs.Put( pDllProc );
75 }
76 meta.GetDllProcs().PullOutAll();
77
78 // クラス
[803]79 foreach (auto pClass, meta.GetClasses())
[271]80 {
[637]81 if( pClass->IsExternal() )
82 {
83 // 外部参照の場合は取り込まない
84 continue;
85 }
86
87 pClass->ResetRelationalObjectModuleIndex( relationTable );
[636]88 pClass->Readed();
[271]89 this->GetClasses().Put( pClass );
90 }
91 meta.GetClasses().PullOutAll();
[270]92
93 // グローバル変数
[288]94 long initAreaBaseOffset = this->globalVars.initAreaBuffer.GetSize();
[750]95 foreach( Variable *pVar, meta.globalVars )
[271]96 {
[637]97 if( pVar->IsExternal() )
98 {
99 // 外部参照の場合は取り込まない
100 continue;
101 }
102
[283]103 // 基底スコープレベルのグローバル変数の生存値をオンにする
104 if( pVar->GetScopeLevel() == 0 )
105 {
[392]106 pVar->isLiving = true;
[283]107 }
108
[287]109 bool isResetOffsetAddress = true;
110 if( pVar->HasInitData() )
111 {
112 // 初期バッファがあるときはデータテーブルオフセットを適用する
[288]113 pVar->SetOffsetAddress( pVar->GetOffsetAddress() + initAreaBaseOffset );
[287]114
115 isResetOffsetAddress = false;
116 }
117
[637]118 pVar->ResetRelationalObjectModuleIndex( relationTable );
[287]119 this->globalVars.Add( pVar, isResetOffsetAddress );
[271]120 }
121 meta.globalVars.PullOutAll();
[288]122 this->globalVars.initAreaBuffer.Put(
123 meta.globalVars.initAreaBuffer.GetBuffer(),
124 meta.globalVars.initAreaBuffer.GetSize()
125 );
[270]126
127 // グローバル定数
[803]128 foreach (auto pConst, meta.GetGlobalConsts())
[271]129 {
[637]130 if( pConst->IsExternal() )
131 {
132 // 外部参照の場合は取り込まない
133 continue;
134 }
135
136 pConst->ResetRelationalObjectModuleIndex( relationTable );
[271]137 this->GetGlobalConsts().Put( pConst );
138 }
139 meta.GetGlobalConsts().PullOutAll();
[270]140
141 // グローバル定数マクロ
[803]142 foreach (auto pConstMacro, meta.GetGlobalConstMacros())
[271]143 {
[637]144 if( pConstMacro->IsExternal() )
145 {
146 // 外部参照の場合は取り込まない
147 continue;
148 }
149
150 pConstMacro->ResetRelationalObjectModuleIndex( relationTable );
[271]151 this->GetGlobalConstMacros().Put( pConstMacro );
152 }
153 meta.GetGlobalConstMacros().PullOutAll();
[270]154
155 // blittable型
[271]156 BOOST_FOREACH( BlittableType &blittableType, meta.blittableTypes )
157 {
[637]158 // TODO: coreモジュール以外でもBlittable型用のクラスモジュールを定義できるようにすべき
[271]159 this->blittableTypes.push_back( blittableType );
160 }
161 meta.blittableTypes.clear();
[270]162
163 // TypeDef
[271]164 BOOST_FOREACH( TypeDef &typeDef, meta.typeDefs )
165 {
[637]166 if( typeDef.IsExternal() )
167 {
168 // 外部参照の場合は取り込まない
169 continue;
170 }
171
172 typeDef.ResetRelationalObjectModuleIndex( relationTable );
[271]173 this->typeDefs.push_back( typeDef );
174 }
175 meta.typeDefs.clear();
[270]176
177 // 関数ポインタ
[750]178 foreach( ProcPointer *pProcPointer, meta.procPointers )
[271]179 {
[637]180 if( pProcPointer->IsExternal() )
181 {
182 // 外部参照の場合は取り込まない
183 continue;
184 }
185
186 pProcPointer->ResetRelationalObjectModuleIndex( relationTable );
[271]187 this->procPointers.push_back( pProcPointer );
188 }
189 meta.procPointers.PullOutAll();
[448]190
191 // デリゲート
[803]192 foreach (auto pDelegate, meta.GetDelegates())
[448]193 {
[637]194 if( pDelegate->IsExternal() )
195 {
196 // 外部参照の場合は取り込まない
197 continue;
198 }
199
200 pDelegate->ResetRelationalObjectModuleIndex( relationTable );
[448]201 this->GetDelegates().Put( pDelegate );
202 }
203 meta.GetDelegates().PullOutAll();
[270]204}
[562]205
206const ::Delegate &Meta::ToDelegate( const CClass &_class )
207{
[803]208 auto dg = this->GetDelegates().GetHashArrayElement(_class.GetName());
209 foreach (auto t, dg)
[562]210 {
[803]211 if( t->IsEqualSymbol( _class.GetNamespaceScopes(), _class.GetName() ) ){
[562]212 //名前空間とクラス名が一致した
[803]213 return *t;
[562]214 }
215 }
216
[803]217 throw std::runtime_error("Meta::ToDelegate");
[562]218}
[566]219
[598]220const CClass *Meta::FindClassSupportedTypeDef( const Symbol &symbol )
[566]221{
[598]222 const CClass *pClass = this->GetClasses().FindEx( symbol );
[566]223 if( pClass )
224 {
225 return pClass;
226 }
227
228 // TypeDefも見る
[632]229 const TypeDef *pTypeDef = this->GetTypeDefs().Find( symbol );
230 if( pTypeDef )
231 {
232 Type type = pTypeDef->GetBaseType();
233 if( type.IsObject() )
234 {
[566]235 return &type.GetClass();
236 }
237 }
238
239 return NULL;
240}
[637]241
[640]242void Meta::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
[637]243{
244 // 関数・メソッド
[803]245 foreach (auto pUserProc, this->GetUserProcs())
[637]246 {
[640]247 pUserProc->Resolve( resolver, resolveErrors );
[637]248 }
249
250 // DLL関数
[803]251 foreach (auto pDllProc, this->GetDllProcs())
[637]252 {
[640]253 pDllProc->Resolve( resolver, resolveErrors );
[637]254 }
255
256 // クラス
[803]257 foreach (auto pClass, this->GetClasses())
[637]258 {
[640]259 pClass->Resolve( resolver, resolveErrors );
[637]260 }
261
262 // グローバル変数
[750]263 foreach( Variable *pVar, globalVars )
[637]264 {
[640]265 pVar->Resolve( resolver, resolveErrors );
[637]266 }
267
268 // グローバル定数
[803]269 foreach (auto pConst, this->GetGlobalConsts())
[637]270 {
[640]271 pConst->Resolve( resolver, resolveErrors );
[637]272 }
273
274 // グローバル定数マクロ
[803]275 foreach (auto pConstMacro, this->GetGlobalConstMacros())
[637]276 {
[640]277 pConstMacro->Resolve( resolver, resolveErrors );
[637]278 }
279
[640]280 // blittable型
281 BOOST_FOREACH( BlittableType &blittableType, blittableTypes )
282 {
283 blittableType.Resolve( resolver, resolveErrors );
284 }
285
[637]286 // TypeDef
287 BOOST_FOREACH( TypeDef &typeDef, typeDefs )
288 {
[640]289 typeDef.Resolve( resolver, resolveErrors );
[637]290 }
291
292 // 関数ポインタ
[750]293 foreach( ProcPointer *pProcPointer, procPointers )
[637]294 {
[640]295 pProcPointer->Resolve( resolver, resolveErrors );
[637]296 }
297
298 // デリゲート
[803]299 foreach (auto pDelegate, this->GetDelegates())
[637]300 {
[640]301 pDelegate->Resolve( resolver, resolveErrors );
[637]302 }
303}
Note: See TracBrowser for help on using the repository browser.