Changeset 3e54399


Ignore:
Timestamp:
Mar 10, 2022, 2:03:43 AM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
f238fcc2
Parents:
786c438
Message:

The compiler now will add a cast to base type for the usage of type enum; but it will fail because of violating some restrictions for the auto-gen functions. Need to investiage more

Location:
src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r786c438 r3e54399  
    305305        }
    306306
    307         const ast::Decl * visit( const ast::EnumDecl * node ) override final { // Marker: what is this for?
    308         // Called in ConverterNewToOld
     307        const ast::Decl * visit( const ast::EnumDecl * node ) override final {
    309308                if ( inCache( node ) ) return nullptr;
    310309                auto decl = new EnumDecl(
    311310                        node->name,
    312311                        get<Attribute>().acceptL( node->attributes ),
    313                         LinkageSpec::Spec( node->linkage.val )
     312                        LinkageSpec::Spec( node->linkage.val ),
     313                        get<Type>().accept1(node->base)
    314314                );
    315315                return aggregatePostamble( decl, node ); // Node info, including members, processed in aggregatePostamble
     
    27682768        }
    27692769
    2770         virtual void visit( const EnumInstType * old ) override final {
    2771                 ast::EnumInstType * ty;
     2770        virtual void visit( const EnumInstType * old ) override final { // Here is visiting the EnumInst Decl not the usage.
     2771                ast::EnumInstType * ty; 
    27722772                if ( old->baseEnum ) {
    27732773                        ty = new ast::EnumInstType{
  • src/AST/Decl.cpp

    r786c438 r3e54399  
    137137                       
    138138                // Handle typed enum by casting the value in (C++) compiler
    139                 if ( base ) { // A typed enum
    140                         if ( const BasicType * bt = dynamic_cast<const BasicType *>(base) ) {
    141                                 switch( bt->kind ) {
    142                                         case BasicType::Kind::Bool:     value = (bool) it->second; break;
    143                                         case BasicType::Kind::Char: value = (char) it->second; break;
    144                                         case BasicType::Kind::SignedChar: value = (signed char) it->second; break;
    145                                         case BasicType::Kind::UnsignedChar: value = (unsigned char) it->second; break;
    146                                         case BasicType::Kind::ShortSignedInt: value = (short signed int) it->second; break;
    147                                         case BasicType::Kind::SignedInt: value = (signed int) it->second; break;
    148                                         case BasicType::Kind::UnsignedInt: value = (unsigned int) it->second; break;
    149                                         case BasicType::Kind::LongSignedInt: value = (long signed int) it->second; break;
    150                                         case BasicType::Kind::LongUnsignedInt: value = (long unsigned int) it->second; break;
    151                                         case BasicType::Kind::LongLongSignedInt: value = (long long signed int) it->second; break;
    152                                         case BasicType::Kind::LongLongUnsignedInt: value = (long long unsigned int) it->second; break;
    153                                         // TODO: value should be able to handle long long unsigned int
     139                // if ( base ) { // A typed enum
     140                //      if ( const BasicType * bt = dynamic_cast<const BasicType *>(base) ) {
     141                //              switch( bt->kind ) {
     142                //                      case BasicType::Kind::Bool:     value = (bool) it->second; break;
     143                //                      case BasicType::Kind::Char: value = (char) it->second; break;
     144                //                      case BasicType::Kind::SignedChar: value = (signed char) it->second; break;
     145                //                      case BasicType::Kind::UnsignedChar: value = (unsigned char) it->second; break;
     146                //                      case BasicType::Kind::ShortSignedInt: value = (short signed int) it->second; break;
     147                //                      case BasicType::Kind::SignedInt: value = (signed int) it->second; break;
     148                //                      case BasicType::Kind::UnsignedInt: value = (unsigned int) it->second; break;
     149                //                      case BasicType::Kind::LongSignedInt: value = (long signed int) it->second; break;
     150                //                      case BasicType::Kind::LongUnsignedInt: value = (long unsigned int) it->second; break;
     151                //                      case BasicType::Kind::LongLongSignedInt: value = (long long signed int) it->second; break;
     152                //                      case BasicType::Kind::LongLongUnsignedInt: value = (long long unsigned int) it->second; break;
     153                //                      // TODO: value should be able to handle long long unsigned int
    154154
    155                                         default:
    156                                         value = it->second;
    157                                 }
    158                         }
    159                 } else {
     155                //                      default:
     156                //                      value = it->second;
     157                //              }
     158                //      }
     159                // } else {
    160160                        value = it->second;
    161                 }
     161                //}
    162162
    163163                return true;
  • src/AST/Decl.hpp

    r786c438 r3e54399  
    302302class EnumDecl final : public AggregateDecl {
    303303public:
    304         Type * base;
     304        ptr<Type> base;
    305305
    306306        EnumDecl( const CodeLocation& loc, const std::string& name,
  • src/CodeGen/CodeGenerator.cc

    r786c438 r3e54399  
    348348                                des->accept( *visitor );
    349349                        } else {
    350                                 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt
     350                                // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element
    351351                                output << "[";
    352352                                des->accept( *visitor );
     
    662662                        output << opInfo->symbol;
    663663                } else {
     664                        if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())
     665                        && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {
     666                                output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';
     667                        }
    664668                        output << mangleName( variableExpr->get_var() );
    665669                } // if
  • src/SymTab/Validate.cc

    r786c438 r3e54399  
    11381138                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
    11391139                } else if ( EnumInstType * enumDecl = dynamic_cast< EnumInstType * >( designatorType ) ) {
    1140                         declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
     1140                        // declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
     1141                        if (enumDecl->baseEnum) {
     1142                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage, enumDecl->baseEnum->base ) );
     1143                        } else {
     1144                                declsToAddBefore.push_back( new EnumDecl( enumDecl->name, noAttributes, tyDecl->linkage ) );
     1145                        }
    11411146                } // if
    11421147                return tyDecl->clone();
  • src/SynTree/Declaration.h

    r786c438 r3e54399  
    339339          LinkageSpec::Spec linkage = LinkageSpec::Cforall,
    340340          Type * baseType = nullptr ) : Parent( name, attributes, linkage ) , base( baseType ){}
    341         EnumDecl( const EnumDecl & other ) : Parent( other ) {}
     341        EnumDecl( const EnumDecl & other ) : Parent( other ), base( other.base ) {}
    342342
    343343        bool valueOf( Declaration * enumerator, long long int & value );
Note: See TracChangeset for help on using the changeset viewer.