[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[637] | 3 |
|
---|
| 4 | void 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 |
|
---|
[640] | 14 | bool Procedure::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[639] | 15 | {
|
---|
[750] | 16 | foreach( Parameter *pParameter, params )
|
---|
[639] | 17 | {
|
---|
[640] | 18 | pParameter->Resolve( resolver, resolveErrors );
|
---|
[639] | 19 | }
|
---|
| 20 |
|
---|
[640] | 21 | returnType.Resolve( resolver, resolveErrors );
|
---|
[639] | 22 |
|
---|
| 23 | return true;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
[637] | 27 | void UserProc::ResetRelationalObjectModuleIndex( const std::vector<int> &relationTable )
|
---|
| 28 | {
|
---|
| 29 | Procedure::ResetRelationalObjectModuleIndex( relationTable );
|
---|
| 30 |
|
---|
| 31 | this->GetNativeCode().ResetRelationalObjectModuleIndex( relationTable );
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[632] | 34 | int id_base = 0;
|
---|
| 35 |
|
---|
[637] | 36 | UserProc::UserProc( const Symbol &symbol, const NamespaceScopesCollection &importedNamespaces, Kind kind, bool isMacro, bool isCdecl, bool isExport )
|
---|
| 37 | : Procedure( symbol, kind, isCdecl )
|
---|
[632] | 38 | , importedNamespaces( importedNamespaces )
|
---|
| 39 | , pParentClass( NULL )
|
---|
| 40 | , pInterface( NULL )
|
---|
| 41 | , pMethod( NULL )
|
---|
| 42 | , isMacro( isMacro )
|
---|
| 43 | , secondParmNum( 0 )
|
---|
| 44 | , realSecondParmNum( 1 )
|
---|
| 45 | , isExport( isExport )
|
---|
[641] | 46 | , isAutoGenerationSystem( false )
|
---|
[632] | 47 | , isAutoGeneration( false )
|
---|
| 48 | , isCompiled( false )
|
---|
| 49 | , beginOpAddress( 0 )
|
---|
| 50 | , endOpAddress( 0 )
|
---|
| 51 | , id( id_base ++ )
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | UserProc::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 )
|
---|
[641] | 67 | , isAutoGenerationSystem( userProc.isAutoGenerationSystem )
|
---|
[632] | 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 |
|
---|
| 78 | UserProc::UserProc()
|
---|
| 79 | {
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | UserProc::~UserProc()
|
---|
| 83 | {
|
---|
[750] | 84 | foreach( Parameter *pParam, realParams ){
|
---|
[632] | 85 | delete pParam;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 |
|
---|
[382] | 89 | bool UserProc::IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const
|
---|
| 90 | {
|
---|
| 91 | if( this->GetName() == pUserProc->GetName() // 名前空間及び名前が等しい
|
---|
[383] | 92 | && this->Params().Equals( actualTypeParametersForThisProc, pUserProc->Params() ) ) // パラメータが等しい
|
---|
[382] | 93 | {
|
---|
| 94 | if( this->returnType.Equals( pUserProc->returnType ) )
|
---|
| 95 | {
|
---|
| 96 | // 戻り値が等しい
|
---|
| 97 | return true;
|
---|
| 98 | }
|
---|
[447] | 99 | else if( this->returnType.IsCovariant( pUserProc->returnType ) )
|
---|
[382] | 100 | {
|
---|
[447] | 101 | // 戻り値が共変
|
---|
| 102 | return true;
|
---|
| 103 | }
|
---|
| 104 | else if( this->returnType.IsTypeParameter() )
|
---|
| 105 | {
|
---|
[382] | 106 | // 型パラメータだったとき
|
---|
[447] | 107 |
|
---|
[382] | 108 | if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].Equals( pUserProc->returnType ) )
|
---|
| 109 | {
|
---|
| 110 | // 戻り値が等しい
|
---|
| 111 | return true;
|
---|
| 112 | }
|
---|
[447] | 113 | else if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].IsCovariant( pUserProc->returnType ) )
|
---|
| 114 | {
|
---|
| 115 | // 戻り値が共変
|
---|
| 116 | return true;
|
---|
| 117 | }
|
---|
[382] | 118 | }
|
---|
| 119 | }
|
---|
| 120 | return false;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
[206] | 124 | std::string UserProc::GetFullName() const
|
---|
| 125 | {
|
---|
| 126 | if( HasParentClass() ){
|
---|
| 127 | return GetParentClass().GetName() + "." + GetName();
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | return GetName();
|
---|
| 131 | }
|
---|
[350] | 132 | bool 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 | }
|
---|
[641] | 140 | bool 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 | }
|
---|
[206] | 159 | const NamespaceScopes &UserProc::GetNamespaceScopes() const
|
---|
| 160 | {
|
---|
[632] | 161 | if( HasParentClass() )
|
---|
| 162 | {
|
---|
[206] | 163 | return GetParentClassPtr()->GetNamespaceScopes();
|
---|
| 164 | }
|
---|
[208] | 165 | return Symbol::GetNamespaceScopes();
|
---|
[206] | 166 | }
|
---|
| 167 | const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const
|
---|
| 168 | {
|
---|
[306] | 169 | if( pParentClass )
|
---|
| 170 | {
|
---|
| 171 | return pParentClass->GetImportedNamespaces();
|
---|
| 172 | }
|
---|
[206] | 173 | return importedNamespaces;
|
---|
| 174 | }
|
---|
| 175 | bool UserProc::IsVirtual() const
|
---|
| 176 | {
|
---|
| 177 | if( pMethod == NULL ){
|
---|
| 178 | return false;
|
---|
| 179 | }
|
---|
| 180 | return ( pMethod->IsVirtual() != 0 );
|
---|
| 181 | }
|
---|
[336] | 182 | const CMethod &UserProc::GetMethod() const
|
---|
| 183 | {
|
---|
| 184 | if( !HasParentClass() )
|
---|
| 185 | {
|
---|
| 186 | Jenga::Throw( "グローバル関数に対してUserProc::GetMethodメソッドが呼ばれた" );
|
---|
| 187 | }
|
---|
| 188 | return *pMethod;
|
---|
| 189 | }
|
---|
[206] | 190 |
|
---|
[640] | 191 | bool UserProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 192 | {
|
---|
[640] | 193 | Procedure::Resolve( resolver, resolveErrors );
|
---|
[639] | 194 |
|
---|
[640] | 195 | if( this->pParentClass )
|
---|
[639] | 196 | {
|
---|
[640] | 197 | if( this->pParentClass->IsNeedResolve() )
|
---|
[639] | 198 | {
|
---|
[640] | 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 | }
|
---|
[639] | 208 | }
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | if( pInterface )
|
---|
| 212 | {
|
---|
[640] | 213 | const_cast<Interface *>(pInterface)->Resolve( resolver, resolveErrors );
|
---|
[639] | 214 | }
|
---|
| 215 |
|
---|
| 216 | if( pMethod )
|
---|
| 217 | {
|
---|
[640] | 218 | pMethod->Resolve( resolver, resolveErrors );
|
---|
[639] | 219 | }
|
---|
| 220 |
|
---|
[750] | 221 | foreach( Parameter *pParameter, realParams )
|
---|
[639] | 222 | {
|
---|
[640] | 223 | pParameter->Resolve( resolver, resolveErrors );
|
---|
[639] | 224 | }
|
---|
| 225 |
|
---|
[750] | 226 | foreach( Variable *pLocalVar, localVars )
|
---|
[639] | 227 | {
|
---|
[640] | 228 | pLocalVar->Resolve( resolver, resolveErrors );
|
---|
[639] | 229 | }
|
---|
| 230 |
|
---|
[640] | 231 | nativeCode.Resolve( resolver, resolveErrors );
|
---|
[637] | 232 | return true;
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[364] | 235 | const UserProc *UserProc::pGlobalProc = NULL;
|
---|
[206] | 236 |
|
---|
| 237 |
|
---|
[576] | 238 | void UserProcs::EnumGlobalProcs( const char *simpleName, const Symbol &localSymbol, std::vector<const UserProc *> &subs )
|
---|
[184] | 239 | {
|
---|
[206] | 240 | ///////////////////////////
|
---|
| 241 | // グローバル関数を検索
|
---|
| 242 | ///////////////////////////
|
---|
[184] | 243 |
|
---|
[206] | 244 | // ハッシュ値を取得
|
---|
| 245 | UserProc *pUserProc = GetHashArrayElement( simpleName );
|
---|
| 246 | while(pUserProc){
|
---|
[208] | 247 | if( pUserProc->IsGlobalProcedure() ){
|
---|
[576] | 248 | if( pUserProc->IsEqualSymbol( localSymbol ) ){
|
---|
[206] | 249 | subs.push_back( pUserProc );
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | pUserProc=pUserProc->GetChainNext();
|
---|
| 254 | }
|
---|
[184] | 255 | }
|
---|
| 256 |
|
---|
[640] | 257 | bool DllProc::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 258 | {
|
---|
[640] | 259 | Procedure::Resolve( resolver, resolveErrors );
|
---|
[637] | 260 | return true;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[640] | 263 | bool ProcPointer::Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors )
|
---|
[637] | 264 | {
|
---|
[640] | 265 | Procedure::Resolve( resolver, resolveErrors );
|
---|
[637] | 266 | return true;
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[206] | 269 | void ProcPointers::Clear()
|
---|
[184] | 270 | {
|
---|
[206] | 271 | ProcPointers &procPointers = *this;
|
---|
[750] | 272 | foreach( ProcPointer *pProcPointer, procPointers ){
|
---|
[184] | 273 | delete pProcPointer;
|
---|
| 274 | }
|
---|
| 275 | this->clear();
|
---|
| 276 | }
|
---|