Ignore:
Timestamp:
Mar 2, 2008, 4:36:33 AM (16 years ago)
Author:
dai_9181
Message:

Enumを大改修。Enumメンバ初期値にリテラル、定数、Enumメンバを指定できるようにした。また、エラー行数を正確に表示可能にした。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abdev/BasicCompiler_Common/Enum.h

    r322 r406  
    33#include <Namespace.h>
    44
    5 class CEnumMember{
     5class EnumMember
     6{
     7    std::string name;
     8    std::string value;
     9    int sourceIndex;
    610public:
    7     char *m_name;
    8     int m_value;
    9     CEnumMember(char *name,int value);
    10     ~CEnumMember();
     11    EnumMember( const std::string &name, const std::string &value, int sourceIndex )
     12        : name( name )
     13        , value( value )
     14        , sourceIndex( sourceIndex )
     15    {
     16    }
     17    const std::string &GetName() const
     18    {
     19        return name;
     20    }
     21    const std::string &GetValueStr() const
     22    {
     23        return value;
     24    }
     25    int GetSourceIndex() const
     26    {
     27        return sourceIndex;
     28    }
    1129};
    1230
    13 class CEnumParent{
    14     NamespaceScopes namespaceScopes;
    15     string name;
     31class EnumInfo
     32    : public Symbol
     33{
    1634
    1735    BOOL bConst;
    1836
    19     CEnumMember **ppobj_EnumMember;
    20     int iEnumMemberNum;
     37    std::vector<EnumMember> members;
    2138public:
    2239
    23     CEnumParent( const NamespaceScopes &namespaceScopes, const char *buffer,int nowLine);
    24     ~CEnumParent();
    25 
    26     const NamespaceScopes &GetNamespaceScopes() const
     40    EnumInfo( const NamespaceScopes &namespaceScopes, const std::string &name )
     41        : Symbol( namespaceScopes, name )
    2742    {
    28         return namespaceScopes;
    29     }
    30     const string &GetName() const
    31     {
    32         return name;
    3343    }
    3444
     45    const std::vector<EnumMember> &GetMembers() const
     46    {
     47        return members;
     48    }
     49
     50    void Collect( const char *buffer, int nowLine );
     51
     52    const EnumMember &GetEnumMember( const std::string &memberName ) const
     53    {
     54        BOOST_FOREACH( const EnumMember &member, members )
     55        {
     56            if( member.GetName() == memberName )
     57            {
     58                return member;
     59            }
     60        }
     61        throw;
     62    }
     63};
     64
     65class EnumInfoCollection
     66    : public std::vector<EnumInfo>
     67{
    3568public:
    36     static void InitEnum(void);
    37     static void DestroyEnum(void);
     69    const EnumInfo *Find( const Symbol &symbol ) const
     70    {
     71        const EnumInfoCollection &thisEnumInfoCollection = *this;
     72        BOOST_FOREACH( const EnumInfo &enumInfo, thisEnumInfoCollection )
     73        {
     74            if( enumInfo.IsEqualSymbol( symbol ) )
     75            {
     76                return &enumInfo;
     77            }
     78        }
     79        return NULL;
     80    };
    3881
    39     static char *GenerateSourceCode(void);
     82    void InitEnum(void);
     83    char *GenerateSourceCode(void);
    4084};
    41 extern CEnumParent **ppobj_EnumParent;
    42 extern int iEnumParentNum;
Note: See TracChangeset for help on using the changeset viewer.