source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Procedure.cpp@ 573

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

Procedureクラスインスタンスを対象としたLexicalAnalyzer::SetParamsAndReturnTypeメソッドを実装。

File size: 3.8 KB
Line 
1#include "stdafx.h"
2
3#include <Compiler.h>
4#include <Procedure.h>
5
6#include "../common.h"
7#ifdef _AMD64_
8#include "../../compiler_x64/opcode.h"
9#else
10#include "../../compiler_x86/opcode.h"
11#endif
12
13using namespace ActiveBasic::Compiler;
14
15
16bool UserProc::IsEqualForOverride( const Types &actualTypeParametersForThisProc, const UserProc *pUserProc ) const
17{
18 if( this->GetName() == pUserProc->GetName() // 名前空間及び名前が等しい
19 && this->Params().Equals( actualTypeParametersForThisProc, pUserProc->Params() ) ) // パラメータが等しい
20 {
21 if( this->returnType.Equals( pUserProc->returnType ) )
22 {
23 // 戻り値が等しい
24 return true;
25 }
26 else if( this->returnType.IsCovariant( pUserProc->returnType ) )
27 {
28 // 戻り値が共変
29 return true;
30 }
31 else if( this->returnType.IsTypeParameter() )
32 {
33 // 型パラメータだったとき
34
35 if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].Equals( pUserProc->returnType ) )
36 {
37 // 戻り値が等しい
38 return true;
39 }
40 else if( actualTypeParametersForThisProc[this->returnType.GetFormalTypeIndex()].IsCovariant( pUserProc->returnType ) )
41 {
42 // 戻り値が共変
43 return true;
44 }
45 }
46 }
47 return false;
48}
49
50
51std::string UserProc::GetFullName() const
52{
53 if( HasParentClass() ){
54 return GetParentClass().GetName() + "." + GetName();
55 }
56
57 return GetName();
58}
59bool UserProc::IsCastOperator() const
60{
61 if( GetName()[0] == 1 && GetName()[1] == ESC_OPERATOR && GetName()[2] == CALC_AS )
62 {
63 return true;
64 }
65 return false;
66}
67const NamespaceScopes &UserProc::GetNamespaceScopes() const
68{
69 if( HasParentClass() ){
70 return GetParentClassPtr()->GetNamespaceScopes();
71 }
72 return Symbol::GetNamespaceScopes();
73}
74const NamespaceScopesCollection &UserProc::GetImportedNamespaces() const
75{
76 if( pParentClass )
77 {
78 return pParentClass->GetImportedNamespaces();
79 }
80 return importedNamespaces;
81}
82bool UserProc::IsVirtual() const
83{
84 if( pMethod == NULL ){
85 return false;
86 }
87 return ( pMethod->IsVirtual() != 0 );
88}
89const CMethod &UserProc::GetMethod() const
90{
91 if( !HasParentClass() )
92 {
93 Jenga::Throw( "グローバル関数に対してUserProc::GetMethodメソッドが呼ばれた" );
94 }
95 return *pMethod;
96}
97
98const UserProc *UserProc::pGlobalProc = NULL;
99
100
101bool UserProcs::Insert( UserProc *pUserProc, int nowLine )
102{
103 /////////////////////////////////
104 // ハッシュデータに追加
105 /////////////////////////////////
106
107 if( !Put( pUserProc ) )
108 {
109 // 重複しているため、失敗
110 compiler.errorMessenger.Output(15,pUserProc->GetName().c_str(),nowLine);
111 return false;
112 }
113
114 return true;
115}
116
117void UserProcs::EnumGlobalProcs( const char *simpleName, const char *localName, std::vector<const UserProc *> &subs )
118{
119 ///////////////////////////
120 // グローバル関数を検索
121 ///////////////////////////
122
123 // ハッシュ値を取得
124 UserProc *pUserProc = GetHashArrayElement( simpleName );
125 while(pUserProc){
126 if( pUserProc->IsGlobalProcedure() ){
127 if( pUserProc->IsEqualSymbol( LexicalAnalyzer::FullNameToSymbol( localName ) ) ){
128 subs.push_back( pUserProc );
129 }
130 }
131
132 pUserProc=pUserProc->GetChainNext();
133 }
134}
135
136int ProcPointers::Add( const std::string &typeExpression )
137{
138 DWORD dwProcType = (DWORD)typeExpression[2];
139 const std::string &paramStr = typeExpression.substr( 3 );
140
141 Procedure::Kind kind = Procedure::Sub;
142 if( dwProcType == ESC_FUNCTION ){
143 kind = Procedure::Function;
144 }
145
146 ProcPointer *pProcPointer = new ProcPointer( kind );
147
148 //buffer[0]は'('となっている
149 extern int cp;
150 LexicalAnalyzer::SetParamsAndReturnType( pProcPointer, paramStr.c_str(), false, cp );
151
152 this->push_back( pProcPointer );
153
154 return (int)this->size()-1;
155}
156
157void ProcPointers::Clear()
158{
159 ProcPointers &procPointers = *this;
160 BOOST_FOREACH( ProcPointer *pProcPointer, procPointers ){
161 delete pProcPointer;
162 }
163 this->clear();
164}
Note: See TracBrowser for help on using the repository browser.