[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 );
|
---|
[816] | 66 | Variable(Variable&& var);
|
---|
[511] | 67 | Variable( const Variable &var );
|
---|
| 68 | Variable();
|
---|
[816] | 69 | Variable& operator =(Variable&& y);
|
---|
| 70 | Variable& operator =(Variable const& y)
|
---|
| 71 | {
|
---|
| 72 | return *this = std::move(Variable(y));
|
---|
| 73 | }
|
---|
[206] | 74 |
|
---|
| 75 | void SetArray( const Subscripts &subscripts ){
|
---|
| 76 | isArray = true;
|
---|
| 77 | this->subscripts = subscripts;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | const Type &GetType() const
|
---|
| 81 | {
|
---|
| 82 | return type;
|
---|
| 83 | }
|
---|
| 84 | void ConstOff(){
|
---|
| 85 | isConst = false;
|
---|
| 86 | }
|
---|
| 87 | void ConstOn(){
|
---|
| 88 | isConst = true;
|
---|
| 89 | }
|
---|
| 90 | bool IsConst() const
|
---|
| 91 | {
|
---|
| 92 | return isConst;
|
---|
| 93 | }
|
---|
| 94 | bool IsRef() const
|
---|
| 95 | {
|
---|
| 96 | return isRef;
|
---|
| 97 | }
|
---|
| 98 | bool IsArray()const
|
---|
| 99 | {
|
---|
| 100 | return isArray;
|
---|
| 101 | }
|
---|
| 102 | const Subscripts &GetSubscripts() const
|
---|
| 103 | {
|
---|
| 104 | return subscripts;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[677] | 107 | void ThisIsByValStructParameter(){
|
---|
[206] | 108 | isParameter = true;
|
---|
| 109 | }
|
---|
[677] | 110 | bool IsByValStructParameter() const
|
---|
[206] | 111 | {
|
---|
| 112 | return isParameter;
|
---|
| 113 | }
|
---|
[275] | 114 | bool HasInitData() const
|
---|
| 115 | {
|
---|
| 116 | return hasInitData;
|
---|
| 117 | }
|
---|
[206] | 118 |
|
---|
| 119 |
|
---|
| 120 | int GetMemorySize() const
|
---|
| 121 | {
|
---|
| 122 | if( isRef || isParameter ){
|
---|
| 123 | return PTR_SIZE;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | int size = type.GetSize();
|
---|
| 127 |
|
---|
| 128 | if( isArray ){
|
---|
| 129 | int num = 1;
|
---|
| 130 | for( int i=0; i<(int)subscripts.size(); i++){
|
---|
| 131 | num *= subscripts[i]+1;
|
---|
| 132 | }
|
---|
| 133 | size *= num;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | if( size % PTR_SIZE ){
|
---|
| 137 | size += PTR_SIZE-(size%PTR_SIZE);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | return size;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | int GetOffsetAddress() const
|
---|
| 144 | {
|
---|
| 145 | return offset;
|
---|
| 146 | }
|
---|
| 147 | void SetOffsetAddress( int offset )
|
---|
| 148 | {
|
---|
| 149 | this->offset = offset;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | const std::string &GetParamStrForConstructor() const
|
---|
| 153 | {
|
---|
| 154 | return paramStrForConstructor;
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | //レキシカルスコープ用
|
---|
| 158 | int GetScopeStartAddress() const
|
---|
| 159 | {
|
---|
| 160 | return scopeStartAddress;
|
---|
| 161 | }
|
---|
| 162 | void SetScopeStartAddress( int scopeStartAddress )
|
---|
| 163 | {
|
---|
| 164 | this->scopeStartAddress = scopeStartAddress;
|
---|
| 165 | }
|
---|
| 166 | int GetScopeEndAddress() const
|
---|
| 167 | {
|
---|
| 168 | return scopeEndAddress;
|
---|
| 169 | }
|
---|
| 170 | void SetScopeEndAddress( int scopeEndAddress )
|
---|
| 171 | {
|
---|
| 172 | this->scopeEndAddress = scopeEndAddress;
|
---|
| 173 | }
|
---|
| 174 | int GetScopeLevel() const
|
---|
| 175 | {
|
---|
| 176 | return scopeLevel;
|
---|
| 177 | }
|
---|
| 178 | void SetScopeLevel( int scopeLevel )
|
---|
| 179 | {
|
---|
| 180 | this->scopeLevel = scopeLevel;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[640] | 183 | virtual bool Resolve( const ObjectModule &resolver, ResolveErrors &resolveErrors );
|
---|
[206] | 184 |
|
---|
[637] | 185 |
|
---|
[392] | 186 | bool isLiving;
|
---|
[206] | 187 | int source_code_address;
|
---|
| 188 |
|
---|
| 189 |
|
---|
| 190 | static int GetSubScriptCounts( const Subscripts &subscripts ){
|
---|
| 191 | // 配列の要素数を取得
|
---|
| 192 | int i,i2;
|
---|
| 193 | for(i=0,i2=1;i<(int)subscripts.size();i++){
|
---|
| 194 | i2 *= subscripts[i]+1;
|
---|
| 195 | }
|
---|
| 196 | return i2;
|
---|
| 197 | }
|
---|
| 198 | };
|
---|
| 199 |
|
---|
[523] | 200 | class Variables : public std::vector<Variable *>
|
---|
[206] | 201 | {
|
---|
[288] | 202 | protected:
|
---|
[273] | 203 | int allSize;
|
---|
[288] | 204 |
|
---|
| 205 | // XMLシリアライズ用
|
---|
| 206 | private:
|
---|
| 207 | friend class boost::serialization::access;
|
---|
| 208 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 209 | {
|
---|
| 210 | trace_for_serialize( "serializing - Variables" );
|
---|
| 211 |
|
---|
| 212 | ar & boost::serialization::make_nvp("vector_Variable", boost::serialization::base_object<vector<Variable *>>(*this));
|
---|
| 213 | }
|
---|
| 214 |
|
---|
[206] | 215 | public:
|
---|
[273] | 216 | Variables()
|
---|
| 217 | : allSize( 0 )
|
---|
| 218 | {
|
---|
| 219 | }
|
---|
[206] | 220 | ~Variables(){
|
---|
[271] | 221 | Clear();
|
---|
[206] | 222 | }
|
---|
| 223 |
|
---|
[271] | 224 | void Clear(){
|
---|
[206] | 225 | for( int i=0; i<(int)this->size(); i++ ){
|
---|
| 226 | delete (*this)[i];
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[273] | 229 | allSize = 0;
|
---|
[271] | 230 | clear();
|
---|
[206] | 231 | }
|
---|
[271] | 232 | void PullOutAll()
|
---|
| 233 | {
|
---|
| 234 | clear();
|
---|
| 235 | }
|
---|
[206] | 236 |
|
---|
[288] | 237 | int GetAllSize() const
|
---|
| 238 | {
|
---|
| 239 | return allSize;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
[570] | 242 | bool DuplicateCheck( const Symbol &symbol, int nowScopeLevel ) const;
|
---|
[206] | 243 |
|
---|
[570] | 244 | const Variable *BackSearch( const Symbol &symbol, int nowScopeLevel ) const;
|
---|
[206] | 245 | const Variable *Find( const Symbol &symbol )const;
|
---|
[288] | 246 | };
|
---|
[206] | 247 |
|
---|
[288] | 248 | class GlobalVars : public Variables
|
---|
| 249 | {
|
---|
| 250 | public:
|
---|
[529] | 251 | Jenga::Common::Binary initAreaBuffer;
|
---|
[206] | 252 |
|
---|
| 253 | // XMLシリアライズ用
|
---|
| 254 | private:
|
---|
| 255 | friend class boost::serialization::access;
|
---|
| 256 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 257 | {
|
---|
[288] | 258 | trace_for_serialize( "serializing - GlobalVars" );
|
---|
[206] | 259 |
|
---|
[288] | 260 | ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP( Variables );
|
---|
| 261 | ar & BOOST_SERIALIZATION_NVP( initAreaBuffer );
|
---|
[206] | 262 | }
|
---|
[287] | 263 | public:
|
---|
[288] | 264 | GlobalVars()
|
---|
[287] | 265 | {
|
---|
| 266 | }
|
---|
[288] | 267 | ~GlobalVars()
|
---|
[287] | 268 | {
|
---|
| 269 | }
|
---|
[288] | 270 |
|
---|
| 271 | void Add( Variable *pVar, bool isResetOffsetAddress = true );
|
---|
[287] | 272 | };
|
---|