Changeset 5170d95
- Timestamp:
- Feb 19, 2019, 11:24:40 PM (5 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, persistent-indexer, pthread-emulation, qualifiedEnum
- Children:
- 2ede686
- Parents:
- 45af7e1
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Resolver.cc
r45af7e1 r5170d95 10 10 // Created On : Sun May 17 12:17:01 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:13:43201913 // Update Count : 2 1612 // Last Modified On : Tue Feb 19 18:09:56 2019 13 // Update Count : 240 14 14 // 15 15 … … 53 53 } 54 54 55 void previsit( FunctionDecl * functionDecl );56 void postvisit( FunctionDecl * functionDecl );57 void previsit( ObjectDecl * objectDecll );55 void previsit( FunctionDecl * functionDecl ); 56 void postvisit( FunctionDecl * functionDecl ); 57 void previsit( ObjectDecl * objectDecll ); 58 58 void previsit( EnumDecl * enumDecl ); 59 59 void previsit( StaticAssertDecl * assertDecl ); … … 62 62 void previsit( PointerType * at ); 63 63 64 void previsit( ExprStmt * exprStmt );65 void previsit( AsmExpr * asmExpr );66 void previsit( AsmStmt * asmStmt );67 void previsit( IfStmt * ifStmt );68 void previsit( WhileStmt * whileStmt );69 void previsit( ForStmt * forStmt );70 void previsit( SwitchStmt * switchStmt );71 void previsit( CaseStmt * caseStmt );72 void previsit( BranchStmt * branchStmt );73 void previsit( ReturnStmt * returnStmt );74 void previsit( ThrowStmt * throwStmt );75 void previsit( CatchStmt * catchStmt );64 void previsit( ExprStmt * exprStmt ); 65 void previsit( AsmExpr * asmExpr ); 66 void previsit( AsmStmt * asmStmt ); 67 void previsit( IfStmt * ifStmt ); 68 void previsit( WhileStmt * whileStmt ); 69 void previsit( ForStmt * forStmt ); 70 void previsit( SwitchStmt * switchStmt ); 71 void previsit( CaseStmt * caseStmt ); 72 void previsit( BranchStmt * branchStmt ); 73 void previsit( ReturnStmt * returnStmt ); 74 void previsit( ThrowStmt * throwStmt ); 75 void previsit( CatchStmt * catchStmt ); 76 76 void previsit( WaitForStmt * stmt ); 77 77 78 void previsit( SingleInit * singleInit );79 void previsit( ListInit * listInit );80 void previsit( ConstructorInit * ctorInit );78 void previsit( SingleInit * singleInit ); 79 void previsit( ListInit * listInit ); 80 void previsit( ConstructorInit * ctorInit ); 81 81 private: 82 82 typedef std::list< Initializer * >::iterator InitIterator; … … 104 104 } 105 105 106 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) {106 void resolveDecl( Declaration * decl, const SymTab::Indexer & indexer ) { 107 107 PassVisitor<Resolver> resolver( indexer ); 108 108 maybeAccept( decl, resolver ); … … 148 148 }; 149 149 150 void finishExpr( Expression *& expr, const TypeEnvironment &env, TypeSubstitution * oldenv = nullptr ) {150 void finishExpr( Expression *& expr, const TypeEnvironment & env, TypeSubstitution * oldenv = nullptr ) { 151 151 expr->env = oldenv ? oldenv->clone() : new TypeSubstitution; 152 152 env.makeSubstitution( *expr->env ); … … 279 279 280 280 // used in resolveTypeof 281 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer ) {281 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer ) { 282 282 TypeEnvironment env; 283 283 return resolveInVoidContext( expr, indexer, env ); 284 284 } 285 285 286 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer &indexer, TypeEnvironment &env ) {286 Expression * resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer, TypeEnvironment & env ) { 287 287 // it's a property of the language that a cast expression has either 1 or 0 interpretations; if it has 0 288 288 // interpretations, an exception has already been thrown. 289 289 assertf( expr, "expected a non-null expression." ); 290 290 291 static CastExpr untyped( nullptr ); // cast to void292 untyped .location = expr->location;291 CastExpr * untyped = new CastExpr( expr ); // cast to void 292 untyped->location = expr->location; 293 293 294 294 // set up and resolve expression cast to void 295 untyped.arg = expr;296 295 Alternative choice; 297 findUnfinishedKindExpression( &untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() );296 findUnfinishedKindExpression( untyped, choice, indexer, "", standardAlternativeFilter, ResolvMode::withAdjustment() ); 298 297 CastExpr * castExpr = strict_dynamic_cast< CastExpr * >( choice.expr ); 298 assert( castExpr ); 299 299 env = std::move( choice.env ); 300 300 … … 304 304 305 305 // unlink the arg so that it isn't deleted twice at the end of the program 306 untyped .arg = nullptr;306 untyped->arg = nullptr; 307 307 return ret; 308 308 } 309 309 310 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {310 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 311 311 resetTyVarRenaming(); 312 312 TypeEnvironment env; … … 317 317 } 318 318 319 void findSingleExpression( Expression *& untyped, const SymTab::Indexer &indexer ) {319 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 320 320 findKindExpression( untyped, indexer, "", standardAlternativeFilter ); 321 321 } … … 336 336 if ( dynamic_cast< EnumInstType * >( type ) ) { 337 337 return true; 338 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) {338 } else if ( BasicType * bt = dynamic_cast< BasicType * >( type ) ) { 339 339 return bt->isInteger(); 340 340 } else if ( dynamic_cast< ZeroType* >( type ) != nullptr || dynamic_cast< OneType* >( type ) != nullptr ) { … … 345 345 } 346 346 347 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) {347 void findIntegralExpression( Expression *& untyped, const SymTab::Indexer & indexer ) { 348 348 findKindExpression( untyped, indexer, "condition", isIntegralType ); 349 349 } … … 401 401 } 402 402 403 void Resolver::previsit( ObjectDecl * objectDecl ) {403 void Resolver::previsit( ObjectDecl * objectDecl ) { 404 404 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 405 405 // class-variable initContext is changed multiple time because the LHS is analysed twice. … … 431 431 } 432 432 433 void Resolver::previsit( FunctionDecl * functionDecl ) {433 void Resolver::previsit( FunctionDecl * functionDecl ) { 434 434 #if 0 435 435 std::cerr << "resolver visiting functiondecl "; … … 441 441 } 442 442 443 void Resolver::postvisit( FunctionDecl * functionDecl ) {443 void Resolver::postvisit( FunctionDecl * functionDecl ) { 444 444 // default value expressions have an environment which shouldn't be there and trips up 445 445 // later passes. … … 466 466 } 467 467 468 void Resolver::previsit( ExprStmt * exprStmt ) {468 void Resolver::previsit( ExprStmt * exprStmt ) { 469 469 visit_children = false; 470 470 assertf( exprStmt->expr, "ExprStmt has null Expression in resolver" ); … … 472 472 } 473 473 474 void Resolver::previsit( AsmExpr * asmExpr ) {474 void Resolver::previsit( AsmExpr * asmExpr ) { 475 475 visit_children = false; 476 476 findVoidExpression( asmExpr->operand, indexer ); … … 480 480 } 481 481 482 void Resolver::previsit( AsmStmt * asmStmt ) {482 void Resolver::previsit( AsmStmt * asmStmt ) { 483 483 visit_children = false; 484 484 acceptAll( asmStmt->get_input(), *visitor ); … … 486 486 } 487 487 488 void Resolver::previsit( IfStmt * ifStmt ) {488 void Resolver::previsit( IfStmt * ifStmt ) { 489 489 findIntegralExpression( ifStmt->condition, indexer ); 490 490 } 491 491 492 void Resolver::previsit( WhileStmt * whileStmt ) {492 void Resolver::previsit( WhileStmt * whileStmt ) { 493 493 findIntegralExpression( whileStmt->condition, indexer ); 494 494 } 495 495 496 void Resolver::previsit( ForStmt * forStmt ) {496 void Resolver::previsit( ForStmt * forStmt ) { 497 497 if ( forStmt->condition ) { 498 498 findIntegralExpression( forStmt->condition, indexer ); … … 504 504 } 505 505 506 void Resolver::previsit( SwitchStmt * switchStmt ) {506 void Resolver::previsit( SwitchStmt * switchStmt ) { 507 507 GuardValue( currentObject ); 508 508 findIntegralExpression( switchStmt->condition, indexer ); … … 511 511 } 512 512 513 void Resolver::previsit( CaseStmt * caseStmt ) {513 void Resolver::previsit( CaseStmt * caseStmt ) { 514 514 if ( caseStmt->condition ) { 515 515 std::list< InitAlternative > initAlts = currentObject.getOptions(); … … 530 530 } 531 531 532 void Resolver::previsit( BranchStmt * branchStmt ) {532 void Resolver::previsit( BranchStmt * branchStmt ) { 533 533 visit_children = false; 534 534 // must resolve the argument for a computed goto … … 541 541 } 542 542 543 void Resolver::previsit( ReturnStmt * returnStmt ) {543 void Resolver::previsit( ReturnStmt * returnStmt ) { 544 544 visit_children = false; 545 545 if ( returnStmt->expr ) { … … 548 548 } 549 549 550 void Resolver::previsit( ThrowStmt * throwStmt ) {550 void Resolver::previsit( ThrowStmt * throwStmt ) { 551 551 visit_children = false; 552 552 // TODO: Replace *exception type with &exception type. … … 560 560 } 561 561 562 void Resolver::previsit( CatchStmt * catchStmt ) {562 void Resolver::previsit( CatchStmt * catchStmt ) { 563 563 if ( catchStmt->cond ) { 564 564 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); … … 724 724 725 725 } 726 catch( SemanticErrorException & e ) {726 catch( SemanticErrorException & e ) { 727 727 errors.append( e ); 728 728 } 729 729 } 730 730 } 731 catch( SemanticErrorException & e ) {731 catch( SemanticErrorException & e ) { 732 732 errors.append( e ); 733 733 } … … 781 781 } 782 782 783 void Resolver::previsit( SingleInit * singleInit ) {783 void Resolver::previsit( SingleInit * singleInit ) { 784 784 visit_children = false; 785 785 // resolve initialization using the possibilities as determined by the currentObject cursor … … 813 813 if ( PointerType * pt = dynamic_cast< PointerType *>( newExpr->get_result() ) ) { 814 814 if ( isCharType( pt->get_base() ) ) { 815 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) {815 if ( CastExpr * ce = dynamic_cast< CastExpr * >( newExpr ) ) { 816 816 // strip cast if we're initializing a char[] with a char *, 817 817 // e.g. char x[] = "hello"; … … 893 893 } 894 894 895 void Resolver::previsit( ConstructorInit * ctorInit ) {895 void Resolver::previsit( ConstructorInit * ctorInit ) { 896 896 visit_children = false; 897 897 // xxx - fallback init has been removed => remove fallbackInit function and remove complexity from FixInit and remove C-init from ConstructorInit -
src/ResolvExpr/Resolver.h
r45af7e1 r5170d95 10 10 // Created On : Sun May 17 12:18:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:36:57 201713 // Update Count : 312 // Last Modified On : Mon Feb 18 20:40:38 2019 13 // Update Count : 4 14 14 // 15 15 … … 29 29 /// Checks types and binds syntactic constructs to typed representations 30 30 void resolve( std::list< Declaration * > translationUnit ); 31 void resolveDecl( Declaration *, const SymTab::Indexer & indexer );32 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer );33 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer );34 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer );35 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer );31 void resolveDecl( Declaration *, const SymTab::Indexer & indexer ); 32 Expression *resolveInVoidContext( Expression * expr, const SymTab::Indexer & indexer ); 33 void findVoidExpression( Expression *& untyped, const SymTab::Indexer & indexer ); 34 void findSingleExpression( Expression *& untyped, const SymTab::Indexer & indexer ); 35 void findSingleExpression( Expression *& untyped, Type * type, const SymTab::Indexer & indexer ); 36 36 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 37 37 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ); -
src/SynTree/Expression.cc
r45af7e1 r5170d95 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 25 14:15:47 201713 // Update Count : 5412 // Last Modified On : Tue Feb 19 18:10:55 2019 13 // Update Count : 60 14 14 // 15 15 … … 33 33 #include "GenPoly/Lvalue.h" 34 34 35 void printInferParams( const InferredParams & inferParams, std::ostream & os, Indenter indent, int level ) {35 void printInferParams( const InferredParams & inferParams, std::ostream & os, Indenter indent, int level ) { 36 36 if ( ! inferParams.empty() ) { 37 37 os << indent << "with inferred parameters " << level << ":" << std::endl; … … 47 47 Expression::Expression() : result( 0 ), env( 0 ) {} 48 48 49 Expression::Expression( const Expression & other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ), resnSlots( other.resnSlots ) {}49 Expression::Expression( const Expression & other ) : BaseSyntaxNode( other ), result( maybeClone( other.result ) ), env( maybeClone( other.env ) ), extension( other.extension ), inferParams( other.inferParams ), resnSlots( other.resnSlots ) {} 50 50 51 51 void Expression::spliceInferParams( Expression * other ) { … … 62 62 } 63 63 64 void Expression::print( std::ostream & os, Indenter indent ) const {64 void Expression::print( std::ostream & os, Indenter indent ) const { 65 65 printInferParams( inferParams, os, indent+1, 0 ); 66 66 … … 79 79 } 80 80 81 ConstantExpr::ConstantExpr( const ConstantExpr & other) : Expression( other ), constant( other.constant ) {81 ConstantExpr::ConstantExpr( const ConstantExpr & other) : Expression( other ), constant( other.constant ) { 82 82 } 83 83 84 84 ConstantExpr::~ConstantExpr() {} 85 85 86 void ConstantExpr::print( std::ostream & os, Indenter indent ) const {86 void ConstantExpr::print( std::ostream & os, Indenter indent ) const { 87 87 os << "constant expression " ; 88 88 constant.print( os ); … … 124 124 } 125 125 126 VariableExpr::VariableExpr( const VariableExpr & other ) : Expression( other ), var( other.var ) {126 VariableExpr::VariableExpr( const VariableExpr & other ) : Expression( other ), var( other.var ) { 127 127 } 128 128 … … 137 137 } 138 138 139 void VariableExpr::print( std::ostream & os, Indenter indent ) const {139 void VariableExpr::print( std::ostream & os, Indenter indent ) const { 140 140 os << "Variable Expression: "; 141 141 var->printShort(os, indent); … … 143 143 } 144 144 145 SizeofExpr::SizeofExpr( Expression * expr_ ) :145 SizeofExpr::SizeofExpr( Expression * expr_ ) : 146 146 Expression(), expr(expr_), type(0), isType(false) { 147 147 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 148 148 } 149 149 150 SizeofExpr::SizeofExpr( Type * type_ ) :150 SizeofExpr::SizeofExpr( Type * type_ ) : 151 151 Expression(), expr(0), type(type_), isType(true) { 152 152 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 153 153 } 154 154 155 SizeofExpr::SizeofExpr( const SizeofExpr & other ) :155 SizeofExpr::SizeofExpr( const SizeofExpr & other ) : 156 156 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 157 157 } … … 162 162 } 163 163 164 void SizeofExpr::print( std::ostream & os, Indenter indent) const {164 void SizeofExpr::print( std::ostream & os, Indenter indent) const { 165 165 os << "Sizeof Expression on: "; 166 166 if (isType) type->print(os, indent+1); … … 169 169 } 170 170 171 AlignofExpr::AlignofExpr( Expression * expr_ ) :171 AlignofExpr::AlignofExpr( Expression * expr_ ) : 172 172 Expression(), expr(expr_), type(0), isType(false) { 173 173 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 174 174 } 175 175 176 AlignofExpr::AlignofExpr( Type * type_ ) :176 AlignofExpr::AlignofExpr( Type * type_ ) : 177 177 Expression(), expr(0), type(type_), isType(true) { 178 178 set_result( new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ) ); 179 179 } 180 180 181 AlignofExpr::AlignofExpr( const AlignofExpr & other ) :181 AlignofExpr::AlignofExpr( const AlignofExpr & other ) : 182 182 Expression( other ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 183 183 } … … 188 188 } 189 189 190 void AlignofExpr::print( std::ostream & os, Indenter indent) const {190 void AlignofExpr::print( std::ostream & os, Indenter indent) const { 191 191 os << "Alignof Expression on: "; 192 192 if (isType) type->print(os, indent+1); … … 195 195 } 196 196 197 UntypedOffsetofExpr::UntypedOffsetofExpr( Type * type, const std::string &member ) :197 UntypedOffsetofExpr::UntypedOffsetofExpr( Type * type, const std::string & member ) : 198 198 Expression(), type(type), member(member) { 199 199 assert( type ); … … 201 201 } 202 202 203 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr & other ) :203 UntypedOffsetofExpr::UntypedOffsetofExpr( const UntypedOffsetofExpr & other ) : 204 204 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 205 205 … … 208 208 } 209 209 210 void UntypedOffsetofExpr::print( std::ostream & os, Indenter indent) const {210 void UntypedOffsetofExpr::print( std::ostream & os, Indenter indent) const { 211 211 os << "Untyped Offsetof Expression on member " << member << " of "; 212 212 type->print(os, indent+1); … … 214 214 } 215 215 216 OffsetofExpr::OffsetofExpr( Type * type, DeclarationWithType *member ) :216 OffsetofExpr::OffsetofExpr( Type * type, DeclarationWithType * member ) : 217 217 Expression(), type(type), member(member) { 218 218 assert( member ); … … 221 221 } 222 222 223 OffsetofExpr::OffsetofExpr( const OffsetofExpr & other ) :223 OffsetofExpr::OffsetofExpr( const OffsetofExpr & other ) : 224 224 Expression( other ), type( maybeClone( other.type ) ), member( other.member ) {} 225 225 … … 228 228 } 229 229 230 void OffsetofExpr::print( std::ostream & os, Indenter indent) const {230 void OffsetofExpr::print( std::ostream & os, Indenter indent) const { 231 231 os << "Offsetof Expression on member " << member->name << " of "; 232 232 type->print(os, indent+1); … … 234 234 } 235 235 236 OffsetPackExpr::OffsetPackExpr( StructInstType * type ) : Expression(), type( type ) {236 OffsetPackExpr::OffsetPackExpr( StructInstType * type ) : Expression(), type( type ) { 237 237 assert( type ); 238 238 set_result( new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0, false, false ) ); 239 239 } 240 240 241 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr & other ) : Expression( other ), type( maybeClone( other.type ) ) {}241 OffsetPackExpr::OffsetPackExpr( const OffsetPackExpr & other ) : Expression( other ), type( maybeClone( other.type ) ) {} 242 242 243 243 OffsetPackExpr::~OffsetPackExpr() { delete type; } 244 244 245 void OffsetPackExpr::print( std::ostream & os, Indenter indent ) const {245 void OffsetPackExpr::print( std::ostream & os, Indenter indent ) const { 246 246 os << "Offset pack expression on "; 247 247 type->print(os, indent+1); … … 249 249 } 250 250 251 AttrExpr::AttrExpr( Expression * attr, Expression *expr_ ) :251 AttrExpr::AttrExpr( Expression * attr, Expression * expr_ ) : 252 252 Expression(), attr( attr ), expr(expr_), type(0), isType(false) { 253 253 } 254 254 255 AttrExpr::AttrExpr( Expression * attr, Type *type_ ) :255 AttrExpr::AttrExpr( Expression * attr, Type * type_ ) : 256 256 Expression(), attr( attr ), expr(0), type(type_), isType(true) { 257 257 } 258 258 259 AttrExpr::AttrExpr( const AttrExpr & other ) :259 AttrExpr::AttrExpr( const AttrExpr & other ) : 260 260 Expression( other ), attr( maybeClone( other.attr ) ), expr( maybeClone( other.expr ) ), type( maybeClone( other.type ) ), isType( other.isType ) { 261 261 } … … 267 267 } 268 268 269 void AttrExpr::print( std::ostream & os, Indenter indent) const {269 void AttrExpr::print( std::ostream & os, Indenter indent) const { 270 270 os << "Attr "; 271 271 attr->print( os, indent+1); … … 278 278 } 279 279 280 CastExpr::CastExpr( Expression * arg, Type *toType, bool isGenerated ) : Expression(),arg(arg), isGenerated( isGenerated ) {280 CastExpr::CastExpr( Expression * arg, Type * toType, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) { 281 281 set_result(toType); 282 282 } 283 283 284 CastExpr::CastExpr( Expression * arg, bool isGenerated ) : Expression(),arg(arg), isGenerated( isGenerated ) {284 CastExpr::CastExpr( Expression * arg, bool isGenerated ) : arg(arg), isGenerated( isGenerated ) { 285 285 set_result( new VoidType( Type::Qualifiers() ) ); 286 286 } 287 287 288 CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) {288 CastExpr::CastExpr( const CastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), isGenerated( other.isGenerated ) { 289 289 } 290 290 … … 293 293 } 294 294 295 void CastExpr::print( std::ostream & os, Indenter indent ) const {296 os << "Cast of:" << std::endl << indent+1;295 void CastExpr::print( std::ostream & os, Indenter indent ) const { 296 os << (isGenerated ? "Generated " : "Explicit ") << "Cast of:" << std::endl << indent+1; 297 297 arg->print(os, indent+1); 298 298 os << std::endl << indent << "... to:"; … … 306 306 } 307 307 308 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {309 } 310 311 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) {308 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) { 309 } 310 311 KeywordCastExpr::KeywordCastExpr( const KeywordCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ), target( other.target ) { 312 312 } 313 313 … … 327 327 } 328 328 329 void KeywordCastExpr::print( std::ostream & os, Indenter indent ) const {329 void KeywordCastExpr::print( std::ostream & os, Indenter indent ) const { 330 330 os << "Keyword Cast of:" << std::endl << indent+1; 331 331 arg->print(os, indent+1); … … 335 335 } 336 336 337 VirtualCastExpr::VirtualCastExpr( Expression * arg_, Type *toType ) : Expression(), arg(arg_) {337 VirtualCastExpr::VirtualCastExpr( Expression * arg_, Type * toType ) : Expression(), arg(arg_) { 338 338 set_result(toType); 339 339 } 340 340 341 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ) {341 VirtualCastExpr::VirtualCastExpr( const VirtualCastExpr & other ) : Expression( other ), arg( maybeClone( other.arg ) ) { 342 342 } 343 343 … … 346 346 } 347 347 348 void VirtualCastExpr::print( std::ostream & os, Indenter indent ) const {348 void VirtualCastExpr::print( std::ostream & os, Indenter indent ) const { 349 349 os << "Virtual Cast of:" << std::endl << indent+1; 350 350 arg->print(os, indent+1); … … 359 359 } 360 360 361 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression * aggregate ) :361 UntypedMemberExpr::UntypedMemberExpr( Expression * member, Expression * aggregate ) : 362 362 Expression(), member(member), aggregate(aggregate) { 363 363 assert( aggregate ); 364 364 } 365 365 366 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr & other ) :366 UntypedMemberExpr::UntypedMemberExpr( const UntypedMemberExpr & other ) : 367 367 Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) { 368 368 } … … 373 373 } 374 374 375 void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const {375 void UntypedMemberExpr::print( std::ostream & os, Indenter indent ) const { 376 376 os << "Untyped Member Expression, with field: " << std::endl << indent+1; 377 377 member->print(os, indent+1 ); … … 381 381 } 382 382 383 MemberExpr::MemberExpr( DeclarationWithType * member, Expression *aggregate ) :383 MemberExpr::MemberExpr( DeclarationWithType * member, Expression * aggregate ) : 384 384 Expression(), member(member), aggregate(aggregate) { 385 385 assert( member ); … … 395 395 } 396 396 397 MemberExpr::MemberExpr( const MemberExpr & other ) :397 MemberExpr::MemberExpr( const MemberExpr & other ) : 398 398 Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) { 399 399 } … … 404 404 } 405 405 406 void MemberExpr::print( std::ostream & os, Indenter indent ) const {406 void MemberExpr::print( std::ostream & os, Indenter indent ) const { 407 407 os << "Member Expression, with field:" << std::endl; 408 408 os << indent+1; … … 413 413 } 414 414 415 UntypedExpr::UntypedExpr( Expression * function, const std::list<Expression *> &args ) :415 UntypedExpr::UntypedExpr( Expression * function, const std::list<Expression *> & args ) : 416 416 Expression(), function(function), args(args) {} 417 417 418 UntypedExpr::UntypedExpr( const UntypedExpr & other ) :418 UntypedExpr::UntypedExpr( const UntypedExpr & other ) : 419 419 Expression( other ), function( maybeClone( other.function ) ) { 420 420 cloneAll( other.args, args ); … … 455 455 456 456 457 void UntypedExpr::print( std::ostream & os, Indenter indent ) const {457 void UntypedExpr::print( std::ostream & os, Indenter indent ) const { 458 458 os << "Applying untyped:" << std::endl; 459 459 os << indent+1; … … 469 469 } 470 470 471 NameExpr::NameExpr( const NameExpr & other ) : Expression( other ), name( other.name ) {471 NameExpr::NameExpr( const NameExpr & other ) : Expression( other ), name( other.name ) { 472 472 } 473 473 474 474 NameExpr::~NameExpr() {} 475 475 476 void NameExpr::print( std::ostream & os, Indenter indent ) const {476 void NameExpr::print( std::ostream & os, Indenter indent ) const { 477 477 os << "Name: " << get_name(); 478 478 Expression::print( os, indent ); 479 479 } 480 480 481 LogicalExpr::LogicalExpr( Expression * arg1_, Expression *arg2_, bool andp ) :481 LogicalExpr::LogicalExpr( Expression * arg1_, Expression * arg2_, bool andp ) : 482 482 Expression(), arg1(arg1_), arg2(arg2_), isAnd(andp) { 483 483 set_result( new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ); 484 484 } 485 485 486 LogicalExpr::LogicalExpr( const LogicalExpr & other ) :486 LogicalExpr::LogicalExpr( const LogicalExpr & other ) : 487 487 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), isAnd( other.isAnd ) { 488 488 } … … 493 493 } 494 494 495 void LogicalExpr::print( std::ostream & os, Indenter indent )const {495 void LogicalExpr::print( std::ostream & os, Indenter indent )const { 496 496 os << "Short-circuited operation (" << (isAnd ? "and" : "or") << ") on: "; 497 497 arg1->print(os); … … 504 504 Expression(), arg1(arg1), arg2(arg2), arg3(arg3) {} 505 505 506 ConditionalExpr::ConditionalExpr( const ConditionalExpr & other ) :506 ConditionalExpr::ConditionalExpr( const ConditionalExpr & other ) : 507 507 Expression( other ), arg1( maybeClone( other.arg1 ) ), arg2( maybeClone( other.arg2 ) ), arg3( maybeClone( other.arg3 ) ) { 508 508 } … … 514 514 } 515 515 516 void ConditionalExpr::print( std::ostream & os, Indenter indent ) const {516 void ConditionalExpr::print( std::ostream & os, Indenter indent ) const { 517 517 os << "Conditional expression on: " << std::endl << indent+1; 518 518 arg1->print( os, indent+1 ); … … 527 527 528 528 529 void AsmExpr::print( std::ostream & os, Indenter indent ) const {529 void AsmExpr::print( std::ostream & os, Indenter indent ) const { 530 530 os << "Asm Expression: " << std::endl; 531 531 if ( inout ) inout->print( os, indent+1 ); … … 555 555 } 556 556 557 void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const {557 void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const { 558 558 os << "Implicit Copy Constructor Expression: " << std::endl << indent+1; 559 559 callExpr->print( os, indent+1 ); … … 581 581 } 582 582 583 void ConstructorExpr::print( std::ostream & os, Indenter indent ) const {583 void ConstructorExpr::print( std::ostream & os, Indenter indent ) const { 584 584 os << "Constructor Expression: " << std::endl << indent+1; 585 585 callExpr->print( os, indent + 2 ); … … 594 594 } 595 595 596 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {}596 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {} 597 597 598 598 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 600 600 } 601 601 602 void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const {602 void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const { 603 603 os << "Compound Literal Expression: " << std::endl << indent+1; 604 604 result->print( os, indent+1 ); … … 608 608 } 609 609 610 RangeExpr::RangeExpr( Expression * low, Expression *high ) : low( low ), high( high ) {}611 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}612 void RangeExpr::print( std::ostream & os, Indenter indent ) const {610 RangeExpr::RangeExpr( Expression * low, Expression * high ) : low( low ), high( high ) {} 611 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 612 void RangeExpr::print( std::ostream & os, Indenter indent ) const { 613 613 os << "Range Expression: "; 614 614 low->print( os, indent ); … … 618 618 } 619 619 620 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) {620 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) { 621 621 computeResult(); 622 622 } 623 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) {623 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) { 624 624 cloneAll( other.returnDecls, returnDecls ); 625 625 cloneAll( other.dtors, dtors ); … … 650 650 } 651 651 } 652 void StmtExpr::print( std::ostream & os, Indenter indent ) const {652 void StmtExpr::print( std::ostream & os, Indenter indent ) const { 653 653 os << "Statement Expression: " << std::endl << indent+1; 654 654 statements->print( os, indent+1 ); … … 666 666 667 667 long long UniqueExpr::count = 0; 668 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {668 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) { 669 669 assert( expr ); 670 670 assert( count != -1 ); … … 674 674 } 675 675 } 676 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {676 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 677 677 } 678 678 UniqueExpr::~UniqueExpr() { … … 681 681 delete var; 682 682 } 683 void UniqueExpr::print( std::ostream & os, Indenter indent ) const {683 void UniqueExpr::print( std::ostream & os, Indenter indent ) const { 684 684 os << "Unique Expression with id:" << id << std::endl << indent+1; 685 685 expr->print( os, indent+1 ); -
src/SynTree/Expression.h
r45af7e1 r5170d95 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Sep 3 19:23:46 201713 // Update Count : 4 812 // Last Modified On : Mon Feb 18 18:29:51 2019 13 // Update Count : 49 14 14 // 15 15 … … 195 195 public: 196 196 Expression * arg; 197 bool isGenerated = true; // whether this cast appeared in the sourceprogram197 bool isGenerated = true; // cast generated implicitly by code generation or explicit in program 198 198 199 199 CastExpr( Expression * arg, bool isGenerated = true );
Note: See TracChangeset
for help on using the changeset viewer.