Changeset 77d2432
- Timestamp:
- Jul 24, 2019, 6:47:41 PM (5 years ago)
- 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:
- a92a4fe
- Parents:
- 83b52f1
- git-author:
- Peter A. Buhr <pabuhr@…> (07/24/19 18:46:00)
- git-committer:
- Peter A. Buhr <pabuhr@…> (07/24/19 18:47:41)
- Location:
- src/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/Eval.cc
r83b52f1 r77d2432 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 6 22:24:16 201813 // Update Count : 4012 // Last Modified On : Wed Jul 24 15:09:06 2019 13 // Update Count : 64 14 14 // 15 15 … … 27 27 bool valid = true; 28 28 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; } 31 31 32 void postvisit( ConstantExpr * expr ) { 32 void postvisit( const SizeofExpr * ) { 33 } 34 35 void postvisit( const ConstantExpr * expr ) { 33 36 value = expr->intValue(); 34 37 } 35 38 36 void postvisit( CastExpr * expr ) {39 void postvisit( const CastExpr * expr ) { 37 40 auto arg = eval(expr->arg); 38 41 valid = arg.second; … … 41 44 } 42 45 43 void postvisit( VariableExpr *expr ) {46 void postvisit( const VariableExpr * const expr ) { 44 47 if ( EnumInstType * inst = dynamic_cast<EnumInstType *>(expr->result) ) { 45 48 if ( EnumDecl * decl = inst->baseEnum ) { … … 52 55 } 53 56 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)); 56 59 if ( ! function || function->linkage != LinkageSpec::Intrinsic ) { valid = false; return; } 57 60 const std::string & fname = function->name; … … 94 97 void postvisit( const ast::ConstantExpr * expr ) { 95 98 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" ) ); 96 105 } 97 106 … … 145 154 }; 146 155 147 std::pair<long long int, bool> eval( Expression * expr) {156 std::pair<long long int, bool> eval( const Expression * expr) { 148 157 PassVisitor<EvalOld> ev; 149 158 if (expr) { -
src/Common/utility.h
r83b52f1 r77d2432 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun May 6 22:24:16 201813 // Update Count : 4 012 // Last Modified On : Wed Jul 24 14:28:19 2019 13 // Update Count : 41 14 14 // 15 15 … … 483 483 // ----------------------------------------------------------------------------- 484 484 /// evaluates expr as a long long int. If second is false, expr could not be evaluated 485 std::pair<long long int, bool> eval( Expression * expr);485 std::pair<long long int, bool> eval(const Expression * expr); 486 486 487 487 namespace ast {
Note: See TracChangeset
for help on using the changeset viewer.