Changeset 4559b34 for src


Ignore:
Timestamp:
Apr 3, 2022, 8:49:42 PM (2 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
92538ab
Parents:
3eb1653
Message:

Update the String Enum implementation. The declaration now can handles creating the enum decl. But the compilation fails when trying to create reference to the Enum. Need a way to resolve InstTypes?

Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r3eb1653 r4559b34  
    14681468                return strict_dynamic_cast< ast::Decl * >( node );
    14691469        }
    1470 
     1470       
    14711471        ConverterOldToNew() = default;
    14721472        ConverterOldToNew(const ConverterOldToNew &) = delete;
     
    27712771                ast::EnumInstType * ty;
    27722772                if ( old->baseEnum ) {
    2773                         ty = new ast::EnumInstType{
     2773                        ty = new ast::EnumInstType{ // Probably here: missing the specification of the base
    27742774                                GET_ACCEPT_1( baseEnum, EnumDecl ),
    27752775                                cv( old ),
  • src/AST/Decl.hpp

    r3eb1653 r4559b34  
    317317        const char * typeString() const override { return aggrString( Enum ); }
    318318
     319        bool isTyped() {return base && base.get();}
     320
    319321private:
    320322        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
  • src/AST/Print.cpp

    r3eb1653 r4559b34  
    210210                }
    211211
     212                auto ptrToEnum = dynamic_cast<const ast::EnumDecl *>(node);
     213                if ( ! short_mode && ptrToEnum && ptrToEnum->base ) {
     214                        os << endl << indent << ".. with (enum) base" << endl;
     215                        ++indent;
     216                        ptrToEnum->base->accept( *this );
     217                        --indent; 
     218                }
     219
    212220                os << endl;
    213221        }
  • src/Common/PassVisitor.impl.h

    r3eb1653 r4559b34  
    754754
    755755        // unlike structs, traits, and unions, enums inject their members into the global scope
    756         if ( node->base ) maybeAccept_impl( node->base, *this ); // Need this? Maybe not?
     756        // if ( node->base ) maybeAccept_impl( node->base, *this ); // Need this? Maybe not?
    757757        maybeAccept_impl( node->parameters, *this );
    758758        maybeAccept_impl( node->members   , *this );
  • src/ResolvExpr/Resolver.cc

    r3eb1653 r4559b34  
    14701470                        // enumerator initializers should not use the enum type to initialize, since the
    14711471                        // enum type is still incomplete at this point. Use `int` instead.
    1472                         objectDecl = fixObjectType(objectDecl, symtab);
    1473                         currentObject = ast::CurrentObject{
    1474                                 objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1472
     1473                        if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) { // const ast::PointerType &
     1474                                const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
     1475                                const ast::PointerType * enumBaseAsPtr = dynamic_cast<const ast::PointerType *>(enumBase);
     1476
     1477                                if ( enumBaseAsPtr ) {
     1478                                        const ast::Type * pointerBase = enumBaseAsPtr->base.get();
     1479                                        if ( dynamic_cast<const ast::BasicType *>(pointerBase) ) {
     1480                                                objectDecl = fixObjectType(objectDecl, symtab);
     1481                                                if (dynamic_cast<const ast::BasicType *>(pointerBase)->kind == ast::BasicType::Char)
     1482                                                currentObject = ast::CurrentObject{
     1483                                                        objectDecl->location,  new ast::PointerType{
     1484                                                                new ast::BasicType{ ast::BasicType::Char }
     1485                                                        } };
     1486                                        } else {
     1487                                                objectDecl = fixObjectType(objectDecl, symtab);
     1488                                                currentObject = ast::CurrentObject{objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1489                                        }
     1490                                }
     1491                        } else {
     1492                                objectDecl = fixObjectType(objectDecl, symtab);
     1493                                currentObject = ast::CurrentObject{
     1494                                        objectDecl->location, new ast::BasicType{ ast::BasicType::SignedInt } };
     1495                        }
     1496
    14751497                }
    14761498                else {
  • src/SymTab/Validate.cc

    r3eb1653 r4559b34  
    939939                                        // need to resolve enumerator initializers early so that other passes that determine if an expression is constexpr have the appropriate information.
    940940                                        SingleInit * init = strict_dynamic_cast<SingleInit *>( field->init );
    941                                         ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     941                                        if ( !enumDecl->base || dynamic_cast<BasicType *>(enumDecl->base))
     942                                                ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     943                                        else {
     944                                                if (dynamic_cast<PointerType *>(enumDecl->base)) {
     945                                                        auto typePtr = dynamic_cast<PointerType *>(enumDecl->base);
     946                                                        ResolvExpr::findSingleExpression( init->value,
     947                                                         new PointerType( Type::Qualifiers(), typePtr->base ), indexer );
     948                                                } else {
     949                                                        ResolvExpr::findSingleExpression( init->value, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), indexer );
     950                                                }
     951                                        }
     952                                       
    942953                                }
    943954                        }
     955
    944956                } // if
    945957        }
  • src/SynTree/AggregateDecl.cc

    r3eb1653 r4559b34  
    5959        } // if
    6060        os << " with body " << has_body();
    61 
    6261        if ( ! parameters.empty() ) {
    6362                os << endl << indent << "... with parameters" << endl;
     
    106105const char * EnumDecl::typeString() const { return aggrString( Enum ); }
    107106
     107void EnumDecl::print( std::ostream & os, Indenter indent ) const {
     108        AggregateDecl::print(os, indent);
     109        os << " with base? " << (base? "True" : "False") << std::endl;
     110        if ( base ) {
     111                os << "Base Type of Enum:" << std::endl;
     112                base->print(os, indent);
     113        }
     114        os <<  std::endl << "End of EnumDecl::print" << std::endl;
     115}
     116
    108117const char * TraitDecl::typeString() const { return aggrString( Trait ); }
    109118
  • src/SynTree/Declaration.h

    r3eb1653 r4559b34  
    290290        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    291291
    292         virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
     292        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    293293        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    294294  protected:
     
    352352        Type * base;
    353353        std::unordered_map< std::string, long long int > enumValues;
     354        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
    354355  private:
    355356        // std::unordered_map< std::string, long long int > enumValues;
Note: See TracChangeset for help on using the changeset viewer.