Changeset 12df6fe


Ignore:
Timestamp:
Sep 19, 2022, 11:48:13 AM (18 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
Children:
4520b77e
Parents:
b0d9ff7
Message:

Fix an enumerator value bug; add basic tests for new features; save the current progress before merge

Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rb0d9ff7 r12df6fe  
    277277                std::list< Declaration* > &memb = enumDecl->get_members();
    278278                if (enumDecl->base && ! memb.empty()) {
    279                         unsigned long long last_val = -1;
     279                        unsigned long long last_val = -1; // if the first enum value has no explicit initializer,
     280                        // as other
    280281                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    281282                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     
    289290                                        if ( obj->get_init() ) {
    290291                                                obj->get_init()->accept( *visitor );
    291                                                 // last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival();
     292                                                last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival();
    292293                                        } else {
    293294                                                output << ++last_val;
  • src/Parser/TypeData.cc

    rb0d9ff7 r12df6fe  
    926926        list< Declaration * >::iterator members = ret->get_members().begin();
    927927        for ( const DeclarationNode * cur = td->enumeration.constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    928                 if ( ret->isTyped && cur->has_enumeratorValue() ) {
     928                if ( ret->isTyped && !ret->base && cur->has_enumeratorValue() ) {
    929929                        SemanticError( td->location, "Enumerator of enum(void) cannot have an explicit initializer value." );
    930930                } else if ( cur->has_enumeratorValue() ) {
  • src/ResolvExpr/Resolver.cc

    rb0d9ff7 r12df6fe  
    14781478                        // enum type is still incomplete at this point. Use `int` instead.
    14791479
    1480                         if (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base) {
     1480                        if ( auto enumBase = dynamic_cast< const ast::EnumInstType * >
     1481                                ( objectDecl->get_type() )->base->base ) {
    14811482                                objectDecl = fixObjectType( objectDecl, context );
    1482                                 const ast::Type * enumBase =  (dynamic_cast< const ast::EnumInstType * >( objectDecl->get_type() )->base->base.get());
    14831483                                currentObject = ast::CurrentObject{
    14841484                                        objectDecl->location,
     
    14931493                }
    14941494                else {
    1495                         if (!objectDecl->isTypeFixed) {
     1495                        if ( !objectDecl->isTypeFixed ) {
    14961496                                auto newDecl = fixObjectType(objectDecl, context);
    14971497                                auto mutDecl = mutate(newDecl);
  • tests/enum_tests/structEnum.cfa

    rb0d9ff7 r12df6fe  
    2424struct Point apple = first;
    2525// Failed due to Qualified name is currently unimplemented.
    26 struct Point banana = PointEnum.first;
    2726
    2827int main() {
    2928     PointEnum vals = second;
    3029     PointEnum val2;
    31      // P1
    32      val2 = vals;
     30     // The failing line: assignment
     31     // val2 = vals;
    3332
    3433     printf("%d %c\n", apple.x, apple.y);
Note: See TracChangeset for help on using the changeset viewer.