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