Changeset 933f32f for src/SynTree
- Timestamp:
- May 24, 2019, 10:19:41 AM (6 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- d908563
- Parents:
- 6a9d4b4 (diff), 292642a (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. - Location:
- src/SynTree
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AddressExpr.cc
r6a9d4b4 r933f32f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 23:54:44 2015 11 // Last Modified By : Rob Schluntz12 // Last Modified On : T ue Apr 26 12:35:13 201613 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 28 13:13:38 2019 13 // Update Count : 10 14 14 // 15 15 … … 47 47 } else { 48 48 // taking address of non-lvalue -- must be a reference, loses one layer of reference 49 ReferenceType * refType = strict_dynamic_cast< ReferenceType * >( arg->result ); 50 set_result( addrType( refType->base ) ); 49 if ( ReferenceType * refType = dynamic_cast< ReferenceType * >( arg->result ) ) { 50 set_result( addrType( refType->base ) ); 51 } else { 52 SemanticError( arg->result, "Attempt to take address of non-lvalue expression: " ); 53 } // if 51 54 } 52 55 // result of & is never an lvalue -
src/SynTree/Attribute.cc
r6a9d4b4 r933f32f 21 21 #include "Expression.h" // for Expression 22 22 23 Attribute::Attribute( const Attribute &other ) : name( other.name ) {23 Attribute::Attribute( const Attribute &other ) : BaseSyntaxNode( other ), name( other.name ) { 24 24 cloneAll( other.parameters, parameters ); 25 25 } -
src/SynTree/BaseSyntaxNode.h
r6a9d4b4 r933f32f 18 18 #include "Common/CodeLocation.h" 19 19 #include "Common/Indenter.h" 20 #include "Common/Stats.h" 21 20 22 class Visitor; 21 23 class Mutator; … … 23 25 class BaseSyntaxNode { 24 26 public: 27 static Stats::Counters::SimpleCounter* new_nodes; 28 25 29 CodeLocation location; 30 31 BaseSyntaxNode() { ++*new_nodes; } 32 BaseSyntaxNode( const BaseSyntaxNode& o ) : location(o.location) { ++*new_nodes; } 26 33 27 34 virtual ~BaseSyntaxNode() {} -
src/SynTree/BasicType.cc
r6a9d4b4 r933f32f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 25 14:14:03 201713 // Update Count : 1 112 // Last Modified On : Thu Jan 31 21:37:36 2019 13 // Update Count : 12 14 14 // 15 15 … … 30 30 31 31 bool BasicType::isInteger() const { 32 return kind <= UnsignedInt128; 33 #if 0 32 34 switch ( kind ) { 33 35 case Bool: … … 63 65 assert( false ); 64 66 return false; 67 #endif 65 68 } 66 69 -
src/SynTree/Constant.cc
r6a9d4b4 r933f32f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Spt 28 14:49:00 201813 // Update Count : 3 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:11:22 2019 13 // Update Count : 32 14 14 // 15 15 … … 25 25 Constant::Constant( Type * type, std::string rep, double val ) : type( type ), rep( rep ), val( val ) {} 26 26 27 Constant::Constant( const Constant &other ) : rep( other.rep ), val( other.val ) {27 Constant::Constant( const Constant &other ) : BaseSyntaxNode( other ), rep( other.rep ), val( other.val ) { 28 28 type = other.type->clone(); 29 29 } -
src/SynTree/Declaration.cc
r6a9d4b4 r933f32f 31 31 32 32 Declaration::Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage ) 33 : name( name ), linkage( linkage ), storageClasses( scs ), uniqueId( 0) {33 : name( name ), linkage( linkage ), uniqueId( 0 ), storageClasses( scs ) { 34 34 } 35 35 36 36 Declaration::Declaration( const Declaration &other ) 37 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), storageClasses( other.storageClasses ), uniqueId( other.uniqueId) {37 : BaseSyntaxNode( other ), name( other.name ), linkage( other.linkage ), extension( other.extension ), uniqueId( other.uniqueId ), storageClasses( other.storageClasses ) { 38 38 } 39 39 -
src/SynTree/Declaration.h
r6a9d4b4 r933f32f 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Sep 3 19:24:06 201713 // Update Count : 13 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Thr May 2 10:47:00 2019 13 // Update Count : 135 14 14 // 15 15 … … 19 19 #include <iosfwd> // for ostream 20 20 #include <list> // for list 21 #include <unordered_map> // for unordered_map 21 22 #include <string> // for string, operator+, allocator, to_string 22 23 … … 70 71 static Declaration *declFromId( UniqueId id ); 71 72 72 private: 73 UniqueId uniqueId; 73 74 Type::StorageClasses storageClasses; 74 UniqueId uniqueId; 75 private: 75 76 }; 76 77 … … 166 167 CompoundStmt *get_statements() const { return statements; } 167 168 void set_statements( CompoundStmt *newValue ) { statements = newValue; } 169 bool has_body() const { return NULL != statements; } 168 170 169 171 static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements ); … … 211 213 TypeDecl::Kind kind; 212 214 bool isComplete; 215 213 216 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {} 214 217 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {} 215 218 Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {} 219 Data( const Data& d1, const Data& d2 ) 220 : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {} 221 216 222 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; } 217 223 bool operator!=(const Data & other) const { return !(*this == other);} … … 239 245 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 240 246 241 private:242 247 Kind kind; 243 248 }; … … 300 305 virtual void accept( Visitor &v ) override { v.visit( this ); } 301 306 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 302 private:303 307 DeclarationNode::Aggregate kind; 308 private: 304 309 virtual std::string typeString() const override; 305 310 }; … … 330 335 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 331 336 private: 332 std:: map< std::string, long long int > enumValues;337 std::unordered_map< std::string, long long int > enumValues; 333 338 virtual std::string typeString() const override; 334 339 }; -
src/SynTree/Expression.cc
r6a9d4b4 r933f32f 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 ); … … 549 549 } 550 550 551 void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const {551 void ImplicitCopyCtorExpr::print( std::ostream & os, Indenter indent ) const { 552 552 os << "Implicit Copy Constructor Expression: " << std::endl << indent+1; 553 553 callExpr->print( os, indent+1 ); … … 570 570 } 571 571 572 void ConstructorExpr::print( std::ostream & os, Indenter indent ) const {572 void ConstructorExpr::print( std::ostream & os, Indenter indent ) const { 573 573 os << "Constructor Expression: " << std::endl << indent+1; 574 574 callExpr->print( os, indent + 2 ); … … 583 583 } 584 584 585 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {}585 CompoundLiteralExpr::CompoundLiteralExpr( const CompoundLiteralExpr & other ) : Expression( other ), initializer( other.initializer->clone() ) {} 586 586 587 587 CompoundLiteralExpr::~CompoundLiteralExpr() { … … 589 589 } 590 590 591 void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const {591 void CompoundLiteralExpr::print( std::ostream & os, Indenter indent ) const { 592 592 os << "Compound Literal Expression: " << std::endl << indent+1; 593 593 result->print( os, indent+1 ); … … 597 597 } 598 598 599 RangeExpr::RangeExpr( Expression * low, Expression *high ) : low( low ), high( high ) {}600 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {}601 void RangeExpr::print( std::ostream & os, Indenter indent ) const {599 RangeExpr::RangeExpr( Expression * low, Expression * high ) : low( low ), high( high ) {} 600 RangeExpr::RangeExpr( const RangeExpr & other ) : Expression( other ), low( other.low->clone() ), high( other.high->clone() ) {} 601 void RangeExpr::print( std::ostream & os, Indenter indent ) const { 602 602 os << "Range Expression: "; 603 603 low->print( os, indent ); … … 607 607 } 608 608 609 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) {609 StmtExpr::StmtExpr( CompoundStmt * statements ) : statements( statements ) { 610 610 computeResult(); 611 611 } 612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) {612 StmtExpr::StmtExpr( const StmtExpr & other ) : Expression( other ), statements( other.statements->clone() ) { 613 613 cloneAll( other.returnDecls, returnDecls ); 614 614 cloneAll( other.dtors, dtors ); … … 639 639 } 640 640 } 641 void StmtExpr::print( std::ostream & os, Indenter indent ) const {641 void StmtExpr::print( std::ostream & os, Indenter indent ) const { 642 642 os << "Statement Expression: " << std::endl << indent+1; 643 643 statements->print( os, indent+1 ); … … 655 655 656 656 long long UniqueExpr::count = 0; 657 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) {657 UniqueExpr::UniqueExpr( Expression * expr, long long idVal ) : expr( expr ), object( nullptr ), var( nullptr ), id( idVal ) { 658 658 assert( expr ); 659 659 assert( count != -1 ); … … 663 663 } 664 664 } 665 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) {665 UniqueExpr::UniqueExpr( const UniqueExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ), object( maybeClone( other.object ) ), var( maybeClone( other.var ) ), id( other.id ) { 666 666 } 667 667 UniqueExpr::~UniqueExpr() { … … 670 670 delete var; 671 671 } 672 void UniqueExpr::print( std::ostream & os, Indenter indent ) const {672 void UniqueExpr::print( std::ostream & os, Indenter indent ) const { 673 673 os << "Unique Expression with id:" << id << std::endl << indent+1; 674 674 expr->print( os, indent+1 ); -
src/SynTree/Expression.h
r6a9d4b4 r933f32f 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 ); -
src/SynTree/Label.h
r6a9d4b4 r933f32f 35 35 operator std::string() const { return name; } 36 36 bool empty() { return name.empty(); } 37 private: 37 38 38 std::string name; 39 39 Statement * labelled; -
src/SynTree/Mutator.h
r6a9d4b4 r933f32f 121 121 virtual Initializer * mutate( ConstructorInit * ctorInit ) = 0 ; 122 122 123 virtual Subrange * mutate( Subrange * subrange ) = 0;124 125 123 virtual Constant * mutate( Constant * constant ) = 0; 126 124 -
src/SynTree/Statement.h
r6a9d4b4 r933f32f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Mar 8 14:53:02 201813 // Update Count : 7812 // Last Modified On : Tue Mar 12 09:01:53 2019 13 // Update Count : 83 14 14 // 15 15 … … 19 19 #include <list> // for list 20 20 #include <memory> // for allocator 21 #include <vector> 21 #include <vector> // for vector 22 22 23 23 #include "BaseSyntaxNode.h" // for BaseSyntaxNode … … 43 43 const std::list<Label> & get_labels() const { return labels; } 44 44 45 virtual Statement * clone() const override = 0;46 virtual void accept( Visitor & v ) override = 0;47 virtual Statement * acceptMutator( Mutator &m ) override = 0;48 virtual void print( std::ostream & os, Indenter indent = {} ) const override;45 virtual Statement * clone() const override = 0; 46 virtual void accept( Visitor & v ) override = 0; 47 virtual Statement * acceptMutator( Mutator & m ) override = 0; 48 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 49 49 }; 50 50 … … 55 55 CompoundStmt(); 56 56 CompoundStmt( std::list<Statement *> stmts ); 57 CompoundStmt( const CompoundStmt & other );57 CompoundStmt( const CompoundStmt & other ); 58 58 virtual ~CompoundStmt(); 59 59 … … 62 62 void push_front( Statement * stmt ) { kids.push_front( stmt ); } 63 63 64 virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); }65 virtual void accept( Visitor & v ) override { v.visit( this ); }66 virtual CompoundStmt * acceptMutator( Mutator &m ) override { return m.mutate( this ); }67 virtual void print( std::ostream & os, Indenter indent = {} ) const override;64 virtual CompoundStmt * clone() const override { return new CompoundStmt( *this ); } 65 virtual void accept( Visitor & v ) override { v.visit( this ); } 66 virtual CompoundStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 67 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 68 68 }; 69 69 … … 72 72 NullStmt( const std::list<Label> & labels = {} ); 73 73 74 virtual NullStmt * clone() const override { return new NullStmt( *this ); }75 virtual void accept( Visitor & v ) override { v.visit( this ); }76 virtual NullStmt * acceptMutator( Mutator &m ) override { return m.mutate( this ); }77 virtual void print( std::ostream & os, Indenter indent = {} ) const override;74 virtual NullStmt * clone() const override { return new NullStmt( *this ); } 75 virtual void accept( Visitor & v ) override { v.visit( this ); } 76 virtual NullStmt * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 77 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 78 78 }; 79 79 80 80 class ExprStmt : public Statement { 81 81 public: 82 Expression * expr;83 84 ExprStmt( Expression * expr );85 ExprStmt( const ExprStmt & other );82 Expression * expr; 83 84 ExprStmt( Expression * expr ); 85 ExprStmt( const ExprStmt & other ); 86 86 virtual ~ExprStmt(); 87 87 88 Expression * get_expr() { return expr; }89 void set_expr( Expression * newValue ) { expr = newValue; }90 91 virtual ExprStmt * clone() const override { return new ExprStmt( *this ); }92 virtual void accept( Visitor & v ) override { v.visit( this ); }93 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }94 virtual void print( std::ostream & os, Indenter indent = {} ) const override;88 Expression * get_expr() { return expr; } 89 void set_expr( Expression * newValue ) { expr = newValue; } 90 91 virtual ExprStmt * clone() const override { return new ExprStmt( *this ); } 92 virtual void accept( Visitor & v ) override { v.visit( this ); } 93 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 94 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 95 95 }; 96 96 … … 98 98 public: 99 99 bool voltile; 100 Expression * instruction;100 Expression * instruction; 101 101 std::list<Expression *> output, input; 102 102 std::list<ConstantExpr *> clobber; 103 103 std::list<Label> gotolabels; 104 104 105 AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels );106 AsmStmt( const AsmStmt & other );105 AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ); 106 AsmStmt( const AsmStmt & other ); 107 107 virtual ~AsmStmt(); 108 108 … … 114 114 void set_output( const std::list<Expression *> & newValue ) { output = newValue; } 115 115 std::list<Expression *> & get_input() { return input; } 116 void set_input( const std::list<Expression *> & newValue ) { input = newValue; }116 void set_input( const std::list<Expression *> & newValue ) { input = newValue; } 117 117 std::list<ConstantExpr *> & get_clobber() { return clobber; } 118 void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; }118 void set_clobber( const std::list<ConstantExpr *> & newValue ) { clobber = newValue; } 119 119 std::list<Label> & get_gotolabels() { return gotolabels; } 120 void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; }120 void set_gotolabels( const std::list<Label> & newValue ) { gotolabels = newValue; } 121 121 122 122 virtual AsmStmt * clone() const { return new AsmStmt( *this ); } … … 141 141 class IfStmt : public Statement { 142 142 public: 143 Expression * condition;144 Statement * thenPart;145 Statement * elsePart;143 Expression * condition; 144 Statement * thenPart; 145 Statement * elsePart; 146 146 std::list<Statement *> initialization; 147 147 148 IfStmt( Expression * condition, Statement *thenPart, Statement *elsePart,148 IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, 149 149 std::list<Statement *> initialization = std::list<Statement *>() ); 150 IfStmt( const IfStmt & other );150 IfStmt( const IfStmt & other ); 151 151 virtual ~IfStmt(); 152 152 153 std::list<Statement *> & get_initialization() { return initialization; }154 Expression * get_condition() { return condition; }155 void set_condition( Expression * newValue ) { condition = newValue; }156 Statement * get_thenPart() { return thenPart; }157 void set_thenPart( Statement * newValue ) { thenPart = newValue; }158 Statement * get_elsePart() { return elsePart; }159 void set_elsePart( Statement * newValue ) { elsePart = newValue; }160 161 virtual IfStmt * clone() const override { return new IfStmt( *this ); }162 virtual void accept( Visitor & v ) override { v.visit( this ); }163 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }164 virtual void print( std::ostream & os, Indenter indent = {} ) const override;153 std::list<Statement *> & get_initialization() { return initialization; } 154 Expression * get_condition() { return condition; } 155 void set_condition( Expression * newValue ) { condition = newValue; } 156 Statement * get_thenPart() { return thenPart; } 157 void set_thenPart( Statement * newValue ) { thenPart = newValue; } 158 Statement * get_elsePart() { return elsePart; } 159 void set_elsePart( Statement * newValue ) { elsePart = newValue; } 160 161 virtual IfStmt * clone() const override { return new IfStmt( *this ); } 162 virtual void accept( Visitor & v ) override { v.visit( this ); } 163 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 164 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 165 165 }; 166 166 … … 170 170 std::list<Statement *> statements; 171 171 172 SwitchStmt( Expression * condition, const std::list<Statement *> &statements );173 SwitchStmt( const SwitchStmt & other );172 SwitchStmt( Expression * condition, const std::list<Statement *> & statements ); 173 SwitchStmt( const SwitchStmt & other ); 174 174 virtual ~SwitchStmt(); 175 175 176 Expression * get_condition() { return condition; }177 void set_condition( Expression * newValue ) { condition = newValue; }176 Expression * get_condition() { return condition; } 177 void set_condition( Expression * newValue ) { condition = newValue; } 178 178 179 179 std::list<Statement *> & get_statements() { return statements; } 180 180 181 virtual void accept( Visitor & v ) override { v.visit( this ); }182 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }183 184 virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); }185 virtual void print( std::ostream & os, Indenter indent = {} ) const override;181 virtual void accept( Visitor & v ) override { v.visit( this ); } 182 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 183 184 virtual SwitchStmt * clone() const override { return new SwitchStmt( *this ); } 185 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 186 186 187 187 }; … … 192 192 std::list<Statement *> stmts; 193 193 194 CaseStmt( Expression * conditions, const std::list<Statement *> &stmts, bool isdef = false ) throw (SemanticErrorException);195 CaseStmt( const CaseStmt & other );194 CaseStmt( Expression * conditions, const std::list<Statement *> & stmts, bool isdef = false ) throw (SemanticErrorException); 195 CaseStmt( const CaseStmt & other ); 196 196 virtual ~CaseStmt(); 197 197 … … 201 201 void set_default(bool b) { _isDefault = b; } 202 202 203 Expression * & get_condition() { return condition; }204 void set_condition( Expression * newValue ) { condition = newValue; }205 206 std::list<Statement *> & get_statements() { return stmts; }207 void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; }208 209 virtual void accept( Visitor & v ) override { v.visit( this ); }210 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }211 212 virtual CaseStmt * clone() const override { return new CaseStmt( *this ); }213 virtual void print( std::ostream & os, Indenter indent = {} ) const override;203 Expression * & get_condition() { return condition; } 204 void set_condition( Expression * newValue ) { condition = newValue; } 205 206 std::list<Statement *> & get_statements() { return stmts; } 207 void set_statements( std::list<Statement *> & newValue ) { stmts = newValue; } 208 209 virtual void accept( Visitor & v ) override { v.visit( this ); } 210 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 211 212 virtual CaseStmt * clone() const override { return new CaseStmt( *this ); } 213 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 214 214 private: 215 215 bool _isDefault; … … 218 218 class WhileStmt : public Statement { 219 219 public: 220 Expression * condition;221 Statement * body;220 Expression * condition; 221 Statement * body; 222 222 std::list<Statement *> initialization; 223 223 bool isDoWhile; 224 224 225 WhileStmt( Expression *condition, 226 Statement *body, std::list<Statement *> & initialization, bool isDoWhile = false ); 227 WhileStmt( const WhileStmt &other ); 225 WhileStmt( Expression * condition, Statement * body, std::list<Statement *> & initialization, bool isDoWhile = false ); 226 WhileStmt( const WhileStmt & other ); 228 227 virtual ~WhileStmt(); 229 228 230 Expression * get_condition() { return condition; }231 void set_condition( Expression * newValue ) { condition = newValue; }232 Statement * get_body() { return body; }233 void set_body( Statement * newValue ) { body = newValue; }229 Expression * get_condition() { return condition; } 230 void set_condition( Expression * newValue ) { condition = newValue; } 231 Statement * get_body() { return body; } 232 void set_body( Statement * newValue ) { body = newValue; } 234 233 bool get_isDoWhile() { return isDoWhile; } 235 234 void set_isDoWhile( bool newValue ) { isDoWhile = newValue; } 236 235 237 virtual WhileStmt * clone() const override { return new WhileStmt( *this ); }238 virtual void accept( Visitor & v ) override { v.visit( this ); }239 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }240 virtual void print( std::ostream & os, Indenter indent = {} ) const override;236 virtual WhileStmt * clone() const override { return new WhileStmt( *this ); } 237 virtual void accept( Visitor & v ) override { v.visit( this ); } 238 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 239 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 241 240 }; 242 241 … … 244 243 public: 245 244 std::list<Statement *> initialization; 246 Expression *condition; 247 Expression *increment; 248 Statement *body; 249 250 ForStmt( std::list<Statement *> initialization, 251 Expression *condition = 0, Expression *increment = 0, Statement *body = 0 ); 252 ForStmt( const ForStmt &other ); 245 Expression * condition; 246 Expression * increment; 247 Statement * body; 248 249 ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 ); 250 ForStmt( const ForStmt & other ); 253 251 virtual ~ForStmt(); 254 252 255 std::list<Statement *> & get_initialization() { return initialization; }256 Expression * get_condition() { return condition; }257 void set_condition( Expression * newValue ) { condition = newValue; }258 Expression * get_increment() { return increment; }259 void set_increment( Expression * newValue ) { increment = newValue; }260 Statement * get_body() { return body; }261 void set_body( Statement * newValue ) { body = newValue; }262 263 virtual ForStmt * clone() const override { return new ForStmt( *this ); }264 virtual void accept( Visitor & v ) override { v.visit( this ); }265 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }266 virtual void print( std::ostream & os, Indenter indent = {} ) const override;253 std::list<Statement *> & get_initialization() { return initialization; } 254 Expression * get_condition() { return condition; } 255 void set_condition( Expression * newValue ) { condition = newValue; } 256 Expression * get_increment() { return increment; } 257 void set_increment( Expression * newValue ) { increment = newValue; } 258 Statement * get_body() { return body; } 259 void set_body( Statement * newValue ) { body = newValue; } 260 261 virtual ForStmt * clone() const override { return new ForStmt( *this ); } 262 virtual void accept( Visitor & v ) override { v.visit( this ); } 263 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 264 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 267 265 }; 268 266 … … 274 272 const Label originalTarget; 275 273 Label target; 276 Expression * computedTarget;274 Expression * computedTarget; 277 275 Type type; 278 276 279 277 BranchStmt( Label target, Type ) throw (SemanticErrorException); 280 BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException);278 BranchStmt( Expression * computedTarget, Type ) throw (SemanticErrorException); 281 279 282 280 Label get_originalTarget() { return originalTarget; } … … 284 282 void set_target( Label newValue ) { target = newValue; } 285 283 286 Expression * get_computedTarget() { return computedTarget; }284 Expression * get_computedTarget() { return computedTarget; } 287 285 void set_target( Expression * newValue ) { computedTarget = newValue; } 288 286 289 287 Type get_type() { return type; } 290 const char * get_typename() { return brType[ type ]; }291 292 virtual BranchStmt * clone() const override { return new BranchStmt( *this ); }293 virtual void accept( Visitor & v ) override { v.visit( this ); }294 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }295 virtual void print( std::ostream & os, Indenter indent = {} ) const override;288 const char * get_typename() { return brType[ type ]; } 289 290 virtual BranchStmt * clone() const override { return new BranchStmt( *this ); } 291 virtual void accept( Visitor & v ) override { v.visit( this ); } 292 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 293 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 296 294 private: 297 static const char * brType[];295 static const char * brType[]; 298 296 }; 299 297 300 298 class ReturnStmt : public Statement { 301 299 public: 302 Expression * expr;303 304 ReturnStmt( Expression * expr );305 ReturnStmt( const ReturnStmt & other );300 Expression * expr; 301 302 ReturnStmt( Expression * expr ); 303 ReturnStmt( const ReturnStmt & other ); 306 304 virtual ~ReturnStmt(); 307 305 308 Expression * get_expr() { return expr; }309 void set_expr( Expression * newValue ) { expr = newValue; }310 311 virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); }312 virtual void accept( Visitor & v ) override { v.visit( this ); }313 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }314 virtual void print( std::ostream & os, Indenter indent = {} ) const override;306 Expression * get_expr() { return expr; } 307 void set_expr( Expression * newValue ) { expr = newValue; } 308 309 virtual ReturnStmt * clone() const override { return new ReturnStmt( *this ); } 310 virtual void accept( Visitor & v ) override { v.visit( this ); } 311 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 312 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 315 313 }; 316 314 … … 324 322 325 323 ThrowStmt( Kind kind, Expression * expr, Expression * target = nullptr ); 326 ThrowStmt( const ThrowStmt & other );324 ThrowStmt( const ThrowStmt & other ); 327 325 virtual ~ThrowStmt(); 328 326 … … 333 331 void set_target( Expression * newTarget ) { target = newTarget; } 334 332 335 virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); }336 virtual void accept( Visitor & v ) override { v.visit( this ); }337 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }338 virtual void print( std::ostream & os, Indenter indent = {} ) const override;333 virtual ThrowStmt * clone() const override { return new ThrowStmt( *this ); } 334 virtual void accept( Visitor & v ) override { v.visit( this ); } 335 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 336 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 339 337 }; 340 338 … … 345 343 FinallyStmt * finallyBlock; 346 344 347 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock = 0 );348 TryStmt( const TryStmt & other );345 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 ); 346 TryStmt( const TryStmt & other ); 349 347 virtual ~TryStmt(); 350 348 351 CompoundStmt * get_block() const { return block; }352 void set_block( CompoundStmt * newValue ) { block = newValue; }349 CompoundStmt * get_block() const { return block; } 350 void set_block( CompoundStmt * newValue ) { block = newValue; } 353 351 std::list<CatchStmt *>& get_catchers() { return handlers; } 354 352 355 FinallyStmt * get_finally() const { return finallyBlock; }356 void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; }357 358 virtual TryStmt * clone() const override { return new TryStmt( *this ); }359 virtual void accept( Visitor & v ) override { v.visit( this ); }360 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }361 virtual void print( std::ostream & os, Indenter indent = {} ) const override;353 FinallyStmt * get_finally() const { return finallyBlock; } 354 void set_finally( FinallyStmt * newValue ) { finallyBlock = newValue; } 355 356 virtual TryStmt * clone() const override { return new TryStmt( *this ); } 357 virtual void accept( Visitor & v ) override { v.visit( this ); } 358 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 359 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 362 360 }; 363 361 … … 367 365 368 366 const Kind kind; 369 Declaration * decl;370 Expression * cond;371 Statement * body;372 373 CatchStmt( Kind kind, Declaration * decl,374 Expression * cond, Statement *body );375 CatchStmt( const CatchStmt & other );367 Declaration * decl; 368 Expression * cond; 369 Statement * body; 370 371 CatchStmt( Kind kind, Declaration * decl, 372 Expression * cond, Statement * body ); 373 CatchStmt( const CatchStmt & other ); 376 374 virtual ~CatchStmt(); 377 375 378 376 Kind get_kind() { return kind; } 379 Declaration * get_decl() { return decl; }380 void set_decl( Declaration * newValue ) { decl = newValue; }381 Expression * get_cond() { return cond; }382 void set_cond( Expression * newCond ) { cond = newCond; }383 Statement * get_body() { return body; }384 void set_body( Statement * newValue ) { body = newValue; }385 386 virtual CatchStmt * clone() const override { return new CatchStmt( *this ); }387 virtual void accept( Visitor & v ) override { v.visit( this ); }388 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }389 virtual void print( std::ostream & os, Indenter indent = {} ) const override;377 Declaration * get_decl() { return decl; } 378 void set_decl( Declaration * newValue ) { decl = newValue; } 379 Expression * get_cond() { return cond; } 380 void set_cond( Expression * newCond ) { cond = newCond; } 381 Statement * get_body() { return body; } 382 void set_body( Statement * newValue ) { body = newValue; } 383 384 virtual CatchStmt * clone() const override { return new CatchStmt( *this ); } 385 virtual void accept( Visitor & v ) override { v.visit( this ); } 386 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 387 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 390 388 }; 391 389 392 390 class FinallyStmt : public Statement { 393 391 public: 394 CompoundStmt * block;395 396 FinallyStmt( CompoundStmt * block );397 FinallyStmt( const FinallyStmt & other );392 CompoundStmt * block; 393 394 FinallyStmt( CompoundStmt * block ); 395 FinallyStmt( const FinallyStmt & other ); 398 396 virtual ~FinallyStmt(); 399 397 400 CompoundStmt * get_block() const { return block; }401 void set_block( CompoundStmt * newValue ) { block = newValue; }402 403 virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); }404 virtual void accept( Visitor & v ) override { v.visit( this ); }405 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }406 virtual void print( std::ostream & os, Indenter indent = {} ) const override;398 CompoundStmt * get_block() const { return block; } 399 void set_block( CompoundStmt * newValue ) { block = newValue; } 400 401 virtual FinallyStmt * clone() const override { return new FinallyStmt( *this ); } 402 virtual void accept( Visitor & v ) override { v.visit( this ); } 403 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 404 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 407 405 }; 408 406 … … 438 436 } orelse; 439 437 440 virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); }441 virtual void accept( Visitor & v ) override { v.visit( this ); }442 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }443 virtual void print( std::ostream & os, Indenter indent = {} ) const override;438 virtual WaitForStmt * clone() const override { return new WaitForStmt( *this ); } 439 virtual void accept( Visitor & v ) override { v.visit( this ); } 440 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 441 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 444 442 445 443 }; … … 464 462 class DeclStmt : public Statement { 465 463 public: 466 Declaration * decl;467 468 DeclStmt( Declaration * decl );469 DeclStmt( const DeclStmt & other );464 Declaration * decl; 465 466 DeclStmt( Declaration * decl ); 467 DeclStmt( const DeclStmt & other ); 470 468 virtual ~DeclStmt(); 471 469 472 Declaration *get_decl() const { return decl; } 473 void set_decl( Declaration *newValue ) { decl = newValue; } 474 475 virtual DeclStmt *clone() const override { return new DeclStmt( *this ); } 476 virtual void accept( Visitor &v ) override { v.visit( this ); } 477 virtual Statement *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 478 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 479 }; 480 481 482 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced 483 /// immediately before and after the call so that qualified objects can be constructed 484 /// with the same functions as unqualified objects. 470 Declaration * get_decl() const { return decl; } 471 void set_decl( Declaration * newValue ) { decl = newValue; } 472 473 virtual DeclStmt * clone() const override { return new DeclStmt( *this ); } 474 virtual void accept( Visitor & v ) override { v.visit( this ); } 475 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 476 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 477 }; 478 479 480 /// represents an implicit application of a constructor or destructor. Qualifiers are replaced immediately before and 481 /// after the call so that qualified objects can be constructed with the same functions as unqualified objects. 485 482 class ImplicitCtorDtorStmt : public Statement { 486 483 public: … … 492 489 virtual ~ImplicitCtorDtorStmt(); 493 490 494 Statement * get_callStmt() const { return callStmt; }491 Statement * get_callStmt() const { return callStmt; } 495 492 void set_callStmt( Statement * newValue ) { callStmt = newValue; } 496 493 497 virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); }498 virtual void accept( Visitor & v ) override { v.visit( this ); }499 virtual Statement * acceptMutator( Mutator &m ) override { return m.mutate( this ); }500 virtual void print( std::ostream & os, Indenter indent = {} ) const override;494 virtual ImplicitCtorDtorStmt * clone() const override { return new ImplicitCtorDtorStmt( *this ); } 495 virtual void accept( Visitor & v ) override { v.visit( this ); } 496 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 497 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 501 498 }; 502 499 -
src/SynTree/SynTree.h
r6a9d4b4 r933f32f 34 34 class NamedTypeDecl; 35 35 class TypeDecl; 36 class FtypeDecl;37 class DtypeDecl;38 36 class TypedefDecl; 39 37 class AsmDecl; … … 90 88 class ConstructorExpr; 91 89 class CompoundLiteralExpr; 92 class UntypedValofExpr;93 90 class RangeExpr; 94 91 class UntypedTupleExpr; … … 132 129 class ConstructorInit; 133 130 134 class Subrange;135 136 131 //template <class T> // emulate a union with templates? 137 132 class Constant; -
src/SynTree/Type.cc
r6a9d4b4 r933f32f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jun 22 10:17:19 201813 // Update Count : 3912 // Last Modified On : Thu Jan 31 21:54:16 2019 13 // Update Count : 43 14 14 // 15 15 #include "Type.h" … … 25 25 26 26 const char *BasicType::typeNames[] = { 27 #if 0 27 28 "_Bool", 28 29 "char", … … 49 50 "unsigned __int128", 50 51 "__float80", 51 "__float128" 52 "__float128", 53 "_Float16", 54 "_Float32", 55 "_Float32x", 56 "_Float64", 57 "_Float64x", 58 "_Float128", 59 "_Float128x", 60 "_Float16 _Complex", 61 "_Float32 _Complex", 62 "_Float32x _Complex", 63 "_Float64 _Complex", 64 "_Float64x _Complex", 65 "_Float128 _Complex", 66 "_Float128x _Complex", 67 #endif 68 "_Bool", 69 "char", 70 "signed char", 71 "unsigned char", 72 "signed short int", 73 "unsigned short int", 74 "signed int", 75 "unsigned int", 76 "signed long int", 77 "unsigned long int", 78 "signed long long int", 79 "unsigned long long int", 80 "__int128", 81 "unsigned __int128", 82 "_Float16", 83 "_Float16 _Complex", 84 "_Float32", 85 "_Float32 _Complex", 86 "float", 87 "float _Complex", 88 //"float _Imaginary", 89 "_Float32x", 90 "_Float32x _Complex", 91 "_Float64", 92 "_Float64 _Complex", 93 "double", 94 "double _Complex", 95 //"double _Imaginary", 96 "_Float64x", 97 "_Float64x _Complex", 98 "__float80", 99 "_Float128", 100 "_Float128 _Complex", 101 "__float128", 102 "long double", 103 "long double _Complex", 104 //"long double _Imaginary", 105 "_Float128x", 106 "_Float128x _Complex", 52 107 }; 53 108 static_assert( -
src/SynTree/Type.h
r6a9d4b4 r933f32f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Sep 25 14:14:01 201713 // Update Count : 1 5412 // Last Modified On : Thu Feb 14 17:11:24 2019 13 // Update Count : 169 14 14 // 15 15 … … 207 207 class BasicType : public Type { 208 208 public: 209 // GENERATED START, DO NOT EDIT 210 // GENERATED BY BasicTypes-gen.cc 209 211 enum Kind { 210 212 Bool, … … 220 222 LongLongSignedInt, 221 223 LongLongUnsignedInt, 222 Float,223 Double,224 LongDouble,225 FloatComplex,226 DoubleComplex,227 LongDoubleComplex,228 FloatImaginary,229 DoubleImaginary,230 LongDoubleImaginary,231 224 SignedInt128, 232 225 UnsignedInt128, 233 Float80, 234 Float128, 226 uFloat16, 227 uFloat16Complex, 228 uFloat32, 229 uFloat32Complex, 230 Float, 231 FloatComplex, 232 uFloat32x, 233 uFloat32xComplex, 234 uFloat64, 235 uFloat64Complex, 236 Double, 237 DoubleComplex, 238 uFloat64x, 239 uFloat64xComplex, 240 uuFloat80, 241 uFloat128, 242 uFloat128Complex, 243 uuFloat128, 244 LongDouble, 245 LongDoubleComplex, 246 uFloat128x, 247 uFloat128xComplex, 235 248 NUMBER_OF_BASIC_TYPES 236 249 } kind; 250 // GENERATED END 237 251 238 252 static const char *typeNames[]; // string names for basic types, MUST MATCH with Kind -
src/SynTree/TypeSubstitution.cc
r6a9d4b4 r933f32f 64 64 } 65 65 66 void TypeSubstitution::addVar( std::string formalExpr, Expression *actualExpr ) { 67 varEnv[ formalExpr ] = actualExpr; 68 } 69 66 70 void TypeSubstitution::remove( std::string formalType ) { 67 71 TypeEnvType::iterator i = typeEnv.find( formalType ); … … 108 112 namespace { 109 113 struct EnvTrimmer { 110 TypeSubstitution * env, * newEnv; 111 EnvTrimmer( TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} 114 const TypeSubstitution * env; 115 TypeSubstitution * newEnv; 116 EnvTrimmer( const TypeSubstitution * env, TypeSubstitution * newEnv ) : env( env ), newEnv( newEnv ){} 112 117 void previsit( TypeDecl * tyDecl ) { 113 118 // transfer known bindings for seen type variables … … 120 125 121 126 /// reduce environment to just the parts that are referenced in a given expression 122 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, TypeSubstitution * env ) {127 TypeSubstitution * TypeSubstitution::newFromExpr( Expression * expr, const TypeSubstitution * env ) { 123 128 if ( env ) { 124 129 TypeSubstitution * newEnv = new TypeSubstitution(); -
src/SynTree/TypeSubstitution.h
r6a9d4b4 r933f32f 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:52:24 201713 // Update Count : 312 // Last Modified On : Tue Apr 30 22:52:47 2019 13 // Update Count : 9 14 14 // 15 15 … … 19 19 #include <iosfwd> // for ostream 20 20 #include <list> // for list<>::iterator, _List_iterator 21 #include < map> // for _Rb_tree_iterator, map, map<>::val...22 #include < set> // for set21 #include <unordered_map> 22 #include <unordered_set> 23 23 #include <string> // for string, operator!= 24 24 #include <utility> // for pair … … 39 39 TypeSubstitution &operator=( const TypeSubstitution &other ); 40 40 41 template< typename SynTreeClass > int apply( SynTreeClass *&input ) ;42 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) ;41 template< typename SynTreeClass > int apply( SynTreeClass *&input ) const; 42 template< typename SynTreeClass > int applyFree( SynTreeClass *&input ) const; 43 43 44 44 void add( std::string formalType, Type *actualType ); … … 48 48 bool empty() const; 49 49 50 void addVar( std::string formalExpr, Expression *actualExpr ); 51 50 52 template< typename FormalIterator, typename ActualIterator > 51 53 void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin ); … … 56 58 57 59 /// create a new TypeSubstitution using bindings from env containing all of the type variables in expr 58 static TypeSubstitution * newFromExpr( Expression * expr, TypeSubstitution * env );60 static TypeSubstitution * newFromExpr( Expression * expr, const TypeSubstitution * env ); 59 61 60 62 void normalize(); … … 78 80 friend class PassVisitor; 79 81 80 typedef std:: map< std::string, Type* > TypeEnvType;81 typedef std:: map< std::string, Expression* > VarEnvType;82 typedef std::unordered_map< std::string, Type * > TypeEnvType; 83 typedef std::unordered_map< std::string, Expression * > VarEnvType; 82 84 TypeEnvType typeEnv; 83 85 VarEnvType varEnv; … … 89 91 auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); } 90 92 auto end() const -> decltype( typeEnv. end() ) { return typeEnv. end(); } 93 94 auto beginVar() -> decltype( varEnv.begin() ) { return varEnv.begin(); } 95 auto endVar() -> decltype( varEnv. end() ) { return varEnv. end(); } 96 auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); } 97 auto endVar() const -> decltype( varEnv. end() ) { return varEnv. end(); } 91 98 }; 92 99 … … 98 105 ActualIterator actualIt = actualBegin; 99 106 for ( ; formalIt != formalEnd; ++formalIt, ++actualIt ) { 100 if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) {101 if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) {107 if ( TypeDecl *formal = dynamic_cast< TypeDecl * >( *formalIt ) ) { 108 if ( TypeExpr *actual = dynamic_cast< TypeExpr * >( *actualIt ) ) { 102 109 if ( formal->get_name() != "" ) { 103 110 TypeEnvType::iterator i = typeEnv.find( formal->get_name() ); … … 130 137 // definitition must happen after PassVisitor is included so that WithGuards can be used 131 138 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> { 132 Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}139 Substituter( const TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {} 133 140 134 141 Type * postmutate( TypeInstType * aggregateUseType ); … … 143 150 void premutate( UnionInstType * aggregateUseType ); 144 151 145 TypeSubstitution & sub;152 const TypeSubstitution & sub; 146 153 int subCount = 0; 147 154 bool freeOnly; 148 typedef std:: set< std::string > BoundVarsType;155 typedef std::unordered_set< std::string > BoundVarsType; 149 156 BoundVarsType boundVars; 150 157 }; 151 158 152 159 template< typename SynTreeClass > 153 int TypeSubstitution::apply( SynTreeClass *&input ) {160 int TypeSubstitution::apply( SynTreeClass *&input ) const { 154 161 assert( input ); 155 162 PassVisitor<Substituter> sub( *this, false ); … … 163 170 164 171 template< typename SynTreeClass > 165 int TypeSubstitution::applyFree( SynTreeClass *&input ) {172 int TypeSubstitution::applyFree( SynTreeClass *&input ) const { 166 173 assert( input ); 167 174 PassVisitor<Substituter> sub( *this, true ); -
src/SynTree/Visitor.h
r6a9d4b4 r933f32f 123 123 virtual void visit( ConstructorInit * ctorInit ) = 0; 124 124 125 virtual void visit( Subrange * subrange ) = 0;126 127 125 virtual void visit( Constant * constant ) = 0; 128 126 -
src/SynTree/module.mk
r6a9d4b4 r933f32f 15 15 ############################################################################### 16 16 17 SRC += SynTree/Type.cc \ 18 SynTree/VoidType.cc \ 19 SynTree/BasicType.cc \ 20 SynTree/PointerType.cc \ 21 SynTree/ArrayType.cc \ 22 SynTree/ReferenceType.cc \ 23 SynTree/FunctionType.cc \ 24 SynTree/ReferenceToType.cc \ 25 SynTree/TupleType.cc \ 26 SynTree/TypeofType.cc \ 27 SynTree/AttrType.cc \ 28 SynTree/VarArgsType.cc \ 29 SynTree/ZeroOneType.cc \ 30 SynTree/Constant.cc \ 31 SynTree/Expression.cc \ 32 SynTree/TupleExpr.cc \ 33 SynTree/CommaExpr.cc \ 34 SynTree/TypeExpr.cc \ 35 SynTree/ApplicationExpr.cc \ 36 SynTree/AddressExpr.cc \ 37 SynTree/Statement.cc \ 38 SynTree/CompoundStmt.cc \ 39 SynTree/DeclStmt.cc \ 40 SynTree/Declaration.cc \ 41 SynTree/DeclarationWithType.cc \ 42 SynTree/ObjectDecl.cc \ 43 SynTree/FunctionDecl.cc \ 44 SynTree/AggregateDecl.cc \ 45 SynTree/NamedTypeDecl.cc \ 46 SynTree/TypeDecl.cc \ 47 SynTree/Initializer.cc \ 48 SynTree/TypeSubstitution.cc \ 49 SynTree/Attribute.cc \ 50 SynTree/DeclReplacer.cc 17 SRC_SYNTREE = \ 18 SynTree/Type.cc \ 19 SynTree/VoidType.cc \ 20 SynTree/BasicType.cc \ 21 SynTree/PointerType.cc \ 22 SynTree/ArrayType.cc \ 23 SynTree/ReferenceType.cc \ 24 SynTree/FunctionType.cc \ 25 SynTree/ReferenceToType.cc \ 26 SynTree/TupleType.cc \ 27 SynTree/TypeofType.cc \ 28 SynTree/AttrType.cc \ 29 SynTree/VarArgsType.cc \ 30 SynTree/ZeroOneType.cc \ 31 SynTree/Constant.cc \ 32 SynTree/Expression.cc \ 33 SynTree/TupleExpr.cc \ 34 SynTree/CommaExpr.cc \ 35 SynTree/TypeExpr.cc \ 36 SynTree/ApplicationExpr.cc \ 37 SynTree/AddressExpr.cc \ 38 SynTree/Statement.cc \ 39 SynTree/CompoundStmt.cc \ 40 SynTree/DeclStmt.cc \ 41 SynTree/Declaration.cc \ 42 SynTree/DeclarationWithType.cc \ 43 SynTree/ObjectDecl.cc \ 44 SynTree/FunctionDecl.cc \ 45 SynTree/AggregateDecl.cc \ 46 SynTree/NamedTypeDecl.cc \ 47 SynTree/TypeDecl.cc \ 48 SynTree/Initializer.cc \ 49 SynTree/TypeSubstitution.cc \ 50 SynTree/Attribute.cc \ 51 SynTree/DeclReplacer.cc 51 52 53 SRC += $(SRC_SYNTREE) 54 SRCDEMANGLE += $(SRC_SYNTREE)
Note:
See TracChangeset
for help on using the changeset viewer.