Ignore:
Timestamp:
May 30, 2019, 4:10:24 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
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:
8d70648
Parents:
eba615c
Message:

Stubs for new resolver, implementation of new indexer, type environment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Resolver.cc

    reba615c rd76c588  
    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
    4648using namespace std;
    4749
    4850namespace ResolvExpr {
    49         struct Resolver final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver>, public WithShortCircuiting, public WithStmtsToAdd {
    50                 Resolver() {}
    51                 Resolver( const SymTab::Indexer & other ) {
     51        struct Resolver_old final : public WithIndexer, public WithGuards, public WithVisitorRef<Resolver_old>, public WithShortCircuiting, public WithStmtsToAdd {
     52                Resolver_old() {}
     53                Resolver_old( const SymTab::Indexer & other ) {
    5254                        indexer = other;
    5355                }
     
    100102
    101103        void resolve( std::list< Declaration * > translationUnit ) {
    102                 PassVisitor<Resolver> resolver;
     104                PassVisitor<Resolver_old> resolver;
    103105                acceptAll( translationUnit, resolver );
    104106        }
    105107
    106108        void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {
    107                 PassVisitor<Resolver> resolver( indexer );
     109                PassVisitor<Resolver_old> resolver( indexer );
    108110                maybeAccept( decl, resolver );
    109111        }
     
    401403        }
    402404
    403         void Resolver::previsit( ObjectDecl * objectDecl ) {
     405        void Resolver_old::previsit( ObjectDecl * objectDecl ) {
    404406                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
    405407                // class-variable initContext is changed multiple time because the LHS is analysed twice.
     
    417419
    418420        template< typename PtrType >
    419         void Resolver::handlePtrType( PtrType * type ) {
     421        void Resolver_old::handlePtrType( PtrType * type ) {
    420422                if ( type->get_dimension() ) {
    421423                        findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );
     
    423425        }
    424426
    425         void Resolver::previsit( ArrayType * at ) {
     427        void Resolver_old::previsit( ArrayType * at ) {
    426428                handlePtrType( at );
    427429        }
    428430
    429         void Resolver::previsit( PointerType * pt ) {
     431        void Resolver_old::previsit( PointerType * pt ) {
    430432                handlePtrType( pt );
    431433        }
    432434
    433         void Resolver::previsit( FunctionDecl * functionDecl ) {
     435        void Resolver_old::previsit( FunctionDecl * functionDecl ) {
    434436#if 0
    435437                std::cerr << "resolver visiting functiondecl ";
     
    441443        }
    442444
    443         void Resolver::postvisit( FunctionDecl * functionDecl ) {
     445        void Resolver_old::postvisit( FunctionDecl * functionDecl ) {
    444446                // default value expressions have an environment which shouldn't be there and trips up
    445447                // later passes.
     
    456458        }
    457459
    458         void Resolver::previsit( EnumDecl * ) {
     460        void Resolver_old::previsit( EnumDecl * ) {
    459461                // in case we decide to allow nested enums
    460462                GuardValue( inEnumDecl );
     
    462464        }
    463465
    464         void Resolver::previsit( StaticAssertDecl * assertDecl ) {
     466        void Resolver_old::previsit( StaticAssertDecl * assertDecl ) {
    465467                findIntegralExpression( assertDecl->condition, indexer );
    466468        }
    467469
    468         void Resolver::previsit( ExprStmt * exprStmt ) {
     470        void Resolver_old::previsit( ExprStmt * exprStmt ) {
    469471                visit_children = false;
    470472                assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" );
     
    472474        }
    473475
    474         void Resolver::previsit( AsmExpr * asmExpr ) {
     476        void Resolver_old::previsit( AsmExpr * asmExpr ) {
    475477                visit_children = false;
    476478                findVoidExpression( asmExpr->operand, indexer );
     
    480482        }
    481483
    482         void Resolver::previsit( AsmStmt * asmStmt ) {
     484        void Resolver_old::previsit( AsmStmt * asmStmt ) {
    483485                visit_children = false;
    484486                acceptAll( asmStmt->get_input(), *visitor );
     
    486488        }
    487489
    488         void Resolver::previsit( IfStmt * ifStmt ) {
     490        void Resolver_old::previsit( IfStmt * ifStmt ) {
    489491                findIntegralExpression( ifStmt->condition, indexer );
    490492        }
    491493
    492         void Resolver::previsit( WhileStmt * whileStmt ) {
     494        void Resolver_old::previsit( WhileStmt * whileStmt ) {
    493495                findIntegralExpression( whileStmt->condition, indexer );
    494496        }
    495497
    496         void Resolver::previsit( ForStmt * forStmt ) {
     498        void Resolver_old::previsit( ForStmt * forStmt ) {
    497499                if ( forStmt->condition ) {
    498500                        findIntegralExpression( forStmt->condition, indexer );
     
    504506        }
    505507
    506         void Resolver::previsit( SwitchStmt * switchStmt ) {
     508        void Resolver_old::previsit( SwitchStmt * switchStmt ) {
    507509                GuardValue( currentObject );
    508510                findIntegralExpression( switchStmt->condition, indexer );
     
    511513        }
    512514
    513         void Resolver::previsit( CaseStmt * caseStmt ) {
     515        void Resolver_old::previsit( CaseStmt * caseStmt ) {
    514516                if ( caseStmt->condition ) {
    515517                        std::list< InitAlternative > initAlts = currentObject.getOptions();
     
    530532        }
    531533
    532         void Resolver::previsit( BranchStmt * branchStmt ) {
     534        void Resolver_old::previsit( BranchStmt * branchStmt ) {
    533535                visit_children = false;
    534536                // must resolve the argument for a computed goto
     
    541543        }
    542544
    543         void Resolver::previsit( ReturnStmt * returnStmt ) {
     545        void Resolver_old::previsit( ReturnStmt * returnStmt ) {
    544546                visit_children = false;
    545547                if ( returnStmt->expr ) {
     
    548550        }
    549551
    550         void Resolver::previsit( ThrowStmt * throwStmt ) {
     552        void Resolver_old::previsit( ThrowStmt * throwStmt ) {
    551553                visit_children = false;
    552554                // TODO: Replace *exception type with &exception type.
     
    560562        }
    561563
    562         void Resolver::previsit( CatchStmt * catchStmt ) {
     564        void Resolver_old::previsit( CatchStmt * catchStmt ) {
    563565                if ( catchStmt->cond ) {
    564566                        findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer );
     
    575577        }
    576578
    577         void Resolver::previsit( WaitForStmt * stmt ) {
     579        void Resolver_old::previsit( WaitForStmt * stmt ) {
    578580                visit_children = false;
    579581
     
    781783        }
    782784
    783         void Resolver::previsit( SingleInit * singleInit ) {
     785        void Resolver_old::previsit( SingleInit * singleInit ) {
    784786                visit_children = false;
    785787                // resolve initialization using the possibilities as determined by the currentObject cursor
     
    833835        }
    834836
    835         void Resolver::previsit( ListInit * listInit ) {
     837        void Resolver_old::previsit( ListInit * listInit ) {
    836838                visit_children = false;
    837839                // move cursor into brace-enclosed initializer-list
     
    868870
    869871        // ConstructorInit - fall back on C-style initializer
    870         void Resolver::fallbackInit( ConstructorInit * ctorInit ) {
     872        void Resolver_old::fallbackInit( ConstructorInit * ctorInit ) {
    871873                // could not find valid constructor, or found an intrinsic constructor
    872874                // fall back on C-style initializer
     
    881883        void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ) {
    882884                assert( ctorInit );
    883                 PassVisitor<Resolver> resolver( indexer );
     885                PassVisitor<Resolver_old> resolver( indexer );
    884886                ctorInit->accept( resolver );
    885887        }
     
    887889        void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ) {
    888890                assert( stmtExpr );
    889                 PassVisitor<Resolver> resolver( indexer );
     891                PassVisitor<Resolver_old> resolver( indexer );
    890892                stmtExpr->accept( resolver );
    891893                stmtExpr->computeResult();
     
    893895        }
    894896
    895         void Resolver::previsit( ConstructorInit * ctorInit ) {
     897        void Resolver_old::previsit( ConstructorInit * ctorInit ) {
    896898                visit_children = false;
    897899                // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit
     
    927929                // }
    928930        }
     931
     932        ///////////////////////////////////////////////////////////////////////////
     933        //
     934        // *** NEW RESOLVER ***
     935        //
     936        ///////////////////////////////////////////////////////////////////////////
     937
     938        class Resolver_new final
     939        : public ast::WithIndexer, public ast::WithGuards, public ast::WithVisitorRef<Resolver_new>,
     940          public ast::WithShortCircuiting, public ast::WithStmtsToAdd<> {
     941                 
     942        public:
     943                Resolver_new() = default;
     944                Resolver_new( const ast::SymbolTable & syms ) { /*symtab = syms;*/ }
     945
     946                void previsit( ast::FunctionDecl * functionDecl );
     947                ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl );
     948                void previsit( ast::ObjectDecl * objectDecl );
     949                void previsit( ast::EnumDecl * enumDecl );
     950                void previsit( ast::StaticAssertDecl * assertDecl );
     951
     952                void previsit( ast::ArrayType * at );
     953                void previsit( ast::PointerType * pt );
     954
     955                void previsit( ast::ExprStmt * exprStmt );
     956                void previsit( ast::AsmExpr * asmExpr );
     957                void previsit( ast::AsmStmt * asmStmt );
     958                void previsit( ast::IfStmt * ifStmt );
     959                void previsit( ast::WhileStmt * whileStmt );
     960                void previsit( ast::ForStmt * forStmt );
     961                void previsit( ast::SwitchStmt * switchStmt );
     962                void previsit( ast::CaseStmt * caseStmt );
     963                void previsit( ast::BranchStmt * branchStmt );
     964                void previsit( ast::ReturnStmt * returnStmt );
     965                void previsit( ast::ThrowStmt * throwStmt );
     966                void previsit( ast::CatchStmt * catchStmt );
     967                void previsit( ast::WaitForStmt * stmt );
     968
     969                void previsit( ast::SingleInit * singleInit );
     970                void previsit( ast::ListInit * listInit );
     971                void previsit( ast::ConstructorInit * ctorInit );
     972        };
     973
     974        void resolve( std::list< ast::ptr<ast::Decl> >& translationUnit ) {
     975                ast::Pass<Resolver_new> resolver;
     976                accept_all( translationUnit, resolver );
     977        }
     978
     979        void previsit( ast::FunctionDecl * functionDecl ) {
     980                #warning unimplemented; Resolver port in progress
     981                (void)functionDecl;
     982                assert(false);
     983        }
     984
     985        ast::DeclWithType * postvisit( ast::FunctionDecl * functionDecl ) {
     986                #warning unimplemented; Resolver port in progress
     987                (void)functionDecl;
     988                assert(false);
     989                return nullptr;
     990        }
     991
     992        void previsit( ast::ObjectDecl * objectDecl ) {
     993                #warning unimplemented; Resolver port in progress
     994                (void)objectDecl;
     995                assert(false);
     996        }
     997
     998        void previsit( ast::EnumDecl * enumDecl ) {
     999                #warning unimplemented; Resolver port in progress
     1000                (void)enumDecl;
     1001                assert(false);
     1002        }
     1003
     1004        void previsit( ast::StaticAssertDecl * assertDecl ) {
     1005                #warning unimplemented; Resolver port in progress
     1006                (void)assertDecl;
     1007                assert(false);
     1008        }
     1009
     1010        void previsit( ast::ArrayType * at ) {
     1011                #warning unimplemented; Resolver port in progress
     1012                (void)at;
     1013                assert(false);
     1014        }
     1015
     1016        void previsit( ast::PointerType * pt ) {
     1017                #warning unimplemented; Resolver port in progress
     1018                (void)pt;
     1019                assert(false);
     1020        }
     1021
     1022        void previsit( ast::ExprStmt * exprStmt ) {
     1023                #warning unimplemented; Resolver port in progress
     1024                (void)exprStmt;
     1025                assert(false);
     1026        }
     1027
     1028        void previsit( ast::AsmExpr * asmExpr ) {
     1029                #warning unimplemented; Resolver port in progress
     1030                (void)asmExpr;
     1031                assert(false);
     1032        }
     1033
     1034        void previsit( ast::AsmStmt * asmStmt ) {
     1035                #warning unimplemented; Resolver port in progress
     1036                (void)asmStmt;
     1037                assert(false);
     1038        }
     1039
     1040        void previsit( ast::IfStmt * ifStmt ) {
     1041                #warning unimplemented; Resolver port in progress
     1042                (void)ifStmt;
     1043                assert(false);
     1044        }
     1045
     1046        void previsit( ast::WhileStmt * whileStmt ) {
     1047                #warning unimplemented; Resolver port in progress
     1048                (void)whileStmt;
     1049                assert(false);
     1050        }
     1051
     1052        void previsit( ast::ForStmt * forStmt ) {
     1053                #warning unimplemented; Resolver port in progress
     1054                (void)forStmt;
     1055                assert(false);
     1056        }
     1057
     1058        void previsit( ast::SwitchStmt * switchStmt ) {
     1059                #warning unimplemented; Resolver port in progress
     1060                (void)switchStmt;
     1061                assert(false);
     1062        }
     1063
     1064        void previsit( ast::CaseStmt * caseStmt ) {
     1065                #warning unimplemented; Resolver port in progress
     1066                (void)caseStmt;
     1067                assert(false);
     1068        }
     1069
     1070        void previsit( ast::BranchStmt * branchStmt ) {
     1071                #warning unimplemented; Resolver port in progress
     1072                (void)branchStmt;
     1073                assert(false);
     1074        }
     1075
     1076        void previsit( ast::ReturnStmt * returnStmt ) {
     1077                #warning unimplemented; Resolver port in progress
     1078                (void)returnStmt;
     1079                assert(false);
     1080        }
     1081
     1082        void previsit( ast::ThrowStmt * throwStmt ) {
     1083                #warning unimplemented; Resolver port in progress
     1084                (void)throwStmt;
     1085                assert(false);
     1086        }
     1087
     1088        void previsit( ast::CatchStmt * catchStmt ) {
     1089                #warning unimplemented; Resolver port in progress
     1090                (void)catchStmt;
     1091                assert(false);
     1092        }
     1093
     1094        void previsit( ast::WaitForStmt * stmt ) {
     1095                #warning unimplemented; Resolver port in progress
     1096                (void)stmt;
     1097                assert(false);
     1098        }
     1099
     1100        void previsit( ast::SingleInit * singleInit ) {
     1101                #warning unimplemented; Resolver port in progress
     1102                (void)singleInit;
     1103                assert(false);
     1104        }
     1105
     1106        void previsit( ast::ListInit * listInit ) {
     1107                #warning unimplemented; Resolver port in progress
     1108                (void)listInit;
     1109                assert(false);
     1110        }
     1111
     1112        void previsit( ast::ConstructorInit * ctorInit ) {
     1113                #warning unimplemented; Resolver port in progress
     1114                (void)ctorInit;
     1115                assert(false);
     1116        }
     1117
    9291118} // namespace ResolvExpr
    9301119
Note: See TracChangeset for help on using the changeset viewer.