[206] | 1 | #pragma once
|
---|
| 2 |
|
---|
| 3 | class Variable : public Symbol
|
---|
| 4 | {
|
---|
| 5 | Type type;
|
---|
| 6 | bool isConst;
|
---|
| 7 | bool isRef;
|
---|
| 8 | bool isArray;
|
---|
| 9 | Subscripts subscripts;
|
---|
| 10 |
|
---|
| 11 | bool isParameter;
|
---|
[275] | 12 | bool hasInitData;
|
---|
[206] | 13 |
|
---|
| 14 | //コンストラクタ用パラメータ
|
---|
| 15 | std::string paramStrForConstructor;
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | /* --- オフセット ---
|
---|
| 19 | ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
|
---|
| 20 | 初期バッファの有無が識別される。
|
---|
| 21 | (その後、スケジュール実行により、実際の配置に並び替えられる)*/
|
---|
| 22 | int offset;
|
---|
| 23 |
|
---|
| 24 |
|
---|
| 25 | //レキシカルスコープ用
|
---|
| 26 | int scopeStartAddress;
|
---|
| 27 | int scopeEndAddress;
|
---|
| 28 | int scopeLevel;
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | // XMLシリアライズ用
|
---|
| 32 | private:
|
---|
| 33 | friend class boost::serialization::access;
|
---|
| 34 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 35 | {
|
---|
| 36 | trace_for_serialize( "serializing - Variable" );
|
---|
| 37 |
|
---|
| 38 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Symbol );
|
---|
| 39 | ar & BOOST_SERIALIZATION_NVP( type );
|
---|
| 40 | ar & BOOST_SERIALIZATION_NVP( isConst );
|
---|
| 41 | ar & BOOST_SERIALIZATION_NVP( isRef );
|
---|
| 42 | ar & BOOST_SERIALIZATION_NVP( isArray );
|
---|
| 43 | ar & BOOST_SERIALIZATION_NVP( subscripts );
|
---|
| 44 | ar & BOOST_SERIALIZATION_NVP( isParameter );
|
---|
[275] | 45 | ar & BOOST_SERIALIZATION_NVP( hasInitData );
|
---|
[206] | 46 | ar & BOOST_SERIALIZATION_NVP( paramStrForConstructor );
|
---|
| 47 | ar & BOOST_SERIALIZATION_NVP( offset );
|
---|
| 48 | ar & BOOST_SERIALIZATION_NVP( scopeStartAddress );
|
---|
| 49 | ar & BOOST_SERIALIZATION_NVP( scopeEndAddress );
|
---|
| 50 | ar & BOOST_SERIALIZATION_NVP( scopeLevel );
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public:
|
---|
[580] | 54 | Variable( const Symbol &symbol, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData );
|
---|
[523] | 55 | Variable( const NamespaceScopes &namespaceScopes, const std::string &name, const Type &type, bool isConst, bool isRef, const std::string ¶mStrForConstructor, bool hasInitData );
|
---|
[511] | 56 | Variable( const Variable &var );
|
---|
| 57 | Variable();
|
---|
[206] | 58 |
|
---|
| 59 | void SetArray( const Subscripts &subscripts ){
|
---|
| 60 | isArray = true;
|
---|
| 61 | this->subscripts = subscripts;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | const Type &GetType() const
|
---|
| 65 | {
|
---|
| 66 | return type;
|
---|
| 67 | }
|
---|
| 68 | void ConstOff(){
|
---|
| 69 | isConst = false;
|
---|
| 70 | }
|
---|
| 71 | void ConstOn(){
|
---|
| 72 | isConst = true;
|
---|
| 73 | }
|
---|
| 74 | bool IsConst() const
|
---|
| 75 | {
|
---|
| 76 | return isConst;
|
---|
| 77 | }
|
---|
| 78 | bool IsRef() const
|
---|
| 79 | {
|
---|
| 80 | return isRef;
|
---|
| 81 | }
|
---|
| 82 | bool IsArray()const
|
---|
| 83 | {
|
---|
| 84 | return isArray;
|
---|
| 85 | }
|
---|
| 86 | const Subscripts &GetSubscripts() const
|
---|
| 87 | {
|
---|
| 88 | return subscripts;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | void ThisIsParameter(){
|
---|
| 92 | isParameter = true;
|
---|
| 93 | }
|
---|
| 94 | bool IsParameter() const
|
---|
| 95 | {
|
---|
| 96 | return isParameter;
|
---|
| 97 | }
|
---|
[275] | 98 | bool HasInitData() const
|
---|
| 99 | {
|
---|
| 100 | return hasInitData;
|
---|
| 101 | }
|
---|
[206] | 102 |
|
---|
| 103 |
|
---|
| 104 | int GetMemorySize() const
|
---|
| 105 | {
|
---|
| 106 | if( isRef || isParameter ){
|
---|
| 107 | return PTR_SIZE;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | int size = type.GetSize();
|
---|
| 111 |
|
---|
| 112 | if( isArray ){
|
---|
| 113 | int num = 1;
|
---|
| 114 | for( int i=0; i<(int)subscripts.size(); i++){
|
---|
| 115 | num *= subscripts[i]+1;
|
---|
| 116 | }
|
---|
| 117 | size *= num;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | if( size % PTR_SIZE ){
|
---|
| 121 | size += PTR_SIZE-(size%PTR_SIZE);
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return size;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | int GetOffsetAddress() const
|
---|
| 128 | {
|
---|
| 129 | return offset;
|
---|
| 130 | }
|
---|
| 131 | void SetOffsetAddress( int offset )
|
---|
| 132 | {
|
---|
| 133 | this->offset = offset;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | const std::string &GetParamStrForConstructor() const
|
---|
| 137 | {
|
---|
| 138 | return paramStrForConstructor;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | //レキシカルスコープ用
|
---|
| 142 | int GetScopeStartAddress() const
|
---|
| 143 | {
|
---|
| 144 | return scopeStartAddress;
|
---|
| 145 | }
|
---|
| 146 | void SetScopeStartAddress( int scopeStartAddress )
|
---|
| 147 | {
|
---|
| 148 | this->scopeStartAddress = scopeStartAddress;
|
---|
| 149 | }
|
---|
| 150 | int GetScopeEndAddress() const
|
---|
| 151 | {
|
---|
| 152 | return scopeEndAddress;
|
---|
| 153 | }
|
---|
| 154 | void SetScopeEndAddress( int scopeEndAddress )
|
---|
| 155 | {
|
---|
| 156 | this->scopeEndAddress = scopeEndAddress;
|
---|
| 157 | }
|
---|
| 158 | int GetScopeLevel() const
|
---|
| 159 | {
|
---|
| 160 | return scopeLevel;
|
---|
| 161 | }
|
---|
| 162 | void SetScopeLevel( int scopeLevel )
|
---|
| 163 | {
|
---|
| 164 | this->scopeLevel = scopeLevel;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 |
|
---|
[392] | 168 | bool isLiving;
|
---|
[206] | 169 | int source_code_address;
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | static int GetSubScriptCounts( const Subscripts &subscripts ){
|
---|
| 173 | // 配列の要素数を取得
|
---|
| 174 | int i,i2;
|
---|
| 175 | for(i=0,i2=1;i<(int)subscripts.size();i++){
|
---|
| 176 | i2 *= subscripts[i]+1;
|
---|
| 177 | }
|
---|
| 178 | return i2;
|
---|
| 179 | }
|
---|
| 180 | };
|
---|
| 181 |
|
---|
[523] | 182 | class Variables : public std::vector<Variable *>
|
---|
[206] | 183 | {
|
---|
[288] | 184 | protected:
|
---|
[273] | 185 | int allSize;
|
---|
[288] | 186 |
|
---|
| 187 | // XMLシリアライズ用
|
---|
| 188 | private:
|
---|
| 189 | friend class boost::serialization::access;
|
---|
| 190 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 191 | {
|
---|
| 192 | trace_for_serialize( "serializing - Variables" );
|
---|
| 193 |
|
---|
| 194 | ar & boost::serialization::make_nvp("vector_Variable", boost::serialization::base_object<vector<Variable *>>(*this));
|
---|
| 195 | }
|
---|
| 196 |
|
---|
[206] | 197 | public:
|
---|
[273] | 198 | Variables()
|
---|
| 199 | : allSize( 0 )
|
---|
| 200 | {
|
---|
| 201 | }
|
---|
[206] | 202 | ~Variables(){
|
---|
[271] | 203 | Clear();
|
---|
[206] | 204 | }
|
---|
| 205 |
|
---|
[271] | 206 | void Clear(){
|
---|
[206] | 207 | for( int i=0; i<(int)this->size(); i++ ){
|
---|
| 208 | delete (*this)[i];
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[273] | 211 | allSize = 0;
|
---|
[271] | 212 | clear();
|
---|
[206] | 213 | }
|
---|
[271] | 214 | void PullOutAll()
|
---|
| 215 | {
|
---|
| 216 | clear();
|
---|
| 217 | }
|
---|
[206] | 218 |
|
---|
[288] | 219 | int GetAllSize() const
|
---|
| 220 | {
|
---|
| 221 | return allSize;
|
---|
| 222 | }
|
---|
| 223 |
|
---|
[570] | 224 | bool DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const;
|
---|
[206] | 225 |
|
---|
[570] | 226 | const Variable *BackSearch( const Symbol &symbol, int nowScopeLevel ) const;
|
---|
[206] | 227 | const Variable *Find( const Symbol &symbol )const;
|
---|
[288] | 228 | };
|
---|
[206] | 229 |
|
---|
[288] | 230 | class GlobalVars : public Variables
|
---|
| 231 | {
|
---|
| 232 | public:
|
---|
[529] | 233 | Jenga::Common::Binary initAreaBuffer;
|
---|
[206] | 234 |
|
---|
| 235 | // XMLシリアライズ用
|
---|
| 236 | private:
|
---|
| 237 | friend class boost::serialization::access;
|
---|
| 238 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 239 | {
|
---|
[288] | 240 | trace_for_serialize( "serializing - GlobalVars" );
|
---|
[206] | 241 |
|
---|
[288] | 242 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Variables );
|
---|
| 243 | ar & BOOST_SERIALIZATION_NVP( initAreaBuffer );
|
---|
[206] | 244 | }
|
---|
[287] | 245 | public:
|
---|
[288] | 246 | GlobalVars()
|
---|
[287] | 247 | {
|
---|
| 248 | }
|
---|
[288] | 249 | ~GlobalVars()
|
---|
[287] | 250 | {
|
---|
| 251 | }
|
---|
[288] | 252 |
|
---|
| 253 | void Add( Variable *pVar, bool isResetOffsetAddress = true );
|
---|
[287] | 254 | };
|
---|