source: dev/trunk/ab5.0/abdev/ab_common/src/Lexical/Parameter.cpp@ 708

Last change on this file since 708 was 708, checked in by dai_9181, 16 years ago
  • #184への対応。ByRef引数を持つデリゲートを宣言するとコンパイルできないバグを修正。
  • オーバーロード用のパラメータ比較にByRef/ByValの相違を考慮するようにした。
File size: 2.5 KB
Line 
1#include "stdafx.h"
2
3Parameter::Parameter( const std::string &varName, const Type &type, bool isRef, const std::string initValue )
4 : Type( type )
5 , varName( varName )
6 , isRef( isRef )
7 , isArray( false )
8 , initValue( initValue )
9{
10}
11
12Parameter::Parameter( const Parameter &param, const Type &type )
13 : Type( type )
14 , varName( param.varName )
15 , isRef( param.isRef )
16 , isArray( param.isArray )
17 , subscripts( param.subscripts )
18 , initValue( param.initValue )
19{
20}
21
22Parameter::Parameter( const Parameter &param )
23 : Type( param )
24 , varName( param.varName )
25 , isRef( param.isRef )
26 , isArray( param.isArray )
27 , subscripts( param.subscripts )
28 , initValue( param.initValue )
29{
30}
31
32Parameter::Parameter()
33{
34}
35
36Parameter::~Parameter()
37{
38}
39
40bool Parameter::Equals( const Parameter &param, bool isContravariant ) const
41{
42 if( Type::Equals( param ) && this->isRef == param.isRef )
43 {
44 return true;
45 }
46 else
47 {
48 if( this->isRef && this->GetBasicType() == DEF_ANY &&
49 param.isRef == false && param.IsPointer()
50 ||
51 this->isRef == false && this->IsPointer() &&
52 param.isRef && param.GetBasicType() == DEF_ANY )
53 {
54 /* ByRef var As Any
55
56 var As VoidPtr
57 は同等
58 */
59 return true;
60 }
61 }
62
63 if( isContravariant )
64 {
65 // 反変引数を許可する
66 if( this->IsContravariant( param ) && this->isRef == param.isRef )
67 {
68 // 反変引数だったとき
69 return true;
70 }
71 }
72
73 return false;
74}
75bool Parameter::Equals( const Types &actualTypeParametersForThisProc, const Parameter &param, bool isContravariant ) const
76{
77 if( Equals( param, isContravariant ) )
78 {
79 return true;
80 }
81
82 if( this->IsTypeParameter() )
83 {
84 // 型パラメータだったとき
85 if( actualTypeParametersForThisProc[this->GetFormalTypeIndex()].Equals( param ) )
86 {
87 // 戻り値が等しい
88 return true;
89 }
90 }
91
92 return false;
93}
94
95bool Parameters::Equals( const Parameters &params, bool isContravariant ) const
96{
97 if( this->size() != params.size() ){
98 return false;
99 }
100
101 int max = (int)this->size();
102 for( int i=0; i<max; i++ ){
103 if( !(*this)[i]->Equals( *params[i], isContravariant ) ){
104 return false;
105 }
106 }
107
108 return true;
109}
110bool Parameters::Equals( const Types &actualTypeParametersForThisProc, const Parameters &params, bool isContravariant ) const
111{
112 if( this->size() != params.size() ){
113 return false;
114 }
115
116 int max = (int)this->size();
117 for( int i=0; i<max; i++ ){
118 if( !(*this)[i]->Equals( actualTypeParametersForThisProc, *params[i], isContravariant ) ){
119 return false;
120 }
121 }
122
123 return true;
124}
Note: See TracBrowser for help on using the repository browser.