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