Changeset 75 in dev for BasicCompiler_Common/Variable.h


Ignore:
Timestamp:
Mar 20, 2007, 4:36:16 AM (17 years ago)
Author:
dai_9181
Message:

TYPEINFO→Typeへのリファクタリングを実施。64bitはほぼ完了。32bitが全般的に未完成。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • BasicCompiler_Common/Variable.h

    r64 r75  
     1
     2class Variable : public Type
     3{
     4    string name;
     5    bool isConst;
     6    bool isRef;
     7    bool isArray;
     8    int subScripts[MAX_ARRAYDIM];
     9
     10    bool isParameter;
     11
     12public:
     13    Variable( const string &name, const Type &type, bool isConst = false, bool isRef = false ):
     14        Type( type ),
     15        name( name ),
     16        isConst( isConst ),
     17        isRef( isRef ),
     18        isArray( false ),
     19        isParameter( false)
     20    {
     21        subScripts[0] = -1;
     22    }
     23    Variable( const Variable &var ):
     24        Type( var ),
     25        name( var.name ),
     26        isConst( var.isConst ),
     27        isRef( var.isRef ),
     28        isArray( false ),
     29        isParameter( false )
     30    {
     31        subScripts[0] = -1;
     32        if( var.isArray ){
     33            SetArray( var.subScripts );
     34        }
     35    }
     36    ~Variable(){}
     37
     38    void SetArray( const int *pSubScripts ){
     39        isArray = true;
     40        memcpy( this->subScripts, pSubScripts, sizeof(int) * MAX_ARRAYDIM );
     41    }
     42
     43    const string &GetName() const
     44    {
     45        return name;
     46    }
     47
     48    void ConstOff(){
     49        isConst = false;
     50    }
     51    void ConstOn(){
     52        isConst = true;
     53    }
     54    bool IsConst() const
     55    {
     56        return isConst;
     57    }
     58    bool IsRef() const
     59    {
     60        return isRef;
     61    }
     62    bool IsArray()const
     63    {
     64        return isArray;
     65    }
     66    const int *GetSubScriptsPtr() const
     67    {
     68        return subScripts;
     69    }
     70
     71    void ThisIsParameter(){
     72        isParameter = true;
     73    }
     74    bool IsParameter() const
     75    {
     76        return isParameter;
     77    }
    178
    279
    3 BOOL IsVariableTopChar(char c);
    4 BOOL IsVariableChar(char c);
    5 BOOL IsPtrType(int type);
    6 BOOL IsSignedType(int type);
    7 BOOL IsNaturalWholeNumberType(int type);
    8 BOOL IsWholeNumberType(int type);
    9 BOOL IsRealNumberType(int type);
    10 BOOL Is64Type(int type);
    11 int GetSignedType(int type);
    12 int GetUnsignedType(int type);
    13 int GetTypeSize(int type,LONG_PTR lpIndex);
    14 int GetPtrType(int type,LONG_PTR lpIndex);
    15 int GetTypeFixed(const char *TypeName,LONG_PTR *lpNum);
    16 void GetOriginalTypeName(char *buffer);
    17 BOOL GetTypeName(int type,LONG_PTR lpIndex,char *name);
    18 bool FormatUseProcReturnObject( const char *term, char *procName, char *parameter, CClass::RefType &refType, char *member );
    19 BOOL GetVarFormatString(char *buffer,char *array,char *array2,char *NestMember, CClass::RefType &refType );
    20 void GetArrayElement(char *buffer,char *variable,char *array_element);
    21 BOOL CheckVarNameError(char *name,int NowLine);
    22 int JumpSubScripts(int *ss);
    23 void GetArrange(char *variable,char *variAnswer,int *SubScripts);
    24 int GetTypeFromSimpleName(char *variable);
    25 int GetVarType(const char *NameBuffer,LONG_PTR *plpIndex,BOOL bError);
    26 BOOL GetVarOffsetReadOnly(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
    27 BOOL GetVarOffsetReadWrite(const char *NameBuffer,int *pType,RELATIVE_VAR *pRelativeVar,LONG_PTR *plpIndex,int *pss=0);
    28 BOOL GetDimentionFormat(const char *buffer, const bool isRef, char *VarName,int *SubScripts,TYPEINFO *pTypeInfo,char *InitBuf,char *ConstractParameter);
    29 BOOL GetNowStaticVarFullName(char *VarName,char *FullName);
    30 void AddGlobalVariable(bool isRef, char *name,int *SubScripts,TYPEINFO *pTypeInfo,int TypeSize,char *InitBuf,char *ConstractParameter,DWORD dwFlag);
     80    int GetMemorySize() const
     81    {
     82        if( isRef || isParameter ){
     83            return PTR_SIZE;
     84        }
    3185
     86        int size = Type::GetSize();
     87
     88        if( isArray ){
     89            int num = 1;
     90            for( int i=0; i<MAX_ARRAYDIM; i++){
     91                if(subScripts[i]==-1) break;
     92                num *= subScripts[i]+1;
     93            }
     94            size *= num;
     95        }
     96
     97        if( size % PTR_SIZE ){
     98            size += PTR_SIZE-(size%PTR_SIZE);
     99        }
     100
     101        return size;
     102    }
     103
     104
     105    /* --- オフセット ---
     106
     107        ※グローバル変数で初期バッファがない場合は最上位ビットに1がセットされ、
     108        初期バッファの有無が識別される。
     109        (その後、スケジュール実行により、実際の配置に並び替えられる)*/
     110    int offset;
     111
     112    //コンストラクタ用パラメータ
     113    string paramStrForConstructor;
     114
     115    //レキシカルスコープ用
     116    int ScopeStartAddress;
     117    int ScopeEndAddress;
     118    int ScopeLevel;
     119    BOOL bLiving;
     120
     121
     122    int source_code_address;
     123};
     124
     125class Variables : public vector<Variable *>
     126{
     127public:
     128    Variables(){}
     129    ~Variables(){
     130        clear();
     131    }
     132
     133    void clear(){
     134        for( int i=0; i<(int)this->size(); i++ ){
     135            delete (*this)[i];
     136        }
     137
     138        vector<Variable *>::clear();
     139    }
     140
     141    bool DuplicateCheck( const string &varName ) const
     142    {
     143        //レキシカルスコープを考慮して重複判定
     144        for( int i=(int)this->size()-1; i>=0 ; i-- ){
     145            Variable &var = *(*this)[i];
     146            if( var.bLiving                                         //現在のスコープで有効なもの
     147                && var.ScopeLevel == obj_LexScopes.GetNowLevel()    //現在のスコープと同一レベル
     148                ){
     149                    if( var.GetName() == varName ){
     150                        return true;
     151                    }
     152            }
     153        }
     154        return false;
     155    }
     156
     157    const Variable *BackSearch( const string &varName ) const
     158    {
     159        //レキシカルスコープを考慮してバックサーチ
     160        for( int i=(int)this->size()-1; i>=0 ; i-- ){
     161            Variable &var = *(*this)[i];
     162            if( var.bLiving                                         //現在のスコープで有効なもの
     163                && var.ScopeLevel <= obj_LexScopes.GetNowLevel()    //現在のスコープレベルを超さないもの(Returnによる解放処理中を考慮)
     164                ){
     165                    if( var.GetName() == varName ){
     166                        return &var;
     167                    }
     168            }
     169        }
     170        return NULL;
     171    }
     172
     173    const Variable *Find( const string &varName )const
     174    {
     175        int max = (int)this->size();
     176        for( int i=0; i<max; i++ ){
     177            Variable *pVar = (*this)[i];
     178            if( pVar->GetName() == varName ){
     179                return pVar;
     180            }
     181        }
     182        return NULL;
     183    }
     184};
     185
     186extern Variables globalVars;
     187
     188
Note: See TracChangeset for help on using the changeset viewer.