source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/NativeCode.cpp@ 655

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

複数のlibの依存関係解決後、使用しているDLL関数を正確にインポートできるようにした。

File size: 5.2 KB
Line 
1#include "stdafx.h"
2
3#define BREAK_EIP(checkEip) (obp+0x00401000>=checkEip)
4
5const ::DllProc &Schedule::GetDllProc() const
6{
7 _ASSERT( type == Schedule::DllProc );
8 return *pDllProc;
9}
10const ::UserProc &Schedule::GetUserProc() const
11{
12 _ASSERT( type == Schedule::UserProc || type == Schedule::AddressOf || type == Schedule::CatchAddress );
13 return *pUserProc;
14}
15const ::CClass &Schedule::GetClass() const
16{
17 _ASSERT( type == Schedule::ComVtbl || type == Schedule::Vtbl || type == Schedule::TypeInfo );
18 return *pClass;
19}
20
21bool Schedule::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
22{
23 switch( type )
24 {
25 case UserProc:
26 case AddressOf:
27 case CatchAddress:
28 if( this->pUserProc->IsNeedResolve() )
29 {
30 const ::UserProc *pTempUserProc = resolver.meta.GetUserProcs().FindLike( this->pUserProc );
31 if( pTempUserProc )
32 {
33 this->pUserProc = pTempUserProc;
34 }
35 else
36 {
37 resolveErrors.Add( ResolveError( this->pUserProc->GetRelationalObjectModuleIndex(), this->pUserProc->GetFullName() ) );
38 }
39 }
40 break;
41 case DllProc:
42 if( this->pDllProc->IsNeedResolve() )
43 {
44 const ::DllProc *pTempDllProc = resolver.meta.GetDllProcs().FindLike( this->pDllProc );
45 if( pTempDllProc )
46 {
47 this->pDllProc = pTempDllProc;
48 }
49 else
50 {
51 resolveErrors.Add( ResolveError( this->pDllProc->GetRelationalObjectModuleIndex(), this->pDllProc->GetFullName() ) );
52 }
53 }
54 break;
55 case ComVtbl:
56 case Vtbl:
57 case TypeInfo:
58 if( this->pClass->IsNeedResolve() )
59 {
60 const CClass *pTempClass = resolver.meta.GetClasses().FindLike( this->pClass );
61 if( pTempClass )
62 {
63 this->pClass = pTempClass;
64 }
65 else
66 {
67 resolveErrors.Add( ResolveError( this->pClass->GetRelationalObjectModuleIndex(), this->pClass->GetFullName() ) );
68 }
69 }
70 break;
71 default:
72 break;
73 }
74
75 return true;
76}
77
78void NativeCode::PutEx( const NativeCode &nativeCode )
79{
80 long baseOffset = GetSize();
81
82 // コードバッファを追加
83 Put( nativeCode.GetBuffer(), nativeCode.GetSize() );
84
85 // スケジュールを追加
86 BOOST_FOREACH( const Schedule &schedule, nativeCode.schedules )
87 {
88 this->schedules.push_back(
89 Schedule(
90 schedule.GetType(),
91 baseOffset + schedule.GetOffset(),
92 schedule.GetLongPtrValue()
93 )
94 );
95 }
96
97 // ソースコード行番号とネイティブコード位置の対応情報を追加
98 BOOST_FOREACH( const SourceLine &sourceLine, nativeCode.sourceLines )
99 {
100 this->sourceLines.push_back(
101 SourceLine(
102 baseOffset + sourceLine.GetNativeCodePos(),
103 sourceLine.GetCodeType(),
104 sourceLine.GetSourceCodePosition()
105 )
106 );
107 }
108}
109
110void NativeCode::PutEx( long l, Schedule::Type scheduleType )
111{
112 if( scheduleType != Schedule::None )
113 {
114 schedules.push_back( Schedule( scheduleType, GetSize() ) );
115 }
116
117 Put( l );
118}
119
120void NativeCode::PutUserProcSchedule( const UserProc *pUserProc, bool isCall )
121{
122 pUserProc->Using();
123
124 Schedule::Type type = isCall ? Schedule::UserProc : Schedule::AddressOf;
125
126 schedules.push_back( Schedule( type, pUserProc, GetSize() ) );
127
128 Put( (long)0 );
129}
130
131void NativeCode::PutCatchAddressSchedule( const UserProc *pUserProc, long codePos )
132{
133 pUserProc->Using();
134
135 schedules.push_back( Schedule( Schedule::CatchAddress, pUserProc, GetSize() ) );
136
137 Put( codePos );
138}
139
140void NativeCode::PutDllProcSchedule( const DllProc *pDllProc )
141{
142 schedules.push_back( Schedule( pDllProc, GetSize() ) );
143
144 Put( (long)0 );
145}
146
147void NativeCode::PutComVtblSchedule( const CClass *pClass )
148{
149 schedules.push_back( Schedule( Schedule::ComVtbl, pClass, GetSize() ) );
150
151 Put( (long)0 );
152}
153
154void NativeCode::PutVtblSchedule( const CClass *pClass )
155{
156 schedules.push_back( Schedule( Schedule::Vtbl, pClass, GetSize() ) );
157
158 Put( (long)0 );
159}
160
161void NativeCode::NextSourceLine( const SourceCodePosition &sourceCodePosition, bool isInSystemProc )
162{
163 if( sourceLines.size() )
164 {
165 if( sourceLines.back().GetNativeCodePos() == GetSize() )
166 {
167 sourceLines.back().SetSourceCodePosition( sourceCodePosition );
168 return;
169 }
170 }
171
172 extern BOOL bDebugSupportProc;
173 DWORD sourceLineType = 0;
174 if( bDebugSupportProc )
175 {
176 sourceLineType |= CODETYPE_DEBUGPROC;
177 }
178 if( isInSystemProc )
179 {
180 sourceLineType |= CODETYPE_SYSTEMPROC;
181 }
182 sourceLines.push_back(
183 SourceLine(
184 GetSize(),
185 sourceLineType,
186 sourceCodePosition
187 )
188 );
189}
190
191void NativeCode::ResetDataSectionBaseOffset( long dataSectionBaseOffset )
192{
193 BOOST_FOREACH( const Schedule &schedule, schedules )
194 {
195 if( schedule.GetType() == Schedule::DataTable )
196 {
197 Overwrite(
198 schedule.GetOffset(),
199 GetLong( schedule.GetOffset() ) + dataSectionBaseOffset
200 );
201 }
202 }
203}
204void NativeCode::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
205{
206 BOOST_FOREACH( SourceLine &sourceLine, sourceLines )
207 {
208 sourceLine.GetSourceCodePosition().SetRelationalObjectModuleIndex(
209 relationTable[sourceLine.GetSourceCodePosition().GetRelationalObjectModuleIndex()]
210 );
211 }
212}
213
214void NativeCode::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
215{
216 BOOST_FOREACH( Schedule &schedule, schedules )
217 {
218 schedule.Resolve( resolver, resolveErrors );
219 }
220}
Note: See TracBrowser for help on using the repository browser.