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