Ignore:
Timestamp:
Jun 4, 2019, 6:39:23 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
c6a1e8a
Parents:
7564e10 (diff), 1346914 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    r7564e10 r67130fe  
    77// Resolver.cc --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Aaron B. Moss
    1010// Created On       : Sun May 17 12:17:01 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb 19 18:09:56 2019
    13 // Update Count     : 240
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Wed May 29 11:00:00 2019
     13// Update Count     : 241
    1414//
    1515
     
    2121#include "Alternative.h"                 // for Alternative, AltList
    2222#include "AlternativeFinder.h"           // for AlternativeFinder, resolveIn...
     23#include "CurrentObject.h"               // for CurrentObject
     24#include "RenameVars.h"                  // for RenameVars, global_renamer
     25#include "Resolver.h"
     26#include "ResolvMode.h"                  // for ResolvMode
     27#include "typeops.h"                     // for extractResultType
     28#include "Unify.h"                       // for unify
     29#include "AST/Pass.hpp"
     30#include "AST/SymbolTable.hpp"
    2331#include "Common/PassVisitor.h"          // for PassVisitor
    2432#include "Common/SemanticError.h"        // for SemanticError
    2533#include "Common/utility.h"              // for ValueGuard, group_iterate
    26 #include "CurrentObject.h"               // for CurrentObject
    2734#include "InitTweak/GenInit.h"
    2835#include "InitTweak/InitTweak.h"         // for isIntrinsicSingleArgCallStmt
    29 #include "RenameVars.h"                  // for RenameVars, global_renamer
    3036#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    31 #include "Resolver.h"
    32 #include "ResolvMode.h"                  // for ResolvMode
    3337#include "SymTab/Autogen.h"              // for SizeType
    3438#include "SymTab/Indexer.h"              // for Indexer
     
    4145#include "SynTree/Visitor.h"             // for acceptAll, maybeAccept
    4246#include "Tuples/Tuples.h"
    43 #include "typeops.h"                     // for extractResultType
    44 #include "Unify.h"                       // for unify
    4547#include "Validate/FindSpecialDecls.h"   // for SizeType
    4648
     
    4850
    4951namespace ResolvExpr {
    50         struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting, public WithStmtsToAdd {
    51                 Resolver() {}
    52                 Resolver( const SymTab::Indexer & other ) {
     52        struct Resolver_old final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver_old>, public WithShortCircuiting, public WithStmtsToAdd {
     53                Resolver_old() {}
     54                Resolver_old( const SymTab::Indexer & other ) {
    5355                        indexer = other;
    5456                }
     
    101103
    102104        void resolve( std::list< Declaration * > translationUnit ) {
    103                 PassVisitor<Resolver> resolver;
     105                PassVisitor<Resolver_old> resolver;
    104106                acceptAll( translationUnit, resolver );
    105107        }
    106108
    107109        void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {
    108                 PassVisitor<Resolver> resolver( indexer );
     110                PassVisitor<Resolver_old> resolver( indexer );
    109111                maybeAccept( decl, resolver );
    110112        }
     
    402404        }
    403405
    404         void Resolver::previsit( ObjectDecl * objectDecl ) {
    405                 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
    406                 // class-variable initContext is changed multiple time because the LHS is analysed twice.
    407                 // The second analysis changes initContext because of a function type can contain object
    408                 // declarations in the return and parameter types. So each value of initContext is
     406        void Resolver_old::previsit( ObjectDecl * objectDecl ) {
     407                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 
     408                // class-variable initContext is changed multiple time because the LHS is analysed twice. 
     409                // The second analysis changes initContext because of a function type can contain object 
     410                // declarations in the return and parameter types. So each value of initContext is 
    409411                // retained, so the type on the first analysis is preserved and used for selecting the RHS.
    410412                GuardValue( currentObject );
     
    418420
    419421        template< typename PtrType >
    420         void Resolver::handlePtrType( PtrType * type ) {
     422        void Resolver_old::handlePtrType( PtrType * type ) {
    421423                if ( type->get_dimension() ) {
    422424                        findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer );
     
    424426        }
    425427
    426         void Resolver::previsit( ArrayType * at ) {
     428        void Resolver_old::previsit( ArrayType * at ) {
    427429                handlePtrType( at );
    428430        }
    429431
    430         void Resolver::previsit( PointerType * pt ) {
     432        void Resolver_old::previsit( PointerType * pt ) {
    431433                handlePtrType( pt );
    432434        }
    433435
    434         void Resolver::previsit( FunctionDecl * functionDecl ) {
     436        void Resolver_old::previsit( FunctionDecl * functionDecl ) {
    435437#if 0
    436438                std::cerr << "resolver visiting functiondecl ";
     
    442444        }
    443445
    444         void Resolver::postvisit( FunctionDecl * functionDecl ) {
    445                 // default value expressions have an environment which shouldn't be there and trips up
     446        void Resolver_old::postvisit( FunctionDecl * functionDecl ) {
     447                // default value expressions have an environment which shouldn't be there and trips up 
    446448                // later passes.
    447449                // xxx - it might be necessary to somehow keep the information from this environment, but I
     
    457459        }
    458460
    459         void Resolver::previsit( EnumDecl * ) {
     461        void Resolver_old::previsit( EnumDecl * ) {
    460462                // in case we decide to allow nested enums
    461463                GuardValue( inEnumDecl );
     
    463465        }
    464466
    465         void Resolver::previsit( StaticAssertDecl * assertDecl ) {
     467        void Resolver_old::previsit( StaticAssertDecl * assertDecl ) {
    466468                findIntegralExpression( assertDecl->condition, indexer );
    467469        }
    468470
    469         void Resolver::previsit( ExprStmt * exprStmt ) {
     471        void Resolver_old::previsit( ExprStmt * exprStmt ) {
    470472                visit_children = false;
    471473                assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" );
     
    473475        }
    474476
    475         void Resolver::previsit( AsmExpr * asmExpr ) {
     477        void Resolver_old::previsit( AsmExpr * asmExpr ) {
    476478                visit_children = false;
    477479                findVoidExpression( asmExpr->operand, indexer );
     
    481483        }
    482484
    483         void Resolver::previsit( AsmStmt * asmStmt ) {
     485        void Resolver_old::previsit( AsmStmt * asmStmt ) {
    484486                visit_children = false;
    485487                acceptAll( asmStmt->get_input(), *visitor );
     
    487489        }
    488490
    489         void Resolver::previsit( IfStmt * ifStmt ) {
     491        void Resolver_old::previsit( IfStmt * ifStmt ) {
    490492                findIntegralExpression( ifStmt->condition, indexer );
    491493        }
    492494
    493         void Resolver::previsit( WhileStmt * whileStmt ) {
     495        void Resolver_old::previsit( WhileStmt * whileStmt ) {
    494496                findIntegralExpression( whileStmt->condition, indexer );
    495497        }
    496498
    497         void Resolver::previsit( ForStmt * forStmt ) {
     499        void Resolver_old::previsit( ForStmt * forStmt ) {
    498500                if ( forStmt->condition ) {
    499501                        findIntegralExpression( forStmt->condition, indexer );
     
    505507        }
    506508
    507         void Resolver::previsit( SwitchStmt * switchStmt ) {
     509        void Resolver_old::previsit( SwitchStmt * switchStmt ) {
    508510                GuardValue( currentObject );
    509511                findIntegralExpression( switchStmt->condition, indexer );
     
    512514        }
    513515
    514         void Resolver::previsit( CaseStmt * caseStmt ) {
     516        void Resolver_old::previsit( CaseStmt * caseStmt ) {
    515517                if ( caseStmt->condition ) {
    516518                        std::list< InitAlternative > initAlts = currentObject.getOptions();
     
    531533        }
    532534
    533         void Resolver::previsit( BranchStmt * branchStmt ) {
     535        void Resolver_old::previsit( BranchStmt * branchStmt ) {
    534536                visit_children = false;
    535537                // must resolve the argument for a computed goto
     
    542544        }
    543545
    544         void Resolver::previsit( ReturnStmt * returnStmt ) {
     546        void Resolver_old::previsit( ReturnStmt * returnStmt ) {
    545547                visit_children = false;
    546548                if ( returnStmt->expr ) {
     
    549551        }
    550552
    551         void Resolver::previsit( ThrowStmt * throwStmt ) {
     553        void Resolver_old::previsit( ThrowStmt * throwStmt ) {
    552554                visit_children = false;
    553555                // TODO: Replace *exception type with &exception type.
     
    561563        }
    562564
    563         void Resolver::previsit( CatchStmt * catchStmt ) {
     565        void Resolver_old::previsit( CatchStmt * catchStmt ) {
    564566                if ( catchStmt->cond ) {
    565567                        findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer );
     
    576578        }
    577579
    578         void Resolver::previsit( WaitForStmt * stmt ) {
     580        void Resolver_old::previsit( WaitForStmt * stmt ) {
    579581                visit_children = false;
    580582
     
    782784        }
    783785
    784         void Resolver::previsit( SingleInit * singleInit ) {
     786        void Resolver_old::previsit( SingleInit * singleInit ) {
    785787                visit_children = false;
    786788                // resolve initialization using the possibilities as determined by the currentObject cursor
     
    834836        }
    835837
    836         void Resolver::previsit( ListInit * listInit ) {
     838        void Resolver_old::previsit( ListInit * listInit ) {
    837839                visit_children = false;
    838840                // move cursor into brace-enclosed initializer-list
     
    869871
    870872        // ConstructorInit - fall back on C-style initializer
    871         void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
     873        void Resolver_old::fallbackInit( ConstructorInit * ctorInit ) {
    872874                // could not find valid constructor, or found an intrinsic constructor
    873875                // fall back on C-style initializer
     
    882884        void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) {
    883885                assert( ctorInit );
    884                 PassVisitor<Resolver> resolver( indexer );
     886                PassVisitor<Resolver_old> resolver( indexer );
    885887                ctorInit->accept( resolver );
    886888        }
     
    888890        void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) {
    889891                assert( stmtExpr );
    890                 PassVisitor<Resolver> resolver( indexer );
     892                PassVisitor<Resolver_old> resolver( indexer );
    891893                stmtExpr->accept( resolver );
    892894                stmtExpr->computeResult();
     
    894896        }
    895897
    896         void Resolver::previsit( ConstructorInit * ctorInit ) {
     898        void Resolver_old::previsit( ConstructorInit * ctorInit ) {
    897899                visit_children = false;
    898900                // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
     
    928930                // }
    929931        }
     932
     933        ///////////////////////////////////////////////////////////////////////////
     934        //
     935        // *** NEW RESOLVER ***
     936        //
     937        ///////////////////////////////////////////////////////////////////////////
     938
     939        class Resolver_new final
     940        : public ast::WithIndexer, public ast::WithGuards, public ast::WithVisitorRef<Resolver_new>,
     941          public ast::WithShortCircuiting, public ast::WithStmtsToAdd<> {
     942                 
     943        public:
     944                Resolver_new() = default;
     945                Resolver_new( const ast::SymbolTable & syms ) { /*symtab = syms;*/ }
     946
     947                void previsit( ast::FunctionDecl * functionDecl );
     948                ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl );
     949                void previsit( ast::ObjectDecl * objectDecl );
     950                void previsit( ast::EnumDecl * enumDecl );
     951                void previsit( ast::StaticAssertDecl * assertDecl );
     952
     953                void previsit( ast::ArrayType * at );
     954                void previsit( ast::PointerType * pt );
     955
     956                void previsit( ast::ExprStmt * exprStmt );
     957                void previsit( ast::AsmExpr * asmExpr );
     958                void previsit( ast::AsmStmt * asmStmt );
     959                void previsit( ast::IfStmt * ifStmt );
     960                void previsit( ast::WhileStmt * whileStmt );
     961                void previsit( ast::ForStmt * forStmt );
     962                void previsit( ast::SwitchStmt * switchStmt );
     963                void previsit( ast::CaseStmt * caseStmt );
     964                void previsit( ast::BranchStmt * branchStmt );
     965                void previsit( ast::ReturnStmt * returnStmt );
     966                void previsit( ast::ThrowStmt * throwStmt );
     967                void previsit( ast::CatchStmt * catchStmt );
     968                void previsit( ast::WaitForStmt * stmt );
     969
     970                void previsit( ast::SingleInit * singleInit );
     971                void previsit( ast::ListInit * listInit );
     972                void previsit( ast::ConstructorInit * ctorInit );
     973        };
     974
     975        void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) {
     976                ast::Pass<Resolver_new> resolver;
     977                accept_all( translationUnit, resolver );
     978        }
     979
     980        void previsit( ast::FunctionDecl * functionDecl ) {
     981                #warning unimplemented; Resolver port in progress
     982                (void)functionDecl;
     983                assert(false);
     984        }
     985
     986        ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl ) {
     987                #warning unimplemented; Resolver port in progress
     988                (void)functionDecl;
     989                assert(false);
     990                return nullptr;
     991        }
     992
     993        void previsit( ast::ObjectDecl * objectDecl ) {
     994                #warning unimplemented; Resolver port in progress
     995                (void)objectDecl;
     996                assert(false);
     997        }
     998
     999        void previsit( ast::EnumDecl * enumDecl ) {
     1000                #warning unimplemented; Resolver port in progress
     1001                (void)enumDecl;
     1002                assert(false);
     1003        }
     1004
     1005        void previsit( ast::StaticAssertDecl * assertDecl ) {
     1006                #warning unimplemented; Resolver port in progress
     1007                (void)assertDecl;
     1008                assert(false);
     1009        }
     1010
     1011        void previsit( ast::ArrayType * at ) {
     1012                #warning unimplemented; Resolver port in progress
     1013                (void)at;
     1014                assert(false);
     1015        }
     1016
     1017        void previsit( ast::PointerType * pt ) {
     1018                #warning unimplemented; Resolver port in progress
     1019                (void)pt;
     1020                assert(false);
     1021        }
     1022
     1023        void previsit( ast::ExprStmt * exprStmt ) {
     1024                #warning unimplemented; Resolver port in progress
     1025                (void)exprStmt;
     1026                assert(false);
     1027        }
     1028
     1029        void previsit( ast::AsmExpr * asmExpr ) {
     1030                #warning unimplemented; Resolver port in progress
     1031                (void)asmExpr;
     1032                assert(false);
     1033        }
     1034
     1035        void previsit( ast::AsmStmt * asmStmt ) {
     1036                #warning unimplemented; Resolver port in progress
     1037                (void)asmStmt;
     1038                assert(false);
     1039        }
     1040
     1041        void previsit( ast::IfStmt * ifStmt ) {
     1042                #warning unimplemented; Resolver port in progress
     1043                (void)ifStmt;
     1044                assert(false);
     1045        }
     1046
     1047        void previsit( ast::WhileStmt * whileStmt ) {
     1048                #warning unimplemented; Resolver port in progress
     1049                (void)whileStmt;
     1050                assert(false);
     1051        }
     1052
     1053        void previsit( ast::ForStmt * forStmt ) {
     1054                #warning unimplemented; Resolver port in progress
     1055                (void)forStmt;
     1056                assert(false);
     1057        }
     1058
     1059        void previsit( ast::SwitchStmt * switchStmt ) {
     1060                #warning unimplemented; Resolver port in progress
     1061                (void)switchStmt;
     1062                assert(false);
     1063        }
     1064
     1065        void previsit( ast::CaseStmt * caseStmt ) {
     1066                #warning unimplemented; Resolver port in progress
     1067                (void)caseStmt;
     1068                assert(false);
     1069        }
     1070
     1071        void previsit( ast::BranchStmt * branchStmt ) {
     1072                #warning unimplemented; Resolver port in progress
     1073                (void)branchStmt;
     1074                assert(false);
     1075        }
     1076
     1077        void previsit( ast::ReturnStmt * returnStmt ) {
     1078                #warning unimplemented; Resolver port in progress
     1079                (void)returnStmt;
     1080                assert(false);
     1081        }
     1082
     1083        void previsit( ast::ThrowStmt * throwStmt ) {
     1084                #warning unimplemented; Resolver port in progress
     1085                (void)throwStmt;
     1086                assert(false);
     1087        }
     1088
     1089        void previsit( ast::CatchStmt * catchStmt ) {
     1090                #warning unimplemented; Resolver port in progress
     1091                (void)catchStmt;
     1092                assert(false);
     1093        }
     1094
     1095        void previsit( ast::WaitForStmt * stmt ) {
     1096                #warning unimplemented; Resolver port in progress
     1097                (void)stmt;
     1098                assert(false);
     1099        }
     1100
     1101        void previsit( ast::SingleInit * singleInit ) {
     1102                #warning unimplemented; Resolver port in progress
     1103                (void)singleInit;
     1104                assert(false);
     1105        }
     1106
     1107        void previsit( ast::ListInit * listInit ) {
     1108                #warning unimplemented; Resolver port in progress
     1109                (void)listInit;
     1110                assert(false);
     1111        }
     1112
     1113        void previsit( ast::ConstructorInit * ctorInit ) {
     1114                #warning unimplemented; Resolver port in progress
     1115                (void)ctorInit;
     1116                assert(false);
     1117        }
     1118
    9301119} // namespace ResolvExpr
    9311120
Note: See TracChangeset for help on using the changeset viewer.