source: dev/trunk/abdev/BasicCompiler_Common/include/Parameter.h@ 333

Last change on this file since 333 was 325, checked in by dai_9181, 17 years ago
File size: 3.0 KB
Line 
1#pragma once
2
3#include <string>
4#include <vector>
5
6#include <jenga/include/smoothie/BasicFixed.h>
7#include <jenga/include/smoothie/LexicalAnalysis.h>
8
9#include <option.h>
10#include <Program.h>
11#include <Type.h>
12
13class Parameter : public Type
14{
15 std::string varName;
16 bool isRef;
17 bool isArray;
18 Subscripts subscripts;
19
20 std::string initValue;
21
22 // XMLシリアライズ用
23private:
24 friend class boost::serialization::access;
25 template<class Archive> void serialize(Archive& ar, const unsigned int version)
26 {
27 trace_for_serialize( "serializing - Parameter" );
28
29 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Type );
30 ar & BOOST_SERIALIZATION_NVP( varName );
31 ar & BOOST_SERIALIZATION_NVP( isRef );
32 ar & BOOST_SERIALIZATION_NVP( isArray );
33 ar & BOOST_SERIALIZATION_NVP( subscripts );
34 ar & BOOST_SERIALIZATION_NVP( initValue );
35 }
36
37public:
38 Parameter( const std::string &varName, const Type &type, bool isRef = false, const std::string initValue = "" ):
39 Type( type ),
40 varName( varName ),
41 isRef( isRef ),
42 isArray( false ),
43 initValue( initValue )
44 {
45 }
46 Parameter( const Parameter &param ):
47 Type( param ),
48 varName( param.varName ),
49 isRef( param.isRef ),
50 isArray( param.isArray ),
51 subscripts( param.subscripts ),
52 initValue( param.initValue )
53 {
54 }
55 Parameter()
56 {
57 }
58 ~Parameter(){}
59
60 void SetArray( const Subscripts &subscripts ){
61 isArray = true;
62 this->subscripts = subscripts;
63 }
64
65 const std::string &GetVarName() const
66 {
67 return varName;
68 }
69
70 bool IsRef() const
71 {
72 return isRef;
73 }
74 bool IsArray(){
75 return isArray;
76 }
77 const Subscripts &GetSubscripts() const
78 {
79 return subscripts;
80 }
81
82 const std::string &GetInitValue() const
83 {
84 return initValue;
85 }
86
87 bool Equals( const Parameter &param ) const
88 {
89 if( Type::Equals( param ) ){
90 return true;
91 }
92 else{
93
94 if( this->isRef && this->GetBasicType() == DEF_ANY &&
95 param.isRef == false && param.IsPointer()
96 ||
97 this->isRef == false && this->IsPointer() &&
98 param.isRef && param.GetBasicType() == DEF_ANY ){
99 /* ByRef var As Any
100
101 var As VoidPtr
102 は同等
103 */
104 return true;
105 }
106 }
107
108 return false;
109 }
110};
111
112class Parameters : public std::vector<Parameter *>
113{
114 // XMLシリアライズ用
115private:
116 friend class boost::serialization::access;
117 template<class Archive> void serialize(Archive& ar, const unsigned int version)
118 {
119 trace_for_serialize( "serializing - Parameters" );
120
121 ar & boost::serialization::make_nvp("vector_Parameter", boost::serialization::base_object<std::vector<Parameter *>>(*this));
122 }
123
124public:
125
126 bool Equals( const Parameters &params ) const
127 {
128 if( this->size() != params.size() ){
129 return false;
130 }
131
132 int max = (int)this->size();
133 for( int i=0; i<max; i++ ){
134 if( !(*this)[i]->Equals( *params[i] ) ){
135 return false;
136 }
137 }
138
139 return true;
140 }
141
142 int GetMemorySize() const
143 {
144 return (int)this->size() * PTR_SIZE;
145 }
146
147 bool Analyze( const char *sourceOfParams, int nowLine );
148
149 std::string GetString() const;
150};
Note: See TracBrowser for help on using the repository browser.