Changeset 5170d95 for src/SynTree
- Timestamp:
- Feb 19, 2019, 11:24:40 PM (6 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/SynTree
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.