source: dev/trunk/ab5.0/abdev/BasicCompiler_Common/src/Parameter.cpp@ 568

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

Parameters::Analyze → LexicalAnalyzer::AnalyzeParameter

File size: 2.1 KB
Line 
1#include "stdafx.h"
2
3
4bool Parameter::Equals( const Parameter &param, bool isContravariant ) const
5{
6 if( Type::Equals( param ) )
7 {
8 return true;
9 }
10 else
11 {
12 if( this->isRef && this->GetBasicType() == DEF_ANY &&
13 param.isRef == false && param.IsPointer()
14 ||
15 this->isRef == false && this->IsPointer() &&
16 param.isRef && param.GetBasicType() == DEF_ANY )
17 {
18 /* ByRef var As Any
19
20 var As VoidPtr
21 は同等
22 */
23 return true;
24 }
25 }
26
27 if( isContravariant )
28 {
29 // 反変引数を許可する
30 if( this->IsContravariant( param ) )
31 {
32 // 反変引数だったとき
33 return true;
34 }
35 }
36
37 return false;
38}
39bool Parameter::Equals( const Types &actualTypeParametersForThisProc, const Parameter &param, bool isContravariant ) const
40{
41 if( Equals( param, isContravariant ) )
42 {
43 return true;
44 }
45
46 if( this->IsTypeParameter() )
47 {
48 // 型パラメータだったとき
49 if( actualTypeParametersForThisProc[this->GetFormalTypeIndex()].Equals( param ) )
50 {
51 // 戻り値が等しい
52 return true;
53 }
54 }
55
56 return false;
57}
58
59bool Parameters::Equals( const Parameters &params, bool isContravariant ) const
60{
61 if( this->size() != params.size() ){
62 return false;
63 }
64
65 int max = (int)this->size();
66 for( int i=0; i<max; i++ ){
67 if( !(*this)[i]->Equals( *params[i], isContravariant ) ){
68 return false;
69 }
70 }
71
72 return true;
73}
74bool Parameters::Equals( const Types &actualTypeParametersForThisProc, const Parameters &params, bool isContravariant ) const
75{
76 if( this->size() != params.size() ){
77 return false;
78 }
79
80 int max = (int)this->size();
81 for( int i=0; i<max; i++ ){
82 if( !(*this)[i]->Equals( actualTypeParametersForThisProc, *params[i], isContravariant ) ){
83 return false;
84 }
85 }
86
87 return true;
88}
89
90std::string Parameters::GetString() const
91{
92 std::string result;
93
94 const Parameters &params = *this;
95 BOOST_FOREACH( const Parameter *pParam, params )
96 {
97 if( result.size() )
98 {
99 result += ",";
100 }
101
102 result += pParam->GetVarName() + " As " + compiler.TypeToString( *pParam );
103 }
104 return result;
105}
Note: See TracBrowser for help on using the repository browser.