Changeset 154672d for src


Ignore:
Timestamp:
Sep 7, 2023, 10:05:33 AM (2 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
0f8b1a7
Parents:
79b05224 (diff), 416b443 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ControlStruct/MultiLevelExit.cpp

    r79b05224 r154672d  
    1010// Created On       : Mon Nov  1 13:48:00 2021
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Mar 28  9:42:00 2022
    13 // Update Count     : 34
     12// Last Modified On : Wed Sep  6 12:00:00 2023
     13// Update Count     : 35
    1414//
    1515
     
    1818#include "AST/Pass.hpp"
    1919#include "AST/Stmt.hpp"
    20 #include "Common/CodeLocationTools.hpp"
    2120#include "LabelGeneratorNew.hpp"
    2221
     
    2625
    2726namespace ControlStruct {
     27
     28namespace {
     29
    2830class Entry {
    2931  public:
     
    3537                bool used = false;
    3638                Target( const Label & label ) : label( label ) {}
    37                 Target() : label( CodeLocation() ) {}
     39                Target() : label( CodeLocation(), "" ) {}
    3840        };
    3941        Target firstTarget;
     
    524526        // if continue is used insert a continue label into the back of the body of the loop
    525527        if ( entry.isContUsed() ) {
    526                 CompoundStmt * new_body = new CompoundStmt( body->location );
    527                 // {}
    528                 new_body->kids.push_back( body );
    529528                // {
    530529                //  body
     530                //  ContinueLabel: ;
    531531                // }
    532                 new_body->kids.push_back(
    533                         labelledNullStmt( body->location, entry.useContExit() ) );
    534                 // {
    535                 //  body
    536                 //  ContinueLabel: {}
    537                 // }
    538                 return new_body;
     532                return new CompoundStmt( body->location, {
     533                        body,
     534                        labelledNullStmt( body->location, entry.useContExit() ),
     535                } );
    539536        }
    540537
     
    620617}
    621618
     619} // namespace
     620
    622621const CompoundStmt * multiLevelExitUpdate(
    623         const CompoundStmt * stmt,
    624         const LabelToStmt & labelTable ) {
     622                const CompoundStmt * stmt, const LabelToStmt & labelTable ) {
    625623        // Must start in the body, so FunctionDecls can be a stopping point.
    626624        Pass<MultiLevelExitCore> visitor( labelTable );
    627         const CompoundStmt * ret = stmt->accept( visitor );
    628         // There are some unset code locations slipping in, possibly by Labels.
    629         const Node * node = localFillCodeLocations( ret->location, ret );
    630         return strict_dynamic_cast<const CompoundStmt *>( node );
    631 }
     625        return stmt->accept( visitor );
     626}
     627
    632628} // namespace ControlStruct
    633629
  • src/ResolvExpr/ResolveTypeof.cc

    r79b05224 r154672d  
    237237            // The designator I want to replace
    238238            const ast::Expr * designator = des->designators.at(0);
    239 
     239            // Stupid flag variable for development, to be removed
     240            bool mutated = false;
    240241            if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {
    241242                auto candidates = context.symtab.lookupId(designatorName->name);
     
    244245                if ( candidates.size() != 1 ) return mutDecl;
    245246                auto candidate = candidates.at(0);
    246                 if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {
     247                if ( const ast::EnumInstType * enumInst = dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type())) {
    247248                    // determine that is an enumInst, swap it with its const value
    248249                    assert( candidates.size() == 1 );
     
    250251                    // Need to iterate over all enum value to find the initializer to swap
    251252                    for ( size_t m = 0; m < baseEnum->members.size(); ++m ) {
     253                        const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
    252254                        if ( baseEnum->members.at(m)->name == designatorName->name ) {
    253                             const ast::ObjectDecl * mem = baseEnum->members.at(m).as<const ast::ObjectDecl>();
    254255                            assert(mem);
    255                             const ast::ConstantExpr * enumAsInit = ast::ConstantExpr::from_int(newDesination->location, m);
    256                             newDesination->designators.push_back( enumAsInit );
     256                            if ( mem->init ) {
     257                                const ast::SingleInit * memInit = mem->init.as<const ast::SingleInit>();
     258                                ast::Expr * initValue = shallowCopy( memInit->value.get() );
     259                                newDesination->designators.push_back( initValue );
     260                                mutated = true;
     261                            }
     262                            break;
    257263                        }
    258                     }
    259                     if ( newDesination->designators.size() == 0 ) {
    260                         SemanticError(des->location, "Resolution Error: Resolving array designation as Enum Instance value, but cannot find a desgination value");
    261264                    }
    262265                } else {
     
    266269                newDesination->designators.push_back( des->designators.at(0) );
    267270            }
    268             mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination);
     271            if ( mutated ) {
     272                mutListInit = ast::mutate_field_index(mutListInit, &ast::ListInit::designations, k, newDesination);
     273            }
    269274        }
    270275    }
  • src/ResolvExpr/Resolver.cc

    r79b05224 r154672d  
    988988                        }
    989989                };
     990
     991                struct ResolveDesignators_new final : public ast::WithShortCircuiting {
     992                        ResolveContext& context;
     993                        bool result = false;
     994
     995                        ResolveDesignators_new( ResolveContext& _context ): context{_context} {};
     996
     997                        void previsit( const ast::Node * ) {
     998                                // short circuit if we already know there are designations
     999                                if ( result ) visit_children = false;
     1000                        }
     1001
     1002                        void previsit( const ast::Designation * des ) {
     1003                                if ( result ) visit_children = false;
     1004                                else if ( ! des->designators.empty() ) {
     1005                                        if ( (des->designators.size() == 1) ) {
     1006                                                const ast::Expr * designator = des->designators.at(0);
     1007                                                if ( const ast::NameExpr * designatorName = dynamic_cast<const ast::NameExpr *>(designator) ) {
     1008                                                        auto candidates = context.symtab.lookupId(designatorName->name);
     1009                                                        for ( auto candidate : candidates ) {
     1010                                                                if ( dynamic_cast<const ast::EnumInstType *>(candidate.id->get_type()) ) {
     1011                                                                        result = true;
     1012                                                                        break;
     1013                                                                }
     1014                                                        }
     1015                                                }
     1016                                        }
     1017                                        visit_children = false;
     1018                                }
     1019                        }
     1020                };
    9901021        } // anonymous namespace
    9911022        /// Check if this expression is or includes a deleted expression
     
    15071538                                if ( InitTweak::tryConstruct( mutDecl ) && ( managedTypes.isManaged( mutDecl ) || ((! isInFunction() || mutDecl->storage.is_static ) && ! InitTweak::isConstExpr( mutDecl->init ) ) ) ) {
    15081539                                        // constructed objects cannot be designated
    1509                                         // if ( InitTweak::isDesignated( mutDecl->init ) ) SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
    15101540                                        if ( InitTweak::isDesignated( mutDecl->init ) ) {
    1511                                                 SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     1541                                                ast::Pass<ResolveDesignators_new> res( context );
     1542                                                maybe_accept( mutDecl->init.get(), res );
     1543                                                if ( !res.core.result ) {
     1544                                                        SemanticError( mutDecl, "Cannot include designations in the initializer for a managed Object. If this is really what you want, then initialize with @=.\n" );
     1545                                                }
    15121546                                        }
    15131547                                        // constructed objects should not have initializers nested too deeply
Note: See TracChangeset for help on using the changeset viewer.