Changeset 4a60488 for src/Common/Eval.cc


Ignore:
Timestamp:
Sep 27, 2019, 3:35:46 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
90ce35aa
Parents:
8e1467d (diff), 849720f (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:

Merged from master taking the lvalue changes to expression and everything before that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Eval.cc

    r8e1467d r4a60488  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May  6 22:24:16 2018
    13 // Update Count     : 40
     12// Last Modified On : Wed Jul 24 15:09:06 2019
     13// Update Count     : 64
    1414//
    1515
     
    2727        bool valid = true;
    2828
    29         void previsit( BaseSyntaxNode * ) { visit_children = false; }
    30         void postvisit( BaseSyntaxNode * ) { valid = false; }
     29        void previsit( const BaseSyntaxNode * ) { visit_children = false; }
     30        void postvisit( const BaseSyntaxNode * ) { valid = false; }
    3131
    32         void postvisit( ConstantExpr * expr ) {
     32        void postvisit( const SizeofExpr * ) {
     33        }
     34
     35        void postvisit( const ConstantExpr * expr ) {
    3336                value = expr->intValue();
    3437        }
    3538
    36         void postvisit( CastExpr * expr ) {
     39        void postvisit( const CastExpr * expr ) {
    3740                auto arg = eval(expr->arg);
    3841                valid = arg.second;
     
    4144        }
    4245
    43         void postvisit( VariableExpr * expr ) {
     46        void postvisit( const VariableExpr * const expr ) {
    4447                if ( EnumInstType * inst = dynamic_cast<EnumInstType *>(expr->result) ) {
    4548                        if ( EnumDecl * decl = inst->baseEnum ) {
     
    5255        }
    5356
    54         void postvisit( ApplicationExpr * expr ) {
    55                 DeclarationWithType * function = InitTweak::getFunction(expr);
     57        void postvisit( const ApplicationExpr * expr ) {
     58                DeclarationWithType * function = InitTweak::getFunction(const_cast<ApplicationExpr *>(expr));
    5659                if ( ! function || function->linkage != LinkageSpec::Intrinsic ) { valid = false; return; }
    5760                const std::string & fname = function->name;
     
    9497        void postvisit( const ast::ConstantExpr * expr ) {
    9598                value = expr->intValue();
     99        }
     100
     101        void postvisit( const ast::SizeofExpr * expr ) {
     102                if ( expr->expr ) value = eval(expr->expr).first;
     103                else if ( expr->type ) value = eval(expr->expr).first;
     104                else SemanticError( expr->location, ::toString( "Internal error: SizeofExpr has no expression or type value" ) );
    96105        }
    97106
     
    145154};
    146155
    147 std::pair<long long int, bool> eval(Expression * expr) {
     156std::pair<long long int, bool> eval( const Expression * expr) {
    148157        PassVisitor<EvalOld> ev;
    149158        if (expr) {
Note: See TracChangeset for help on using the changeset viewer.