Changeset 7030dab for src/SynTree
- Timestamp:
- Apr 6, 2020, 4:46:28 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- e3bc51c
- Parents:
- 71d6bd8 (diff), 057298e (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:
-
- 1 added
- 19 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/SynTree/AggregateDecl.cc
r71d6bd8 r7030dab 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 23:56:39 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Aug 4 14:22:00 201713 // Update Count : 2211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 15:07:20 2019 13 // Update Count : 31 14 14 // 15 15 … … 21 21 #include "Common/utility.h" // for printAll, cloneAll, deleteAll 22 22 #include "Declaration.h" // for AggregateDecl, TypeDecl, Declaration 23 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall 23 #include "Initializer.h" 24 #include "LinkageSpec.h" // for Spec, linkageName, Cforall 24 25 #include "Type.h" // for Type, Type::StorageClasses 25 26 27 28 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations. 29 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" }; 30 31 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) { 32 return aggregateNames[aggr]; 33 } 26 34 27 35 AggregateDecl::AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, Type::StorageClasses(), linkage ), body( false ), attributes( attributes ) { … … 47 55 os << typeString() << " " << name << ":"; 48 56 if ( get_linkage() != LinkageSpec::Cforall ) { 49 os << " " << LinkageSpec:: linkageName( linkage );57 os << " " << LinkageSpec::name( linkage ); 50 58 } // if 51 59 os << " with body " << has_body(); … … 78 86 } 79 87 80 std::string StructDecl::typeString() const { return "struct"; }88 const char * StructDecl::typeString() const { return aggrString( kind ); } 81 89 82 std::string UnionDecl::typeString() const { return "union"; }90 const char * UnionDecl::typeString() const { return aggrString( Union ); } 83 91 84 std::string EnumDecl::typeString() const { return "enum"; }92 const char * EnumDecl::typeString() const { return aggrString( Enum ); } 85 93 86 std::string TraitDecl::typeString() const { return "trait"; }94 const char * TraitDecl::typeString() const { return aggrString( Trait ); } 87 95 88 96 bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) { -
src/SynTree/Attribute.h
r71d6bd8 r7030dab 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:54:14 201713 // Update Count : 3912 // Last Modified On : Thu Feb 13 21:34:08 2020 13 // Update Count : 40 14 14 // 15 15 … … 38 38 virtual ~Attribute(); 39 39 40 std::stringget_name() const { return name; }40 const std::string & get_name() const { return name; } 41 41 void set_name( const std::string & newValue ) { name = newValue; } 42 42 std::list< Expression * > & get_parameters() { return parameters; } -
src/SynTree/Declaration.cc
r71d6bd8 r7030dab 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 : Wed Aug 9 14:38:00 201713 // Update Count : 2511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:39:56 2019 13 // Update Count : 36 14 14 // 15 15 … … 24 24 #include "SynTree/Statement.h" // for AsmStmt 25 25 #include "SynTree/SynTree.h" // for UniqueId 26 #include "SynTree/Expression.h" 26 27 #include "Type.h" // for Type, Type::StorageClasses 27 28 29 // To canonicalize declarations 28 30 static UniqueId lastUniqueId = 0; 29 31 -
src/SynTree/Declaration.h
r71d6bd8 r7030dab 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 : Thr May 2 10:47:00201913 // Update Count : 1 3511 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:11:22 2019 13 // Update Count : 157 14 14 // 15 15 … … 24 24 #include "BaseSyntaxNode.h" // for BaseSyntaxNode 25 25 #include "Mutator.h" // for Mutator 26 #include "Parser/LinkageSpec.h" // for Spec, Cforall 27 #include "Parser/ParseNode.h" // for DeclarationNode, DeclarationNode::Ag... 26 #include "LinkageSpec.h" // for Spec, Cforall 28 27 #include "SynTree.h" // for UniqueId 29 28 #include "SynTree/Type.h" // for Type, Type::StorageClasses, Type::Fu... … … 44 43 bool extension = false; 45 44 46 Declaration( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage );47 Declaration( const Declaration & other );45 Declaration( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage ); 46 Declaration( const Declaration & other ); 48 47 virtual ~Declaration(); 49 48 50 const std::string & get_name() const { return name; }49 const std::string & get_name() const { return name; } 51 50 void set_name( std::string newValue ) { name = newValue; } 52 51 … … 59 58 60 59 bool get_extension() const { return extension; } 61 Declaration * set_extension( bool exten ) { extension = exten; return this; }60 Declaration * set_extension( bool exten ) { extension = exten; return this; } 62 61 63 62 void fixUniqueId( void ); 64 virtual Declaration * clone() const override = 0;63 virtual Declaration * clone() const override = 0; 65 64 virtual void accept( Visitor & v ) override = 0; 66 65 virtual void accept( Visitor & v ) const override = 0; 67 virtual Declaration * acceptMutator( Mutator &m ) override = 0;68 virtual void print( std::ostream & os, Indenter indent = {} ) const override = 0;69 virtual void printShort( std::ostream & os, Indenter indent = {} ) const = 0;66 virtual Declaration * acceptMutator( Mutator & m ) override = 0; 67 virtual void print( std::ostream & os, Indenter indent = {} ) const override = 0; 68 virtual void printShort( std::ostream & os, Indenter indent = {} ) const = 0; 70 69 71 70 UniqueId uniqueId; … … 81 80 int scopeLevel = 0; 82 81 83 Expression * asmName;82 Expression * asmName; 84 83 std::list< Attribute * > attributes; 85 84 bool isDeleted = false; 86 85 87 DeclarationWithType( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );88 DeclarationWithType( const DeclarationWithType & other );86 DeclarationWithType( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs ); 87 DeclarationWithType( const DeclarationWithType & other ); 89 88 virtual ~DeclarationWithType(); 90 89 … … 97 96 DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; } 98 97 99 Expression * get_asmName() const { return asmName; }100 DeclarationWithType * set_asmName( Expression * newValue ) { asmName = newValue; return this; }98 Expression * get_asmName() const { return asmName; } 99 DeclarationWithType * set_asmName( Expression * newValue ) { asmName = newValue; return this; } 101 100 102 101 std::list< Attribute * >& get_attributes() { return attributes; } … … 106 105 //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; } 107 106 108 virtual DeclarationWithType * clone() const override = 0;109 virtual DeclarationWithType * acceptMutator( Mutator &m ) override = 0;107 virtual DeclarationWithType * clone() const override = 0; 108 virtual DeclarationWithType * acceptMutator( Mutator & m ) override = 0; 110 109 111 110 virtual Type * get_type() const = 0; … … 119 118 typedef DeclarationWithType Parent; 120 119 public: 121 Type * type;122 Initializer * init;123 Expression * bitfieldWidth;124 125 ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,120 Type * type; 121 Initializer * init; 122 Expression * bitfieldWidth; 123 124 ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init, 126 125 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 127 ObjectDecl( const ObjectDecl & other );126 ObjectDecl( const ObjectDecl & other ); 128 127 virtual ~ObjectDecl(); 129 128 130 129 virtual Type * get_type() const override { return type; } 131 virtual void set_type(Type * newType) override { type = newType; }132 133 Initializer * get_init() const { return init; }134 void set_init( Initializer * newValue ) { init = newValue; }135 136 Expression * get_bitfieldWidth() const { return bitfieldWidth; }137 void set_bitfieldWidth( Expression * newValue ) { bitfieldWidth = newValue; }130 virtual void set_type(Type * newType) override { type = newType; } 131 132 Initializer * get_init() const { return init; } 133 void set_init( Initializer * newValue ) { init = newValue; } 134 135 Expression * get_bitfieldWidth() const { return bitfieldWidth; } 136 void set_bitfieldWidth( Expression * newValue ) { bitfieldWidth = newValue; } 138 137 139 138 static ObjectDecl * newObject( const std::string & name, Type * type, Initializer * init ); 140 139 141 virtual ObjectDecl * clone() const override { return new ObjectDecl( *this ); }142 virtual void accept( Visitor & v ) override { v.visit( this ); } 143 virtual void accept( Visitor & v ) const override { v.visit( this ); } 144 virtual DeclarationWithType * acceptMutator( Mutator &m ) override { return m.mutate( this ); }145 virtual void print( std::ostream & os, Indenter indent = {} ) const override;146 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;140 virtual ObjectDecl * clone() const override { return new ObjectDecl( *this ); } 141 virtual void accept( Visitor & v ) override { v.visit( this ); } 142 virtual void accept( Visitor & v ) const override { v.visit( this ); } 143 virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 144 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 145 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 147 146 }; 148 147 … … 150 149 typedef DeclarationWithType Parent; 151 150 public: 152 FunctionType * type;153 CompoundStmt * statements;151 FunctionType * type; 152 CompoundStmt * statements; 154 153 std::list< Expression * > withExprs; 155 154 156 FunctionDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,155 FunctionDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType * type, CompoundStmt * statements, 157 156 const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() ); 158 FunctionDecl( const FunctionDecl & other );157 FunctionDecl( const FunctionDecl & other ); 159 158 virtual ~FunctionDecl(); 160 159 … … 163 162 164 163 FunctionType * get_functionType() const { return type; } 165 void set_functionType( FunctionType * newValue ) { type = newValue; }166 CompoundStmt * get_statements() const { return statements; }167 void set_statements( CompoundStmt * newValue ) { statements = newValue; }164 void set_functionType( FunctionType * newValue ) { type = newValue; } 165 CompoundStmt * get_statements() const { return statements; } 166 void set_statements( CompoundStmt * newValue ) { statements = newValue; } 168 167 bool has_body() const { return NULL != statements; } 169 168 170 169 static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements ); 171 170 172 virtual FunctionDecl * clone() const override { return new FunctionDecl( *this ); }173 virtual void accept( Visitor & v ) override { v.visit( this ); } 174 virtual void accept( Visitor & v ) const override { v.visit( this ); } 175 virtual DeclarationWithType * acceptMutator( Mutator &m ) override { return m.mutate( this ); }176 virtual void print( std::ostream & os, Indenter indent = {} ) const override;177 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;171 virtual FunctionDecl * clone() const override { return new FunctionDecl( *this ); } 172 virtual void accept( Visitor & v ) override { v.visit( this ); } 173 virtual void accept( Visitor & v ) const override { v.visit( this ); } 174 virtual DeclarationWithType * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 175 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 176 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 178 177 }; 179 178 … … 181 180 typedef Declaration Parent; 182 181 public: 183 Type * base;184 std::list< TypeDecl * > parameters;185 std::list< DeclarationWithType * > assertions;186 187 NamedTypeDecl( const std::string & name, Type::StorageClasses scs, Type *type );188 NamedTypeDecl( const NamedTypeDecl & other );182 Type * base; 183 std::list< TypeDecl * > parameters; 184 std::list< DeclarationWithType * > assertions; 185 186 NamedTypeDecl( const std::string & name, Type::StorageClasses scs, Type * type ); 187 NamedTypeDecl( const NamedTypeDecl & other ); 189 188 virtual ~NamedTypeDecl(); 190 189 191 Type * get_base() const { return base; }192 void set_base( Type * newValue ) { base = newValue; }193 std::list< TypeDecl* > & get_parameters() { return parameters; }194 std::list< DeclarationWithType * >& get_assertions() { return assertions; }195 196 virtual std::stringtypeString() const = 0;197 198 virtual NamedTypeDecl * clone() const override = 0;199 virtual void print( std::ostream & os, Indenter indent = {} ) const override;200 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;190 Type * get_base() const { return base; } 191 void set_base( Type * newValue ) { base = newValue; } 192 std::list< TypeDecl* > & get_parameters() { return parameters; } 193 std::list< DeclarationWithType * >& get_assertions() { return assertions; } 194 195 virtual const char * typeString() const = 0; 196 197 virtual NamedTypeDecl * clone() const override = 0; 198 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 199 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 201 200 }; 202 201 … … 204 203 typedef NamedTypeDecl Parent; 205 204 public: 206 enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS }; 207 205 enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS }; 206 207 Kind kind; 208 bool sized; 208 209 Type * init; 209 bool sized;210 210 211 211 /// Data extracted from a type decl 212 212 struct Data { 213 TypeDecl::Kind kind;213 Kind kind; 214 214 bool isComplete; 215 215 216 Data() : kind( (TypeDecl::Kind)-1), isComplete( false ) {}217 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}216 Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {} 217 Data( const TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {} 218 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 222 bool operator==( const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }223 bool operator!=( const Data & other) const { return !(*this == other);}219 Data( const Data & d1, const Data & d2 ) 220 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 221 222 bool operator==( const Data & other ) const { return kind == other.kind && isComplete == other.isComplete; } 223 bool operator!=( const Data & other ) const { return !(*this == other);} 224 224 }; 225 225 226 TypeDecl( const std::string & name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr );227 TypeDecl( const TypeDecl & other );226 TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init = nullptr ); 227 TypeDecl( const TypeDecl & other ); 228 228 virtual ~TypeDecl(); 229 229 … … 237 237 TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; } 238 238 239 virtual std::string typeString() const override; 240 virtual std::string genTypeString() const; 241 242 virtual TypeDecl *clone() const override { return new TypeDecl( *this ); } 243 virtual void accept( Visitor & v ) override { v.visit( this ); } 244 virtual void accept( Visitor & v ) const override { v.visit( this ); } 245 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 246 virtual void print( std::ostream &os, Indenter indent = {} ) const override; 247 248 Kind kind; 239 virtual const char * typeString() const override; 240 virtual const char * genTypeString() const; 241 242 virtual TypeDecl * clone() const override { return new TypeDecl( *this ); } 243 virtual void accept( Visitor & v ) override { v.visit( this ); } 244 virtual void accept( Visitor & v ) const override { v.visit( this ); } 245 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 246 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 249 247 }; 250 248 … … 252 250 typedef NamedTypeDecl Parent; 253 251 public: 254 TypedefDecl( const std::string & name, CodeLocation location, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall )252 TypedefDecl( const std::string & name, CodeLocation location, Type::StorageClasses scs, Type * type, LinkageSpec::Spec spec = LinkageSpec::Cforall ) 255 253 : Parent( name, scs, type ) { set_linkage( spec ); this->location = location; } 256 254 257 TypedefDecl( const TypedefDecl & other ) : Parent( other ) {}258 259 virtual std::stringtypeString() const override;260 261 virtual TypedefDecl * clone() const override { return new TypedefDecl( *this ); }262 virtual void accept( Visitor & v ) override { v.visit( this ); } 263 virtual void accept( Visitor & v ) const override { v.visit( this ); } 264 virtual Declaration * acceptMutator( Mutator &m ) override { return m.mutate( this ); }255 TypedefDecl( const TypedefDecl & other ) : Parent( other ) {} 256 257 virtual const char * typeString() const override; 258 259 virtual TypedefDecl * clone() const override { return new TypedefDecl( *this ); } 260 virtual void accept( Visitor & v ) override { v.visit( this ); } 261 virtual void accept( Visitor & v ) const override { v.visit( this ); } 262 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 265 263 private: 266 264 }; … … 269 267 typedef Declaration Parent; 270 268 public: 269 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; 270 static const char * aggrString( Aggregate aggr ); 271 271 272 std::list<Declaration*> members; 272 273 std::list<TypeDecl*> parameters; … … 275 276 AggregateDecl * parent = nullptr; 276 277 277 AggregateDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );278 AggregateDecl( const AggregateDecl & other );278 AggregateDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ); 279 AggregateDecl( const AggregateDecl & other ); 279 280 virtual ~AggregateDecl(); 280 281 … … 288 289 AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; } 289 290 290 virtual void print( std::ostream & os, Indenter indent = {} ) const override final;291 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;291 virtual void print( std::ostream & os, Indenter indent = {} ) const override final; 292 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 292 293 protected: 293 virtual std::stringtypeString() const = 0;294 virtual const char * typeString() const = 0; 294 295 }; 295 296 … … 297 298 typedef AggregateDecl Parent; 298 299 public: 299 StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {} 300 StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {} 301 302 bool is_coroutine() { return kind == DeclarationNode::Coroutine; } 303 bool is_monitor() { return kind == DeclarationNode::Monitor; } 304 bool is_thread() { return kind == DeclarationNode::Thread; } 305 306 virtual StructDecl *clone() const override { return new StructDecl( *this ); } 307 virtual void accept( Visitor & v ) override { v.visit( this ); } 308 virtual void accept( Visitor & v ) const override { v.visit( this ); } 309 virtual Declaration *acceptMutator( Mutator &m ) override { return m.mutate( this ); } 310 DeclarationNode::Aggregate kind; 311 private: 312 virtual std::string typeString() const override; 300 StructDecl( const std::string & name, Aggregate kind = Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {} 301 StructDecl( const StructDecl & other ) : Parent( other ), kind( other.kind ) {} 302 303 bool is_coroutine() { return kind == Coroutine; } 304 bool is_generator() { return kind == Generator; } 305 bool is_monitor () { return kind == Monitor ; } 306 bool is_thread () { return kind == Thread ; } 307 308 virtual StructDecl * clone() const override { return new StructDecl( *this ); } 309 virtual void accept( Visitor & v ) override { v.visit( this ); } 310 virtual void accept( Visitor & v ) const override { v.visit( this ); } 311 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 312 Aggregate kind; 313 private: 314 virtual const char * typeString() const override; 313 315 }; 314 316 … … 316 318 typedef AggregateDecl Parent; 317 319 public: 318 UnionDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}319 UnionDecl( const UnionDecl & other ) : Parent( other ) {}320 321 virtual UnionDecl * clone() const override { return new UnionDecl( *this ); }322 virtual void accept( Visitor & v ) override { v.visit( this ); } 323 virtual void accept( Visitor & v ) const override { v.visit( this ); } 324 virtual Declaration * acceptMutator( Mutator &m ) override { return m.mutate( this ); }325 private: 326 virtual std::stringtypeString() const override;320 UnionDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {} 321 UnionDecl( const UnionDecl & other ) : Parent( other ) {} 322 323 virtual UnionDecl * clone() const override { return new UnionDecl( *this ); } 324 virtual void accept( Visitor & v ) override { v.visit( this ); } 325 virtual void accept( Visitor & v ) const override { v.visit( this ); } 326 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 327 private: 328 virtual const char * typeString() const override; 327 329 }; 328 330 … … 330 332 typedef AggregateDecl Parent; 331 333 public: 332 EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}333 EnumDecl( const EnumDecl & other ) : Parent( other ) {}334 EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {} 335 EnumDecl( const EnumDecl & other ) : Parent( other ) {} 334 336 335 337 bool valueOf( Declaration * enumerator, long long int & value ); 336 338 337 virtual EnumDecl * clone() const override { return new EnumDecl( *this ); }338 virtual void accept( Visitor & v ) override { v.visit( this ); } 339 virtual void accept( Visitor & v ) const override { v.visit( this ); } 340 virtual Declaration * acceptMutator( Mutator &m ) override { return m.mutate( this ); }339 virtual EnumDecl * clone() const override { return new EnumDecl( *this ); } 340 virtual void accept( Visitor & v ) override { v.visit( this ); } 341 virtual void accept( Visitor & v ) const override { v.visit( this ); } 342 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 341 343 private: 342 344 std::unordered_map< std::string, long long int > enumValues; 343 virtual std::stringtypeString() const override;345 virtual const char * typeString() const override; 344 346 }; 345 347 … … 347 349 typedef AggregateDecl Parent; 348 350 public: 349 TraitDecl( const std::string & name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) {351 TraitDecl( const std::string & name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) { 350 352 assertf( attributes.empty(), "attribute unsupported for traits" ); 351 353 } 352 TraitDecl( const TraitDecl & other ) : Parent( other ) {}353 354 virtual TraitDecl * clone() const override { return new TraitDecl( *this ); }355 virtual void accept( Visitor & v ) override { v.visit( this ); } 356 virtual void accept( Visitor & v ) const override { v.visit( this ); } 357 virtual Declaration * acceptMutator( Mutator &m ) override { return m.mutate( this ); }358 private: 359 virtual std::stringtypeString() const override;354 TraitDecl( const TraitDecl & other ) : Parent( other ) {} 355 356 virtual TraitDecl * clone() const override { return new TraitDecl( *this ); } 357 virtual void accept( Visitor & v ) override { v.visit( this ); } 358 virtual void accept( Visitor & v ) const override { v.visit( this ); } 359 virtual Declaration * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 360 private: 361 virtual const char * typeString() const override; 360 362 }; 361 363 … … 379 381 class AsmDecl : public Declaration { 380 382 public: 381 AsmStmt * stmt;382 383 AsmDecl( AsmStmt * stmt );384 AsmDecl( const AsmDecl & other );383 AsmStmt * stmt; 384 385 AsmDecl( AsmStmt * stmt ); 386 AsmDecl( const AsmDecl & other ); 385 387 virtual ~AsmDecl(); 386 388 387 AsmStmt * get_stmt() { return stmt; }388 void set_stmt( AsmStmt * newValue ) { stmt = newValue; }389 390 virtual AsmDecl * clone() const override { return new AsmDecl( *this ); }391 virtual void accept( Visitor & v ) override { v.visit( this ); } 392 virtual void accept( Visitor & v ) const override { v.visit( this ); } 393 virtual AsmDecl * acceptMutator( Mutator &m ) override { return m.mutate( this ); }394 virtual void print( std::ostream & os, Indenter indent = {} ) const override;395 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;389 AsmStmt * get_stmt() { return stmt; } 390 void set_stmt( AsmStmt * newValue ) { stmt = newValue; } 391 392 virtual AsmDecl * clone() const override { return new AsmDecl( *this ); } 393 virtual void accept( Visitor & v ) override { v.visit( this ); } 394 virtual void accept( Visitor & v ) const override { v.visit( this ); } 395 virtual AsmDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 396 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 397 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 396 398 }; 397 399 … … 408 410 virtual void accept( Visitor & v ) override { v.visit( this ); } 409 411 virtual void accept( Visitor & v ) const override { v.visit( this ); } 410 virtual StaticAssertDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); }411 virtual void print( std::ostream & os, Indenter indent = {} ) const override;412 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;412 virtual StaticAssertDecl * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 413 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 414 virtual void printShort( std::ostream & os, Indenter indent = {} ) const override; 413 415 }; 414 416 -
src/SynTree/DeclarationWithType.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 08:34:35 201713 // Update Count : 2 512 // Last Modified On : Fri Dec 13 23:45:16 2019 13 // Update Count : 26 14 14 // 15 15 … … 20 20 #include "Common/utility.h" // for cloneAll, deleteAll, maybeClone 21 21 #include "Declaration.h" // for DeclarationWithType, Declaration 22 #include " Parser/LinkageSpec.h"// for Spec23 #include " SynTree/Expression.h"// for ConstantExpr22 #include "LinkageSpec.h" // for Spec 23 #include "Expression.h" // for ConstantExpr 24 24 #include "Type.h" // for Type, Type::FuncSpecifiers, Type::St... 25 25 -
src/SynTree/Expression.cc
r71d6bd8 r7030dab 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 : Thr Aug 15 13:43:00201913 // Update Count : 6411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 07:55:15 2019 13 // Update Count : 70 14 14 // 15 15 … … 22 22 23 23 #include "Common/utility.h" // for maybeClone, cloneAll, deleteAll 24 #include "Declaration.h" // for ObjectDecl, DeclarationWithType25 24 #include "Expression.h" // for Expression, ImplicitCopyCtorExpr 26 25 #include "InitTweak/InitTweak.h" // for getCallArg, getPointerBase … … 294 293 } 295 294 296 KeywordCastExpr::KeywordCastExpr( Expression * arg, Targettarget ) : Expression(), arg(arg), target( target ) {295 KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ) : Expression(), arg(arg), target( target ) { 297 296 } 298 297 … … 304 303 } 305 304 306 const std::string & KeywordCastExpr::targetString() const { 307 static const std::string targetStrs[] = { 308 "coroutine", "thread", "monitor" 309 }; 310 static_assert( 311 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 312 "Each KeywordCastExpr::Target should have a corresponding string representation" 313 ); 314 return targetStrs[(unsigned long)target]; 305 const char * KeywordCastExpr::targetString() const { 306 return AggregateDecl::aggrString( target ); 315 307 } 316 308 -
src/SynTree/Expression.h
r71d6bd8 r7030dab 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 : Thr Aug 15 13:46:00201913 // Update Count : 5411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 16:50:19 2019 13 // Update Count : 60 14 14 // 15 15 … … 28 28 #include "Label.h" // for Label 29 29 #include "Mutator.h" // for Mutator 30 #include "Declaration.h" // for Aggregate 30 31 #include "SynTree.h" // for UniqueId 31 32 #include "Visitor.h" // for Visitor … … 229 230 public: 230 231 Expression * arg; 231 enum Target { 232 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS 233 } target; 234 235 KeywordCastExpr( Expression * arg, Target target ); 232 struct Concrete { 233 std::string field; 234 std::string getter; 235 }; 236 AggregateDecl::Aggregate target; 237 Concrete concrete_target; 238 239 KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ); 236 240 KeywordCastExpr( const KeywordCastExpr & other ); 237 241 virtual ~KeywordCastExpr(); 238 242 239 const std::string &targetString() const;243 const char * targetString() const; 240 244 241 245 virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); } -
src/SynTree/FunctionDecl.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 08:33:41 201713 // Update Count : 7 412 // Last Modified On : Mon Dec 16 15:11:20 2019 13 // Update Count : 77 14 14 // 15 15 … … 23 23 #include "Common/utility.h" // for maybeClone, printAll 24 24 #include "Declaration.h" // for FunctionDecl, FunctionDecl::Parent 25 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall 25 #include "Expression.h" 26 #include "LinkageSpec.h" // for Spec, linkageName, Cforall 26 27 #include "Statement.h" // for CompoundStmt 27 28 #include "Type.h" // for Type, FunctionType, Type::FuncSpecif... … … 72 73 } // if 73 74 if ( linkage != LinkageSpec::Cforall ) { 74 os << LinkageSpec:: linkageName( linkage ) << " ";75 os << LinkageSpec::name( linkage ) << " "; 75 76 } // if 76 77 -
src/SynTree/LinkageSpec.h
r71d6bd8 r7030dab 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Sat May 16 13:24:28 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Jul 10 16:02:34 201913 // Update Count : 1811 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Mar 2 16:13:00 2020 13 // Update Count : 21 14 14 // 15 15 … … 18 18 #include <string> 19 19 20 #include "Common/CodeLocation.h" 20 struct CodeLocation; 21 21 22 22 namespace LinkageSpec { 23 // All linkage specs are some combination of these flags: 24 enum { Mangle = 1 << 0, Generate = 1 << 1, Overrideable = 1 << 2, Builtin = 1 << 3, GccBuiltin = 1 << 4, NoOfSpecs = 1 << 5, }; 23 // Bitflags for linkage specifiers 24 enum { 25 Mangle = 1 << 0, 26 Generate = 1 << 1, 27 Overrideable = 1 << 2, 28 Builtin = 1 << 3, 29 GccBuiltin = 1 << 4, 30 }; 25 31 32 // Bitflag type for storage classes 26 33 union Spec { 27 34 unsigned int val; … … 42 49 43 50 44 Spec linkageUpdate( CodeLocation location, Spec old_spec, const std::string * cmd ); 45 /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false 46 * If cmd = "Cforall" returns old_spec Spec with is_mangled = true 47 */ 51 Spec update( CodeLocation location, Spec spec, const std::string * cmd ); 52 // If cmd = "C" returns a Spec that is old_spec with is_mangled = false 53 // If cmd = "Cforall" returns old_spec Spec with is_mangled = true 48 54 49 std::string linkageName( Spec );55 std::string name( Spec ); 50 56 51 57 // To Update: LinkageSpec::isXyz( cur_spec ) -> cur_spec.is_xyz -
src/SynTree/Mutator.h
r71d6bd8 r7030dab 51 51 virtual Statement * mutate( CatchStmt * catchStmt ) = 0; 52 52 virtual Statement * mutate( FinallyStmt * catchStmt ) = 0; 53 virtual Statement * mutate( SuspendStmt * suspendStmt ) = 0; 53 54 virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0; 54 55 virtual Declaration * mutate( WithStmt * withStmt ) = 0; -
src/SynTree/NamedTypeDecl.cc
r71d6bd8 r7030dab 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 : Wed Aug 9 13:28:00 201713 // Update Count : 1 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Dec 16 15:11:40 2019 13 // Update Count : 17 14 14 // 15 15 … … 20 20 #include "Common/utility.h" // for printAll, cloneAll, deleteAll, maybe... 21 21 #include "Declaration.h" // for NamedTypeDecl, DeclarationWithType 22 #include " Parser/LinkageSpec.h"// for Spec, Cforall, linkageName22 #include "LinkageSpec.h" // for Spec, Cforall, linkageName 23 23 #include "Type.h" // for Type, Type::StorageClasses 24 24 … … 44 44 45 45 if ( linkage != LinkageSpec::Cforall ) { 46 os << LinkageSpec:: linkageName( linkage ) << " ";46 os << LinkageSpec::name( linkage ) << " "; 47 47 } // if 48 48 get_storageClasses().print( os ); … … 78 78 } 79 79 80 std::stringTypedefDecl::typeString() const { return "typedef"; }80 const char * TypedefDecl::typeString() const { return "typedef"; } 81 81 82 82 // Local Variables: // -
src/SynTree/ObjectDecl.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 08:34:27 201713 // Update Count : 5912 // Last Modified On : Mon Dec 16 15:12:03 2019 13 // Update Count : 61 14 14 // 15 15 … … 23 23 #include "Expression.h" // for Expression 24 24 #include "Initializer.h" // for Initializer 25 #include " Parser/LinkageSpec.h"// for Spec, linkageName, Cforall25 #include "LinkageSpec.h" // for Spec, linkageName, Cforall 26 26 #include "Type.h" // for Type, Type::StorageClasses, Type::Fu... 27 27 … … 48 48 49 49 if ( linkage != LinkageSpec::Cforall ) { 50 os << LinkageSpec:: linkageName( linkage ) << " ";50 os << LinkageSpec::name( linkage ) << " "; 51 51 } // if 52 52 -
src/SynTree/Statement.cc
r71d6bd8 r7030dab 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 20:46:44 201713 // Update Count : 6811 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon Jan 20 16:03:00 2020 13 // Update Count : 71 14 14 // 15 15 … … 46 46 Statement::~Statement() {} 47 47 48 ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {}49 50 ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}48 ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {} 49 50 ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} 51 51 52 52 ExprStmt::~ExprStmt() { … … 54 54 } 55 55 56 void ExprStmt::print( std::ostream & os, Indenter indent ) const {56 void ExprStmt::print( std::ostream & os, Indenter indent ) const { 57 57 os << "Expression Statement:" << endl << indent+1; 58 58 expr->print( os, indent+1 ); … … 60 60 61 61 62 AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}62 AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {} 63 63 64 64 AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) { … … 75 75 } 76 76 77 void AsmStmt::print( std::ostream & os, Indenter indent ) const {77 void AsmStmt::print( std::ostream & os, Indenter indent ) const { 78 78 os << "Assembler Statement:" << endl; 79 79 os << indent+1 << "instruction: " << endl << indent; … … 96 96 DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {} 97 97 98 void DirectiveStmt::print( std::ostream & os, Indenter ) const {98 void DirectiveStmt::print( std::ostream & os, Indenter ) const { 99 99 os << "GCC Directive:" << directive << endl; 100 100 } 101 101 102 102 103 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" }; 103 const char * BranchStmt::brType[] = { 104 "Goto", "Break", "Continue", "Fall Through", "Fall Through Default", 105 }; 104 106 105 107 BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) : … … 111 113 } 112 114 113 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :115 BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) : 114 116 Statement(), computedTarget( computedTarget ), type( type ) { 115 117 if ( type != BranchStmt::Goto || computedTarget == nullptr ) { … … 118 120 } 119 121 120 void BranchStmt::print( std::ostream &os, Indenter indent ) const { 122 void BranchStmt::print( std::ostream & os, Indenter indent ) const { 123 assert(type < 5); 121 124 os << "Branch (" << brType[type] << ")" << endl ; 122 125 if ( target != "" ) os << indent+1 << "with target: " << target << endl; … … 125 128 } 126 129 127 ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {}130 ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {} 128 131 129 132 ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {} … … 133 136 } 134 137 135 void ReturnStmt::print( std::ostream & os, Indenter indent ) const {138 void ReturnStmt::print( std::ostream & os, Indenter indent ) const { 136 139 os << "Return Statement, returning: "; 137 140 if ( expr != nullptr ) { … … 142 145 } 143 146 144 IfStmt::IfStmt( Expression * condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):147 IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ): 145 148 Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {} 146 149 … … 157 160 } 158 161 159 void IfStmt::print( std::ostream & os, Indenter indent ) const {162 void IfStmt::print( std::ostream & os, Indenter indent ) const { 160 163 os << "If on condition: " << endl; 161 164 os << indent+1; … … 176 179 thenPart->print( os, indent+1 ); 177 180 178 if ( elsePart != 0) {181 if ( elsePart != nullptr ) { 179 182 os << indent << "... else: " << endl; 180 183 os << indent+1; … … 183 186 } 184 187 185 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):188 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ): 186 189 Statement(), condition( condition ), statements( statements ) { 187 190 } … … 198 201 } 199 202 200 void SwitchStmt::print( std::ostream & os, Indenter indent ) const {203 void SwitchStmt::print( std::ostream & os, Indenter indent ) const { 201 204 os << "Switch on condition: "; 202 205 condition->print( os ); … … 208 211 } 209 212 210 CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :213 CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) : 211 214 Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) { 212 if ( isDefault() && condition != 0) SemanticError( condition, "default case with condition: " );215 if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " ); 213 216 } 214 217 … … 229 232 } 230 233 231 void CaseStmt::print( std::ostream & os, Indenter indent ) const {234 void CaseStmt::print( std::ostream & os, Indenter indent ) const { 232 235 if ( isDefault() ) os << indent << "Default "; 233 236 else { … … 243 246 } 244 247 245 WhileStmt::WhileStmt( Expression * condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):248 WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ): 246 249 Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) { 247 250 } … … 256 259 } 257 260 258 void WhileStmt::print( std::ostream & os, Indenter indent ) const {261 void WhileStmt::print( std::ostream & os, Indenter indent ) const { 259 262 os << "While on condition: " << endl ; 260 263 condition->print( os, indent+1 ); … … 262 265 os << indent << "... with body: " << endl; 263 266 264 if ( body != 0) body->print( os, indent+1 );265 } 266 267 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression *increment, Statement *body ):267 if ( body != nullptr ) body->print( os, indent+1 ); 268 } 269 270 ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ): 268 271 Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) { 269 272 } … … 282 285 } 283 286 284 void ForStmt::print( std::ostream & os, Indenter indent ) const {287 void ForStmt::print( std::ostream & os, Indenter indent ) const { 285 288 Statement::print( os, indent ); // print labels 286 289 … … 305 308 } 306 309 307 if ( body != 0) {310 if ( body != nullptr ) { 308 311 os << "\n" << indent << "... with body: \n" << indent+1; 309 312 body->print( os, indent+1 ); … … 317 320 } 318 321 319 ThrowStmt::ThrowStmt( const ThrowStmt & other ) :322 ThrowStmt::ThrowStmt( const ThrowStmt & other ) : 320 323 Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) { 321 324 } … … 326 329 } 327 330 328 void ThrowStmt::print( std::ostream & os, Indenter indent) const {331 void ThrowStmt::print( std::ostream & os, Indenter indent) const { 329 332 if ( target ) os << "Non-Local "; 330 333 os << "Throw Statement, raising: "; … … 336 339 } 337 340 338 TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :341 TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) : 339 342 Statement(), block( tryBlock ), handlers( handlers ), finallyBlock( finallyBlock ) { 340 343 } 341 344 342 TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {345 TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) { 343 346 cloneAll( other.handlers, handlers ); 344 347 } … … 350 353 } 351 354 352 void TryStmt::print( std::ostream & os, Indenter indent ) const {355 void TryStmt::print( std::ostream & os, Indenter indent ) const { 353 356 os << "Try Statement" << endl; 354 357 os << indent << "... with block:" << endl << indent+1; … … 363 366 364 367 // finally block 365 if ( finallyBlock != 0) {368 if ( finallyBlock != nullptr ) { 366 369 os << indent << "... and finally:" << endl << indent+1; 367 370 finallyBlock->print( os, indent+1 ); … … 369 372 } 370 373 371 CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression *cond, Statement *body ) :374 CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) : 372 375 Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) { 373 376 assertf( decl, "Catch clause must have a declaration." ); … … 383 386 } 384 387 385 void CatchStmt::print( std::ostream & os, Indenter indent ) const {388 void CatchStmt::print( std::ostream & os, Indenter indent ) const { 386 389 os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl; 387 390 … … 401 404 402 405 403 FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) {406 FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) { 404 407 } 405 408 … … 411 414 } 412 415 413 void FinallyStmt::print( std::ostream & os, Indenter indent ) const {416 void FinallyStmt::print( std::ostream & os, Indenter indent ) const { 414 417 os << "Finally Statement" << endl; 415 418 os << indent << "... with block:" << endl << indent+1; 416 419 block->print( os, indent+1 ); 420 } 421 422 SuspendStmt::SuspendStmt( const SuspendStmt & other ) 423 : Statement( other ) 424 , then( maybeClone(other.then) ) 425 {} 426 427 SuspendStmt::~SuspendStmt() { 428 delete then; 429 } 430 431 void SuspendStmt::print( std::ostream & os, Indenter indent ) const { 432 os << "Suspend Statement"; 433 switch (type) { 434 case None : os << " with implicit target"; break; 435 case Generator: os << " for generator" ; break; 436 case Coroutine: os << " for coroutine" ; break; 437 } 438 os << endl; 439 indent += 1; 440 441 if(then) { 442 os << indent << " with post statement :" << endl; 443 then->print( os, indent + 1); 444 } 417 445 } 418 446 … … 458 486 } 459 487 460 void WaitForStmt::print( std::ostream & os, Indenter indent ) const {488 void WaitForStmt::print( std::ostream & os, Indenter indent ) const { 461 489 os << "Waitfor Statement" << endl; 462 490 indent += 1; … … 514 542 } 515 543 516 void NullStmt::print( std::ostream & os, Indenter indent ) const {544 void NullStmt::print( std::ostream & os, Indenter indent ) const { 517 545 os << "Null Statement" << endl; 518 546 Statement::print( os, indent ); … … 530 558 } 531 559 532 void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {560 void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const { 533 561 os << "Implicit Ctor Dtor Statement" << endl; 534 562 os << indent << "... with Ctor/Dtor: "; -
src/SynTree/Statement.h
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 12 09:01:53 201913 // Update Count : 8 312 // Last Modified On : Fri Jan 10 14:13:24 2020 13 // Update Count : 85 14 14 // 15 15 … … 257 257 Statement * body; 258 258 259 ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0);259 ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr ); 260 260 ForStmt( const ForStmt & other ); 261 261 virtual ~ForStmt(); … … 357 357 FinallyStmt * finallyBlock; 358 358 359 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0);359 TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = nullptr ); 360 360 TryStmt( const TryStmt & other ); 361 361 virtual ~TryStmt(); … … 422 422 }; 423 423 424 class SuspendStmt : public Statement { 425 public: 426 CompoundStmt * then = nullptr; 427 enum Type { None, Coroutine, Generator } type = None; 428 429 SuspendStmt() = default; 430 SuspendStmt( const SuspendStmt & ); 431 virtual ~SuspendStmt(); 432 433 virtual SuspendStmt * clone() const override { return new SuspendStmt( *this ); } 434 virtual void accept( Visitor & v ) override { v.visit( this ); } 435 virtual void accept( Visitor & v ) const override { v.visit( this ); } 436 virtual Statement * acceptMutator( Mutator & m ) override { return m.mutate( this ); } 437 virtual void print( std::ostream & os, Indenter indent = {} ) const override; 438 }; 439 424 440 class WaitForStmt : public Statement { 425 441 public: -
src/SynTree/SynTree.h
r71d6bd8 r7030dab 54 54 class CatchStmt; 55 55 class FinallyStmt; 56 class SuspendStmt; 56 57 class WaitForStmt; 57 58 class WithStmt; -
src/SynTree/TupleType.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 1 17:10:58 201713 // Update Count : 312 // Last Modified On : Fri Dec 13 23:44:38 2019 13 // Update Count : 4 14 14 // 15 15 … … 20 20 #include "Declaration.h" // for Declaration, ObjectDecl 21 21 #include "Initializer.h" // for ListInit 22 #include " Parser/LinkageSpec.h"// for Cforall22 #include "LinkageSpec.h" // for Cforall 23 23 #include "Type.h" // for TupleType, Type, Type::Qualifiers 24 24 -
src/SynTree/Type.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 4 21:05:07 201913 // Update Count : 4 512 // Last Modified On : Sun Dec 15 16:52:37 2019 13 // Update Count : 49 14 14 // 15 15 #include "Type.h" … … 24 24 using namespace std; 25 25 26 // GENERATED START, DO NOT EDIT 27 // GENERATED BY BasicTypes-gen.cc 26 28 const char * BasicType::typeNames[] = { 27 29 "_Bool", … … 45 47 "float", 46 48 "float _Complex", 47 //"float _Imaginary",48 49 "_Float32x", 49 50 "_Float32x _Complex", … … 52 53 "double", 53 54 "double _Complex", 54 //"double _Imaginary",55 55 "_Float64x", 56 56 "_Float64x _Complex", … … 61 61 "long double", 62 62 "long double _Complex", 63 //"long double _Imaginary",64 63 "_Float128x", 65 64 "_Float128x _Complex", 66 65 }; 67 static_assert( 68 sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES, 69 "Each basic type name should have a corresponding kind enum value" 70 ); 66 // GENERATED END 71 67 72 68 Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {} -
src/SynTree/TypeDecl.cc
r71d6bd8 r7030dab 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 : Wed Aug 9 14:35:00 201713 // Update Count : 611 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 15:26:14 2019 13 // Update Count : 21 14 14 // 15 15 … … 21 21 #include "Type.h" // for Type, Type::StorageClasses 22 22 23 TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Ttype || sized ), kind( kind) {23 TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), kind( kind ), sized( kind == Ttype || sized ), init( init ) { 24 24 } 25 25 26 TypeDecl::TypeDecl( const TypeDecl & other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind) {26 TypeDecl::TypeDecl( const TypeDecl & other ) : Parent( other ), kind( other.kind ), sized( other.sized ), init( maybeClone( other.init ) ) { 27 27 } 28 28 29 29 TypeDecl::~TypeDecl() { 30 30 delete init; 31 31 } 32 32 33 std::stringTypeDecl::typeString() const {34 static const std::string kindNames[] = { "object type", "function type", "tuple type" };35 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." );36 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl'skind is out of bounds." );37 return (isComplete() ? "sized " : "") + kindNames[ kind ];33 const char * TypeDecl::typeString() const { 34 static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" }; 35 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." ); 36 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 37 return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0' 38 38 } 39 39 40 std::stringTypeDecl::genTypeString() const {41 static const std::string kindNames[] = { "dtype", "ftype", "ttype" };42 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );43 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl'skind is out of bounds." );40 const char * TypeDecl::genTypeString() const { 41 static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" }; 42 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." ); 43 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 44 44 return kindNames[ kind ]; 45 45 } 46 46 47 47 void TypeDecl::print( std::ostream &os, Indenter indent ) const { 48 49 50 51 52 } 48 NamedTypeDecl::print( os, indent ); 49 if ( init ) { 50 os << std::endl << indent << "with type initializer: "; 51 init->print( os, indent + 1 ); 52 } // if 53 53 } 54 54 55 56 55 std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) { 57 56 return os << data.kind << ", " << data.isComplete; 58 57 } 59 58 -
src/SynTree/Visitor.h
r71d6bd8 r7030dab 78 78 virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); } 79 79 virtual void visit( const FinallyStmt * finallyStmt ) = 0; 80 virtual void visit( SuspendStmt * node ) { visit( const_cast<const SuspendStmt *>(node) ); } 81 virtual void visit( const SuspendStmt * suspendStmt ) = 0; 80 82 virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); } 81 83 virtual void visit( const WaitForStmt * waitforStmt ) = 0; -
src/SynTree/module.mk
r71d6bd8 r7030dab 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Mon Jun 1 17:54:09 201514 ## Update Count : 113 ## Last Modified On : Sat Dec 14 07:26:43 2019 14 ## Update Count : 2 15 15 ############################################################################### 16 16 17 17 SRC_SYNTREE = \ 18 SynTree/Type.cc \ 19 SynTree/VoidType.cc \ 18 SynTree/AddressExpr.cc \ 19 SynTree/AggregateDecl.cc \ 20 SynTree/ApplicationExpr.cc \ 21 SynTree/ArrayType.cc \ 22 SynTree/AttrType.cc \ 23 SynTree/Attribute.cc \ 20 24 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 \ 25 SynTree/CommaExpr.cc \ 26 SynTree/CompoundStmt.cc \ 31 27 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 \ 28 SynTree/DeclReplacer.cc \ 40 29 SynTree/DeclStmt.cc \ 41 30 SynTree/Declaration.cc \ 42 31 SynTree/DeclarationWithType.cc \ 32 SynTree/Expression.cc \ 33 SynTree/FunctionDecl.cc \ 34 SynTree/FunctionType.cc \ 35 SynTree/Initializer.cc \ 36 SynTree/LinkageSpec.cc \ 37 SynTree/NamedTypeDecl.cc \ 43 38 SynTree/ObjectDecl.cc \ 44 SynTree/FunctionDecl.cc \ 45 SynTree/AggregateDecl.cc \ 46 SynTree/NamedTypeDecl.cc \ 39 SynTree/PointerType.cc \ 40 SynTree/ReferenceToType.cc \ 41 SynTree/ReferenceType.cc \ 42 SynTree/Statement.cc \ 43 SynTree/TupleExpr.cc \ 44 SynTree/TupleType.cc \ 45 SynTree/Type.cc \ 47 46 SynTree/TypeDecl.cc \ 48 SynTree/ Initializer.cc \47 SynTree/TypeExpr.cc \ 49 48 SynTree/TypeSubstitution.cc \ 50 SynTree/Attribute.cc \ 51 SynTree/DeclReplacer.cc 49 SynTree/TypeofType.cc \ 50 SynTree/VarArgsType.cc \ 51 SynTree/VoidType.cc \ 52 SynTree/ZeroOneType.cc 52 53 53 54 SRC += $(SRC_SYNTREE)
Note:
See TracChangeset
for help on using the changeset viewer.