- 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
- Files:
-
- 1 added
- 2 deleted
- 99 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Convert.cpp
r71d6bd8 r7030dab 10 10 // Created On : Thu May 09 15::37::05 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:21:46201913 // Update Count : 1312 // Last Modified On : Wed Dec 11 21:39:32 2019 13 // Update Count : 33 14 14 // 15 15 … … 245 245 auto decl = new StructDecl( 246 246 node->name, 247 node->kind,247 (AggregateDecl::Aggregate)node->kind, 248 248 get<Attribute>().acceptL( node->attributes ), 249 249 LinkageSpec::Spec( node->linkage.val ) … … 493 493 } 494 494 495 const ast::Stmt * visit(const ast::SuspendStmt * node ) override final { 496 if ( inCache( node ) ) return nullptr; 497 auto stmt = new SuspendStmt(); 498 stmt->then = get<CompoundStmt>().accept1( node->then ); 499 switch(node->type) { 500 case ast::SuspendStmt::None : stmt->type = SuspendStmt::None ; break; 501 case ast::SuspendStmt::Coroutine: stmt->type = SuspendStmt::Coroutine; break; 502 case ast::SuspendStmt::Generator: stmt->type = SuspendStmt::Generator; break; 503 } 504 return stmtPostamble( stmt, node ); 505 } 506 495 507 const ast::Stmt * visit( const ast::WaitForStmt * node ) override final { 496 508 if ( inCache( node ) ) return nullptr; … … 686 698 687 699 const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final { 688 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS; 689 switch (node->target) { 690 case ast::KeywordCastExpr::Coroutine: 691 castTarget = KeywordCastExpr::Coroutine; 692 break; 693 case ast::KeywordCastExpr::Thread: 694 castTarget = KeywordCastExpr::Thread; 695 break; 696 case ast::KeywordCastExpr::Monitor: 697 castTarget = KeywordCastExpr::Monitor; 698 break; 699 default: 700 break; 701 } 702 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS ); 700 AggregateDecl::Aggregate castTarget = (AggregateDecl::Aggregate)node->target; 701 assert( AggregateDecl::Generator <= castTarget && castTarget <= AggregateDecl::Thread ); 703 702 auto expr = visitBaseExpr( node, 704 703 new KeywordCastExpr( … … 1247 1246 cv( node ), 1248 1247 node->name, 1249 node->kind == ast::Type Var::Ftype,1248 node->kind == ast::TypeDecl::Ftype, 1250 1249 get<Attribute>().acceptL( node->attributes ) 1251 1250 }; … … 1515 1514 old->location, 1516 1515 old->name, 1517 old->kind,1516 (ast::AggregateDecl::Aggregate)old->kind, 1518 1517 GET_ACCEPT_V(attributes, Attribute), 1519 1518 { old->linkage.val } … … 1602 1601 { old->storageClasses.val }, 1603 1602 GET_ACCEPT_1(base, Type), 1604 (ast::Type Var::Kind)(unsigned)old->kind,1603 (ast::TypeDecl::Kind)(unsigned)old->kind, 1605 1604 old->sized, 1606 1605 GET_ACCEPT_1(init, Type) … … 1883 1882 } 1884 1883 1884 virtual void visit( const SuspendStmt * old ) override final { 1885 if ( inCache( old ) ) return; 1886 ast::SuspendStmt::Type type; 1887 switch (old->type) { 1888 case SuspendStmt::Coroutine: type = ast::SuspendStmt::Coroutine; break; 1889 case SuspendStmt::Generator: type = ast::SuspendStmt::Generator; break; 1890 case SuspendStmt::None : type = ast::SuspendStmt::None ; break; 1891 default: abort(); 1892 } 1893 this->node = new ast::SuspendStmt( 1894 old->location, 1895 GET_ACCEPT_1(then , CompoundStmt), 1896 type, 1897 GET_LABELS_V(old->labels) 1898 ); 1899 cache.emplace( old, this->node ); 1900 } 1901 1885 1902 virtual void visit( const WaitForStmt * old ) override final { 1886 1903 if ( inCache( old ) ) return; … … 2056 2073 } 2057 2074 2058 virtual void visit( const KeywordCastExpr * old) override final { 2059 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS; 2060 switch (old->target) { 2061 case KeywordCastExpr::Coroutine: 2062 castTarget = ast::KeywordCastExpr::Coroutine; 2063 break; 2064 case KeywordCastExpr::Thread: 2065 castTarget = ast::KeywordCastExpr::Thread; 2066 break; 2067 case KeywordCastExpr::Monitor: 2068 castTarget = ast::KeywordCastExpr::Monitor; 2069 break; 2070 default: 2071 break; 2072 } 2073 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS ); 2075 virtual void visit( const KeywordCastExpr * old ) override final { 2076 ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target; 2077 assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread ); 2074 2078 this->node = visitBaseExpr( old, 2075 2079 new ast::KeywordCastExpr( … … 2599 2603 ty = new ast::TypeInstType{ 2600 2604 old->name, 2601 old->isFtype ? ast::Type Var::Ftype : ast::TypeVar::Dtype,2605 old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype, 2602 2606 cv( old ), 2603 2607 GET_ACCEPT_V( attributes, Attribute ) -
src/AST/Decl.cpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 16:23:15 2019 13 // Update Count : 20 14 14 // 15 15 … … 18 18 #include <cassert> // for assert, strict_dynamic_cast 19 19 #include <iostream> 20 #include <string>21 20 #include <unordered_map> 22 21 … … 27 26 #include "Node.hpp" // for readonly 28 27 #include "Type.hpp" // for readonly 29 #include "Parser/ParseNode.h" // for DeclarationNode30 28 31 29 namespace ast { … … 58 56 // --- TypeDecl 59 57 60 std::string TypeDecl::typeString() const { 61 static const std::string kindNames[] = { "object type", "function type", "tuple type" }; 62 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, 63 "typeString: kindNames is out of sync." ); 64 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." ); 65 return (sized ? "sized " : "") + kindNames[ kind ]; 58 const char * TypeDecl::typeString() const { 59 static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" }; 60 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." ); 61 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 62 return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0' 66 63 } 67 64 68 std::stringTypeDecl::genTypeString() const {69 static const std::string kindNames[] = { "dtype", "ftype", "ttype" };70 assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );71 assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl'skind is out of bounds." );65 const char * TypeDecl::genTypeString() const { 66 static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" }; 67 static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." ); 68 assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." ); 72 69 return kindNames[ kind ]; 73 70 } … … 75 72 std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) { 76 73 return out << data.kind << ", " << data.isComplete; 74 } 75 76 // --- AggregateDecl 77 78 // These must harmonize with the corresponding AggregateDecl::Aggregate enumerations. 79 static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" }; 80 81 const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) { 82 return aggregateNames[aggr]; 77 83 } 78 84 -
src/AST/Decl.hpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 17:38:33 2019 13 // Update Count : 29 14 14 // 15 15 … … 20 20 #include <unordered_map> 21 21 #include <vector> 22 #include <algorithm> 22 23 23 24 #include "FunctionSpec.hpp" … … 27 28 #include "ParseNode.hpp" 28 29 #include "StorageClasses.hpp" 29 #include "TypeVar.hpp"30 30 #include "Visitor.hpp" 31 #include "Parser/ParseNode.h" // for DeclarationNode::Aggregate 31 #include "Common/utility.h" 32 #include "Common/SemanticError.h" // error_str 32 33 33 34 // Must be included in *all* AST classes; should be #undef'd at the end of the file … … 127 128 std::vector< ptr<Expr> > withExprs; 128 129 129 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,130 FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type, 130 131 CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, 131 132 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}) … … 138 139 bool has_body() const { return stmts; } 139 140 140 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }141 const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); } 141 142 private: 142 143 FunctionDecl * clone() const override { return new FunctionDecl( *this ); } … … 151 152 std::vector<ptr<DeclWithType>> assertions; 152 153 153 NamedTypeDecl( 154 NamedTypeDecl( 154 155 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 155 156 const Type * b, Linkage::Spec spec = Linkage::Cforall ) … … 157 158 158 159 /// Produces a name for the kind of alias 159 virtual std::stringtypeString() const = 0;160 virtual const char * typeString() const = 0; 160 161 161 162 private: … … 166 167 /// Cforall type variable: `dtype T` 167 168 class TypeDecl final : public NamedTypeDecl { 168 public: 169 TypeVar::Kind kind; 169 public: 170 enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS }; 171 172 Kind kind; 170 173 bool sized; 171 174 ptr<Type> init; … … 173 176 /// Data extracted from a type decl 174 177 struct Data { 175 TypeVar::Kind kind;178 Kind kind; 176 179 bool isComplete; 177 180 178 Data() : kind( (TypeVar::Kind)-1), isComplete( false ) {}181 Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {} 179 182 Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {} 180 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}183 Data( Kind k, bool c ) : kind( k ), isComplete( c ) {} 181 184 Data( const Data & d1, const Data & d2 ) 182 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 183 184 bool operator== ( const Data & o ) const { 185 return kind == o.kind && isComplete == o.isComplete; 186 } 187 bool operator!= ( const Data & o ) const { return !(*this == o); } 185 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {} 186 187 bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; } 188 bool operator!=( const Data & o ) const { return !(*this == o); } 188 189 }; 189 190 190 TypeDecl( 191 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 191 TypeDecl( 192 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 192 193 const Type * b, TypeVar::Kind k, bool s, const Type * i = nullptr ) 193 194 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ), 194 195 init( i ) {} 195 196 196 std::stringtypeString() const override;197 const char * typeString() const override; 197 198 /// Produces a name for generated code 198 std::stringgenTypeString() const;199 const char * genTypeString() const; 199 200 200 201 /// convenience accessor to match Type::isComplete() … … 202 203 203 204 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 204 private:205 private: 205 206 TypeDecl * clone() const override { return new TypeDecl{ *this }; } 206 207 MUTATE_FRIEND … … 216 217 : NamedTypeDecl( loc, name, storage, b, spec ) {} 217 218 218 std::stringtypeString() const override { return "typedef"; }219 const char * typeString() const override { return "typedef"; } 219 220 220 221 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } … … 227 228 class AggregateDecl : public Decl { 228 229 public: 230 enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate }; 231 static const char * aggrString( Aggregate aggr ); 232 229 233 std::vector<ptr<Decl>> members; 230 234 std::vector<ptr<TypeDecl>> params; … … 241 245 242 246 /// Produces a name for the kind of aggregate 243 virtual std::stringtypeString() const = 0;247 virtual const char * typeString() const = 0; 244 248 245 249 private: … … 251 255 class StructDecl final : public AggregateDecl { 252 256 public: 253 DeclarationNode::Aggregate kind;257 Aggregate kind; 254 258 255 259 StructDecl( const CodeLocation& loc, const std::string& name, 256 DeclarationNode::Aggregate kind = DeclarationNode::Struct,260 Aggregate kind = Struct, 257 261 std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall ) 258 262 : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {} 259 263 260 bool is_coroutine() { return kind == DeclarationNode::Coroutine; } 261 bool is_monitor() { return kind == DeclarationNode::Monitor; } 262 bool is_thread() { return kind == DeclarationNode::Thread; } 263 264 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 265 266 std::string typeString() const override { return "struct"; } 264 bool is_coroutine() { return kind == Coroutine; } 265 bool is_generator() { return kind == Generator; } 266 bool is_monitor () { return kind == Monitor ; } 267 bool is_thread () { return kind == Thread ; } 268 269 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 270 271 const char * typeString() const override { return aggrString( kind ); } 267 272 268 273 private: … … 280 285 const Decl * accept( Visitor& v ) const override { return v.visit( this ); } 281 286 282 std::string typeString() const override { return "union"; }287 const char * typeString() const override { return aggrString( Union ); } 283 288 284 289 private: … … 299 304 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 300 305 301 std::string typeString() const override { return "enum"; }306 const char * typeString() const override { return aggrString( Enum ); } 302 307 303 308 private: … … 318 323 const Decl * accept( Visitor & v ) const override { return v.visit( this ); } 319 324 320 std::stringtypeString() const override { return "trait"; }325 const char * typeString() const override { return "trait"; } 321 326 322 327 private: … … 344 349 ptr<AsmStmt> stmt; 345 350 346 AsmDecl( const CodeLocation & loc, AsmStmt * stmt )351 AsmDecl( const CodeLocation & loc, AsmStmt * stmt ) 347 352 : Decl( loc, "", {}, {} ), stmt(stmt) {} 348 353 349 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }350 private: 351 AsmDecl * clone() const override { return new AsmDecl( *this ); }354 const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); } 355 private: 356 AsmDecl * clone() const override { return new AsmDecl( *this ); } 352 357 MUTATE_FRIEND 353 358 }; … … 361 366 : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {} 362 367 363 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }368 const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); } 364 369 private: 365 370 StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); } -
src/AST/Expr.cpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 15 17:00:00 2019 11 // Last Modified By : Andrew Beach12 // Created On : Fri Oct 4 15:34:00 201913 // Update Count : 411 // Last Modified By : Peter A. Buhr 12 // Created On : Thr Jun 13 13:38:00 2019 13 // Update Count : 6 14 14 // 15 15 … … 163 163 // --- KeywordCastExpr 164 164 165 const std::string & KeywordCastExpr::targetString() const { 166 static const std::string targetStrs[] = { 167 "coroutine", "thread", "monitor" 168 }; 169 static_assert( 170 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS), 171 "Each KeywordCastExpr::Target should have a corresponding string representation" 172 ); 173 return targetStrs[(unsigned long)target]; 165 const char * KeywordCastExpr::targetString() const { 166 return AggregateDecl::aggrString( target ); 174 167 } 175 168 -
src/AST/Expr.hpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Fri May 10 10:30:00 2019 11 // Last Modified By : Andrew Beach12 // Created On : Thr Sep 26 12:51:00 201913 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Created On : Fri May 10 10:30:00 2019 13 // Update Count : 7 14 14 // 15 15 … … 26 26 #include "Fwd.hpp" // for UniqueId 27 27 #include "Label.hpp" 28 #include "Decl.hpp" 28 29 #include "ParseNode.hpp" 29 30 #include "Visitor.hpp" … … 310 311 public: 311 312 ptr<Expr> arg; 312 enum Target { Coroutine, Thread, Monitor, NUMBER_OF_TARGETS }target;313 314 KeywordCastExpr( const CodeLocation & loc, const Expr * a, Targett )313 ast::AggregateDecl::Aggregate target; 314 315 KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t ) 315 316 : Expr( loc ), arg( a ), target( t ) {} 316 317 317 318 /// Get a name for the target type 318 const std::string&targetString() const;319 const char * targetString() const; 319 320 320 321 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/Fwd.hpp
r71d6bd8 r7030dab 53 53 class CatchStmt; 54 54 class FinallyStmt; 55 class SuspendStmt; 55 56 class WaitForStmt; 56 57 class WithStmt; -
src/AST/Pass.hpp
r71d6bd8 r7030dab 114 114 const ast::Stmt * visit( const ast::CatchStmt * ) override final; 115 115 const ast::Stmt * visit( const ast::FinallyStmt * ) override final; 116 const ast::Stmt * visit( const ast::SuspendStmt * ) override final; 116 117 const ast::Stmt * visit( const ast::WaitForStmt * ) override final; 117 118 const ast::Decl * visit( const ast::WithStmt * ) override final; -
src/AST/Pass.impl.hpp
r71d6bd8 r7030dab 838 838 839 839 //-------------------------------------------------------------------------- 840 // FinallyStmt 841 template< typename pass_t > 842 const ast::Stmt * ast::Pass< pass_t >::visit( const ast::SuspendStmt * node ) { 843 VISIT_START( node ); 844 845 VISIT( 846 maybe_accept( node, &SuspendStmt::then ); 847 ) 848 849 VISIT_END( Stmt, node ); 850 } 851 852 //-------------------------------------------------------------------------- 840 853 // WaitForStmt 841 854 template< typename pass_t > -
src/AST/Print.cpp
r71d6bd8 r7030dab 674 674 safe_print( node->body ); 675 675 --indent; 676 677 return node; 678 } 679 680 virtual const ast::Stmt * visit( const ast::SuspendStmt * node ) override final { 681 os << "Suspend Statement"; 682 switch (node->type) { 683 case ast::SuspendStmt::None : os << " with implicit target"; break; 684 case ast::SuspendStmt::Generator: os << " for generator"; break; 685 case ast::SuspendStmt::Coroutine: os << " for coroutine"; break; 686 } 687 os << endl; 688 689 ++indent; 690 if(node->then) { 691 os << indent << " with post statement :" << endl; 692 safe_print( node->then ); 693 } 694 ++indent; 676 695 677 696 return node; … … 1359 1378 preprint( node ); 1360 1379 os << "instance of type " << node->name 1361 << " (" << (node->kind == ast::Type Var::Ftype ? "" : "not ") << "function type)";1380 << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)"; 1362 1381 print( node->params ); 1363 1382 -
src/AST/Stmt.hpp
r71d6bd8 r7030dab 344 344 }; 345 345 346 /// Suspend statement 347 class SuspendStmt final : public Stmt { 348 public: 349 ptr<CompoundStmt> then; 350 enum Type { None, Coroutine, Generator } type = None; 351 352 SuspendStmt( const CodeLocation & loc, const CompoundStmt * then, Type type, std::vector<Label> && labels = {} ) 353 : Stmt(loc, std::move(labels)), then(then), type(type) {} 354 355 const Stmt * accept( Visitor & v ) const override { return v.visit( this ); } 356 private: 357 SuspendStmt * clone() const override { return new SuspendStmt{ *this }; } 358 MUTATE_FRIEND 359 }; 360 346 361 /// Wait for concurrency statement `when (...) waitfor (... , ...) ... timeout(...) ... else ...` 347 362 class WaitForStmt final : public Stmt { -
src/AST/Type.cpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Mon May 13 15:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Mon May 13 15:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Dec 15 16:56:28 2019 13 // Update Count : 4 14 14 // 15 15 … … 50 50 // --- BasicType 51 51 52 const char *BasicType::typeNames[] = { 52 // GENERATED START, DO NOT EDIT 53 // GENERATED BY BasicTypes-gen.cc 54 const char * BasicType::typeNames[] = { 53 55 "_Bool", 54 56 "char", … … 88 90 "_Float128x _Complex", 89 91 }; 90 static_assert( 91 sizeof(BasicType::typeNames)/sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES, 92 "Each basic type name should have a corresponding kind enum value" 93 ); 92 // GENERATED END 94 93 95 94 // --- ParameterizedType -
src/AST/Type.hpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Thu May 9 10:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Thu May 9 10:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:56:46 2019 13 // Update Count : 5 14 14 // 15 15 … … 26 26 #include "Fwd.hpp" 27 27 #include "Node.hpp" // for Node, ptr, ptr_base 28 #include "TypeVar.hpp"29 28 #include "Visitor.hpp" 30 29 … … 448 447 public: 449 448 readonly<TypeDecl> base; 450 Type Var::Kind kind;449 TypeDecl::Kind kind; 451 450 452 451 TypeInstType( … … 454 453 std::vector<ptr<Attribute>> && as = {} ) 455 454 : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {} 456 457 TypeInstType( 458 const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {}, 455 TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {}, 459 456 std::vector<ptr<Attribute>> && as = {} ) 460 457 : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {} -
src/AST/TypeEnvironment.cpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 29 11:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Wed May 29 11:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:49:13 2019 13 // Update Count : 4 14 14 // 15 15 … … 240 240 return true; 241 241 } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) { 242 return typeInst->kind == Type Var::Ftype;242 return typeInst->kind == TypeDecl::Ftype; 243 243 } else return false; 244 244 } … … 248 248 bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) { 249 249 switch ( data.kind ) { 250 case Type Var::Dtype:250 case TypeDecl::Dtype: 251 251 // to bind to an object type variable, the type must not be a function type. 252 252 // if the type variable is specified to be a complete type then the incoming … … 254 254 // xxx - should this also check that type is not a tuple type and that it's not a ttype? 255 255 return ! isFtype( type ) && ( ! data.isComplete || type->isComplete() ); 256 case Type Var::Ftype:256 case TypeDecl::Ftype: 257 257 return isFtype( type ); 258 case Type Var::Ttype:258 case TypeDecl::Ttype: 259 259 // ttype unifies with any tuple type 260 260 return dynamic_cast< const TupleType * >( type ) || Tuples::isTtype( type ); -
src/AST/TypeEnvironment.hpp
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Wed May 29 11:00:00 2019 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Wed May 29 11:00:00201913 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Dec 11 21:55:54 2019 13 // Update Count : 3 14 14 // 15 15 … … 28 28 #include "Type.hpp" 29 29 #include "TypeSubstitution.hpp" 30 #include "TypeVar.hpp"31 30 #include "Common/Indenter.h" 32 31 #include "ResolvExpr/WidenMode.h" … … 107 106 /// Singleton class constructor from substitution 108 107 EqvClass( const std::string & v, const Type * b ) 109 : vars{ v }, bound( b ), allowWidening( false ), data( Type Var::Dtype, false ) {}108 : vars{ v }, bound( b ), allowWidening( false ), data( TypeDecl::Dtype, false ) {} 110 109 111 110 /// Single-var constructor (strips qualifiers from bound type) -
src/AST/Visitor.hpp
r71d6bd8 r7030dab 47 47 virtual const ast::Stmt * visit( const ast::CatchStmt * ) = 0; 48 48 virtual const ast::Stmt * visit( const ast::FinallyStmt * ) = 0; 49 virtual const ast::Stmt * visit( const ast::SuspendStmt * ) = 0; 49 50 virtual const ast::Stmt * visit( const ast::WaitForStmt * ) = 0; 50 51 virtual const ast::Decl * visit( const ast::WithStmt * ) = 0; -
src/AST/module.mk
r71d6bd8 r7030dab 10 10 ## Author : Thierry Delisle 11 11 ## Created On : Thu May 09 16:05:36 2019 12 ## Last Modified By : 13 ## Last Modified On : 14 ## Update Count : 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Sat Dec 14 07:29:10 2019 14 ## Update Count : 3 15 15 ############################################################################### 16 16 … … 35 35 AST/TypeSubstitution.cpp 36 36 37 38 39 37 SRC += $(SRC_AST) 40 38 SRCDEMANGLE += $(SRC_AST) -
src/BasicTypes-gen.cc
r71d6bd8 r7030dab 273 273 274 274 275 #define Type TOP_SRCDIR "src/SynTree/Type.h"276 resetInput( file, Type , buffer, code, str );277 278 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", Type );275 #define TypeH TOP_SRCDIR "src/SynTree/Type.h" 276 resetInput( file, TypeH, buffer, code, str ); 277 278 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH ); 279 279 start += sizeof( STARTMK ); // includes newline 280 280 code << str.substr( 0, start ); … … 289 289 code << "\t"; // indentation for end marker 290 290 291 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", Type ); 292 code << str.substr( start ); 293 294 output( file, Type, code ); 291 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH ); 292 code << str.substr( start ); 293 294 output( file, TypeH, code ); 295 // cout << code.str(); 296 297 298 #define TypeC TOP_SRCDIR "src/SynTree/Type.cc" 299 resetInput( file, TypeC, buffer, code, str ); 300 301 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC ); 302 start += sizeof( STARTMK ); // includes newline 303 code << str.substr( 0, start ); 304 305 code << BYMK << endl; 306 code << "const char * BasicType::typeNames[] = {" << endl; 307 for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { 308 code << "\t\"" << graph[r].type << "\"," << endl; 309 } // for 310 code << "};" << endl; 311 312 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC ); 313 code << str.substr( start ); 314 315 output( file, TypeC, code ); 295 316 // cout << code.str(); 296 317 297 318 298 319 // TEMPORARY DURING CHANGE OVER 299 #define Type AST TOP_SRCDIR "src/AST/Type.hpp"300 resetInput( file, Type AST, buffer, code, str );301 302 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", Type AST );320 #define TypeH_AST TOP_SRCDIR "src/AST/Type.hpp" 321 resetInput( file, TypeH_AST, buffer, code, str ); 322 323 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeH_AST ); 303 324 start += sizeof( STARTMK ); // includes newline 304 325 code << str.substr( 0, start ); … … 313 334 code << "\t"; // indentation for end marker 314 335 315 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeAST ); 316 code << str.substr( start ); 317 318 output( file, TypeAST, code ); 336 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeH_AST ); 337 code << str.substr( start ); 338 339 output( file, TypeH_AST, code ); 340 // cout << code.str(); 341 342 343 #define TypeC_AST TOP_SRCDIR "src/AST/Type.cpp" 344 resetInput( file, TypeC_AST, buffer, code, str ); 345 346 if ( (start = str.find( STARTMK )) == string::npos ) Abort( "start", TypeC_AST ); 347 start += sizeof( STARTMK ); // includes newline 348 code << str.substr( 0, start ); 349 350 code << BYMK << endl; 351 code << "const char * BasicType::typeNames[] = {" << endl; 352 for ( int r = 0; r < NUMBER_OF_BASIC_TYPES; r += 1 ) { 353 code << "\t\"" << graph[r].type << "\"," << endl; 354 } // for 355 code << "};" << endl; 356 357 if ( (start = str.find( ENDMK, start + 1 )) == string::npos ) Abort( "end", TypeC_AST ); 358 code << str.substr( start ); 359 360 output( file, TypeC_AST, code ); 319 361 // cout << code.str(); 320 362 -
src/CodeGen/CodeGenerator.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 : S at Oct 19 19:30:38 201913 // Update Count : 5 0612 // Last Modified On : Sun Feb 16 08:32:48 2020 13 // Update Count : 532 14 14 // 15 15 #include "CodeGenerator.h" … … 23 23 #include "InitTweak/InitTweak.h" // for getPointerBase 24 24 #include "OperatorTable.h" // for OperatorInfo, operatorLookup 25 #include " Parser/LinkageSpec.h"// for Spec, Intrinsic25 #include "SynTree/LinkageSpec.h" // for Spec, Intrinsic 26 26 #include "SynTree/Attribute.h" // for Attribute 27 27 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode … … 39 39 int CodeGenerator::tabsize = 4; 40 40 41 // the kinds of statements that would ideally be followed by whitespace41 // The kinds of statements that would ideally be followed by whitespace. 42 42 bool wantSpacing( Statement * stmt) { 43 43 return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) || … … 78 78 } 79 79 80 /* Using updateLocation at the beginning of a node and endl 81 * within a node should become the method of formating. 82 */ 80 // Using updateLocation at the beginning of a node and endl within a node should become the method of formating. 83 81 void CodeGenerator::updateLocation( CodeLocation const & to ) { 84 82 // skip if linemarks shouldn't appear or if codelocation is unset … … 95 93 } else { 96 94 output << "\n# " << to.first_line << " \"" << to.filename 97 95 << "\"\n" << indent; 98 96 currentLocation = to; 99 97 } … … 131 129 132 130 void CodeGenerator::genAttributes( list< Attribute * > & attributes ) { 133 131 if ( attributes.empty() ) return; 134 132 output << "__attribute__ (("; 135 133 for ( list< Attribute * >::iterator attr( attributes.begin() );; ) { … … 140 138 output << ")"; 141 139 } // if 142 140 if ( ++attr == attributes.end() ) break; 143 141 output << ","; // separator 144 142 } // for … … 165 163 previsit( (BaseSyntaxNode *)node ); 166 164 GuardAction( [this, node](){ 167 if ( options.printExprTypes && node->result ) {168 output << " /* " << genType( node->result, "", options ) << " */ ";169 }170 } );165 if ( options.printExprTypes && node->result ) { 166 output << " /* " << genType( node->result, "", options ) << " */ "; 167 } 168 } ); 171 169 } 172 170 … … 399 397 extension( applicationExpr ); 400 398 if ( VariableExpr * varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) { 401 OperatorInfoopInfo;402 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo) ) {399 const OperatorInfo * opInfo; 400 if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && ( opInfo = operatorLookup( varExpr->get_var()->get_name() ) ) ) { 403 401 std::list< Expression* >::iterator arg = applicationExpr->get_args().begin(); 404 switch ( opInfo .type ) {402 switch ( opInfo->type ) { 405 403 case OT_INDEX: 406 404 assert( applicationExpr->get_args().size() == 2 ); … … 423 421 output << "("; 424 422 (*arg++)->accept( *visitor ); 425 output << ") /* " << opInfo .inputName << " */";423 output << ") /* " << opInfo->inputName << " */"; 426 424 } else if ( applicationExpr->get_args().size() == 2 ) { 427 425 // intrinsic two parameter constructors are essentially bitwise assignment 428 426 output << "("; 429 427 (*arg++)->accept( *visitor ); 430 output << opInfo .symbol;428 output << opInfo->symbol; 431 429 (*arg)->accept( *visitor ); 432 output << ") /* " << opInfo .inputName << " */";430 output << ") /* " << opInfo->inputName << " */"; 433 431 } else { 434 432 // no constructors with 0 or more than 2 parameters … … 441 439 assert( applicationExpr->get_args().size() == 1 ); 442 440 output << "("; 443 output << opInfo .symbol;441 output << opInfo->symbol; 444 442 (*arg)->accept( *visitor ); 445 443 output << ")"; … … 450 448 assert( applicationExpr->get_args().size() == 1 ); 451 449 (*arg)->accept( *visitor ); 452 output << opInfo .symbol;450 output << opInfo->symbol; 453 451 break; 454 452 … … 459 457 output << "("; 460 458 (*arg++)->accept( *visitor ); 461 output << opInfo .symbol;459 output << opInfo->symbol; 462 460 (*arg)->accept( *visitor ); 463 461 output << ")"; … … 486 484 extension( untypedExpr ); 487 485 if ( NameExpr * nameExpr = dynamic_cast< NameExpr* >( untypedExpr->function ) ) { 488 OperatorInfo opInfo;489 if ( op eratorLookup( nameExpr->name, opInfo )) {486 const OperatorInfo * opInfo = operatorLookup( nameExpr->name ); 487 if ( opInfo ) { 490 488 std::list< Expression* >::iterator arg = untypedExpr->args.begin(); 491 switch ( opInfo .type ) {489 switch ( opInfo->type ) { 492 490 case OT_INDEX: 493 491 assert( untypedExpr->args.size() == 2 ); … … 508 506 output << "("; 509 507 (*arg++)->accept( *visitor ); 510 output << ") /* " << opInfo .inputName << " */";508 output << ") /* " << opInfo->inputName << " */"; 511 509 } else if ( untypedExpr->get_args().size() == 2 ) { 512 510 // intrinsic two parameter constructors are essentially bitwise assignment 513 511 output << "("; 514 512 (*arg++)->accept( *visitor ); 515 output << opInfo .symbol;513 output << opInfo->symbol; 516 514 (*arg)->accept( *visitor ); 517 output << ") /* " << opInfo .inputName << " */";515 output << ") /* " << opInfo->inputName << " */"; 518 516 } else { 519 517 // no constructors with 0 or more than 2 parameters … … 521 519 output << "("; 522 520 (*arg++)->accept( *visitor ); 523 output << opInfo .symbol << "{ ";521 output << opInfo->symbol << "{ "; 524 522 genCommaList( arg, untypedExpr->args.end() ); 525 output << "}) /* " << opInfo .inputName << " */";523 output << "}) /* " << opInfo->inputName << " */"; 526 524 } // if 527 525 break; … … 532 530 assert( untypedExpr->args.size() == 1 ); 533 531 output << "("; 534 output << opInfo .symbol;532 output << opInfo->symbol; 535 533 (*arg)->accept( *visitor ); 536 534 output << ")"; … … 541 539 assert( untypedExpr->args.size() == 1 ); 542 540 (*arg)->accept( *visitor ); 543 output << opInfo .symbol;541 output << opInfo->symbol; 544 542 break; 545 543 … … 549 547 output << "("; 550 548 (*arg++)->accept( *visitor ); 551 output << opInfo .symbol;549 output << opInfo->symbol; 552 550 (*arg)->accept( *visitor ); 553 551 output << ")"; … … 581 579 void CodeGenerator::postvisit( NameExpr * nameExpr ) { 582 580 extension( nameExpr ); 583 OperatorInfo opInfo;584 if ( op eratorLookup( nameExpr->name, opInfo )) {585 if ( opInfo .type == OT_CONSTANT ) {586 output << opInfo .symbol;581 const OperatorInfo * opInfo = operatorLookup( nameExpr->name ); 582 if ( opInfo ) { 583 if ( opInfo->type == OT_CONSTANT ) { 584 output << opInfo->symbol; 587 585 } else { 588 output << opInfo .outputName;586 output << opInfo->outputName; 589 587 } 590 588 } else { … … 654 652 void CodeGenerator::postvisit( VariableExpr * variableExpr ) { 655 653 extension( variableExpr ); 656 OperatorInfoopInfo;657 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {658 output << opInfo .symbol;654 const OperatorInfo * opInfo; 655 if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && (opInfo = operatorLookup( variableExpr->get_var()->get_name() )) && opInfo->type == OT_CONSTANT ) { 656 output << opInfo->symbol; 659 657 } else { 660 658 output << mangleName( variableExpr->get_var() ); … … 1011 1009 case BranchStmt::FallThroughDefault: 1012 1010 assertf( ! options.genC, "fallthru should not reach code generation." ); 1013 1011 output << "fallthru"; 1014 1012 break; 1015 1013 } // switch … … 1035 1033 1036 1034 output << ((throwStmt->get_kind() == ThrowStmt::Terminate) ? 1037 1035 "throw" : "throwResume"); 1038 1036 if (throwStmt->get_expr()) { 1039 1037 output << " "; … … 1050 1048 1051 1049 output << ((stmt->get_kind() == CatchStmt::Terminate) ? 1052 "catch" : "catchResume");1050 "catch" : "catchResume"); 1053 1051 output << "( "; 1054 1052 stmt->decl->accept( *visitor ); … … 1187 1185 1188 1186 std::string genName( DeclarationWithType * decl ) { 1189 CodeGen::OperatorInfo opInfo;1190 if ( op eratorLookup( decl->get_name(), opInfo )) {1191 return opInfo .outputName;1187 const OperatorInfo * opInfo = operatorLookup( decl->get_name() ); 1188 if ( opInfo ) { 1189 return opInfo->outputName; 1192 1190 } else { 1193 1191 return decl->get_name(); -
src/CodeGen/CodeGenerator.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 : Tue Apr 30 12:01:00 201913 // Update Count : 5711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 16 03:58:31 2020 13 // Update Count : 62 14 14 // 15 15 … … 29 29 namespace CodeGen { 30 30 struct CodeGenerator : public WithShortCircuiting, public WithGuards, public WithVisitorRef<CodeGenerator> { 31 31 static int tabsize; 32 32 33 33 CodeGenerator( std::ostream &os, bool pretty = false, bool genC = false, bool lineMarks = false, bool printExprTypes = false ); … … 104 104 void postvisit( AsmStmt * ); 105 105 void postvisit( DirectiveStmt * ); 106 void postvisit( AsmDecl * ); // special: statement in declaration context106 void postvisit( AsmDecl * ); // special: statement in declaration context 107 107 void postvisit( IfStmt * ); 108 108 void postvisit( SwitchStmt * ); … … 147 147 LabelPrinter printLabels; 148 148 Options options; 149 public:149 public: 150 150 LineEnder endl; 151 private:151 private: 152 152 153 153 CodeLocation currentLocation; … … 162 162 template< class Iterator > 163 163 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) { 164 164 if ( begin == end ) return; 165 165 for ( ;; ) { 166 166 (*begin++)->accept( *visitor ); 167 167 if ( begin == end ) break; 168 168 output << ", "; // separator 169 169 } // for -
src/CodeGen/FixMain.h
r71d6bd8 r7030dab 10 10 // Created On : Thr Jan 12 14:11:09 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:16:59 201713 // Update Count : 112 // Last Modified On : Sun Feb 16 03:24:32 2020 13 // Update Count : 5 14 14 // 15 15 … … 19 19 #include <memory> 20 20 21 #include " Parser/LinkageSpec.h"21 #include "SynTree/LinkageSpec.h" 22 22 23 23 class FunctionDecl; … … 42 42 static std::unique_ptr<FunctionDecl> main_signature; 43 43 }; 44 } ;44 } // namespace CodeGen -
src/CodeGen/FixNames.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 Jun 28 15:26:00 201713 // Update Count : 2 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:39:14 2019 13 // Update Count : 21 14 14 // 15 15 … … 22 22 #include "Common/SemanticError.h" // for SemanticError 23 23 #include "FixMain.h" // for FixMain 24 #include "Parser/LinkageSpec.h" // for Cforall, isMangled25 24 #include "SymTab/Mangler.h" // for Mangler 25 #include "SynTree/LinkageSpec.h" // for Cforall, isMangled 26 26 #include "SynTree/Constant.h" // for Constant 27 27 #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declarat... -
src/CodeGen/GenType.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 : Tue Apr 30 11:47:00 201913 // Update Count : 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 16 04:11:40 2020 13 // Update Count : 5 14 14 // 15 15 … … 25 25 std::string genType( Type *type, const std::string &baseString, const Options &options ); 26 26 std::string genType( Type *type, const std::string &baseString, bool pretty = false, bool genC = false, bool lineMarks = false ); 27 27 std::string genPrettyType( Type * type, const std::string & baseString ); 28 28 } // namespace CodeGen 29 29 -
src/CodeGen/Generate.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 : Fri Aug 18 15:39:00 201713 // Update Count : 711 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 16 03:01:51 2020 13 // Update Count : 9 14 14 // 15 15 #include "Generate.h" … … 22 22 #include "GenType.h" // for genPrettyType 23 23 #include "Common/PassVisitor.h" // for PassVisitor 24 #include " Parser/LinkageSpec.h"// for isBuiltin, isGeneratable24 #include "SynTree/LinkageSpec.h" // for isBuiltin, isGeneratable 25 25 #include "SynTree/BaseSyntaxNode.h" // for BaseSyntaxNode 26 26 #include "SynTree/Declaration.h" // for Declaration … … 64 64 void generate( BaseSyntaxNode * node, std::ostream & os ) { 65 65 if ( Type * type = dynamic_cast< Type * >( node ) ) { 66 os << CodeGen::genPrettyType( type, "" );66 os << genPrettyType( type, "" ); 67 67 } else { 68 68 PassVisitor<CodeGenerator> cgv( os, true, false, false, false ); -
src/CodeGen/OperatorTable.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 : Sat Jul 15 17:12:22 201713 // Update Count : 1512 // Last Modified On : Tue Feb 18 15:55:01 2020 13 // Update Count : 55 14 14 // 15 15 … … 17 17 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 18 18 #include <utility> // for pair 19 using namespace std; 19 20 20 21 #include "OperatorTable.h" … … 22 23 23 24 namespace CodeGen { 24 namespace{25 const OperatorInfo tableValues[] = {26 { "?[?]", "", "_operator_index", OT_INDEX},27 { "?{}", "=", "_constructor", OT_CTOR},28 { "^?{}", "", "_destructor", OT_DTOR},29 { "?()", "", "_operator_call", OT_CALL},30 { "?++", "++", "_operator_postincr", OT_POSTFIXASSIGN},31 { "?--", "--", "_operator_postdecr", OT_POSTFIXASSIGN},32 { "*?", "*", "_operator_deref", OT_PREFIX},33 { "+?", "+", "_operator_unaryplus", OT_PREFIX},34 { "-?", "-", "_operator_unaryminus", OT_PREFIX},35 { "~?", "~", "_operator_bitnot", OT_PREFIX},36 { "!?", "!", "_operator_lognot", OT_PREFIX},37 { "++?", "++", "_operator_preincr", OT_PREFIXASSIGN},38 { "--?", "--", "_operator_predecr", OT_PREFIXASSIGN},39 { "?\\?", "\\", "_operator_exponential", OT_INFIX},40 { "?*?", "*", "_operator_multiply", OT_INFIX},41 { "?/?", "/", "_operator_divide", OT_INFIX},42 { "?%?", "%", "_operator_modulus", OT_INFIX},43 { "?+?", "+", "_operator_add", OT_INFIX},44 { "?-?", "-", "_operator_subtract", OT_INFIX},45 { "?<<?", "<<", "_operator_shiftleft", OT_INFIX},46 { "?>>?", ">>", "_operator_shiftright", OT_INFIX},47 { "?<?", "<", "_operator_less", OT_INFIX},48 { "?>?", ">", "_operator_greater", OT_INFIX},49 { "?<=?", "<=", "_operator_lessequal", OT_INFIX},50 { "?>=?", ">=", "_operator_greaterequal", OT_INFIX},51 { "?==?", "==", "_operator_equal", OT_INFIX},52 { "?!=?", "!=", "_operator_notequal", OT_INFIX},53 { "?&?", "&", "_operator_bitand", OT_INFIX},54 { "?^?", "^", "_operator_bitxor", OT_INFIX},55 { "?|?", "|", "_operator_bitor", OT_INFIX},56 { "?=?", "=", "_operator_assign", OT_INFIXASSIGN},57 { "?\\=?", "\\=", "_operator_expassign", OT_INFIXASSIGN},58 { "?*=?", "*=", "_operator_multassign", OT_INFIXASSIGN},59 { "?/=?", "/=", "_operator_divassign", OT_INFIXASSIGN},60 { "?%=?", "%=", "_operator_modassign", OT_INFIXASSIGN},61 { "?+=?", "+=", "_operator_addassign", OT_INFIXASSIGN},62 { "?-=?", "-=", "_operator_subassign", OT_INFIXASSIGN},63 { "?<<=?", "<<=", "_operator_shiftleftassign", OT_INFIXASSIGN},64 { "?>>=?", ">>=", "_operator_shiftrightassign", OT_INFIXASSIGN},65 { "?&=?", "&=", "_operator_bitandassign", OT_INFIXASSIGN},66 { "?^=?", "^=", "_operator_bitxorassign", OT_INFIXASSIGN},67 { "?|=?", "|=", "_operator_bitorassign", OT_INFIXASSIGN},68 };25 const OperatorInfo CodeGen::tableValues[] = { 26 // inputName symbol outputName friendlyName type 27 { "?[?]", "", "_operator_index", "Index", OT_INDEX }, 28 { "?{}", "=", "_constructor", "Constructor", OT_CTOR }, 29 { "^?{}", "", "_destructor", "Destructor", OT_DTOR }, 30 { "?()", "", "_operator_call", "Call Operator", OT_CALL }, 31 { "?++", "++", "_operator_postincr", "Postfix Increment", OT_POSTFIXASSIGN }, 32 { "?--", "--", "_operator_postdecr", "Postfix Decrement", OT_POSTFIXASSIGN }, 33 { "*?", "*", "_operator_deref", "Dereference", OT_PREFIX }, 34 { "+?", "+", "_operator_unaryplus", "Plus", OT_PREFIX }, 35 { "-?", "-", "_operator_unaryminus", "Minus", OT_PREFIX }, 36 { "~?", "~", "_operator_bitnot", "Bitwise Not", OT_PREFIX }, 37 { "!?", "!", "_operator_lognot", "Logical Not", OT_PREFIX }, 38 { "++?", "++", "_operator_preincr", "Prefix Increment", OT_PREFIXASSIGN }, 39 { "--?", "--", "_operator_predecr", "Prefix Decrement", OT_PREFIXASSIGN }, 40 { "?\\?", "\\", "_operator_exponential", "Exponentiation", OT_INFIX }, 41 { "?*?", "*", "_operator_multiply", "Multiplication", OT_INFIX }, 42 { "?/?", "/", "_operator_divide", "Division", OT_INFIX }, 43 { "?%?", "%", "_operator_modulus", "Modulo", OT_INFIX }, 44 { "?+?", "+", "_operator_add", "Addition", OT_INFIX }, 45 { "?-?", "-", "_operator_subtract", "Substraction", OT_INFIX }, 46 { "?<<?", "<<", "_operator_shiftleft", "Shift Left", OT_INFIX }, 47 { "?>>?", ">>", "_operator_shiftright", "Shift Right", OT_INFIX }, 48 { "?<?", "<", "_operator_less", "Less-than", OT_INFIX }, 49 { "?>?", ">", "_operator_greater", "Greater-than", OT_INFIX }, 50 { "?<=?", "<=", "_operator_lessequal", "Less-than-or-Equal", OT_INFIX }, 51 { "?>=?", ">=", "_operator_greaterequal", "Greater-than-or-Equal", OT_INFIX }, 52 { "?==?", "==", "_operator_equal", "Equality", OT_INFIX }, 53 { "?!=?", "!=", "_operator_notequal", "Not-Equal", OT_INFIX }, 54 { "?&?", "&", "_operator_bitand", "Bitwise And", OT_INFIX }, 55 { "?^?", "^", "_operator_bitxor", "Bitwise Xor", OT_INFIX }, 56 { "?|?", "|", "_operator_bitor", "Bitwise Or", OT_INFIX }, 57 { "?=?", "=", "_operator_assign", "Assignment", OT_INFIXASSIGN }, 58 { "?\\=?", "\\=", "_operator_expassign", "Exponentiation Assignment", OT_INFIXASSIGN }, 59 { "?*=?", "*=", "_operator_multassign", "Multiplication Assignment", OT_INFIXASSIGN }, 60 { "?/=?", "/=", "_operator_divassign", "Division Assignment", OT_INFIXASSIGN }, 61 { "?%=?", "%=", "_operator_modassign", "Modulo Assignment", OT_INFIXASSIGN }, 62 { "?+=?", "+=", "_operator_addassign", "Addition Assignment", OT_INFIXASSIGN }, 63 { "?-=?", "-=", "_operator_subassign", "Substrction Assignment", OT_INFIXASSIGN }, 64 { "?<<=?", "<<=", "_operator_shiftleftassign", "Shift Left Assignment", OT_INFIXASSIGN }, 65 { "?>>=?", ">>=", "_operator_shiftrightassign", "Shift Right Assignment", OT_INFIXASSIGN }, 66 { "?&=?", "&=", "_operator_bitandassign", "Bitwise And Assignment", OT_INFIXASSIGN }, 67 { "?^=?", "^=", "_operator_bitxorassign", "Bitwise Xor Assignment", OT_INFIXASSIGN }, 68 { "?|=?", "|=", "_operator_bitorassign", "Bitwise Or Assignment", OT_INFIXASSIGN }, 69 }; // tableValues 69 70 70 const int numOps = sizeof( tableValues ) / sizeof( OperatorInfo );71 std::map< std::string, OperatorInfo > CodeGen::table; 71 72 72 std::map< std::string, OperatorInfo > table; 73 74 void initialize() { 75 for ( int i = 0; i < numOps; ++i ) { 76 table[ tableValues[i].inputName ] = tableValues[i]; 77 } // for 78 } 79 } // namespace 80 81 bool operatorLookup( const std::string & funcName, OperatorInfo & info ) { 82 static bool init = false; 83 if ( ! init ) { 84 initialize(); 85 } // if 86 87 std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName ); 88 if ( i == table.end() ) { 89 if ( isPrefix( funcName, "?`" ) ) { 90 // handle literal suffixes, which are user-defined postfix operators 91 info.inputName = funcName; 92 info.symbol = funcName.substr(2); 93 info.outputName = toString( "__operator_literal_", info.symbol ); 94 info.type = OT_POSTFIX; 95 return true; 96 } 97 return false; 98 } else { 99 info = i->second; 100 return true; 101 } // if 73 CodeGen::CodeGen() { 74 enum { numOps = sizeof( tableValues ) / sizeof( OperatorInfo ) }; 75 for ( int i = 0; i < numOps; i += 1 ) { 76 table[ tableValues[i].inputName ] = tableValues[i]; 77 } // for 102 78 } 103 79 104 bool isOperator( const std::string & funcName ) { 105 OperatorInfo info; 106 return operatorLookup( funcName, info ); 80 const OperatorInfo * operatorLookup( const string & funcName ) { 81 if ( funcName.find_first_of( "?^*+-!", 0, 1 ) == string::npos ) return nullptr; // prefilter 82 const OperatorInfo * ret = &CodeGen::table.find( funcName )->second; // must be in the table 83 assert( ret ); 84 return ret; 107 85 } 108 86 109 /// determines if a given function name is one of the operator types between [begin, end) 110 template<typename Iterator> 111 bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) { 112 OperatorInfo info; 113 if ( operatorLookup( funcName, info ) ) { 114 return std::find( begin, end, info.type ) != end; 115 } 87 bool isOperator( const string & funcName ) { 88 return operatorLookup( funcName ) != nullptr; 89 } 90 91 string operatorFriendlyName( const string & funcName ) { 92 const OperatorInfo * info = operatorLookup( funcName ); 93 if ( info ) return info->friendlyName; 94 return ""; 95 } 96 97 bool isConstructor( const string & funcName ) { 98 const OperatorInfo * info = operatorLookup( funcName ); 99 if ( info ) return info->type == OT_CTOR; 116 100 return false; 117 101 } 118 102 119 bool isConstructor( const std::string & funcName ) { 120 static OperatorType types[] = { OT_CTOR }; 121 return isOperatorType( funcName, std::begin(types), std::end(types) ); 103 bool isDestructor( const string & funcName ) { 104 const OperatorInfo * info = operatorLookup( funcName ); 105 if ( info ) return info->type == OT_DTOR; 106 return false; 122 107 } 123 108 124 bool isDestructor( const std::string & funcName ) { 125 static OperatorType types[] = { OT_DTOR }; 126 return isOperatorType( funcName, std::begin(types), std::end(types) ); 109 bool isCtorDtor( const string & funcName ) { 110 const OperatorInfo * info = operatorLookup( funcName ); 111 if ( info ) return info->type <= OT_CONSTRUCTOR; 112 return false; 127 113 } 128 114 129 bool isAssignment( const std::string & funcName ) { 130 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 131 return isOperatorType( funcName, std::begin(types), std::end(types) ); 115 bool isAssignment( const string & funcName ) { 116 const OperatorInfo * info = operatorLookup( funcName ); 117 if ( info ) return info->type > OT_CONSTRUCTOR && info->type <= OT_ASSIGNMENT; 118 return false; 132 119 } 133 120 134 bool isCtorDtor( const std::string & funcName ) { 135 static OperatorType types[] = { OT_CTOR, OT_DTOR }; 136 return isOperatorType( funcName, std::begin(types), std::end(types) ); 121 bool isCtorDtorAssign( const string & funcName ) { 122 const OperatorInfo * info = operatorLookup( funcName ); 123 if ( info ) return info->type <= OT_ASSIGNMENT; 124 return false; 137 125 } 138 126 139 bool isCtorDtorAssign( const std::string & funcName ) { 140 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 141 return isOperatorType( funcName, std::begin(types), std::end(types) ); 142 } 127 CodeGen codegen; // initialize singleton package 143 128 } // namespace CodeGen 144 129 145 130 // Local Variables: // 146 131 // tab-width: 4 // 147 // mode: c++ //148 // compile-command: "make install" //149 132 // End: // -
src/CodeGen/OperatorTable.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 : Fri Jul 21 22:17:11 201713 // Update Count : 612 // Last Modified On : Sun Feb 16 08:13:34 2020 13 // Update Count : 26 14 14 // 15 15 … … 17 17 18 18 #include <string> 19 #include <map> 19 20 20 21 namespace CodeGen { 21 22 enum OperatorType { 22 OT_INDEX,23 23 OT_CTOR, 24 24 OT_DTOR, 25 OT_CALL, 26 OT_PREFIX, 27 OT_POSTFIX, 28 OT_INFIX, 25 OT_CONSTRUCTOR = OT_DTOR, 29 26 OT_PREFIXASSIGN, 30 27 OT_POSTFIXASSIGN, 31 28 OT_INFIXASSIGN, 29 OT_ASSIGNMENT = OT_INFIXASSIGN, 30 OT_CALL, 31 OT_PREFIX, 32 OT_INFIX, 33 OT_POSTFIX, 34 OT_INDEX, 32 35 OT_LABELADDRESS, 33 36 OT_CONSTANT … … 38 41 std::string symbol; 39 42 std::string outputName; 43 std::string friendlyName; 40 44 OperatorType type; 41 45 }; 42 46 47 class CodeGen { 48 friend const OperatorInfo * operatorLookup( const std::string & funcName ); 49 50 static const OperatorInfo tableValues[]; 51 static std::map< std::string, OperatorInfo > table; 52 public: 53 CodeGen(); 54 }; // CodeGen 55 43 56 bool isOperator( const std::string & funcName ); 44 bool operatorLookup( const std::string & funcName, OperatorInfo & info ); 57 const OperatorInfo * operatorLookup( const std::string & funcName ); 58 std::string operatorFriendlyName( const std::string & funcName ); 45 59 46 60 bool isConstructor( const std::string & ); -
src/CodeGen/Options.h
r71d6bd8 r7030dab 9 9 // Author : Andrew Beach 10 10 // Created On : Tue Apr 30 11:36:00 2019 11 // Last Modified By : Andrew Beach12 // Last Modified On : Thr May 2 10:45:00 201913 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 18:37:06 2020 13 // Update Count : 3 14 14 // 15 15 16 16 #pragma once 17 17 18 namespace CodeGen { 19 struct Options { 20 // External Options: Same thoughout a pass. 21 bool pretty; 22 bool genC; 23 bool lineMarks; 24 bool printExprTypes; 18 struct Options { 19 // External Options: Same thoughout a pass. 20 bool pretty; 21 bool genC; 22 bool lineMarks; 23 bool printExprTypes; 25 24 26 27 25 // Internal Options: Changed on some recurisive calls. 26 bool anonymousUnused = false; 28 27 29 30 28 Options(bool pretty, bool genC, bool lineMarks, bool printExprTypes) : 29 pretty(pretty), genC(genC), lineMarks(lineMarks), printExprTypes(printExprTypes) 31 30 {} 32 }; 33 } // namespace CodeGen 31 }; 34 32 35 33 // Local Variables: // -
src/CodeGen/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 : Tue Jun 2 11:17:02 201514 ## Update Count : 313 ## Last Modified On : Sat Dec 14 07:29:42 2019 14 ## Update Count : 4 15 15 ############################################################################### 16 16 … … 24 24 CodeGen/OperatorTable.cc 25 25 26 27 26 SRC += $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/FixNames.cc 28 27 SRCDEMANGLE += $(SRC_CODEGEN) -
src/CodeTools/DeclStats.cc
r71d6bd8 r7030dab 9 9 // Author : Aaron Moss 10 10 // Created On : Wed Jan 31 16:40:00 2016 11 // Last Modified By : Aaron Moss12 // Last Modified On : Wed Jan 31 16:40:00 201613 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:39:33 2019 13 // Update Count : 2 14 14 // 15 15 … … 26 26 #include "Common/VectorMap.h" // for VectorMap 27 27 #include "GenPoly/GenPoly.h" // for hasPolyBase 28 #include " Parser/LinkageSpec.h"// for ::NoOfSpecs, Spec28 #include "SynTree/LinkageSpec.h" // for ::NoOfSpecs, Spec 29 29 #include "SynTree/Declaration.h" // for FunctionDecl, TypeDecl, Declaration 30 30 #include "SynTree/Expression.h" // for UntypedExpr, Expression -
src/CodeTools/ResolvProtoDump.cc
r71d6bd8 r7030dab 9 9 // Author : Aaron Moss 10 10 // Created On : Tue Sep 11 09:04:00 2018 11 // Last Modified By : Aaron Moss12 // Last Modified On : Tue Sep 11 09:04:00 201813 // Update Count : 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 13:50:11 2020 13 // Update Count : 3 14 14 // 15 15 … … 182 182 183 183 // replace operator names 184 CodeGen::OperatorInfo info;185 if ( CodeGen::operatorLookup( name, info )) {184 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( name ); 185 if ( opInfo ) { 186 186 ss << new_prefix(pre, ""); 187 op_name( info.outputName, ss );187 op_name( opInfo->outputName, ss ); 188 188 return; 189 189 } -
src/Common/Debug.h
r71d6bd8 r7030dab 9 9 // Author : Rob Schluntz 10 10 // Created On : Fri Sep 1 11:09:14 2017 11 // Last Modified By : Rob Schluntz12 // Last Modified On : Fri Sep 1 11:09:36 201713 // Update Count : 211 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:39:42 2019 13 // Update Count : 3 14 14 // 15 15 … … 21 21 22 22 #include "CodeGen/Generate.h" 23 #include " Parser/LinkageSpec.h"23 #include "SynTree/LinkageSpec.h" 24 24 #include "SynTree/Declaration.h" 25 25 -
src/Common/PassVisitor.h
r71d6bd8 r7030dab 110 110 virtual void visit( FinallyStmt * finallyStmt ) override final; 111 111 virtual void visit( const FinallyStmt * finallyStmt ) override final; 112 virtual void visit( SuspendStmt * suspendStmt ) override final; 113 virtual void visit( const SuspendStmt * suspendStmt ) override final; 112 114 virtual void visit( WaitForStmt * waitforStmt ) override final; 113 115 virtual void visit( const WaitForStmt * waitforStmt ) override final; … … 276 278 virtual Statement * mutate( CatchStmt * catchStmt ) override final; 277 279 virtual Statement * mutate( FinallyStmt * finallyStmt ) override final; 280 virtual Statement * mutate( SuspendStmt * suspendStmt ) override final; 278 281 virtual Statement * mutate( WaitForStmt * waitforStmt ) override final; 279 282 virtual Declaration * mutate( WithStmt * withStmt ) override final; -
src/Common/PassVisitor.impl.h
r71d6bd8 r7030dab 1522 1522 1523 1523 //-------------------------------------------------------------------------- 1524 // SuspendStmt 1525 template< typename pass_type > 1526 void PassVisitor< pass_type >::visit( SuspendStmt * node ) { 1527 VISIT_START( node ); 1528 1529 maybeAccept_impl( node->then , *this ); 1530 1531 VISIT_END( node ); 1532 } 1533 1534 template< typename pass_type > 1535 void PassVisitor< pass_type >::visit( const SuspendStmt * node ) { 1536 VISIT_START( node ); 1537 1538 maybeAccept_impl( node->then , *this ); 1539 1540 VISIT_END( node ); 1541 } 1542 1543 template< typename pass_type > 1544 Statement * PassVisitor< pass_type >::mutate( SuspendStmt * node ) { 1545 MUTATE_START( node ); 1546 1547 maybeMutate_impl( node->then , *this ); 1548 1549 MUTATE_END( Statement, node ); 1550 } 1551 1552 //-------------------------------------------------------------------------- 1524 1553 // WaitForStmt 1525 1554 template< typename pass_type > … … 3302 3331 VISIT_START( node ); 3303 3332 3304 indexerAdd Struct( node->name );3333 indexerAddUnion( node->name ); 3305 3334 3306 3335 { … … 3317 3346 VISIT_START( node ); 3318 3347 3319 indexerAdd Struct( node->name );3348 indexerAddUnion( node->name ); 3320 3349 3321 3350 { … … 3332 3361 MUTATE_START( node ); 3333 3362 3334 indexerAdd Struct( node->name );3363 indexerAddUnion( node->name ); 3335 3364 3336 3365 { -
src/Common/SemanticError.cc
r71d6bd8 r7030dab 149 149 // Helpers 150 150 namespace ErrorHelpers { 151 Colors colors = Colors::Auto; 152 153 static inline bool with_colors() { 154 return colors == Colors::Auto ? isatty( STDERR_FILENO ) : bool(colors); 155 } 156 151 157 const std::string & error_str() { 152 static std::string str = isatty( STDERR_FILENO) ? "\e[31merror:\e[39m " : "error: ";158 static std::string str = with_colors() ? "\e[31merror:\e[39m " : "error: "; 153 159 return str; 154 160 } 155 161 156 162 const std::string & warning_str() { 157 static std::string str = isatty( STDERR_FILENO) ? "\e[95mwarning:\e[39m " : "warning: ";163 static std::string str = with_colors() ? "\e[95mwarning:\e[39m " : "warning: "; 158 164 return str; 159 165 } 160 166 161 167 const std::string & bold_ttycode() { 162 static std::string str = isatty( STDERR_FILENO) ? "\e[1m" : "";168 static std::string str = with_colors() ? "\e[1m" : ""; 163 169 return str; 164 170 } 165 171 166 172 const std::string & reset_font_ttycode() { 167 static std::string str = isatty( STDERR_FILENO) ? "\e[0m" : "";173 static std::string str = with_colors() ? "\e[0m" : ""; 168 174 return str; 169 175 } -
src/Common/SemanticError.h
r71d6bd8 r7030dab 49 49 struct WarningData { 50 50 const char * const name; 51 const Severity default_severity; 51 52 const char * const message; 52 const Severity default_severity;53 53 }; 54 54 55 55 constexpr WarningData WarningFormats[] = { 56 {"self-assign" , "self assignment of expression: %s" , Severity::Warn}, 57 {"reference-conversion" , "rvalue to reference conversion of rvalue: %s" , Severity::Warn}, 58 {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn}, 59 {"aggregate-forward-decl" , "forward declaration of nested aggregate: %s" , Severity::Warn}, 60 {"superfluous-decl" , "declaration does not allocate storage: %s" , Severity::Warn}, 61 {"gcc-attributes" , "invalid attribute: %s" , Severity::Warn}, 56 {"self-assign" , Severity::Warn , "self assignment of expression: %s" }, 57 {"reference-conversion" , Severity::Warn , "rvalue to reference conversion of rvalue: %s" }, 58 {"qualifiers-zero_t-one_t", Severity::Warn , "questionable use of type qualifier %s with %s" }, 59 {"aggregate-forward-decl" , Severity::Warn , "forward declaration of nested aggregate: %s" }, 60 {"superfluous-decl" , Severity::Warn , "declaration does not allocate storage: %s" }, 61 {"gcc-attributes" , Severity::Warn , "invalid attribute: %s" }, 62 {"c++-like-copy" , Severity::Warn , "Constructor from reference is not a valid copy constructor" }, 62 63 }; 63 64 … … 69 70 SuperfluousDecl, 70 71 GccAttributes, 72 CppCopy, 71 73 NUMBER_OF_WARNINGS, // This MUST be the last warning 72 74 }; … … 97 99 // Helpers 98 100 namespace ErrorHelpers { 101 enum class Colors { 102 Never = false, 103 Always = true, 104 Auto, 105 }; 106 107 extern Colors colors; 108 99 109 const std::string & error_str(); 100 110 const std::string & warning_str(); -
src/Common/Stats/Time.h
r71d6bd8 r7030dab 9 9 // Author : Thierry Delisle 10 10 // Created On : Fri Mar 01 15:14:11 2019 11 // Last Modified By : 11 // Last Modified By : Andrew Beach 12 12 // Last Modified On : 13 13 // Update Count : … … 41 41 f(); 42 42 } 43 44 template<typename ret_t = void, typename func_t, typename... arg_t> 45 inline ret_t TimeCall( 46 const char *, func_t func, arg_t&&... arg) { 47 return func(std::forward<arg_t>(arg)...); 48 } 43 49 # else 44 50 void StartGlobal(); … … 59 65 func(); 60 66 } 67 68 template<typename ret_t = void, typename func_t, typename... arg_t> 69 inline ret_t TimeCall( 70 const char * name, func_t func, arg_t&&... arg) { 71 BlockGuard guard(name); 72 return func(std::forward<arg_t>(arg)...); 73 } 61 74 # endif 62 75 } -
src/Common/utility.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 : Wed Jul 24 14:28:19 201913 // Update Count : 4112 // Last Modified On : Tue Feb 11 13:00:36 2020 13 // Update Count : 50 14 14 // 15 15 … … 29 29 #include <utility> 30 30 #include <vector> 31 #include <cstring> // memcmp 31 32 32 33 #include "Common/Indenter.h" … … 264 265 } 265 266 266 // / determines if `pref` is a prefix of `str`267 static inline bool isPrefix( const std::string & str, const std::string & pref ) {267 // determines if pref is a prefix of str 268 static inline bool isPrefix( const std::string & str, const std::string & pref, unsigned int start = 0 ) { 268 269 if ( pref.size() > str.size() ) return false; 269 auto its = std::mismatch( pref.begin(), pref.end(), str.begin() );270 return its.first == pref.end();270 return 0 == memcmp( str.c_str() + start, pref.c_str(), pref.size() ); 271 // return prefix == full.substr(0, prefix.size()); // for future, requires c++17 271 272 } 272 273 -
src/Concurrency/Keywords.cc
r71d6bd8 r7030dab 11 11 // Last Modified By : 12 12 // Last Modified On : 13 // Update Count : 513 // Update Count : 10 14 14 // 15 15 16 16 #include "Concurrency/Keywords.h" 17 17 18 #include <cassert> // for assert 19 #include <string> // for string, operator== 20 21 #include "Common/PassVisitor.h" // for PassVisitor 22 #include "Common/SemanticError.h" // for SemanticError 23 #include "Common/utility.h" // for deleteAll, map_range 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 #include "InitTweak/InitTweak.h" // for getPointerBase 26 #include "Parser/LinkageSpec.h" // for Cforall 27 #include "SynTree/Constant.h" // for Constant 28 #include "SynTree/Declaration.h" // for StructDecl, FunctionDecl, ObjectDecl 29 #include "SynTree/Expression.h" // for VariableExpr, ConstantExpr, Untype... 30 #include "SynTree/Initializer.h" // for SingleInit, ListInit, Initializer ... 31 #include "SynTree/Label.h" // for Label 32 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt 33 #include "SynTree/Type.h" // for StructInstType, Type, PointerType 34 #include "SynTree/Visitor.h" // for Visitor, acceptAll 18 #include <cassert> // for assert 19 #include <string> // for string, operator== 20 21 #include "Common/PassVisitor.h" // for PassVisitor 22 #include "Common/SemanticError.h" // for SemanticError 23 #include "Common/utility.h" // for deleteAll, map_range 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 #include "ControlStruct/LabelGenerator.h" // for LebelGenerator 26 #include "InitTweak/InitTweak.h" // for getPointerBase 27 #include "SynTree/LinkageSpec.h" // for Cforall 28 #include "SynTree/Constant.h" // for Constant 29 #include "SynTree/Declaration.h" // for StructDecl, FunctionDecl, ObjectDecl 30 #include "SynTree/Expression.h" // for VariableExpr, ConstantExpr, Untype... 31 #include "SynTree/Initializer.h" // for SingleInit, ListInit, Initializer ... 32 #include "SynTree/Label.h" // for Label 33 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt 34 #include "SynTree/Type.h" // for StructInstType, Type, PointerType 35 #include "SynTree/Visitor.h" // for Visitor, acceptAll 35 36 36 37 class Attribute; … … 53 54 public: 54 55 55 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Targetcast_target ) :56 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) : 56 57 type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {} 57 58 … … 59 60 60 61 Declaration * postmutate( StructDecl * decl ); 62 DeclarationWithType * postmutate( FunctionDecl * decl ); 61 63 62 64 void handle( StructDecl * ); … … 75 77 const std::string context_error; 76 78 bool needs_main; 77 KeywordCastExpr::Target cast_target; 78 79 StructDecl* type_decl = nullptr; 79 AggregateDecl::Aggregate cast_target; 80 81 StructDecl * type_decl = nullptr; 82 FunctionDecl * dtor_decl = nullptr; 80 83 }; 81 84 … … 86 89 // int data; int data; 87 90 // a_struct_t more_data; a_struct_t more_data; 88 // => thread_desc__thrd_d;91 // => $thread __thrd_d; 89 92 // }; }; 90 // static inline thread_desc* get_thread( MyThread * this ) { return &this->__thrd_d; }93 // static inline $thread * get_thread( MyThread * this ) { return &this->__thrd_d; } 91 94 // 92 95 class ThreadKeyword final : public ConcurrentSueKeyword { … … 94 97 95 98 ThreadKeyword() : ConcurrentSueKeyword( 96 " thread_desc",99 "$thread", 97 100 "__thrd", 98 101 "get_thread", 99 "thread keyword requires threads to be in scope, add #include <thread.hfa> ",102 "thread keyword requires threads to be in scope, add #include <thread.hfa>\n", 100 103 true, 101 KeywordCastExpr::Thread104 AggregateDecl::Thread 102 105 ) 103 106 {} … … 118 121 // int data; int data; 119 122 // a_struct_t more_data; a_struct_t more_data; 120 // => coroutine_desc__cor_d;123 // => $coroutine __cor_d; 121 124 // }; }; 122 // static inline coroutine_desc* get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }125 // static inline $coroutine * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; } 123 126 // 124 127 class CoroutineKeyword final : public ConcurrentSueKeyword { … … 126 129 127 130 CoroutineKeyword() : ConcurrentSueKeyword( 128 " coroutine_desc",131 "$coroutine", 129 132 "__cor", 130 133 "get_coroutine", 131 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa> ",134 "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n", 132 135 true, 133 KeywordCastExpr::Coroutine136 AggregateDecl::Coroutine 134 137 ) 135 138 {} … … 144 147 } 145 148 }; 149 150 146 151 147 152 //----------------------------------------------------------------------------- … … 150 155 // int data; int data; 151 156 // a_struct_t more_data; a_struct_t more_data; 152 // => monitor_desc__mon_d;157 // => $monitor __mon_d; 153 158 // }; }; 154 // static inline monitor_desc* get_coroutine( MyMonitor * this ) { return &this->__cor_d; }159 // static inline $monitor * get_coroutine( MyMonitor * this ) { return &this->__cor_d; } 155 160 // 156 161 class MonitorKeyword final : public ConcurrentSueKeyword { … … 158 163 159 164 MonitorKeyword() : ConcurrentSueKeyword( 160 " monitor_desc",165 "$monitor", 161 166 "__mon", 162 167 "get_monitor", 163 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa> ",168 "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n", 164 169 false, 165 KeywordCastExpr::Monitor170 AggregateDecl::Monitor 166 171 ) 167 172 {} … … 178 183 179 184 //----------------------------------------------------------------------------- 185 //Handles generator type declarations : 186 // generator MyGenerator { struct MyGenerator { 187 // int data; int data; 188 // a_struct_t more_data; a_struct_t more_data; 189 // => int __gen_next; 190 // }; }; 191 // 192 class GeneratorKeyword final : public ConcurrentSueKeyword { 193 public: 194 195 GeneratorKeyword() : ConcurrentSueKeyword( 196 "$generator", 197 "__generator_state", 198 "get_generator", 199 "Unable to find builtin type $generator\n", 200 true, 201 AggregateDecl::Generator 202 ) 203 {} 204 205 virtual ~GeneratorKeyword() {} 206 207 virtual bool is_target( StructDecl * decl ) override final { return decl->is_generator(); } 208 209 static void implement( std::list< Declaration * > & translationUnit ) { 210 PassVisitor< GeneratorKeyword > impl; 211 mutateAll( translationUnit, impl ); 212 } 213 }; 214 215 216 //----------------------------------------------------------------------------- 217 class SuspendKeyword final : public WithStmtsToAdd, public WithGuards { 218 public: 219 SuspendKeyword() = default; 220 virtual ~SuspendKeyword() = default; 221 222 void premutate( FunctionDecl * ); 223 DeclarationWithType * postmutate( FunctionDecl * ); 224 225 Statement * postmutate( SuspendStmt * ); 226 227 static void implement( std::list< Declaration * > & translationUnit ) { 228 PassVisitor< SuspendKeyword > impl; 229 mutateAll( translationUnit, impl ); 230 } 231 232 private: 233 DeclarationWithType * is_main( FunctionDecl * ); 234 bool is_real_suspend( FunctionDecl * ); 235 236 Statement * make_generator_suspend( SuspendStmt * ); 237 Statement * make_coroutine_suspend( SuspendStmt * ); 238 239 struct LabelPair { 240 Label obj; 241 int idx; 242 }; 243 244 LabelPair make_label() { 245 labels.push_back( gen.newLabel("generator") ); 246 return { labels.back(), int(labels.size()) }; 247 } 248 249 DeclarationWithType * in_generator = nullptr; 250 FunctionDecl * decl_suspend = nullptr; 251 std::vector<Label> labels; 252 ControlStruct::LabelGenerator & gen = *ControlStruct::LabelGenerator::getGenerator(); 253 }; 254 255 //----------------------------------------------------------------------------- 180 256 //Handles mutex routines definitions : 181 257 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 182 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };258 // $monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 183 259 // monitor_guard_t __guard = { __monitors, 2 }; 184 260 // /*Some code*/ => /*Some code*/ … … 219 295 //Handles mutex routines definitions : 220 296 // void foo( A * mutex a, B * mutex b, int i ) { void foo( A * a, B * b, int i ) { 221 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };297 // $monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 222 298 // monitor_guard_t __guard = { __monitors, 2 }; 223 299 // /*Some code*/ => /*Some code*/ … … 249 325 CoroutineKeyword ::implement( translationUnit ); 250 326 MonitorKeyword ::implement( translationUnit ); 327 GeneratorKeyword ::implement( translationUnit ); 328 SuspendKeyword ::implement( translationUnit ); 251 329 } 252 330 … … 284 362 } 285 363 364 DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) { 365 if( !type_decl ) return decl; 366 if( !CodeGen::isDestructor( decl->name ) ) return decl; 367 368 auto params = decl->type->parameters; 369 if( params.size() != 1 ) return decl; 370 371 auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() ); 372 if( !type ) return decl; 373 374 auto stype = dynamic_cast<StructInstType*>( type->base ); 375 if( !stype ) return decl; 376 if( stype->baseStruct != type_decl ) return decl; 377 378 if( !dtor_decl ) dtor_decl = decl; 379 return decl; 380 } 381 286 382 Expression * ConcurrentSueKeyword::postmutate( KeywordCastExpr * cast ) { 287 383 if ( cast_target == cast->target ) { 288 // convert (thread &)t to ( thread_desc&)*get_thread(t), etc.384 // convert (thread &)t to ($thread &)*get_thread(t), etc. 289 385 if( !type_decl ) SemanticError( cast, context_error ); 290 Expression * arg = cast->arg; 291 cast->arg = nullptr; 292 delete cast; 293 return new CastExpr( 294 UntypedExpr::createDeref( 295 new UntypedExpr( new NameExpr( getter_name ), { arg } ) 296 ), 297 new ReferenceType( 298 noQualifiers, 299 new StructInstType( noQualifiers, type_decl ) ) 300 ); 386 if( !dtor_decl ) SemanticError( cast, context_error ); 387 assert( cast->result == nullptr ); 388 cast->set_result( new ReferenceType( noQualifiers, new StructInstType( noQualifiers, type_decl ) ) ); 389 cast->concrete_target.field = field_name; 390 cast->concrete_target.getter = getter_name; 301 391 } 302 392 return cast; … … 308 398 309 399 if( !type_decl ) SemanticError( decl, context_error ); 400 if( !dtor_decl ) SemanticError( decl, context_error ); 310 401 311 402 FunctionDecl * func = forwardDeclare( decl ); … … 362 453 get_type, 363 454 nullptr, 364 noAttributes,455 { new Attribute("const") }, 365 456 Type::Inline 366 457 ); … … 431 522 432 523 declsToAddAfter.push_back( get_decl ); 433 434 // get_decl->fixUniqueId(); 435 } 524 } 525 526 //============================================================================================= 527 // Suspend keyword implementation 528 //============================================================================================= 529 DeclarationWithType * SuspendKeyword::is_main( FunctionDecl * func) { 530 if(func->name != "main") return nullptr; 531 if(func->type->parameters.size() != 1) return nullptr; 532 533 auto param = func->type->parameters.front(); 534 535 auto type = dynamic_cast<ReferenceType * >(param->get_type()); 536 if(!type) return nullptr; 537 538 auto obj = dynamic_cast<StructInstType *>(type->base); 539 if(!obj) return nullptr; 540 541 if(!obj->baseStruct->is_generator()) return nullptr; 542 543 return param; 544 } 545 546 bool SuspendKeyword::is_real_suspend( FunctionDecl * func ) { 547 if(isMangled(func->linkage)) return false; // the real suspend isn't mangled 548 if(func->name != "__cfactx_suspend") return false; // the real suspend has a specific name 549 if(func->type->parameters.size() != 0) return false; // Too many parameters 550 if(func->type->returnVals.size() != 0) return false; // Too many return values 551 552 return true; 553 } 554 555 void SuspendKeyword::premutate( FunctionDecl * func ) { 556 GuardValue(in_generator); 557 in_generator = nullptr; 558 559 // Is this the real suspend? 560 if(is_real_suspend(func)) { 561 decl_suspend = decl_suspend ? decl_suspend : func; 562 return; 563 } 564 565 // Is this the main of a generator? 566 auto param = is_main( func ); 567 if(!param) return; 568 569 if(func->type->returnVals.size() != 0) SemanticError(func->location, "Generator main must return void"); 570 571 in_generator = param; 572 GuardValue(labels); 573 labels.clear(); 574 } 575 576 DeclarationWithType * SuspendKeyword::postmutate( FunctionDecl * func ) { 577 if( !func->statements ) return func; // Not the actual definition, don't do anything 578 if( !in_generator ) return func; // Not in a generator, don't do anything 579 if( labels.empty() ) return func; // Generator has no states, nothing to do, could throw a warning 580 581 // This is a generator main, we need to add the following code to the top 582 // static void * __generator_labels[] = {&&s0, &&s1, ...}; 583 // goto * __generator_labels[gen.__generator_state]; 584 const auto & loc = func->location; 585 586 const auto first_label = gen.newLabel("generator"); 587 588 // for each label add to declaration 589 std::list<Initializer*> inits = { new SingleInit( new LabelAddressExpr( first_label ) ) }; 590 for(const auto & label : labels) { 591 inits.push_back( 592 new SingleInit( 593 new LabelAddressExpr( label ) 594 ) 595 ); 596 } 597 auto init = new ListInit(std::move(inits), noDesignators, true); 598 labels.clear(); 599 600 // create decl 601 auto decl = new ObjectDecl( 602 "__generator_labels", 603 Type::StorageClasses( Type::Static ), 604 LinkageSpec::AutoGen, 605 nullptr, 606 new ArrayType( 607 Type::Qualifiers(), 608 new PointerType( 609 Type::Qualifiers(), 610 new VoidType( Type::Qualifiers() ) 611 ), 612 nullptr, 613 false, false 614 ), 615 init 616 ); 617 618 // create the goto 619 assert(in_generator); 620 621 auto go_decl = new ObjectDecl( 622 "__generator_label", 623 noStorageClasses, 624 LinkageSpec::AutoGen, 625 nullptr, 626 new PointerType( 627 Type::Qualifiers(), 628 new VoidType( Type::Qualifiers() ) 629 ), 630 new SingleInit( 631 new UntypedExpr( 632 new NameExpr("?[?]"), 633 { 634 new NameExpr("__generator_labels"), 635 new UntypedMemberExpr( 636 new NameExpr("__generator_state"), 637 new VariableExpr( in_generator ) 638 ) 639 } 640 ) 641 ) 642 ); 643 go_decl->location = loc; 644 645 auto go = new BranchStmt( 646 new VariableExpr( go_decl ), 647 BranchStmt::Goto 648 ); 649 go->location = loc; 650 go->computedTarget->location = loc; 651 652 auto noop = new NullStmt({ first_label }); 653 noop->location = loc; 654 655 // wrap everything in a nice compound 656 auto body = new CompoundStmt({ 657 new DeclStmt( decl ), 658 new DeclStmt( go_decl ), 659 go, 660 noop, 661 func->statements 662 }); 663 body->location = loc; 664 func->statements = body; 665 666 return func; 667 } 668 669 Statement * SuspendKeyword::postmutate( SuspendStmt * stmt ) { 670 SuspendStmt::Type type = stmt->type; 671 if(type == SuspendStmt::None) { 672 // This suspend has a implicit target, find it 673 type = in_generator ? SuspendStmt::Generator : SuspendStmt::Coroutine; 674 } 675 676 // Check that the target makes sense 677 if(!in_generator && type == SuspendStmt::Generator) SemanticError( stmt->location, "'suspend generator' must be used inside main of generator type."); 678 679 // Act appropriately 680 switch(type) { 681 case SuspendStmt::Generator: return make_generator_suspend(stmt); 682 case SuspendStmt::Coroutine: return make_coroutine_suspend(stmt); 683 default: abort(); 684 } 685 } 686 687 Statement * SuspendKeyword::make_generator_suspend( SuspendStmt * stmt ) { 688 assert(in_generator); 689 // Target code is : 690 // gen.__generator_state = X; 691 // { THEN } 692 // return; 693 // __gen_X:; 694 695 // Save the location and delete the old statement, we only need the location from this point on 696 auto loc = stmt->location; 697 698 // Build the label and get its index 699 auto label = make_label(); 700 701 // Create the context saving statement 702 auto save = new ExprStmt( new UntypedExpr( 703 new NameExpr( "?=?" ), 704 { 705 new UntypedMemberExpr( 706 new NameExpr("__generator_state"), 707 new VariableExpr( in_generator ) 708 ), 709 new ConstantExpr( 710 Constant::from_int( label.idx ) 711 ) 712 } 713 )); 714 assert(save->expr); 715 save->location = loc; 716 stmtsToAddBefore.push_back( save ); 717 718 // if we have a then add it here 719 auto then = stmt->then; 720 stmt->then = nullptr; 721 delete stmt; 722 if(then) stmtsToAddBefore.push_back( then ); 723 724 // Create the return statement 725 auto ret = new ReturnStmt( nullptr ); 726 ret->location = loc; 727 stmtsToAddBefore.push_back( ret ); 728 729 // Create the null statement with the created label 730 auto noop = new NullStmt({ label.obj }); 731 noop->location = loc; 732 733 // Return the null statement to take the place of the previous statement 734 return noop; 735 } 736 737 Statement * SuspendKeyword::make_coroutine_suspend( SuspendStmt * stmt ) { 738 if(stmt->then) SemanticError( stmt->location, "Compound statement following coroutines is not implemented."); 739 740 // Save the location and delete the old statement, we only need the location from this point on 741 auto loc = stmt->location; 742 delete stmt; 743 744 // Create the call expression 745 if(!decl_suspend) SemanticError( loc, "suspend keyword applied to coroutines requires coroutines to be in scope, add #include <coroutine.hfa>\n"); 746 auto expr = new UntypedExpr( VariableExpr::functionPointer( decl_suspend ) ); 747 expr->location = loc; 748 749 // Change this statement into a regular expr 750 assert(expr); 751 auto nstmt = new ExprStmt( expr ); 752 nstmt->location = loc; 753 return nstmt; 754 } 755 436 756 437 757 //============================================================================================= … … 501 821 void MutexKeyword::postvisit(StructDecl* decl) { 502 822 503 if( decl->name == " monitor_desc" && decl->body ) {823 if( decl->name == "$monitor" && decl->body ) { 504 824 assert( !monitor_decl ); 505 825 monitor_decl = decl; … … 597 917 ); 598 918 599 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };919 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 600 920 body->push_front( new DeclStmt( monitors) ); 601 921 } … … 658 978 ); 659 979 660 // monitor_desc* __monitors[] = { get_monitor(a), get_monitor(b) };980 //$monitor * __monitors[] = { get_monitor(a), get_monitor(b) }; 661 981 body->push_front( new DeclStmt( monitors) ); 662 982 } … … 666 986 //============================================================================================= 667 987 void ThreadStarter::previsit( StructDecl * decl ) { 668 if( decl->name == " thread_desc" && decl->body ) {988 if( decl->name == "$thread" && decl->body ) { 669 989 assert( !thread_decl ); 670 990 thread_decl = decl; … … 701 1021 new UntypedExpr( 702 1022 new NameExpr( "__thrd_start" ), 703 { new VariableExpr( param ) }1023 { new VariableExpr( param ), new NameExpr("main") } 704 1024 ) 705 1025 ) -
src/Concurrency/Waitfor.cc
r71d6bd8 r7030dab 11 11 // Last Modified By : 12 12 // Last Modified On : 13 // Update Count : 713 // Update Count : 12 14 14 // 15 15 … … 23 23 #include "Common/PassVisitor.h" // for PassVisitor 24 24 #include "Common/SemanticError.h" // for SemanticError 25 #include "Common/UniqueName.h" // for UniqueName 25 26 #include "Common/utility.h" // for deleteAll, map_range 26 27 #include "CodeGen/OperatorTable.h" // for isConstructor 27 28 #include "InitTweak/InitTweak.h" // for getPointerBase 28 #include "Parser/LinkageSpec.h" // for Cforall29 29 #include "ResolvExpr/Resolver.h" // for findVoidExpression 30 #include "SynTree/LinkageSpec.h" // for Cforall 30 31 #include "SynTree/Constant.h" // for Constant 31 32 #include "SynTree/Declaration.h" // for StructDecl, FunctionDecl, ObjectDecl … … 41 42 void foo() { 42 43 while( true ) { 43 when( a < 1 ) waitfor( f ,a ) { bar(); }44 when( a < 1 ) waitfor( f : a ) { bar(); } 44 45 or timeout( swagl() ); 45 or waitfor( g ,a ) { baz(); }46 or waitfor( ^?{} ,a ) { break; }46 or waitfor( g : a ) { baz(); } 47 or waitfor( ^?{} : a ) { break; } 47 48 or waitfor( ^?{} ) { break; } 48 49 } … … 243 244 decl_mask = decl; 244 245 } 245 else if( decl->name == " monitor_desc" ) {246 else if( decl->name == "$monitor" ) { 246 247 assert( !decl_monitor ); 247 248 decl_monitor = decl; -
src/ControlStruct/ExceptTranslate.cc
r71d6bd8 r7030dab 9 9 // Author : Andrew Beach 10 10 // Created On : Wed Jun 14 16:49:00 2017 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed Feb 13 18:15:29 201913 // Update Count : 1 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 11:58:00 2020 13 // Update Count : 13 14 14 // 15 15 … … 24 24 #include "Common/SemanticError.h" // for SemanticError 25 25 #include "Common/utility.h" // for CodeLocation 26 #include " Parser/LinkageSpec.h"// for Cforall26 #include "SynTree/LinkageSpec.h" // for Cforall 27 27 #include "SynTree/Attribute.h" // for Attribute 28 28 #include "SynTree/Constant.h" // for Constant … … 211 211 ThrowStmt *throwStmt ) { 212 212 // __throw_terminate( `throwStmt->get_name()` ); } 213 return create_given_throw( "__cfa abi_ehm__throw_terminate", throwStmt );213 return create_given_throw( "__cfaehm_throw_terminate", throwStmt ); 214 214 } 215 215 … … 232 232 ) ) ); 233 233 result->push_back( new ExprStmt( 234 new UntypedExpr( new NameExpr( "__cfa abi_ehm__rethrow_terminate" ) )234 new UntypedExpr( new NameExpr( "__cfaehm_rethrow_terminate" ) ) 235 235 ) ); 236 236 delete throwStmt; … … 241 241 ThrowStmt *throwStmt ) { 242 242 // __throw_resume( `throwStmt->get_name` ); 243 return create_given_throw( "__cfa abi_ehm__throw_resume", throwStmt );243 return create_given_throw( "__cfaehm_throw_resume", throwStmt ); 244 244 } 245 245 … … 309 309 local_except->get_attributes().push_back( new Attribute( 310 310 "cleanup", 311 { new NameExpr( "__cfa abi_ehm__cleanup_terminate" ) }311 { new NameExpr( "__cfaehm_cleanup_terminate" ) } 312 312 ) ); 313 313 … … 429 429 FunctionDecl * terminate_catch, 430 430 FunctionDecl * terminate_match ) { 431 // { __cfa abi_ehm__try_terminate(`try`, `catch`, `match`); }431 // { __cfaehm_try_terminate(`try`, `catch`, `match`); } 432 432 433 433 UntypedExpr * caller = new UntypedExpr( new NameExpr( 434 "__cfa abi_ehm__try_terminate" ) );434 "__cfaehm_try_terminate" ) ); 435 435 std::list<Expression *>& args = caller->get_args(); 436 436 args.push_back( nameOf( try_wrapper ) ); … … 486 486 487 487 // struct __try_resume_node __resume_node 488 // __attribute__((cleanup( __cfa abi_ehm__try_resume_cleanup )));488 // __attribute__((cleanup( __cfaehm_try_resume_cleanup ))); 489 489 // ** unwinding of the stack here could cause problems ** 490 490 // ** however I don't think that can happen currently ** 491 // __cfa abi_ehm__try_resume_setup( &__resume_node, resume_handler );491 // __cfaehm_try_resume_setup( &__resume_node, resume_handler ); 492 492 493 493 std::list< Attribute * > attributes; … … 495 495 std::list< Expression * > attr_params; 496 496 attr_params.push_back( new NameExpr( 497 "__cfa abi_ehm__try_resume_cleanup" ) );497 "__cfaehm_try_resume_cleanup" ) ); 498 498 attributes.push_back( new Attribute( "cleanup", attr_params ) ); 499 499 } … … 514 514 515 515 UntypedExpr *setup = new UntypedExpr( new NameExpr( 516 "__cfa abi_ehm__try_resume_setup" ) );516 "__cfaehm_try_resume_setup" ) ); 517 517 setup->get_args().push_back( new AddressExpr( nameOf( obj ) ) ); 518 518 setup->get_args().push_back( nameOf( resume_handler ) ); … … 539 539 ObjectDecl * ExceptionMutatorCore::create_finally_hook( 540 540 FunctionDecl * finally_wrapper ) { 541 // struct __cfa abi_ehm__cleanup_hook __finally_hook541 // struct __cfaehm_cleanup_hook __finally_hook 542 542 // __attribute__((cleanup( finally_wrapper ))); 543 543 … … 593 593 // Skip children? 594 594 return; 595 } else if ( structDecl->get_name() == "__cfa abi_ehm__base_exception_t" ) {595 } else if ( structDecl->get_name() == "__cfaehm_base_exception_t" ) { 596 596 assert( nullptr == except_decl ); 597 597 except_decl = structDecl; 598 598 init_func_types(); 599 } else if ( structDecl->get_name() == "__cfa abi_ehm__try_resume_node" ) {599 } else if ( structDecl->get_name() == "__cfaehm_try_resume_node" ) { 600 600 assert( nullptr == node_decl ); 601 601 node_decl = structDecl; 602 } else if ( structDecl->get_name() == "__cfa abi_ehm__cleanup_hook" ) {602 } else if ( structDecl->get_name() == "__cfaehm_cleanup_hook" ) { 603 603 assert( nullptr == hook_decl ); 604 604 hook_decl = structDecl; -
src/ControlStruct/LabelFixer.cc
r71d6bd8 r7030dab 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Mar 11 22:26:02 201913 // Update Count : 1 5911 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jan 21 10:32:00 2020 13 // Update Count : 160 14 14 // 15 15 … … 21 21 #include "ControlStruct/LabelGenerator.h" // for LabelGenerator 22 22 #include "LabelFixer.h" 23 #include "MLEMutator.h" // for M LEMutator23 #include "MLEMutator.h" // for MultiLevelExitMutator 24 24 #include "SynTree/Declaration.h" // for FunctionDecl 25 25 #include "SynTree/Expression.h" // for NameExpr, Expression, Unty... … … 44 44 45 45 void LabelFixer::postvisit( FunctionDecl * functionDecl ) { 46 PassVisitor<MLEMutator> mlemut( resolveJumps(), generator ); 47 functionDecl->acceptMutator( mlemut ); 46 PassVisitor<MultiLevelExitMutator> mlem( resolveJumps(), generator ); 47 // We start in the body so we can stop when we hit another FunctionDecl. 48 maybeMutate( functionDecl->statements, mlem ); 48 49 } 49 50 … … 75 76 76 77 77 // sets the definition of the labelTable entry to be the provided statement for every label in the list78 // parameter. Happens for every kind of statement78 // Sets the definition of the labelTable entry to be the provided statement for every label in 79 // the list parameter. Happens for every kind of statement. 79 80 Label LabelFixer::setLabelsDef( std::list< Label > & llabel, Statement * definition ) { 80 81 assert( definition != 0 ); 81 82 assert( llabel.size() > 0 ); 82 83 Entry * e = new Entry( definition );84 83 85 84 for ( std::list< Label >::iterator i = llabel.begin(); i != llabel.end(); i++ ) { … … 87 86 l.set_statement( definition ); // attach statement to the label to be used later 88 87 if ( labelTable.find( l ) == labelTable.end() ) { 89 // all labels on this statement need to use the same entry, so this should only be created once 88 // All labels on this statement need to use the same entry, 89 // so this should only be created once. 90 90 // undefined and unused until now, add an entry 91 labelTable[ l ] = e;91 labelTable[ l ] = new Entry( definition ); 92 92 } else if ( labelTable[ l ]->defined() ) { 93 93 // defined twice, error 94 SemanticError( l.get_statement()->location, "Duplicate definition of label: " + l.get_name() ); 95 } else { 94 SemanticError( l.get_statement()->location, 95 "Duplicate definition of label: " + l.get_name() ); 96 } else { 96 97 // used previously, but undefined until now -> link with this entry 98 // Question: Is changing objects important? 97 99 delete labelTable[ l ]; 98 labelTable[ l ] = e;100 labelTable[ l ] = new Entry( definition ); 99 101 } // if 100 102 } // for 101 103 102 // produce one of the labels attached to this statement to be temporarily used as the canonical label 104 // Produce one of the labels attached to this statement to be temporarily used as the 105 // canonical label. 103 106 return labelTable[ llabel.front() ]->get_label(); 104 107 } -
src/ControlStruct/MLEMutator.cc
r71d6bd8 r7030dab 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Oct 22 17:22:44 201913 // Update Count : 22 011 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jan 22 11:50:00 2020 13 // Update Count : 223 14 14 // 15 15 … … 33 33 34 34 namespace ControlStruct { 35 M LEMutator::~MLEMutator() {35 MultiLevelExitMutator::~MultiLevelExitMutator() { 36 36 delete targetTable; 37 37 targetTable = 0; 38 38 } 39 39 namespace { 40 bool isLoop( const MLEMutator::Entry & e ) { return dynamic_cast< WhileStmt * >( e.get_controlStructure() ) || dynamic_cast< ForStmt * >( e.get_controlStructure() ); } 41 bool isSwitch( const MLEMutator::Entry & e ) { return dynamic_cast< SwitchStmt *>( e.get_controlStructure() ); } 42 43 bool isBreakTarget( const MLEMutator::Entry & e ) { return isLoop( e ) || isSwitch( e ) || dynamic_cast< CompoundStmt *>( e.get_controlStructure() ); } 44 bool isContinueTarget( const MLEMutator::Entry & e ) { return isLoop( e ); } 45 bool isFallthroughTarget( const MLEMutator::Entry & e ) { return dynamic_cast< CaseStmt *>( e.get_controlStructure() );; } 46 bool isFallthroughDefaultTarget( const MLEMutator::Entry & e ) { return isSwitch( e ); } 40 bool isLoop( const MultiLevelExitMutator::Entry & e ) { 41 return dynamic_cast< WhileStmt * >( e.get_controlStructure() ) 42 || dynamic_cast< ForStmt * >( e.get_controlStructure() ); 43 } 44 bool isSwitch( const MultiLevelExitMutator::Entry & e ) { 45 return dynamic_cast< SwitchStmt *>( e.get_controlStructure() ); 46 } 47 48 bool isBreakTarget( const MultiLevelExitMutator::Entry & e ) { 49 return isLoop( e ) || isSwitch( e ) 50 || dynamic_cast< CompoundStmt *>( e.get_controlStructure() ); 51 } 52 bool isContinueTarget( const MultiLevelExitMutator::Entry & e ) { 53 return isLoop( e ); 54 } 55 bool isFallthroughTarget( const MultiLevelExitMutator::Entry & e ) { 56 return dynamic_cast< CaseStmt *>( e.get_controlStructure() ); 57 } 58 bool isFallthroughDefaultTarget( const MultiLevelExitMutator::Entry & e ) { 59 return isSwitch( e ); 60 } 47 61 } // namespace 62 63 void MultiLevelExitMutator::premutate( FunctionDecl * ) { 64 visit_children = false; 65 } 48 66 49 67 // break labels have to come after the statement they break out of, so mutate a statement, then if they inform us 50 68 // through the breakLabel field tha they need a place to jump to on a break statement, add the break label to the 51 69 // body of statements 52 void M LEMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) {70 void MultiLevelExitMutator::fixBlock( std::list< Statement * > &kids, bool caseClause ) { 53 71 SemanticErrorException errors; 54 72 … … 81 99 } 82 100 83 void M LEMutator::premutate( CompoundStmt *cmpndStmt ) {101 void MultiLevelExitMutator::premutate( CompoundStmt *cmpndStmt ) { 84 102 visit_children = false; 85 103 bool labeledBlock = !(cmpndStmt->labels.empty()); … … 118 136 } 119 137 } 120 assertf( false, "Could not find label '%s' on statement %s", originalTarget.get_name().c_str(), toString( stmt ).c_str() ); 121 } 122 123 124 Statement *MLEMutator::postmutate( BranchStmt *branchStmt ) throw ( SemanticErrorException ) { 138 assertf( false, "Could not find label '%s' on statement %s", 139 originalTarget.get_name().c_str(), toString( stmt ).c_str() ); 140 } 141 142 143 Statement *MultiLevelExitMutator::postmutate( BranchStmt *branchStmt ) 144 throw ( SemanticErrorException ) { 125 145 std::string originalTarget = branchStmt->originalTarget; 126 146 … … 230 250 } 231 251 232 Statement *MLEMutator::mutateLoop( Statement *bodyLoop, Entry &e ) { 252 Statement *MultiLevelExitMutator::mutateLoop( Statement *bodyLoop, Entry &e ) { 253 // only generate these when needed 254 if( !e.isContUsed() && !e.isBreakUsed() ) return bodyLoop; 255 233 256 // ensure loop body is a block 234 CompoundStmt *newBody; 235 if ( ! (newBody = dynamic_cast<CompoundStmt *>( bodyLoop )) ) { 236 newBody = new CompoundStmt(); 237 newBody->get_kids().push_back( bodyLoop ); 238 } // if 239 240 // only generate these when needed 257 CompoundStmt * newBody = new CompoundStmt(); 258 newBody->get_kids().push_back( bodyLoop ); 241 259 242 260 if ( e.isContUsed() ) { … … 255 273 256 274 template< typename LoopClass > 257 void M LEMutator::prehandleLoopStmt( LoopClass * loopStmt ) {275 void MultiLevelExitMutator::prehandleLoopStmt( LoopClass * loopStmt ) { 258 276 // remember this as the most recent enclosing loop, then mutate the body of the loop -- this will determine 259 277 // whether brkLabel and contLabel are used with branch statements and will recursively do the same to nested … … 266 284 267 285 template< typename LoopClass > 268 Statement * M LEMutator::posthandleLoopStmt( LoopClass * loopStmt ) {286 Statement * MultiLevelExitMutator::posthandleLoopStmt( LoopClass * loopStmt ) { 269 287 assert( ! enclosingControlStructures.empty() ); 270 288 Entry &e = enclosingControlStructures.back(); … … 277 295 } 278 296 279 void M LEMutator::premutate( WhileStmt * whileStmt ) {297 void MultiLevelExitMutator::premutate( WhileStmt * whileStmt ) { 280 298 return prehandleLoopStmt( whileStmt ); 281 299 } 282 300 283 void M LEMutator::premutate( ForStmt * forStmt ) {301 void MultiLevelExitMutator::premutate( ForStmt * forStmt ) { 284 302 return prehandleLoopStmt( forStmt ); 285 303 } 286 304 287 Statement * M LEMutator::postmutate( WhileStmt * whileStmt ) {305 Statement * MultiLevelExitMutator::postmutate( WhileStmt * whileStmt ) { 288 306 return posthandleLoopStmt( whileStmt ); 289 307 } 290 308 291 Statement * M LEMutator::postmutate( ForStmt * forStmt ) {309 Statement * MultiLevelExitMutator::postmutate( ForStmt * forStmt ) { 292 310 return posthandleLoopStmt( forStmt ); 293 311 } 294 312 295 void M LEMutator::premutate( IfStmt * ifStmt ) {313 void MultiLevelExitMutator::premutate( IfStmt * ifStmt ) { 296 314 // generate a label for breaking out of a labeled if 297 315 bool labeledBlock = !(ifStmt->get_labels().empty()); … … 303 321 } 304 322 305 Statement * M LEMutator::postmutate( IfStmt * ifStmt ) {323 Statement * MultiLevelExitMutator::postmutate( IfStmt * ifStmt ) { 306 324 bool labeledBlock = !(ifStmt->get_labels().empty()); 307 325 if ( labeledBlock ) { … … 313 331 } 314 332 315 void M LEMutator::premutate( TryStmt * tryStmt ) {333 void MultiLevelExitMutator::premutate( TryStmt * tryStmt ) { 316 334 // generate a label for breaking out of a labeled if 317 335 bool labeledBlock = !(tryStmt->get_labels().empty()); … … 323 341 } 324 342 325 Statement * M LEMutator::postmutate( TryStmt * tryStmt ) {343 Statement * MultiLevelExitMutator::postmutate( TryStmt * tryStmt ) { 326 344 bool labeledBlock = !(tryStmt->get_labels().empty()); 327 345 if ( labeledBlock ) { … … 333 351 } 334 352 335 void MLEMutator::premutate( CaseStmt *caseStmt ) { 353 void MultiLevelExitMutator::premutate( FinallyStmt * ) { 354 GuardAction([this, old = std::move(enclosingControlStructures)]() { 355 enclosingControlStructures = std::move(old); 356 }); 357 enclosingControlStructures = std::list<Entry>(); 358 GuardValue( inFinally ); 359 inFinally = true; 360 } 361 362 void MultiLevelExitMutator::premutate( ReturnStmt *returnStmt ) { 363 if ( inFinally ) { 364 SemanticError( returnStmt->location, "'return' may not appear in a finally clause" ); 365 } 366 } 367 368 void MultiLevelExitMutator::premutate( CaseStmt *caseStmt ) { 336 369 visit_children = false; 337 370 … … 372 405 } 373 406 374 void M LEMutator::premutate( SwitchStmt *switchStmt ) {407 void MultiLevelExitMutator::premutate( SwitchStmt *switchStmt ) { 375 408 // generate a label for breaking out of a labeled switch 376 409 Label brkLabel = generator->newLabel("switchBreak", switchStmt); … … 398 431 } 399 432 400 Statement * M LEMutator::postmutate( SwitchStmt * switchStmt ) {433 Statement * MultiLevelExitMutator::postmutate( SwitchStmt * switchStmt ) { 401 434 Entry &e = enclosingControlStructures.back(); 402 435 assert ( e == switchStmt ); -
src/ControlStruct/MLEMutator.h
r71d6bd8 r7030dab 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Oct 22 17:22:47 201913 // Update Count : 4 511 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed Jan 22 11:50:00 2020 13 // Update Count : 48 14 14 // 15 15 … … 30 30 class LabelGenerator; 31 31 32 class MLEMutator : public WithVisitorRef<MLEMutator>, public WithShortCircuiting, public WithGuards { 32 class MultiLevelExitMutator : public WithVisitorRef<MultiLevelExitMutator>, 33 public WithShortCircuiting, public WithGuards { 33 34 public: 34 35 class Entry; 35 MLEMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 36 ~MLEMutator(); 36 MultiLevelExitMutator( std::map<Label, Statement *> *t, LabelGenerator *gen = 0 ) : 37 targetTable( t ), breakLabel(std::string("")), generator( gen ) {} 38 ~MultiLevelExitMutator(); 39 40 void premutate( FunctionDecl * ); 37 41 38 42 void premutate( CompoundStmt *cmpndStmt ); … … 47 51 void premutate( SwitchStmt *switchStmt ); 48 52 Statement * postmutate( SwitchStmt *switchStmt ); 53 void premutate( ReturnStmt *returnStmt ); 49 54 void premutate( TryStmt *tryStmt ); 50 55 Statement * postmutate( TryStmt *tryStmt ); 56 void premutate( FinallyStmt *finallyStmt ); 51 57 52 58 Statement *mutateLoop( Statement *bodyLoop, Entry &e ); … … 110 116 Label breakLabel; 111 117 LabelGenerator *generator; 118 bool inFinally = false; 112 119 113 120 template< typename LoopClass > -
src/ControlStruct/Mutate.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 Aug 4 11:39:08 201613 // Update Count : 912 // Last Modified On : Sun Feb 16 03:22:07 2020 13 // Update Count : 10 14 14 // 15 15 … … 37 37 mutateAll( translationUnit, formut ); 38 38 } 39 } // namespace Co deGen39 } // namespace ControlStruct 40 40 41 41 // Local Variables: // -
src/GenPoly/Box.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 Jun 21 15:49:59 201713 // Update Count : 34 612 // Last Modified On : Fri Dec 13 23:40:34 2019 13 // Update Count : 347 14 14 // 15 15 … … 37 37 #include "InitTweak/InitTweak.h" // for getFunctionName, isAssignment 38 38 #include "Lvalue.h" // for generalizedLvalue 39 #include "Parser/LinkageSpec.h" // for C, Spec, Cforall, Intrinsic40 39 #include "ResolvExpr/TypeEnvironment.h" // for EqvClass 41 40 #include "ResolvExpr/typeops.h" // for typesCompatible … … 44 43 #include "SymTab/Indexer.h" // for Indexer 45 44 #include "SymTab/Mangler.h" // for Mangler 45 #include "SynTree/LinkageSpec.h" // for C, Spec, Cforall, Intrinsic 46 46 #include "SynTree/Attribute.h" // for Attribute 47 47 #include "SynTree/Constant.h" // for Constant -
src/GenPoly/Lvalue.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 : Fri Mar 17 09:11:18 201713 // Update Count : 512 // Last Modified On : Fri Dec 13 23:14:38 2019 13 // Update Count : 7 14 14 // 15 15 … … 17 17 #include <string> // for string 18 18 19 #include "Common/UniqueName.h" 19 20 #include "Common/PassVisitor.h" 20 21 #include "GenPoly.h" // for isPolyType … … 22 23 23 24 #include "InitTweak/InitTweak.h" 24 #include "Parser/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic25 25 #include "ResolvExpr/TypeEnvironment.h" // for AssertionSet, OpenVarSet 26 26 #include "ResolvExpr/Unify.h" // for unify 27 27 #include "ResolvExpr/typeops.h" 28 28 #include "SymTab/Indexer.h" // for Indexer 29 #include "SynTree/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic 29 30 #include "SynTree/Declaration.h" // for Declaration, FunctionDecl 30 31 #include "SynTree/Expression.h" // for Expression, ConditionalExpr … … 60 61 } 61 62 62 struct ReferenceConversions final : public WithStmtsToAdd {63 struct ReferenceConversions final : public WithStmtsToAdd, public WithGuards { 63 64 Expression * postmutate( CastExpr * castExpr ); 64 65 Expression * postmutate( AddressExpr * addrExpr ); … … 71 72 72 73 struct FixIntrinsicResult final : public WithGuards { 74 enum { 75 NoSkip, 76 Skip, 77 SkipInProgress 78 } skip = NoSkip; 79 80 void premutate( AsmExpr * ) { GuardValue( skip ); skip = Skip; } 81 void premutate( ApplicationExpr * ) { GuardValue( skip ); skip = (skip == Skip) ? SkipInProgress : NoSkip; } 82 83 73 84 Expression * postmutate( ApplicationExpr * appExpr ); 74 85 void premutate( FunctionDecl * funcDecl ); … … 162 173 163 174 Expression * FixIntrinsicResult::postmutate( ApplicationExpr * appExpr ) { 164 if ( isIntrinsicReference( appExpr ) ) {175 if ( skip != SkipInProgress && isIntrinsicReference( appExpr ) ) { 165 176 // eliminate reference types from intrinsic applications - now they return lvalues 166 177 ReferenceType * result = strict_dynamic_cast< ReferenceType * >( appExpr->result ); -
src/GenPoly/Specialize.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 07:53:59 201713 // Update Count : 3 112 // Last Modified On : Fri Dec 13 23:40:49 2019 13 // Update Count : 32 14 14 // 15 15 … … 27 27 #include "GenPoly.h" // for getFunctionType 28 28 #include "InitTweak/InitTweak.h" // for isIntrinsicCallExpr 29 #include "Parser/LinkageSpec.h" // for C30 29 #include "ResolvExpr/FindOpenVars.h" // for findOpenVars 31 30 #include "ResolvExpr/TypeEnvironment.h" // for OpenVarSet, AssertionSet 32 31 #include "Specialize.h" 32 #include "SynTree/LinkageSpec.h" // for C 33 33 #include "SynTree/Attribute.h" // for Attribute 34 34 #include "SynTree/Declaration.h" // for FunctionDecl, DeclarationWit... -
src/InitTweak/FixGlobalInit.cc
r71d6bd8 r7030dab 10 10 // Created On : Mon May 04 15:14:56 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 16 07:53:11 201713 // Update Count : 1 812 // Last Modified On : Fri Dec 13 23:41:10 2019 13 // Update Count : 19 14 14 // 15 15 … … 23 23 #include "Common/UniqueName.h" // for UniqueName 24 24 #include "InitTweak.h" // for isIntrinsicSingleArgCallStmt 25 #include " Parser/LinkageSpec.h"// for C25 #include "SynTree/LinkageSpec.h" // for C 26 26 #include "SynTree/Attribute.h" // for Attribute 27 27 #include "SynTree/Constant.h" // for Constant -
src/InitTweak/FixInit.cc
r71d6bd8 r7030dab 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:15:56 201913 // Update Count : 7612 // Last Modified On : Sun Feb 16 04:17:07 2020 13 // Update Count : 82 14 14 // 15 15 #include "FixInit.h" … … 38 38 #include "GenPoly/GenPoly.h" // for getFunctionType 39 39 #include "InitTweak.h" // for getFunctionName, getCallArg 40 #include "Parser/LinkageSpec.h" // for C, Spec, Cforall, isBuiltin41 40 #include "ResolvExpr/Resolver.h" // for findVoidExpression 42 41 #include "ResolvExpr/typeops.h" // for typesCompatible … … 44 43 #include "SymTab/Indexer.h" // for Indexer 45 44 #include "SymTab/Mangler.h" // for Mangler 45 #include "SynTree/LinkageSpec.h" // for C, Spec, Cforall, isBuiltin 46 46 #include "SynTree/Attribute.h" // for Attribute 47 47 #include "SynTree/Constant.h" // for Constant … … 745 745 } 746 746 747 // to prevent warnings ( ‘_unq0’may be used uninitialized in this function),747 // to prevent warnings ('_unq0' may be used uninitialized in this function), 748 748 // insert an appropriate zero initializer for UniqueExpr temporaries. 749 749 Initializer * makeInit( Type * t ) { -
src/InitTweak/FixInit.h
r71d6bd8 r7030dab 10 10 // Created On : Wed Jan 13 16:29:30 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : S at Jul 22 09:31:06 201713 // Update Count : 612 // Last Modified On : Sun Feb 16 07:54:50 2020 13 // Update Count : 8 14 14 // 15 15 … … 22 22 23 23 namespace InitTweak { 24 /// replace constructor initializers with expression statements 25 /// and unwrap basic C-style initializers 24 /// replace constructor initializers with expression statements and unwrap basic C-style initializers 26 25 void fix( std::list< Declaration * > & translationUnit, bool inLibrary ); 27 26 } // namespace -
src/InitTweak/GenInit.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 : Fri Mar 17 09:12:36 201713 // Update Count : 18 312 // Last Modified On : Fri Dec 13 23:15:10 2019 13 // Update Count : 184 14 14 // 15 15 #include "GenInit.h" … … 34 34 #include "GenPoly/ScopedSet.h" // for ScopedSet, ScopedSet<>::const_iter... 35 35 #include "InitTweak.h" // for isConstExpr, InitExpander, checkIn... 36 #include "Parser/LinkageSpec.h" // for isOverridable, C37 36 #include "ResolvExpr/Resolver.h" 38 37 #include "SymTab/Autogen.h" // for genImplicitCall 39 38 #include "SymTab/Mangler.h" // for Mangler 39 #include "SynTree/LinkageSpec.h" // for isOverridable, C 40 40 #include "SynTree/Declaration.h" // for ObjectDecl, DeclarationWithType 41 41 #include "SynTree/Expression.h" // for VariableExpr, UntypedExpr, Address... -
src/InitTweak/InitTweak.cc
r71d6bd8 r7030dab 10 10 // Created On : Fri May 13 11:26:36 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:21:48201913 // Update Count : 712 // Last Modified On : Fri Dec 13 23:15:52 2019 13 // Update Count : 8 14 14 // 15 15 … … 33 33 #include "GenPoly/GenPoly.h" // for getFunctionType 34 34 #include "InitTweak.h" 35 #include "Parser/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic36 35 #include "ResolvExpr/typeops.h" // for typesCompatibleIgnoreQualifiers 37 36 #include "SymTab/Autogen.h" 38 37 #include "SymTab/Indexer.h" // for Indexer 38 #include "SynTree/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic 39 39 #include "SynTree/Attribute.h" // for Attribute 40 40 #include "SynTree/Constant.h" // for Constant -
src/MakeLibCfa.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 10:33:33 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Feb 1 7 21:08:09 201913 // Update Count : 4 112 // Last Modified On : Sun Feb 16 03:49:49 2020 13 // Update Count : 45 14 14 // 15 15 … … 23 23 #include "Common/SemanticError.h" // for SemanticError 24 24 #include "Common/UniqueName.h" // for UniqueName 25 #include " Parser/LinkageSpec.h"// for Spec, Intrinsic, C25 #include "SynTree/LinkageSpec.h" // for Spec, Intrinsic, C 26 26 #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declara... 27 27 #include "SynTree/Expression.h" // for NameExpr, UntypedExpr, VariableExpr … … 96 96 97 97 FunctionDecl *funcDecl = origFuncDecl->clone(); 98 CodeGen::OperatorInfoopInfo;99 bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo);100 assert( lookResult);98 const CodeGen::OperatorInfo * opInfo; 99 opInfo = CodeGen::operatorLookup( funcDecl->get_name() ); 100 assert( opInfo ); 101 101 assert( ! funcDecl->get_statements() ); 102 102 // build a recursive call - this is okay, as the call will actually be codegen'd using operator syntax … … 120 120 121 121 Statement * stmt = nullptr; 122 switch ( opInfo .type ) {122 switch ( opInfo->type ) { 123 123 case CodeGen::OT_INDEX: 124 124 case CodeGen::OT_CALL: -
src/Makefile.in
r71d6bd8 r7030dab 213 213 SymTab/Indexer.$(OBJEXT) SymTab/Mangler.$(OBJEXT) \ 214 214 SymTab/ManglerCommon.$(OBJEXT) SymTab/Validate.$(OBJEXT) 215 am__objects_7 = SynTree/Type.$(OBJEXT) SynTree/VoidType.$(OBJEXT) \ 216 SynTree/BasicType.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \ 217 SynTree/ArrayType.$(OBJEXT) SynTree/ReferenceType.$(OBJEXT) \ 218 SynTree/FunctionType.$(OBJEXT) \ 219 SynTree/ReferenceToType.$(OBJEXT) SynTree/TupleType.$(OBJEXT) \ 220 SynTree/TypeofType.$(OBJEXT) SynTree/AttrType.$(OBJEXT) \ 221 SynTree/VarArgsType.$(OBJEXT) SynTree/ZeroOneType.$(OBJEXT) \ 222 SynTree/Constant.$(OBJEXT) SynTree/Expression.$(OBJEXT) \ 223 SynTree/TupleExpr.$(OBJEXT) SynTree/CommaExpr.$(OBJEXT) \ 224 SynTree/TypeExpr.$(OBJEXT) SynTree/ApplicationExpr.$(OBJEXT) \ 225 SynTree/AddressExpr.$(OBJEXT) SynTree/Statement.$(OBJEXT) \ 226 SynTree/CompoundStmt.$(OBJEXT) SynTree/DeclStmt.$(OBJEXT) \ 215 am__objects_7 = SynTree/AddressExpr.$(OBJEXT) \ 216 SynTree/AggregateDecl.$(OBJEXT) \ 217 SynTree/ApplicationExpr.$(OBJEXT) SynTree/ArrayType.$(OBJEXT) \ 218 SynTree/AttrType.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \ 219 SynTree/BasicType.$(OBJEXT) SynTree/CommaExpr.$(OBJEXT) \ 220 SynTree/CompoundStmt.$(OBJEXT) SynTree/Constant.$(OBJEXT) \ 221 SynTree/DeclReplacer.$(OBJEXT) SynTree/DeclStmt.$(OBJEXT) \ 227 222 SynTree/Declaration.$(OBJEXT) \ 228 223 SynTree/DeclarationWithType.$(OBJEXT) \ 229 SynTree/ObjectDecl.$(OBJEXT) SynTree/FunctionDecl.$(OBJEXT) \ 230 SynTree/AggregateDecl.$(OBJEXT) \ 231 SynTree/NamedTypeDecl.$(OBJEXT) SynTree/TypeDecl.$(OBJEXT) \ 232 SynTree/Initializer.$(OBJEXT) \ 233 SynTree/TypeSubstitution.$(OBJEXT) SynTree/Attribute.$(OBJEXT) \ 234 SynTree/DeclReplacer.$(OBJEXT) 224 SynTree/Expression.$(OBJEXT) SynTree/FunctionDecl.$(OBJEXT) \ 225 SynTree/FunctionType.$(OBJEXT) SynTree/Initializer.$(OBJEXT) \ 226 SynTree/LinkageSpec.$(OBJEXT) SynTree/NamedTypeDecl.$(OBJEXT) \ 227 SynTree/ObjectDecl.$(OBJEXT) SynTree/PointerType.$(OBJEXT) \ 228 SynTree/ReferenceToType.$(OBJEXT) \ 229 SynTree/ReferenceType.$(OBJEXT) SynTree/Statement.$(OBJEXT) \ 230 SynTree/TupleExpr.$(OBJEXT) SynTree/TupleType.$(OBJEXT) \ 231 SynTree/Type.$(OBJEXT) SynTree/TypeDecl.$(OBJEXT) \ 232 SynTree/TypeExpr.$(OBJEXT) SynTree/TypeSubstitution.$(OBJEXT) \ 233 SynTree/TypeofType.$(OBJEXT) SynTree/VarArgsType.$(OBJEXT) \ 234 SynTree/VoidType.$(OBJEXT) SynTree/ZeroOneType.$(OBJEXT) 235 235 am__objects_8 = CompilationState.$(OBJEXT) $(am__objects_1) \ 236 236 $(am__objects_2) Concurrency/Keywords.$(OBJEXT) \ 237 237 $(am__objects_3) $(am__objects_4) GenPoly/GenPoly.$(OBJEXT) \ 238 238 GenPoly/Lvalue.$(OBJEXT) InitTweak/GenInit.$(OBJEXT) \ 239 InitTweak/InitTweak.$(OBJEXT) Parser/LinkageSpec.$(OBJEXT) \240 $(am__objects_ 5) $(am__objects_6) SymTab/Demangle.$(OBJEXT) \241 $(am__objects_7)Tuples/TupleAssignment.$(OBJEXT) \239 InitTweak/InitTweak.$(OBJEXT) $(am__objects_5) \ 240 $(am__objects_6) SymTab/Demangle.$(OBJEXT) $(am__objects_7) \ 241 Tuples/TupleAssignment.$(OBJEXT) \ 242 242 Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \ 243 243 Tuples/Tuples.$(OBJEXT) Validate/HandleAttributes.$(OBJEXT) \ … … 262 262 InitTweak/GenInit.$(OBJEXT) InitTweak/FixInit.$(OBJEXT) \ 263 263 InitTweak/FixGlobalInit.$(OBJEXT) \ 264 InitTweak/InitTweak.$(OBJEXT) Parser/ parser.$(OBJEXT) \265 Parser/ lex.$(OBJEXT) Parser/TypedefTable.$(OBJEXT) \266 Parser/ ParseNode.$(OBJEXT) Parser/DeclarationNode.$(OBJEXT) \267 Parser/ ExpressionNode.$(OBJEXT) Parser/StatementNode.$(OBJEXT) \268 Parser/ InitializerNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \269 Parser/ LinkageSpec.$(OBJEXT) Parser/parserutility.$(OBJEXT) \264 InitTweak/InitTweak.$(OBJEXT) Parser/DeclarationNode.$(OBJEXT) \ 265 Parser/ExpressionNode.$(OBJEXT) \ 266 Parser/InitializerNode.$(OBJEXT) Parser/ParseNode.$(OBJEXT) \ 267 Parser/StatementNode.$(OBJEXT) Parser/TypeData.$(OBJEXT) \ 268 Parser/TypedefTable.$(OBJEXT) Parser/lex.$(OBJEXT) \ 269 Parser/parser.$(OBJEXT) Parser/parserutility.$(OBJEXT) \ 270 270 $(am__objects_5) ResolvExpr/AlternativePrinter.$(OBJEXT) \ 271 271 $(am__objects_6) $(am__objects_7) \ … … 560 560 InitTweak/GenInit.cc InitTweak/FixInit.cc \ 561 561 InitTweak/FixGlobalInit.cc InitTweak/InitTweak.cc \ 562 Parser/ parser.yy Parser/lex.ll Parser/TypedefTable.cc \563 Parser/ ParseNode.cc Parser/DeclarationNode.cc \564 Parser/ ExpressionNode.cc Parser/StatementNode.cc \565 Parser/ InitializerNode.cc Parser/TypeData.cc\566 Parser/ LinkageSpec.cc Parser/parserutility.cc\567 $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc\568 $(SRC_SYMTAB) $(SRC_SYNTREE) Tuples/TupleAssignment.cc \569 Tuples/ TupleExpansion.cc Tuples/Explode.cc Tuples/Tuples.cc \562 Parser/DeclarationNode.cc Parser/ExpressionNode.cc \ 563 Parser/InitializerNode.cc Parser/ParseNode.cc \ 564 Parser/StatementNode.cc Parser/TypeData.cc \ 565 Parser/TypedefTable.cc Parser/lex.ll Parser/parser.yy \ 566 Parser/parserutility.cc $(SRC_RESOLVEXPR) \ 567 ResolvExpr/AlternativePrinter.cc $(SRC_SYMTAB) $(SRC_SYNTREE) \ 568 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 569 Tuples/Explode.cc Tuples/Tuples.cc \ 570 570 Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc \ 571 571 Virtual/ExpandCasts.cc … … 573 573 Concurrency/Keywords.cc $(SRC_COMMON) $(SRC_CONTROLSTRUCT) \ 574 574 GenPoly/GenPoly.cc GenPoly/Lvalue.cc InitTweak/GenInit.cc \ 575 InitTweak/InitTweak.cc Parser/LinkageSpec.cc $(SRC_RESOLVEXPR) \ 576 $(SRC_SYMTAB) SymTab/Demangle.cc $(SRC_SYNTREE) \ 577 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 578 Tuples/Explode.cc Tuples/Tuples.cc \ 575 InitTweak/InitTweak.cc $(SRC_RESOLVEXPR) $(SRC_SYMTAB) \ 576 SymTab/Demangle.cc $(SRC_SYNTREE) Tuples/TupleAssignment.cc \ 577 Tuples/TupleExpansion.cc Tuples/Explode.cc Tuples/Tuples.cc \ 579 578 Validate/HandleAttributes.cc Validate/FindSpecialDecls.cc 580 579 MAINTAINERCLEANFILES = ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}} … … 665 664 666 665 SRC_SYNTREE = \ 667 SynTree/Type.cc \ 668 SynTree/VoidType.cc \ 666 SynTree/AddressExpr.cc \ 667 SynTree/AggregateDecl.cc \ 668 SynTree/ApplicationExpr.cc \ 669 SynTree/ArrayType.cc \ 670 SynTree/AttrType.cc \ 671 SynTree/Attribute.cc \ 669 672 SynTree/BasicType.cc \ 670 SynTree/PointerType.cc \ 671 SynTree/ArrayType.cc \ 672 SynTree/ReferenceType.cc \ 673 SynTree/FunctionType.cc \ 674 SynTree/ReferenceToType.cc \ 675 SynTree/TupleType.cc \ 676 SynTree/TypeofType.cc \ 677 SynTree/AttrType.cc \ 678 SynTree/VarArgsType.cc \ 679 SynTree/ZeroOneType.cc \ 673 SynTree/CommaExpr.cc \ 674 SynTree/CompoundStmt.cc \ 680 675 SynTree/Constant.cc \ 681 SynTree/Expression.cc \ 682 SynTree/TupleExpr.cc \ 683 SynTree/CommaExpr.cc \ 684 SynTree/TypeExpr.cc \ 685 SynTree/ApplicationExpr.cc \ 686 SynTree/AddressExpr.cc \ 687 SynTree/Statement.cc \ 688 SynTree/CompoundStmt.cc \ 676 SynTree/DeclReplacer.cc \ 689 677 SynTree/DeclStmt.cc \ 690 678 SynTree/Declaration.cc \ 691 679 SynTree/DeclarationWithType.cc \ 680 SynTree/Expression.cc \ 681 SynTree/FunctionDecl.cc \ 682 SynTree/FunctionType.cc \ 683 SynTree/Initializer.cc \ 684 SynTree/LinkageSpec.cc \ 685 SynTree/NamedTypeDecl.cc \ 692 686 SynTree/ObjectDecl.cc \ 693 SynTree/FunctionDecl.cc \ 694 SynTree/AggregateDecl.cc \ 695 SynTree/NamedTypeDecl.cc \ 687 SynTree/PointerType.cc \ 688 SynTree/ReferenceToType.cc \ 689 SynTree/ReferenceType.cc \ 690 SynTree/Statement.cc \ 691 SynTree/TupleExpr.cc \ 692 SynTree/TupleType.cc \ 693 SynTree/Type.cc \ 696 694 SynTree/TypeDecl.cc \ 697 SynTree/ Initializer.cc \695 SynTree/TypeExpr.cc \ 698 696 SynTree/TypeSubstitution.cc \ 699 SynTree/Attribute.cc \ 700 SynTree/DeclReplacer.cc 697 SynTree/TypeofType.cc \ 698 SynTree/VarArgsType.cc \ 699 SynTree/VoidType.cc \ 700 SynTree/ZeroOneType.cc 701 701 702 702 … … 873 873 InitTweak/InitTweak.$(OBJEXT): InitTweak/$(am__dirstamp) \ 874 874 InitTweak/$(DEPDIR)/$(am__dirstamp) 875 Parser/$(am__dirstamp):876 @$(MKDIR_P) Parser877 @: > Parser/$(am__dirstamp)878 Parser/$(DEPDIR)/$(am__dirstamp):879 @$(MKDIR_P) Parser/$(DEPDIR)880 @: > Parser/$(DEPDIR)/$(am__dirstamp)881 Parser/LinkageSpec.$(OBJEXT): Parser/$(am__dirstamp) \882 Parser/$(DEPDIR)/$(am__dirstamp)883 875 ResolvExpr/$(am__dirstamp): 884 876 @$(MKDIR_P) ResolvExpr … … 961 953 @$(MKDIR_P) SynTree/$(DEPDIR) 962 954 @: > SynTree/$(DEPDIR)/$(am__dirstamp) 955 SynTree/AddressExpr.$(OBJEXT): SynTree/$(am__dirstamp) \ 956 SynTree/$(DEPDIR)/$(am__dirstamp) 957 SynTree/AggregateDecl.$(OBJEXT): SynTree/$(am__dirstamp) \ 958 SynTree/$(DEPDIR)/$(am__dirstamp) 959 SynTree/ApplicationExpr.$(OBJEXT): SynTree/$(am__dirstamp) \ 960 SynTree/$(DEPDIR)/$(am__dirstamp) 961 SynTree/ArrayType.$(OBJEXT): SynTree/$(am__dirstamp) \ 962 SynTree/$(DEPDIR)/$(am__dirstamp) 963 SynTree/AttrType.$(OBJEXT): SynTree/$(am__dirstamp) \ 964 SynTree/$(DEPDIR)/$(am__dirstamp) 965 SynTree/Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \ 966 SynTree/$(DEPDIR)/$(am__dirstamp) 967 SynTree/BasicType.$(OBJEXT): SynTree/$(am__dirstamp) \ 968 SynTree/$(DEPDIR)/$(am__dirstamp) 969 SynTree/CommaExpr.$(OBJEXT): SynTree/$(am__dirstamp) \ 970 SynTree/$(DEPDIR)/$(am__dirstamp) 971 SynTree/CompoundStmt.$(OBJEXT): SynTree/$(am__dirstamp) \ 972 SynTree/$(DEPDIR)/$(am__dirstamp) 973 SynTree/Constant.$(OBJEXT): SynTree/$(am__dirstamp) \ 974 SynTree/$(DEPDIR)/$(am__dirstamp) 975 SynTree/DeclReplacer.$(OBJEXT): SynTree/$(am__dirstamp) \ 976 SynTree/$(DEPDIR)/$(am__dirstamp) 977 SynTree/DeclStmt.$(OBJEXT): SynTree/$(am__dirstamp) \ 978 SynTree/$(DEPDIR)/$(am__dirstamp) 979 SynTree/Declaration.$(OBJEXT): SynTree/$(am__dirstamp) \ 980 SynTree/$(DEPDIR)/$(am__dirstamp) 981 SynTree/DeclarationWithType.$(OBJEXT): SynTree/$(am__dirstamp) \ 982 SynTree/$(DEPDIR)/$(am__dirstamp) 983 SynTree/Expression.$(OBJEXT): SynTree/$(am__dirstamp) \ 984 SynTree/$(DEPDIR)/$(am__dirstamp) 985 SynTree/FunctionDecl.$(OBJEXT): SynTree/$(am__dirstamp) \ 986 SynTree/$(DEPDIR)/$(am__dirstamp) 987 SynTree/FunctionType.$(OBJEXT): SynTree/$(am__dirstamp) \ 988 SynTree/$(DEPDIR)/$(am__dirstamp) 989 SynTree/Initializer.$(OBJEXT): SynTree/$(am__dirstamp) \ 990 SynTree/$(DEPDIR)/$(am__dirstamp) 991 SynTree/LinkageSpec.$(OBJEXT): SynTree/$(am__dirstamp) \ 992 SynTree/$(DEPDIR)/$(am__dirstamp) 993 SynTree/NamedTypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \ 994 SynTree/$(DEPDIR)/$(am__dirstamp) 995 SynTree/ObjectDecl.$(OBJEXT): SynTree/$(am__dirstamp) \ 996 SynTree/$(DEPDIR)/$(am__dirstamp) 997 SynTree/PointerType.$(OBJEXT): SynTree/$(am__dirstamp) \ 998 SynTree/$(DEPDIR)/$(am__dirstamp) 999 SynTree/ReferenceToType.$(OBJEXT): SynTree/$(am__dirstamp) \ 1000 SynTree/$(DEPDIR)/$(am__dirstamp) 1001 SynTree/ReferenceType.$(OBJEXT): SynTree/$(am__dirstamp) \ 1002 SynTree/$(DEPDIR)/$(am__dirstamp) 1003 SynTree/Statement.$(OBJEXT): SynTree/$(am__dirstamp) \ 1004 SynTree/$(DEPDIR)/$(am__dirstamp) 1005 SynTree/TupleExpr.$(OBJEXT): SynTree/$(am__dirstamp) \ 1006 SynTree/$(DEPDIR)/$(am__dirstamp) 1007 SynTree/TupleType.$(OBJEXT): SynTree/$(am__dirstamp) \ 1008 SynTree/$(DEPDIR)/$(am__dirstamp) 963 1009 SynTree/Type.$(OBJEXT): SynTree/$(am__dirstamp) \ 964 1010 SynTree/$(DEPDIR)/$(am__dirstamp) 1011 SynTree/TypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \ 1012 SynTree/$(DEPDIR)/$(am__dirstamp) 1013 SynTree/TypeExpr.$(OBJEXT): SynTree/$(am__dirstamp) \ 1014 SynTree/$(DEPDIR)/$(am__dirstamp) 1015 SynTree/TypeSubstitution.$(OBJEXT): SynTree/$(am__dirstamp) \ 1016 SynTree/$(DEPDIR)/$(am__dirstamp) 1017 SynTree/TypeofType.$(OBJEXT): SynTree/$(am__dirstamp) \ 1018 SynTree/$(DEPDIR)/$(am__dirstamp) 1019 SynTree/VarArgsType.$(OBJEXT): SynTree/$(am__dirstamp) \ 1020 SynTree/$(DEPDIR)/$(am__dirstamp) 965 1021 SynTree/VoidType.$(OBJEXT): SynTree/$(am__dirstamp) \ 966 1022 SynTree/$(DEPDIR)/$(am__dirstamp) 967 SynTree/BasicType.$(OBJEXT): SynTree/$(am__dirstamp) \968 SynTree/$(DEPDIR)/$(am__dirstamp)969 SynTree/PointerType.$(OBJEXT): SynTree/$(am__dirstamp) \970 SynTree/$(DEPDIR)/$(am__dirstamp)971 SynTree/ArrayType.$(OBJEXT): SynTree/$(am__dirstamp) \972 SynTree/$(DEPDIR)/$(am__dirstamp)973 SynTree/ReferenceType.$(OBJEXT): SynTree/$(am__dirstamp) \974 SynTree/$(DEPDIR)/$(am__dirstamp)975 SynTree/FunctionType.$(OBJEXT): SynTree/$(am__dirstamp) \976 SynTree/$(DEPDIR)/$(am__dirstamp)977 SynTree/ReferenceToType.$(OBJEXT): SynTree/$(am__dirstamp) \978 SynTree/$(DEPDIR)/$(am__dirstamp)979 SynTree/TupleType.$(OBJEXT): SynTree/$(am__dirstamp) \980 SynTree/$(DEPDIR)/$(am__dirstamp)981 SynTree/TypeofType.$(OBJEXT): SynTree/$(am__dirstamp) \982 SynTree/$(DEPDIR)/$(am__dirstamp)983 SynTree/AttrType.$(OBJEXT): SynTree/$(am__dirstamp) \984 SynTree/$(DEPDIR)/$(am__dirstamp)985 SynTree/VarArgsType.$(OBJEXT): SynTree/$(am__dirstamp) \986 SynTree/$(DEPDIR)/$(am__dirstamp)987 1023 SynTree/ZeroOneType.$(OBJEXT): SynTree/$(am__dirstamp) \ 988 SynTree/$(DEPDIR)/$(am__dirstamp)989 SynTree/Constant.$(OBJEXT): SynTree/$(am__dirstamp) \990 SynTree/$(DEPDIR)/$(am__dirstamp)991 SynTree/Expression.$(OBJEXT): SynTree/$(am__dirstamp) \992 SynTree/$(DEPDIR)/$(am__dirstamp)993 SynTree/TupleExpr.$(OBJEXT): SynTree/$(am__dirstamp) \994 SynTree/$(DEPDIR)/$(am__dirstamp)995 SynTree/CommaExpr.$(OBJEXT): SynTree/$(am__dirstamp) \996 SynTree/$(DEPDIR)/$(am__dirstamp)997 SynTree/TypeExpr.$(OBJEXT): SynTree/$(am__dirstamp) \998 SynTree/$(DEPDIR)/$(am__dirstamp)999 SynTree/ApplicationExpr.$(OBJEXT): SynTree/$(am__dirstamp) \1000 SynTree/$(DEPDIR)/$(am__dirstamp)1001 SynTree/AddressExpr.$(OBJEXT): SynTree/$(am__dirstamp) \1002 SynTree/$(DEPDIR)/$(am__dirstamp)1003 SynTree/Statement.$(OBJEXT): SynTree/$(am__dirstamp) \1004 SynTree/$(DEPDIR)/$(am__dirstamp)1005 SynTree/CompoundStmt.$(OBJEXT): SynTree/$(am__dirstamp) \1006 SynTree/$(DEPDIR)/$(am__dirstamp)1007 SynTree/DeclStmt.$(OBJEXT): SynTree/$(am__dirstamp) \1008 SynTree/$(DEPDIR)/$(am__dirstamp)1009 SynTree/Declaration.$(OBJEXT): SynTree/$(am__dirstamp) \1010 SynTree/$(DEPDIR)/$(am__dirstamp)1011 SynTree/DeclarationWithType.$(OBJEXT): SynTree/$(am__dirstamp) \1012 SynTree/$(DEPDIR)/$(am__dirstamp)1013 SynTree/ObjectDecl.$(OBJEXT): SynTree/$(am__dirstamp) \1014 SynTree/$(DEPDIR)/$(am__dirstamp)1015 SynTree/FunctionDecl.$(OBJEXT): SynTree/$(am__dirstamp) \1016 SynTree/$(DEPDIR)/$(am__dirstamp)1017 SynTree/AggregateDecl.$(OBJEXT): SynTree/$(am__dirstamp) \1018 SynTree/$(DEPDIR)/$(am__dirstamp)1019 SynTree/NamedTypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \1020 SynTree/$(DEPDIR)/$(am__dirstamp)1021 SynTree/TypeDecl.$(OBJEXT): SynTree/$(am__dirstamp) \1022 SynTree/$(DEPDIR)/$(am__dirstamp)1023 SynTree/Initializer.$(OBJEXT): SynTree/$(am__dirstamp) \1024 SynTree/$(DEPDIR)/$(am__dirstamp)1025 SynTree/TypeSubstitution.$(OBJEXT): SynTree/$(am__dirstamp) \1026 SynTree/$(DEPDIR)/$(am__dirstamp)1027 SynTree/Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \1028 SynTree/$(DEPDIR)/$(am__dirstamp)1029 SynTree/DeclReplacer.$(OBJEXT): SynTree/$(am__dirstamp) \1030 1024 SynTree/$(DEPDIR)/$(am__dirstamp) 1031 1025 Tuples/$(am__dirstamp): … … 1144 1138 InitTweak/FixGlobalInit.$(OBJEXT): InitTweak/$(am__dirstamp) \ 1145 1139 InitTweak/$(DEPDIR)/$(am__dirstamp) 1140 Parser/$(am__dirstamp): 1141 @$(MKDIR_P) Parser 1142 @: > Parser/$(am__dirstamp) 1143 Parser/$(DEPDIR)/$(am__dirstamp): 1144 @$(MKDIR_P) Parser/$(DEPDIR) 1145 @: > Parser/$(DEPDIR)/$(am__dirstamp) 1146 Parser/DeclarationNode.$(OBJEXT): Parser/$(am__dirstamp) \ 1147 Parser/$(DEPDIR)/$(am__dirstamp) 1148 Parser/ExpressionNode.$(OBJEXT): Parser/$(am__dirstamp) \ 1149 Parser/$(DEPDIR)/$(am__dirstamp) 1150 Parser/InitializerNode.$(OBJEXT): Parser/$(am__dirstamp) \ 1151 Parser/$(DEPDIR)/$(am__dirstamp) 1152 Parser/ParseNode.$(OBJEXT): Parser/$(am__dirstamp) \ 1153 Parser/$(DEPDIR)/$(am__dirstamp) 1154 Parser/StatementNode.$(OBJEXT): Parser/$(am__dirstamp) \ 1155 Parser/$(DEPDIR)/$(am__dirstamp) 1156 Parser/TypeData.$(OBJEXT): Parser/$(am__dirstamp) \ 1157 Parser/$(DEPDIR)/$(am__dirstamp) 1158 Parser/TypedefTable.$(OBJEXT): Parser/$(am__dirstamp) \ 1159 Parser/$(DEPDIR)/$(am__dirstamp) 1160 Parser/lex.$(OBJEXT): Parser/$(am__dirstamp) \ 1161 Parser/$(DEPDIR)/$(am__dirstamp) 1146 1162 Parser/parser.hh: Parser/parser.cc 1147 1163 @if test ! -f $@; then rm -f Parser/parser.cc; else :; fi 1148 1164 @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) Parser/parser.cc; else :; fi 1149 1165 Parser/parser.$(OBJEXT): Parser/$(am__dirstamp) \ 1150 Parser/$(DEPDIR)/$(am__dirstamp)1151 Parser/lex.$(OBJEXT): Parser/$(am__dirstamp) \1152 Parser/$(DEPDIR)/$(am__dirstamp)1153 Parser/TypedefTable.$(OBJEXT): Parser/$(am__dirstamp) \1154 Parser/$(DEPDIR)/$(am__dirstamp)1155 Parser/ParseNode.$(OBJEXT): Parser/$(am__dirstamp) \1156 Parser/$(DEPDIR)/$(am__dirstamp)1157 Parser/DeclarationNode.$(OBJEXT): Parser/$(am__dirstamp) \1158 Parser/$(DEPDIR)/$(am__dirstamp)1159 Parser/ExpressionNode.$(OBJEXT): Parser/$(am__dirstamp) \1160 Parser/$(DEPDIR)/$(am__dirstamp)1161 Parser/StatementNode.$(OBJEXT): Parser/$(am__dirstamp) \1162 Parser/$(DEPDIR)/$(am__dirstamp)1163 Parser/InitializerNode.$(OBJEXT): Parser/$(am__dirstamp) \1164 Parser/$(DEPDIR)/$(am__dirstamp)1165 Parser/TypeData.$(OBJEXT): Parser/$(am__dirstamp) \1166 1166 Parser/$(DEPDIR)/$(am__dirstamp) 1167 1167 Parser/parserutility.$(OBJEXT): Parser/$(am__dirstamp) \ … … 1275 1275 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/ExpressionNode.Po@am__quote@ 1276 1276 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/InitializerNode.Po@am__quote@ 1277 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/LinkageSpec.Po@am__quote@1278 1277 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/ParseNode.Po@am__quote@ 1279 1278 @AMDEP_TRUE@@am__include@ @am__quote@Parser/$(DEPDIR)/StatementNode.Po@am__quote@ … … 1334 1333 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/FunctionType.Po@am__quote@ 1335 1334 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/Initializer.Po@am__quote@ 1335 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/LinkageSpec.Po@am__quote@ 1336 1336 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/NamedTypeDecl.Po@am__quote@ 1337 1337 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/ObjectDecl.Po@am__quote@ -
src/Parser/DeclarationNode.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 12:34:05 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:17:10201913 // Update Count : 11 1612 // Last Modified On : Mon Dec 16 15:32:22 2019 13 // Update Count : 1133 14 14 // 15 15 … … 24 24 #include "Common/UniqueName.h" // for UniqueName 25 25 #include "Common/utility.h" // for maybeClone, maybeBuild, CodeLocation 26 #include "Parser/LinkageSpec.h" // for Spec, linkageName, Cforall27 26 #include "Parser/ParseNode.h" // for DeclarationNode, ExpressionNode 27 #include "SynTree/LinkageSpec.h" // for Spec, linkageName, Cforall 28 28 #include "SynTree/Attribute.h" // for Attribute 29 29 #include "SynTree/Declaration.h" // for TypeDecl, ObjectDecl, Declaration … … 47 47 const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" }; 48 48 const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" }; 49 const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };50 const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };51 49 const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" }; 52 50 … … 59 57 60 58 // variable.name = nullptr; 61 variable.tyClass = NoTypeClass;59 variable.tyClass = TypeDecl::NUMBER_OF_KINDS; 62 60 variable.assertions = nullptr; 63 61 variable.initializer = nullptr; … … 135 133 136 134 if ( linkage != LinkageSpec::Cforall ) { 137 os << LinkageSpec:: linkageName( linkage ) << " ";135 os << LinkageSpec::name( linkage ) << " "; 138 136 } // if 139 137 … … 267 265 } 268 266 269 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {267 DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) { 270 268 DeclarationNode * newnode = new DeclarationNode; 271 269 newnode->type = new TypeData( TypeData::Aggregate ); … … 313 311 } // DeclarationNode::newFromTypeGen 314 312 315 DeclarationNode * DeclarationNode::newTypeParam( Type Classtc, const string * name ) {313 DeclarationNode * DeclarationNode::newTypeParam( TypeDecl::Kind tc, const string * name ) { 316 314 DeclarationNode * newnode = new DeclarationNode; 317 315 newnode->type = nullptr; … … 328 326 newnode->type = new TypeData( TypeData::Aggregate ); 329 327 newnode->type->aggregate.name = name; 330 newnode->type->aggregate.kind = Trait;328 newnode->type->aggregate.kind = AggregateDecl::Trait; 331 329 newnode->type->aggregate.params = params; 332 330 newnode->type->aggregate.fields = asserts; … … 338 336 newnode->type = new TypeData( TypeData::AggregateInst ); 339 337 newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate ); 340 newnode->type->aggInst.aggregate->aggregate.kind = Trait;338 newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait; 341 339 newnode->type->aggInst.aggregate->aggregate.name = name; 342 340 newnode->type->aggInst.params = params; … … 671 669 672 670 DeclarationNode * DeclarationNode::addAssertions( DeclarationNode * assertions ) { 673 if ( variable.tyClass != NoTypeClass) {671 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 674 672 if ( variable.assertions ) { 675 673 variable.assertions->appendList( assertions ); … … 876 874 877 875 DeclarationNode * DeclarationNode::addTypeInitializer( DeclarationNode * init ) { 878 assertf( variable.tyClass != NoTypeClass, "Called addTypeInitializer on something that isn't a type variable." );876 assertf( variable.tyClass != TypeDecl::NUMBER_OF_KINDS, "Called addTypeInitializer on something that isn't a type variable." ); 879 877 variable.initializer = init; 880 878 return this; … … 1075 1073 } // if 1076 1074 1077 if ( variable.tyClass != NoTypeClass) {1075 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1078 1076 // otype is internally converted to dtype + otype parameters 1079 1077 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype }; 1080 assertf( sizeof(kindMap)/sizeof(kindMap[0]) == NoTypeClass, "DeclarationNode::build: kindMap is out of sync." );1078 static_assert( sizeof(kindMap)/sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." ); 1081 1079 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1082 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == Otype, variable.initializer ? variable.initializer->buildType() : nullptr );1080 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1083 1081 buildList( variable.assertions, ret->get_assertions() ); 1084 1082 return ret; -
src/Parser/ExpressionNode.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 13:17:07 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 4 20:57:55201913 // Update Count : 9 7812 // Last Modified On : Wed Dec 18 21:14:58 2019 13 // Update Count : 981 14 14 // 15 15 … … 265 265 static const BasicType::Kind kind[2][12] = { 266 266 { BasicType::Float, BasicType::Double, BasicType::LongDouble, BasicType::uuFloat80, BasicType::uuFloat128, BasicType::uFloat16, BasicType::uFloat32, BasicType::uFloat32x, BasicType::uFloat64, BasicType::uFloat64x, BasicType::uFloat128, BasicType::uFloat128x }, 267 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, (BasicType::Kind)-1, (BasicType::Kind)-1, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex },267 { BasicType::FloatComplex, BasicType::DoubleComplex, BasicType::LongDoubleComplex, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::NUMBER_OF_BASIC_TYPES, BasicType::uFloat16Complex, BasicType::uFloat32Complex, BasicType::uFloat32xComplex, BasicType::uFloat64Complex, BasicType::uFloat64xComplex, BasicType::uFloat128Complex, BasicType::uFloat128xComplex }, 268 268 }; 269 269 … … 374 374 375 375 Expression * build_field_name_FLOATING_DECIMALconstant( const string & str ) { 376 if ( str[str.size() -1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str );376 if ( str[str.size() - 1] != '.' ) SemanticError( yylloc, "invalid tuple index " + str ); 377 377 Expression * ret = build_constantInteger( *new string( str.substr( 0, str.size()-1 ) ) ); 378 378 delete &str; … … 434 434 } // build_cast 435 435 436 Expression * build_keyword_cast( KeywordCastExpr::Targettarget, ExpressionNode * expr_node ) {436 Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) { 437 437 return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target ); 438 438 } -
src/Parser/ParseNode.h
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jul 25 22:17:10 201913 // Update Count : 8 7612 // Last Modified On : Fri Feb 7 17:56:02 2020 13 // Update Count : 891 14 14 // 15 15 … … 28 28 #include "Common/UniqueName.h" // for UniqueName 29 29 #include "Common/utility.h" // for maybeClone, maybeBuild 30 #include "Parser/LinkageSpec.h" // for Spec 30 #include "SynTree/LinkageSpec.h" // for Spec 31 #include "SynTree/Declaration.h" // for Aggregate 31 32 #include "SynTree/Expression.h" // for Expression, ConstantExpr (ptr only) 32 33 #include "SynTree/Label.h" // for Label … … 184 185 185 186 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 186 Expression * build_keyword_cast( KeywordCastExpr::Targettarget, ExpressionNode * expr_node );187 Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ); 187 188 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 188 189 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ); … … 217 218 enum Length { Short, Long, LongLong, NoLength }; 218 219 static const char * lengthNames[]; 219 enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate };220 static const char * aggregateNames[];221 enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };222 static const char * typeClassNames[];223 220 enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType }; 224 221 static const char * builtinTypeNames[]; … … 237 234 static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * ); 238 235 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 239 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );236 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 240 237 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body ); 241 238 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 242 239 static DeclarationNode * newName( const std::string * ); 243 240 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params ); 244 static DeclarationNode * newTypeParam( Type Class, const std::string * );241 static DeclarationNode * newTypeParam( TypeDecl::Kind, const std::string * ); 245 242 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 246 243 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); … … 312 309 struct Variable_t { 313 310 // const std::string * name; 314 DeclarationNode::TypeClasstyClass;311 TypeDecl::Kind tyClass; 315 312 DeclarationNode * assertions; 316 313 DeclarationNode * initializer; … … 431 428 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 432 429 Statement * build_directive( std::string * directive ); 430 SuspendStmt * build_suspend( StatementNode *, SuspendStmt::Type = SuspendStmt::None); 433 431 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 434 432 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); … … 452 450 * out++ = result; 453 451 } else { 454 assertf(false, "buildList unknown type");452 SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." ); 455 453 } // if 456 454 } catch( SemanticErrorException & e ) { -
src/Parser/ParserTypes.h
r71d6bd8 r7030dab 10 10 // Created On : Sat Sep 22 08:58:10 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:33:28 201713 // Update Count : 35 012 // Last Modified On : Sat Feb 15 11:04:40 2020 13 // Update Count : 351 14 14 // 15 15 … … 27 27 // current location in the input 28 28 extern int yylineno; 29 extern char * yyfilename;29 extern char * yyfilename; 30 30 31 31 struct Location { 32 char * file;32 char * file; 33 33 int line; 34 34 }; // Location 35 35 36 36 struct Token { 37 std::string * str; // must be pointer as used in union37 std::string * str; // must be pointer as used in union 38 38 Location loc; 39 39 -
src/Parser/StatementNode.cc
r71d6bd8 r7030dab 249 249 } // build_finally 250 250 251 SuspendStmt * build_suspend( StatementNode * then, SuspendStmt::Type type ) { 252 auto node = new SuspendStmt(); 253 254 node->type = type; 255 256 std::list< Statement * > stmts; 257 buildMoveList< Statement, StatementNode >( then, stmts ); 258 if(!stmts.empty()) { 259 assert( stmts.size() == 1 ); 260 node->then = dynamic_cast< CompoundStmt * >( stmts.front() ); 261 } 262 263 return node; 264 } 265 251 266 WaitForStmt * build_waitfor( ExpressionNode * targetExpr, StatementNode * stmt, ExpressionNode * when ) { 252 267 auto node = new WaitForStmt(); -
src/Parser/TypeData.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 15:12:51 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Feb 13 18:16:23201913 // Update Count : 6 4912 // Last Modified On : Mon Dec 16 07:56:46 2019 13 // Update Count : 662 14 14 // 15 15 … … 67 67 case Aggregate: 68 68 // aggregate = new Aggregate_t; 69 aggregate.kind = DeclarationNode::NoAggregate;69 aggregate.kind = AggregateDecl::NoAggregate; 70 70 aggregate.name = nullptr; 71 71 aggregate.params = nullptr; … … 345 345 break; 346 346 case Aggregate: 347 os << DeclarationNode::aggregateNames[ aggregate.kind ]<< ' ' << *aggregate.name << endl;347 os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl; 348 348 if ( aggregate.params ) { 349 349 os << string( indent + 2, ' ' ) << "with type parameters" << endl; … … 489 489 for ( typename ForallList::iterator i = outputList.begin(); i != outputList.end(); ++i, n = (DeclarationNode*)n->get_next() ) { 490 490 TypeDecl * td = static_cast<TypeDecl *>(*i); 491 if ( n->variable.tyClass == DeclarationNode::Otype ) {491 if ( n->variable.tyClass == TypeDecl::Otype ) { 492 492 // add assertion parameters to `type' tyvars in reverse order 493 493 // add dtor: void ^?{}(T *) … … 522 522 switch ( td->kind ) { 523 523 case TypeData::Unknown: 524 525 524 // fill in implicit int 525 return new BasicType( buildQualifiers( td ), BasicType::SignedInt ); 526 526 case TypeData::Basic: 527 527 return buildBasicType( td ); 528 528 case TypeData::Pointer: 529 529 return buildPointer( td ); 530 530 case TypeData::Array: 531 531 return buildArray( td ); 532 532 case TypeData::Reference: 533 533 return buildReference( td ); 534 534 case TypeData::Function: 535 535 return buildFunction( td ); 536 536 case TypeData::AggregateInst: 537 537 return buildAggInst( td ); 538 538 case TypeData::EnumConstant: 539 540 539 // the name gets filled in later -- by SymTab::Validate 540 return new EnumInstType( buildQualifiers( td ), "" ); 541 541 case TypeData::SymbolicInst: 542 542 return buildSymbolicInst( td ); 543 543 case TypeData::Tuple: 544 544 return buildTuple( td ); 545 545 case TypeData::Typeof: 546 546 case TypeData::Basetypeof: 547 547 return buildTypeof( td ); 548 548 case TypeData::Builtin: 549 if (td->builtintype == DeclarationNode::Zero) { 550 return new ZeroType( noQualifiers ); 551 } 552 else if (td->builtintype == DeclarationNode::One) { 553 return new OneType( noQualifiers ); 554 } 555 else { 556 return new VarArgsType( buildQualifiers( td ) ); 557 } 549 switch ( td->builtintype ) { 550 case DeclarationNode::Zero: 551 return new ZeroType( noQualifiers ); 552 case DeclarationNode::One: 553 return new OneType( noQualifiers ); 554 default: 555 return new VarArgsType( buildQualifiers( td ) ); 556 } // switch 558 557 case TypeData::GlobalScope: 559 560 561 558 return new GlobalScopeType(); 559 case TypeData::Qualified: 560 return new QualifiedType( buildQualifiers( td ), typebuild( td->qualified.parent ), typebuild( td->qualified.child ) ); 562 561 case TypeData::Symbolic: 563 562 case TypeData::Enum: 564 563 case TypeData::Aggregate: 565 564 assert( false ); 566 565 } // switch 567 566 … … 768 767 AggregateDecl * at; 769 768 switch ( td->aggregate.kind ) { 770 case DeclarationNode::Struct: 771 case DeclarationNode::Coroutine: 772 case DeclarationNode::Monitor: 773 case DeclarationNode::Thread: 769 case AggregateDecl::Struct: 770 case AggregateDecl::Coroutine: 771 case AggregateDecl::Generator: 772 case AggregateDecl::Monitor: 773 case AggregateDecl::Thread: 774 774 at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage ); 775 775 buildForall( td->aggregate.params, at->get_parameters() ); 776 776 break; 777 case DeclarationNode::Union:777 case AggregateDecl::Union: 778 778 at = new UnionDecl( *td->aggregate.name, attributes, linkage ); 779 779 buildForall( td->aggregate.params, at->get_parameters() ); 780 780 break; 781 case DeclarationNode::Trait:781 case AggregateDecl::Trait: 782 782 at = new TraitDecl( *td->aggregate.name, attributes, linkage ); 783 783 buildList( td->aggregate.params, at->get_parameters() ); … … 809 809 AggregateDecl * typedecl = buildAggregate( type, attributes, linkage ); 810 810 switch ( type->aggregate.kind ) { 811 case DeclarationNode::Struct:812 case DeclarationNode::Coroutine:813 case DeclarationNode::Monitor:814 case DeclarationNode::Thread:811 case AggregateDecl::Struct: 812 case AggregateDecl::Coroutine: 813 case AggregateDecl::Monitor: 814 case AggregateDecl::Thread: 815 815 ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl ); 816 816 break; 817 case DeclarationNode::Union:817 case AggregateDecl::Union: 818 818 ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl ); 819 819 break; 820 case DeclarationNode::Trait:820 case AggregateDecl::Trait: 821 821 assert( false ); 822 822 //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl ); … … 827 827 } else { 828 828 switch ( type->aggregate.kind ) { 829 case DeclarationNode::Struct:830 case DeclarationNode::Coroutine:831 case DeclarationNode::Monitor:832 case DeclarationNode::Thread:829 case AggregateDecl::Struct: 830 case AggregateDecl::Coroutine: 831 case AggregateDecl::Monitor: 832 case AggregateDecl::Thread: 833 833 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 834 834 break; 835 case DeclarationNode::Union:835 case AggregateDecl::Union: 836 836 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 837 837 break; 838 case DeclarationNode::Trait:838 case AggregateDecl::Trait: 839 839 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 840 840 break; … … 863 863 case TypeData::Aggregate: { 864 864 switch ( type->aggregate.kind ) { 865 case DeclarationNode::Struct:866 case DeclarationNode::Coroutine:867 case DeclarationNode::Monitor:868 case DeclarationNode::Thread:865 case AggregateDecl::Struct: 866 case AggregateDecl::Coroutine: 867 case AggregateDecl::Monitor: 868 case AggregateDecl::Thread: 869 869 ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name ); 870 870 break; 871 case DeclarationNode::Union:871 case AggregateDecl::Union: 872 872 ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name ); 873 873 break; 874 case DeclarationNode::Trait:874 case AggregateDecl::Trait: 875 875 ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name ); 876 876 break; -
src/Parser/TypeData.h
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 15:18:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Nov 1 20:56:46 201813 // Update Count : 19 612 // Last Modified On : Fri Dec 13 23:42:35 2019 13 // Update Count : 199 14 14 // 15 15 … … 21 21 22 22 #include "ParseNode.h" // for DeclarationNode, DeclarationNode::Ag... 23 #include " Parser/LinkageSpec.h"// for Spec23 #include "SynTree/LinkageSpec.h" // for Spec 24 24 #include "SynTree/Type.h" // for Type, ReferenceToType (ptr only) 25 25 #include "SynTree/SynTree.h" // for Visitor Nodes … … 30 30 31 31 struct Aggregate_t { 32 DeclarationNode::Aggregate kind;32 AggregateDecl::Aggregate kind; 33 33 const std::string * name = nullptr; 34 34 DeclarationNode * params = nullptr; -
src/Parser/TypedefTable.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 15:20:13 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 25 15:32:35 201813 // Update Count : 25 812 // Last Modified On : Sat Feb 15 08:06:36 2020 13 // Update Count : 259 14 14 // 15 15 … … 47 47 } // TypedefTable::~TypedefTable 48 48 49 bool TypedefTable::exists( const string & identifier ) {49 bool TypedefTable::exists( const string & identifier ) const { 50 50 return kindTable.find( identifier ) != kindTable.end(); 51 51 } // TypedefTable::exists 52 52 53 bool TypedefTable::existsCurr( const string & identifier ) {53 bool TypedefTable::existsCurr( const string & identifier ) const { 54 54 return kindTable.findAt( kindTable.currentScope() - 1, identifier ) != kindTable.end(); 55 55 } // TypedefTable::exists -
src/Parser/TypedefTable.h
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 15:24:36 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 25 15:33:55 201813 // Update Count : 11 412 // Last Modified On : Sat Feb 15 08:06:37 2020 13 // Update Count : 117 14 14 // 15 15 … … 30 30 ~TypedefTable(); 31 31 32 bool exists( const std::string & identifier ) ;33 bool existsCurr( const std::string & identifier ) ;32 bool exists( const std::string & identifier ) const; 33 bool existsCurr( const std::string & identifier ) const; 34 34 int isKind( const std::string & identifier ) const; 35 35 void makeTypedef( const std::string & name, int kind = TYPEDEFname ); -
src/Parser/lex.ll
r71d6bd8 r7030dab 10 10 * Created On : Sat Sep 22 08:58:10 2001 11 11 * Last Modified By : Peter A. Buhr 12 * Last Modified On : S un Aug 4 20:53:47 201913 * Update Count : 7 1912 * Last Modified On : Sat Feb 15 11:05:50 2020 13 * Update Count : 737 14 14 */ 15 15 … … 43 43 #include "TypedefTable.h" 44 44 45 string * build_postfix_name( string * name ); 46 45 47 char *yyfilename; 46 48 string *strtext; // accumulate parts of character and string constant value … … 63 65 #define FLOATXX(v) KEYWORD_RETURN(v); 64 66 #else 65 #define FLOATXX(v) IDENTIFIER_RETURN(); 67 #define FLOATXX(v) IDENTIFIER_RETURN(); 66 68 #endif // HAVE_KEYWORDS_FLOATXX 67 69 … … 299 301 _Static_assert { KEYWORD_RETURN(STATICASSERT); } // C11 300 302 struct { KEYWORD_RETURN(STRUCT); } 301 /* suspend { KEYWORD_RETURN(SUSPEND); } // CFA */ 303 suspend { KEYWORD_RETURN(SUSPEND); } // CFA 302 304 switch { KEYWORD_RETURN(SWITCH); } 303 305 thread { KEYWORD_RETURN(THREAD); } // C11 … … 330 332 /* identifier */ 331 333 {identifier} { IDENTIFIER_RETURN(); } 332 "` "{identifier}"`" {// CFA333 yytext[yyleng - 1] = '\0'; yytext += 1;// SKULLDUGGERY: remove backquotes (ok to shorten?)334 "``"{identifier} { // CFA 335 yytext[yyleng] = '\0'; yytext += 2; // SKULLDUGGERY: remove backquotes (ok to shorten?) 334 336 IDENTIFIER_RETURN(); 335 337 } … … 432 434 "?"({op_unary_pre_post}|"()"|"[?]"|"{}") { IDENTIFIER_RETURN(); } 433 435 "^?{}" { IDENTIFIER_RETURN(); } 434 "?`"{identifier} { IDENTIFIER_RETURN(); } // postfix operator 436 "?`"{identifier} { // postfix operator 437 yylval.tok.str = new string( &yytext[2] ); // remove ?` 438 yylval.tok.str = build_postfix_name( yylval.tok.str ); // add prefix 439 RETURN_LOCN( typedefTable.isKind( *yylval.tok.str ) ); 440 } 435 441 "?"{op_binary_over}"?" { IDENTIFIER_RETURN(); } // binary 436 442 /* -
src/Parser/module.mk
r71d6bd8 r7030dab 11 11 ## Created On : Sat May 16 15:29:09 2015 12 12 ## Last Modified By : Peter A. Buhr 13 ## Last Modified On : Wed Jun 28 21:58:29 201714 ## Update Count : 10 413 ## Last Modified On : Sat Dec 14 07:34:47 2019 14 ## Update Count : 107 15 15 ############################################################################### 16 16 … … 19 19 AM_YFLAGS = -d -t -v 20 20 21 SRC += Parser/parser.yy \ 22 Parser/lex.ll \ 23 Parser/TypedefTable.cc \ 24 Parser/ParseNode.cc \ 21 SRC += \ 25 22 Parser/DeclarationNode.cc \ 26 23 Parser/ExpressionNode.cc \ 24 Parser/InitializerNode.cc \ 25 Parser/ParseNode.cc \ 27 26 Parser/StatementNode.cc \ 28 Parser/InitializerNode.cc \29 27 Parser/TypeData.cc \ 30 Parser/LinkageSpec.cc \ 28 Parser/TypedefTable.cc \ 29 Parser/lex.ll \ 30 Parser/parser.yy \ 31 31 Parser/parserutility.cc 32 32 33 SRCDEMANGLE += \34 Parser/LinkageSpec.cc35 36 37 33 MOSTLYCLEANFILES += Parser/lex.cc Parser/parser.cc Parser/parser.hh Parser/parser.output -
src/Parser/parser.yy
r71d6bd8 r7030dab 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Aug 4 21:48:23 201913 // Update Count : 4 36412 // Last Modified On : Fri Mar 6 17:26:45 2020 13 // Update Count : 4474 14 14 // 15 15 … … 51 51 using namespace std; 52 52 53 #include "SynTree/Declaration.h" 53 54 #include "ParseNode.h" 54 55 #include "TypedefTable.h" 55 56 #include "TypeData.h" 56 #include " LinkageSpec.h"57 #include "SynTree/LinkageSpec.h" 57 58 #include "Common/SemanticError.h" // error_str 58 59 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... … … 165 166 } // rebindForall 166 167 167 NameExpr * build_postfix_name( const string * name ) { 168 NameExpr * new_name = build_varref( new string( "?`" + *name ) ); 169 delete name; 170 return new_name; 168 string * build_postfix_name( string * name ) { 169 *name = string("__postfix_func_") + *name; 170 return name; 171 171 } // build_postfix_name 172 172 … … 210 210 } // if 211 211 } // forCtrl 212 213 212 214 213 bool forall = false, yyy = false; // aggregate have one or more forall qualifiers ? … … 237 236 ExpressionNode * en; 238 237 DeclarationNode * decl; 239 DeclarationNode::Aggregate aggKey;240 DeclarationNode::TypeClasstclass;238 AggregateDecl::Aggregate aggKey; 239 TypeDecl::Kind tclass; 241 240 StatementNode * sn; 242 241 WaitForStmt * wfs; … … 279 278 %token OTYPE FTYPE DTYPE TTYPE TRAIT // CFA 280 279 %token SIZEOF OFFSETOF 281 // %token SUSPEND RESUME // CFA 280 // %token RESUME // CFA 281 %token SUSPEND // CFA 282 282 %token ATTRIBUTE EXTENSION // GCC 283 283 %token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN … … 323 323 %type<op> ptrref_operator unary_operator assignment_operator 324 324 %type<en> primary_expression postfix_expression unary_expression 325 %type<en> cast_expression exponential_expression multiplicative_expression additive_expression325 %type<en> cast_expression_list cast_expression exponential_expression multiplicative_expression additive_expression 326 326 %type<en> shift_expression relational_expression equality_expression 327 327 %type<en> AND_expression exclusive_OR_expression inclusive_OR_expression … … 365 365 %type<decl> abstract_parameter_declaration 366 366 367 %type<aggKey> aggregate_key 367 %type<aggKey> aggregate_key aggregate_data aggregate_control 368 368 %type<decl> aggregate_type aggregate_type_nobody 369 369 … … 579 579 | '(' compound_statement ')' // GCC, lambda expression 580 580 { $$ = new ExpressionNode( new StmtExpr( dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >($2) ) ) ); } 581 | constant '`' IDENTIFIER // CFA, postfix call582 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }583 | string_literal '`' IDENTIFIER // CFA, postfix call584 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( $1 ) ) ); }585 | IDENTIFIER '`' IDENTIFIER // CFA, postfix call586 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), new ExpressionNode( build_varref( $1 ) ) ) ); }587 | tuple '`' IDENTIFIER // CFA, postfix call588 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $3 ) ), $1 ) ); }589 | '(' comma_expression ')' '`' IDENTIFIER // CFA, postfix call590 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_postfix_name( $5 ) ), $2 ) ); }591 581 | type_name '.' identifier // CFA, nested type 592 582 { SemanticError( yylloc, "Qualified name is currently unimplemented." ); $$ = nullptr; } … … 642 632 | postfix_expression '(' argument_expression_list ')' 643 633 { $$ = new ExpressionNode( build_func( $1, $3 ) ); } 634 | postfix_expression '`' identifier // CFA, postfix call 635 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 636 | constant '`' identifier // CFA, postfix call 637 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), $1 ) ); } 638 | string_literal '`' identifier // CFA, postfix call 639 { $$ = new ExpressionNode( build_func( new ExpressionNode( build_varref( build_postfix_name( $3 ) ) ), new ExpressionNode( $1 ) ) ); } 644 640 | postfix_expression '.' identifier 645 641 { $$ = new ExpressionNode( build_fieldSel( $1, build_varref( $3 ) ) ); } … … 650 646 | postfix_expression '.' '[' field_name_list ']' // CFA, tuple field selector 651 647 { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); } 648 | postfix_expression '.' aggregate_control 649 { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); } 652 650 | postfix_expression ARROW identifier 653 651 { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); } … … 664 662 | '(' type_no_function ')' '@' '{' initializer_list_opt comma_opt '}' // CFA, explicit C compound-literal 665 663 { $$ = new ExpressionNode( build_compoundLiteral( $2, (new InitializerNode( $6, true ))->set_maybeConstructed( false ) ) ); } 666 | '^' primary_expression '{' argument_expression_list '}' // CFA 664 | '^' primary_expression '{' argument_expression_list '}' // CFA, destructor call 667 665 { 668 666 Token fn; … … 677 675 | argument_expression 678 676 | argument_expression_list ',' argument_expression 679 { $$ = (ExpressionNode *)( 677 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 680 678 ; 681 679 … … 689 687 field_name_list: // CFA, tuple field selector 690 688 field 691 | field_name_list ',' field { $$ = (ExpressionNode *) $1->set_last( $3); }689 | field_name_list ',' field { $$ = (ExpressionNode *)($1->set_last( $3 )); } 692 690 ; 693 691 … … 793 791 | '(' type_no_function ')' cast_expression 794 792 { $$ = new ExpressionNode( build_cast( $2, $4 ) ); } 795 // keyword cast cannot be grouped because of reduction in aggregate_key 796 | '(' GENERATOR '&' ')' cast_expression // CFA 797 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 798 | '(' COROUTINE '&' ')' cast_expression // CFA 799 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Coroutine, $5 ) ); } 800 | '(' THREAD '&' ')' cast_expression // CFA 801 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Thread, $5 ) ); } 802 | '(' MONITOR '&' ')' cast_expression // CFA 803 { $$ = new ExpressionNode( build_keyword_cast( KeywordCastExpr::Monitor, $5 ) ); } 793 | '(' aggregate_control '&' ')' cast_expression // CFA 794 { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); } 804 795 // VIRTUAL cannot be opt because of look ahead issues 805 796 | '(' VIRTUAL ')' cast_expression // CFA … … 928 919 conditional_expression 929 920 | unary_expression assignment_operator assignment_expression 930 { $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); } 921 { 922 if ( $2 == OperKinds::AtAssn ) { 923 SemanticError( yylloc, "C @= assignment is currently unimplemented." ); $$ = nullptr; 924 } else { 925 $$ = new ExpressionNode( build_binary_val( $2, $1, $3 ) ); 926 } // if 927 } 931 928 | unary_expression '=' '{' initializer_list_opt comma_opt '}' 932 929 { SemanticError( yylloc, "Initializer assignment is currently unimplemented." ); $$ = nullptr; } … … 965 962 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)(new ExpressionNode( nullptr ) )->set_last( $3 ) ) ); } 966 963 | '[' push assignment_expression pop ',' tuple_expression_list ']' 967 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *) $3->set_last( $6 ) )); }964 { $$ = new ExpressionNode( build_tuple( (ExpressionNode *)($3->set_last( $6 ) ) )); } 968 965 ; 969 966 … … 971 968 assignment_expression_opt 972 969 | tuple_expression_list ',' assignment_expression_opt 973 { $$ = (ExpressionNode *) $1->set_last( $3); }970 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 974 971 ; 975 972 … … 1195 1192 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 1193 OperKinds::LThan, $1->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1194 | '=' comma_expression // CFA 1195 { $$ = forCtrl( $2, new string( DeclarationNode::anonymous.newName() ), new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1196 OperKinds::LEThan, $2->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1197 1197 | comma_expression inclexcl comma_expression // CFA 1198 1198 { $$ = forCtrl( $1, new string( DeclarationNode::anonymous.newName() ), $1->clone(), $2, $3, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1202 1202 { $$ = forCtrl( $3, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1203 1203 OperKinds::LThan, $3->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 | comma_expression ';' '=' comma_expression // CFA 1205 { $$ = forCtrl( $4, $1, new ExpressionNode( build_constantInteger( *new string( "0" ) ) ), 1206 OperKinds::LEThan, $4->clone(), new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } 1204 1207 | comma_expression ';' comma_expression inclexcl comma_expression // CFA 1205 1208 { $$ = forCtrl( $3, $1, $3->clone(), $4, $5, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ); } … … 1263 1266 | RETURN '{' initializer_list_opt comma_opt '}' ';' 1264 1267 { SemanticError( yylloc, "Initializer return is currently unimplemented." ); $$ = nullptr; } 1265 // | SUSPEND ';' 1266 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1267 // | SUSPEND compound_statement ';' 1268 // { SemanticError( yylloc, "Suspend expression is currently unimplemented." ); $$ = nullptr; } 1268 | SUSPEND ';' 1269 { $$ = new StatementNode( build_suspend( nullptr ) ); } 1270 | SUSPEND compound_statement 1271 { $$ = new StatementNode( build_suspend( $2 ) ); } 1272 | SUSPEND COROUTINE ';' 1273 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Coroutine ) ); } 1274 | SUSPEND COROUTINE compound_statement 1275 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Coroutine ) ); } 1276 | SUSPEND GENERATOR ';' 1277 { $$ = new StatementNode( build_suspend( nullptr, SuspendStmt::Generator ) ); } 1278 | SUSPEND GENERATOR compound_statement 1279 { $$ = new StatementNode( build_suspend( $3, SuspendStmt::Generator ) ); } 1269 1280 | THROW assignment_expression_opt ';' // handles rethrow 1270 1281 { $$ = new StatementNode( build_throw( $2 ) ); } … … 1306 1317 WAITFOR '(' cast_expression ')' 1307 1318 { $$ = $3; } 1308 | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1309 { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1319 // | WAITFOR '(' cast_expression ',' argument_expression_list ')' 1320 // { $$ = (ExpressionNode *)$3->set_last( $5 ); } 1321 | WAITFOR '(' cast_expression_list ':' argument_expression_list ')' 1322 { $$ = (ExpressionNode *)($3->set_last( $5 )); } 1323 ; 1324 1325 cast_expression_list: 1326 cast_expression 1327 | cast_expression_list ',' cast_expression 1328 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1310 1329 ; 1311 1330 … … 1418 1437 asm_operand 1419 1438 | asm_operands_list ',' asm_operand 1420 { $$ = (ExpressionNode *) $1->set_last( $3); }1439 { $$ = (ExpressionNode *)($1->set_last( $3 )); } 1421 1440 ; 1422 1441 … … 1434 1453 { $$ = new ExpressionNode( $1 ); } 1435 1454 | asm_clobbers_list_opt ',' string_literal 1436 // set_last returns ParseNode * 1437 { $$ = (ExpressionNode *)$1->set_last( new ExpressionNode( $3 ) ); } 1455 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( $3 ) )); } 1438 1456 ; 1439 1457 … … 1586 1604 // type_specifier can resolve to just TYPEDEFname (e.g., typedef int T; int f( T );). Therefore this must be 1587 1605 // flattened to allow lookahead to the '(' without having to reduce identifier_or_type_name. 1588 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1606 cfa_abstract_tuple identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1589 1607 // To obtain LR(1 ), this rule must be factored out from function return type (see cfa_abstract_declarator). 1590 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1591 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' 1592 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 ) ; }1608 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1609 | cfa_function_return identifier_or_type_name '(' push cfa_parameter_ellipsis_list_opt pop ')' attribute_list_opt 1610 { $$ = DeclarationNode::newFunction( $2, $1, $5, 0 )->addQualifiers( $8 ); } 1593 1611 ; 1594 1612 … … 2059 2077 2060 2078 aggregate_key: 2079 aggregate_data 2080 | aggregate_control 2081 ; 2082 2083 aggregate_data: 2061 2084 STRUCT 2062 { yyy = true; $$ = DeclarationNode::Struct; }2085 { yyy = true; $$ = AggregateDecl::Struct; } 2063 2086 | UNION 2064 { yyy = true; $$ = DeclarationNode::Union; } 2065 | EXCEPTION 2066 { yyy = true; $$ = DeclarationNode::Exception; } 2067 | GENERATOR 2068 { yyy = true; $$ = DeclarationNode::Coroutine; } 2087 { yyy = true; $$ = AggregateDecl::Union; } 2088 | EXCEPTION // CFA 2089 { yyy = true; $$ = AggregateDecl::Exception; } 2090 ; 2091 2092 aggregate_control: // CFA 2093 GENERATOR 2094 { yyy = true; $$ = AggregateDecl::Generator; } 2095 | MONITOR GENERATOR 2096 { SemanticError( yylloc, "monitor generator is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2069 2097 | COROUTINE 2070 { yyy = true; $$ = DeclarationNode::Coroutine; }2098 { yyy = true; $$ = AggregateDecl::Coroutine; } 2071 2099 | MONITOR 2072 { yyy = true; $$ = DeclarationNode::Monitor; } 2100 { yyy = true; $$ = AggregateDecl::Monitor; } 2101 | MONITOR COROUTINE 2102 { SemanticError( yylloc, "monitor coroutine is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2073 2103 | THREAD 2074 { yyy = true; $$ = DeclarationNode::Thread; } 2104 { yyy = true; $$ = AggregateDecl::Thread; } 2105 | MONITOR THREAD 2106 { SemanticError( yylloc, "monitor thread is currently unimplemented." ); $$ = AggregateDecl::NoAggregate; } 2075 2107 ; 2076 2108 … … 2096 2128 distInl( $3 ); 2097 2129 } 2130 | INLINE aggregate_control ';' // CFA 2131 { SemanticError( yylloc, "INLINE aggregate control currently unimplemented." ); $$ = nullptr; } 2098 2132 | typedef_declaration ';' // CFA 2099 2133 | cfa_field_declaring_list ';' // CFA, new style field declaration … … 2348 2382 | initializer_list_opt ',' initializer { $$ = (InitializerNode *)( $1->set_last( $3 ) ); } 2349 2383 | initializer_list_opt ',' designation initializer 2350 { $$ = (InitializerNode *)( $1->set_last( $4->set_designators( $3 ) )); }2384 { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); } 2351 2385 ; 2352 2386 … … 2370 2404 designator 2371 2405 | designator_list designator 2372 { $$ = (ExpressionNode *)( $1->set_last( $2 )); }2406 { $$ = (ExpressionNode *)($1->set_last( $2 )); } 2373 2407 //| designator_list designator { $$ = new ExpressionNode( $1, $2 ); } 2374 2408 ; … … 2426 2460 | type_specifier identifier_parameter_declarator 2427 2461 | assertion_list 2428 { $$ = DeclarationNode::newTypeParam( DeclarationNode::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); }2462 { $$ = DeclarationNode::newTypeParam( TypeDecl::Dtype, new string( DeclarationNode::anonymous.newName() ) )->addAssertions( $1 ); } 2429 2463 ; 2430 2464 2431 2465 type_class: // CFA 2432 2466 OTYPE 2433 { $$ = DeclarationNode::Otype; }2467 { $$ = TypeDecl::Otype; } 2434 2468 | DTYPE 2435 { $$ = DeclarationNode::Dtype; }2469 { $$ = TypeDecl::Dtype; } 2436 2470 | FTYPE 2437 { $$ = DeclarationNode::Ftype; }2471 { $$ = TypeDecl::Ftype; } 2438 2472 | TTYPE 2439 { $$ = DeclarationNode::Ttype; }2473 { $$ = TypeDecl::Ttype; } 2440 2474 ; 2441 2475 … … 2467 2501 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $1->build()) ); $$ = nullptr; } 2468 2502 | type_list ',' type 2469 { $$ = (ExpressionNode *)( $1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); }2503 { $$ = (ExpressionNode *)($1->set_last( new ExpressionNode( new TypeExpr( maybeMoveBuildType( $3 ) ) ) )); } 2470 2504 | type_list ',' assignment_expression 2471 2505 { SemanticError( yylloc, toString("Expression generic parameters are currently unimplemented: ", $3->build()) ); $$ = nullptr; } … … 2578 2612 { 2579 2613 linkageStack.push( linkage ); // handle nested extern "C"/"Cforall" 2580 linkage = LinkageSpec:: linkageUpdate( yylloc, linkage, $2 );2614 linkage = LinkageSpec::update( yylloc, linkage, $2 ); 2581 2615 } 2582 2616 '{' up external_definition_list_opt down '}' -
src/ResolvExpr/AdjustExprType.cc
r71d6bd8 r7030dab 10 10 // Created On : Sat May 16 23:41:42 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:34:53 201613 // Update Count : 412 // Last Modified On : Wed Dec 11 21:43:56 2019 13 // Update Count : 6 14 14 // 15 15 … … 134 134 // replace known function-type-variables with pointer-to-function 135 135 if ( const ast::EqvClass * eqvClass = tenv.lookup( inst->name ) ) { 136 if ( eqvClass->data.kind == ast::Type Var::Ftype ) {136 if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) { 137 137 return new ast::PointerType{ inst }; 138 138 } 139 139 } else if ( const ast::NamedTypeDecl * ntDecl = symtab.lookupType( inst->name ) ) { 140 140 if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( ntDecl ) ) { 141 if ( tyDecl->kind == ast::Type Var::Ftype ) {141 if ( tyDecl->kind == ast::TypeDecl::Ftype ) { 142 142 return new ast::PointerType{ inst }; 143 143 } -
src/ResolvExpr/AlternativeFinder.cc
r71d6bd8 r7030dab 69 69 void postvisit( CastExpr * castExpr ); 70 70 void postvisit( VirtualCastExpr * castExpr ); 71 void postvisit( KeywordCastExpr * castExpr ); 71 72 void postvisit( UntypedMemberExpr * memberExpr ); 72 73 void postvisit( MemberExpr * memberExpr ); … … 1255 1256 } 1256 1257 1258 void AlternativeFinder::Finder::postvisit( KeywordCastExpr * castExpr ) { 1259 assertf( castExpr->get_result(), "Cast target should have been set in Validate." ); 1260 auto ref = dynamic_cast<ReferenceType*>(castExpr->get_result()); 1261 assert(ref); 1262 auto inst = dynamic_cast<StructInstType*>(ref->base); 1263 assert(inst); 1264 auto target = inst->baseStruct; 1265 1266 AlternativeFinder finder( indexer, env ); 1267 1268 auto pick_alternatives = [target, this](AltList & found, bool expect_ref) { 1269 for(auto & alt : found) { 1270 Type * expr = alt.expr->get_result(); 1271 if(expect_ref) { 1272 auto res = dynamic_cast<ReferenceType*>(expr); 1273 if(!res) { continue; } 1274 expr = res->base; 1275 } 1276 1277 if(auto insttype = dynamic_cast<TypeInstType*>(expr)) { 1278 auto td = alt.env.lookup(insttype->name); 1279 if(!td) { continue; } 1280 expr = td->type; 1281 } 1282 1283 if(auto base = dynamic_cast<StructInstType*>(expr)) { 1284 if(base->baseStruct == target) { 1285 alternatives.push_back( 1286 std::move(alt) 1287 ); 1288 } 1289 } 1290 } 1291 }; 1292 1293 try { 1294 // Attempt 1 : turn (thread&)X into ($thread&)X.__thrd 1295 // Clone is purely for memory management 1296 std::unique_ptr<Expression> tech1 { new UntypedMemberExpr(new NameExpr(castExpr->concrete_target.field), castExpr->arg->clone()) }; 1297 1298 // don't prune here, since it's guaranteed all alternatives will have the same type 1299 finder.findWithoutPrune( tech1.get() ); 1300 pick_alternatives(finder.alternatives, false); 1301 1302 return; 1303 } catch(SemanticErrorException & ) {} 1304 1305 // Fallback : turn (thread&)X into ($thread&)get_thread(X) 1306 std::unique_ptr<Expression> fallback { UntypedExpr::createDeref( new UntypedExpr(new NameExpr(castExpr->concrete_target.getter), { castExpr->arg->clone() })) }; 1307 // don't prune here, since it's guaranteed all alternatives will have the same type 1308 finder.findWithoutPrune( fallback.get() ); 1309 1310 pick_alternatives(finder.alternatives, true); 1311 1312 // Whatever happens here, we have no more fallbacks 1313 } 1314 1257 1315 namespace { 1258 1316 /// Gets name from untyped member expression (member must be NameExpr) -
src/ResolvExpr/PtrsCastable.cc
r71d6bd8 r7030dab 10 10 // Created On : Sun May 17 11:48:00 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 2 17:36:18 201613 // Update Count : 812 // Last Modified On : Wed Dec 11 21:48:33 2019 13 // Update Count : 9 14 14 // 15 15 … … 176 176 if ( const ast::NamedTypeDecl * named = symtab.lookupType( inst->name ) ) { 177 177 if ( auto tyDecl = dynamic_cast< const ast::TypeDecl * >( named ) ) { 178 if ( tyDecl->kind == ast::Type Var::Ftype ) {178 if ( tyDecl->kind == ast::TypeDecl::Ftype ) { 179 179 return -1; 180 180 } 181 181 } 182 182 } else if ( const ast::EqvClass * eqvClass = env.lookup( inst->name ) ) { 183 if ( eqvClass->data.kind == ast::Type Var::Ftype ) {183 if ( eqvClass->data.kind == ast::TypeDecl::Ftype ) { 184 184 return -1; 185 185 } -
src/ResolvExpr/Resolver.cc
r71d6bd8 r7030dab 9 9 // Author : Aaron B. Moss 10 10 // Created On : Sun May 17 12:17:01 2015 11 // Last Modified By : A aron B. Moss12 // Last Modified On : Wed May 29 11:00:00 201913 // Update Count : 24 111 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Mar 27 11:58:00 2020 13 // Update Count : 242 14 14 // 15 15 … … 84 84 void previsit( ThrowStmt * throwStmt ); 85 85 void previsit( CatchStmt * catchStmt ); 86 void postvisit( CatchStmt * catchStmt ); 86 87 void previsit( WaitForStmt * stmt ); 87 88 … … 559 560 // TODO: Replace *exception type with &exception type. 560 561 if ( throwStmt->get_expr() ) { 561 const StructDecl * exception_decl = indexer.lookupStruct( "__cfa abi_ehm__base_exception_t" );562 const StructDecl * exception_decl = indexer.lookupStruct( "__cfaehm_base_exception_t" ); 562 563 assert( exception_decl ); 563 564 Type * exceptType = new PointerType( noQualifiers, new StructInstType( noQualifiers, const_cast<StructDecl *>(exception_decl) ) ); … … 567 568 568 569 void Resolver_old::previsit( CatchStmt * catchStmt ) { 570 // Until we are very sure this invarent (ifs that move between passes have thenPart) 571 // holds, check it. This allows a check for when to decode the mangling. 572 if ( IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ) ) { 573 assert( ifStmt->thenPart ); 574 } 575 // Encode the catchStmt so the condition can see the declaration. 569 576 if ( catchStmt->cond ) { 570 findSingleExpression( catchStmt->cond, new BasicType( noQualifiers, BasicType::Bool ), indexer ); 577 IfStmt * ifStmt = new IfStmt( catchStmt->cond, nullptr, catchStmt->body ); 578 catchStmt->cond = nullptr; 579 catchStmt->body = ifStmt; 580 } 581 } 582 583 void Resolver_old::postvisit( CatchStmt * catchStmt ) { 584 // Decode the catchStmt so everything is stored properly. 585 IfStmt * ifStmt = dynamic_cast<IfStmt *>( catchStmt->body ); 586 if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) { 587 assert( ifStmt->condition ); 588 assert( ifStmt->elsePart ); 589 catchStmt->cond = ifStmt->condition; 590 catchStmt->body = ifStmt->elsePart; 591 ifStmt->condition = nullptr; 592 ifStmt->elsePart = nullptr; 593 delete ifStmt; 571 594 } 572 595 } … … 1454 1477 if ( throwStmt->expr ) { 1455 1478 const ast::StructDecl * exceptionDecl = 1456 symtab.lookupStruct( "__cfa abi_ehm__base_exception_t" );1479 symtab.lookupStruct( "__cfaehm_base_exception_t" ); 1457 1480 assert( exceptionDecl ); 1458 1481 ast::ptr< ast::Type > exceptType = … … 1466 1489 1467 1490 const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) { 1491 // TODO: This will need a fix for the decl/cond scoping problem. 1468 1492 if ( catchStmt->cond ) { 1469 1493 ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool }; -
src/ResolvExpr/Unify.cc
r71d6bd8 r7030dab 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Sep 4 10:00:00201913 // Update Count : 4 411 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:43:05 2019 13 // Update Count : 46 14 14 // 15 15 … … 34 34 #include "Common/PassVisitor.h" // for PassVisitor 35 35 #include "FindOpenVars.h" // for findOpenVars 36 #include " Parser/LinkageSpec.h"// for C36 #include "SynTree/LinkageSpec.h" // for C 37 37 #include "SynTree/Constant.h" // for Constant 38 38 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Data, Declarati... … … 771 771 if ( const ast::EqvClass * clz = tenv.lookup( typeInst->name ) ) { 772 772 // expand ttype parameter into its actual type 773 if ( clz->data.kind == ast::Type Var::Ttype && clz->bound ) {773 if ( clz->data.kind == ast::TypeDecl::Ttype && clz->bound ) { 774 774 return clz->bound; 775 775 } -
src/SymTab/Autogen.h
r71d6bd8 r7030dab 10 10 // Created On : Sun May 17 21:53:34 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Jul 22 09:50:25 201713 // Update Count : 1 512 // Last Modified On : Fri Dec 13 16:38:06 2019 13 // Update Count : 16 14 14 // 15 15 … … 35 35 #include "SynTree/Expression.h" // for NameExpr, ConstantExpr, UntypedExpr... 36 36 #include "SynTree/Type.h" // for Type, ArrayType, Type::Qualifiers 37 #include "SynTree/Statement.h" // for CompoundStmt, DeclStmt, ExprStmt 37 38 38 39 class CompoundStmt; -
src/SymTab/Demangle.cc
r71d6bd8 r7030dab 10 10 // Created On : Thu Jul 19 12:52:41 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 30 13:46:33 201913 // Update Count : 312 // Last Modified On : Tue Feb 11 15:09:18 2020 13 // Update Count : 10 14 14 // 15 15 … … 19 19 #include "CodeGen/GenType.h" 20 20 #include "Common/PassVisitor.h" 21 #include "Common/utility.h" // isPrefix 21 22 #include "Mangler.h" 22 23 #include "SynTree/Type.h" … … 366 367 // type variable types 367 368 for (size_t k = 0; k < TypeDecl::NUMBER_OF_KINDS; ++k) { 368 static const std::string typeVariableNames[] = { "DT", " FT", "TT", };369 static const std::string typeVariableNames[] = { "DT", "OT", "FT", "TT", }; 369 370 static_assert( 370 371 sizeof(typeVariableNames)/sizeof(typeVariableNames[0]) == TypeDecl::NUMBER_OF_KINDS, … … 416 417 417 418 bool StringView::isPrefix(const std::string & pref) { 418 if ( pref.size() > str.size()-idx ) return false; 419 auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) ); 420 if (its.first == pref.end()) { 419 // if ( pref.size() > str.size()-idx ) return false; 420 // auto its = std::mismatch( pref.begin(), pref.end(), std::next(str.begin(), idx) ); 421 // if (its.first == pref.end()) { 422 // idx += pref.size(); 423 // return true; 424 // } 425 426 // This update is untested because there are no tests for this code. 427 if ( ::isPrefix( str, pref, idx ) ) { 421 428 idx += pref.size(); 422 429 return true; … … 429 436 PRINT( std::cerr << "====== " << str.size() << " " << str << std::endl; ) 430 437 if (str.size() < 2+Encoding::manglePrefix.size()) return false; // +2 for at least _1 suffix 431 if ( ! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back())) return false;438 if ( ! isPrefix(Encoding::manglePrefix) || ! isdigit(str.back() ) ) return false; 432 439 433 440 // get name -
src/SymTab/Indexer.cc
r71d6bd8 r7030dab 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:37:33 2015 11 // Last Modified By : Aaron B. Moss12 // Last Modified On : Fri Mar 8 13:55:00201913 // Update Count : 2 111 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:43:19 2019 13 // Update Count : 22 14 14 // 15 15 … … 31 31 #include "InitTweak/InitTweak.h" // for isConstructor, isCopyFunction, isC... 32 32 #include "Mangler.h" // for Mangler 33 #include "Parser/LinkageSpec.h" // for isMangled, isOverridable, Spec34 33 #include "ResolvExpr/typeops.h" // for typesCompatible 34 #include "SynTree/LinkageSpec.h" // for isMangled, isOverridable, Spec 35 35 #include "SynTree/Constant.h" // for Constant 36 36 #include "SynTree/Declaration.h" // for DeclarationWithType, FunctionDecl -
src/SymTab/Mangler.cc
r71d6bd8 r7030dab 10 10 // Created On : Sun May 17 21:40:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 30 13:46:10 201913 // Update Count : 2612 // Last Modified On : Sat Feb 15 13:55:12 2020 13 // Update Count : 33 14 14 // 15 15 #include "Mangler.h" … … 26 26 #include "Common/SemanticError.h" // for SemanticError 27 27 #include "Common/utility.h" // for toString 28 #include "Parser/LinkageSpec.h" // for Spec, isOverridable, AutoGen, Int...29 28 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 29 #include "SynTree/LinkageSpec.h" // for Spec, isOverridable, AutoGen, Int... 30 30 #include "SynTree/Declaration.h" // for TypeDecl, DeclarationWithType 31 31 #include "SynTree/Expression.h" // for TypeExpr, Expression, operator<< … … 128 128 } // if 129 129 mangleName << Encoding::manglePrefix; 130 CodeGen::OperatorInfo opInfo;131 if ( op eratorLookup( declaration->get_name(), opInfo )) {132 mangleName << opInfo .outputName.size() << opInfo.outputName;130 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( declaration->get_name() ); 131 if ( opInfo ) { 132 mangleName << opInfo->outputName.size() << opInfo->outputName; 133 133 } else { 134 134 mangleName << declaration->name.size() << declaration->name; … … 471 471 } // if 472 472 mangleName << Encoding::manglePrefix; 473 CodeGen::OperatorInfo opInfo;474 if ( op eratorLookup( decl->name, opInfo )) {475 mangleName << opInfo .outputName.size() << opInfo.outputName;473 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( decl->name ); 474 if ( opInfo ) { 475 mangleName << opInfo->outputName.size() << opInfo->outputName; 476 476 } else { 477 477 mangleName << decl->name.size() << decl->name; … … 654 654 // aside from the assert false. 655 655 assertf(false, "Mangler_new should not visit typedecl: %s", toCString(decl)); 656 assertf( decl->kind < ast::Type Var::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind );656 assertf( decl->kind < ast::TypeDecl::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 657 657 mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) << decl->name; 658 658 } … … 674 674 for ( const ast::TypeDecl * decl : ptype->forall ) { 675 675 switch ( decl->kind ) { 676 case ast::Type Var::Kind::Dtype:676 case ast::TypeDecl::Kind::Dtype: 677 677 dcount++; 678 678 break; 679 case ast::Type Var::Kind::Ftype:679 case ast::TypeDecl::Kind::Ftype: 680 680 fcount++; 681 681 break; 682 case ast::Type Var::Kind::Ttype:682 case ast::TypeDecl::Kind::Ttype: 683 683 vcount++; 684 684 break; -
src/SymTab/ManglerCommon.cc
r71d6bd8 r7030dab 10 10 // Created On : Sun May 17 21:44:03 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Feb 14 17:06:37201913 // Update Count : 2 612 // Last Modified On : Fri Dec 13 14:54:38 2019 13 // Update Count : 28 14 14 // 15 15 … … 104 104 const std::string typeVariables[] = { 105 105 "BD", // dtype 106 "BO", // otype 106 107 "BF", // ftype 107 108 "BT", // ttype -
src/SymTab/Validate.cc
r71d6bd8 r7030dab 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:50:04 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Wed Aug 7 6:42:00201913 // Update Count : 36 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:43:34 2019 13 // Update Count : 363 14 14 // 15 15 … … 69 69 #include "InitTweak/GenInit.h" // for fixReturnStatements 70 70 #include "InitTweak/InitTweak.h" // for isCtorDtorAssign 71 #include "Parser/LinkageSpec.h" // for C72 71 #include "ResolvExpr/typeops.h" // for typesCompatible 73 72 #include "ResolvExpr/Resolver.h" // for findSingleExpression 74 73 #include "ResolvExpr/ResolveTypeof.h" // for resolveTypeof 75 74 #include "SymTab/Autogen.h" // for SizeType 75 #include "SynTree/LinkageSpec.h" // for C 76 76 #include "SynTree/Attribute.h" // for noAttributes, Attribute 77 77 #include "SynTree/Constant.h" // for Constant … … 311 311 Stats::Heap::newPass("validate-A"); 312 312 Stats::Time::BlockGuard guard("validate-A"); 313 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors 313 314 acceptAll( translationUnit, hoistDecls ); 314 315 ReplaceTypedef::replaceTypedef( translationUnit ); … … 336 337 Stats::Time::BlockGuard guard("validate-C"); 337 338 acceptAll( translationUnit, genericParams ); // check as early as possible - can't happen before LinkReferenceToTypes_old 338 VerifyCtorDtorAssign::verify( translationUnit ); // must happen before autogen, because autogen examines existing ctor/dtors339 339 ReturnChecker::checkFunctionReturns( translationUnit ); 340 340 InitTweak::fixReturnStatements( translationUnit ); // must happen before autogen … … 375 375 Stats::Heap::newPass("validate-F"); 376 376 Stats::Time::BlockGuard guard("validate-F"); 377 Stats::Time::TimeBlock("Fix Object Type", [&]() { 378 FixObjectType::fix( translationUnit ); 379 }); 380 Stats::Time::TimeBlock("Array Length", [&]() { 381 ArrayLength::computeLength( translationUnit ); 382 }); 383 Stats::Time::TimeBlock("Find Special Declarations", [&]() { 384 Validate::findSpecialDecls( translationUnit ); 385 }); 386 Stats::Time::TimeBlock("Fix Label Address", [&]() { 387 mutateAll( translationUnit, labelAddrFixer ); 388 }); 389 Stats::Time::TimeBlock("Handle Attributes", [&]() { 390 Validate::handleAttributes( translationUnit ); 391 }); 377 Stats::Time::TimeCall("Fix Object Type", 378 FixObjectType::fix, translationUnit); 379 Stats::Time::TimeCall("Array Length", 380 ArrayLength::computeLength, translationUnit); 381 Stats::Time::TimeCall("Find Special Declarations", 382 Validate::findSpecialDecls, translationUnit); 383 Stats::Time::TimeCall("Fix Label Address", 384 mutateAll<LabelAddressFixer>, translationUnit, labelAddrFixer); 385 Stats::Time::TimeCall("Handle Attributes", 386 Validate::handleAttributes, translationUnit); 392 387 } 393 388 } … … 1049 1044 Type * designatorType = tyDecl->base->stripDeclarator(); 1050 1045 if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) { 1051 declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );1046 declsToAddBefore.push_back( new StructDecl( aggDecl->name, AggregateDecl::Struct, noAttributes, tyDecl->linkage ) ); 1052 1047 } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) { 1053 1048 declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) ); … … 1187 1182 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 1188 1183 if ( params.size() == 0 ) { 1189 SemanticError( funcDecl , "Constructors, destructors, and assignment functions require at least one parameter" );1184 SemanticError( funcDecl->location, "Constructors, destructors, and assignment functions require at least one parameter." ); 1190 1185 } 1191 1186 ReferenceType * refType = dynamic_cast< ReferenceType * >( params.front()->get_type() ); 1192 1187 if ( ! refType ) { 1193 SemanticError( funcDecl , "First parameter of a constructor, destructor, or assignment function must be a reference" );1188 SemanticError( funcDecl->location, "First parameter of a constructor, destructor, or assignment function must be a reference." ); 1194 1189 } 1195 1190 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 1196 SemanticError( funcDecl, "Constructors and destructors cannot have explicit return values " ); 1191 if(!returnVals.front()->get_type()->isVoid()) { 1192 SemanticError( funcDecl->location, "Constructors and destructors cannot have explicit return values." ); 1193 } 1197 1194 } 1198 1195 } -
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) -
src/Tuples/TupleAssignment.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 : Fri Mar 17 09:43:03 201713 // Update Count : 812 // Last Modified On : Fri Dec 13 23:45:33 2019 13 // Update Count : 9 14 14 // 15 15 … … 34 34 #include "InitTweak/GenInit.h" // for genCtorInit 35 35 #include "InitTweak/InitTweak.h" // for getPointerBase, isAssignment 36 #include "Parser/LinkageSpec.h" // for Cforall37 36 #include "ResolvExpr/Alternative.h" // for AltList, Alternative 38 37 #include "ResolvExpr/AlternativeFinder.h" // for AlternativeFinder, simpleC... … … 41 40 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 42 41 #include "ResolvExpr/typeops.h" // for combos 42 #include "SynTree/LinkageSpec.h" // for Cforall 43 43 #include "SynTree/Declaration.h" // for ObjectDecl 44 44 #include "SynTree/Expression.h" // for Expression, CastExpr, Name... -
src/Tuples/TupleExpansion.cc
r71d6bd8 r7030dab 9 9 // Author : Rodolfo G. Esteves 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Andrew Beach12 // Last Modified On : Fri Oct 4 15:38:00201913 // Update Count : 2 311 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 13 23:45:51 2019 13 // Update Count : 24 14 14 // 15 15 … … 27 27 #include "Common/utility.h" // for CodeLocation 28 28 #include "InitTweak/InitTweak.h" // for getFunction 29 #include " Parser/LinkageSpec.h"// for Spec, C, Intrinsic29 #include "SynTree/LinkageSpec.h" // for Spec, C, Intrinsic 30 30 #include "SynTree/Constant.h" // for Constant 31 31 #include "SynTree/Declaration.h" // for StructDecl, DeclarationWithType … … 361 361 const ast::TypeInstType * isTtype( const ast::Type * type ) { 362 362 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) { 363 if ( inst->base && inst->base->kind == ast::Type Var::Ttype ) {363 if ( inst->base && inst->base->kind == ast::TypeDecl::Ttype ) { 364 364 return inst; 365 365 } -
src/cfa.make
r71d6bd8 r7030dab 1 2 3 1 CFACOMPILE = $(CFACC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(CFAFLAGS) $(AM_CFLAGS) $(CFLAGS) 4 2 LTCFACOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ 5 3 $(LIBTOOLFLAGS) --mode=compile $(CFACC) $(DEFS) \ 6 $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(CFAFLAGS) \ 7 $(AM_CFLAGS) $(CFLAGS) 4 $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CFAFLAGS) $(AM_CFLAGS) $(CFAFLAGS) $(CFLAGS) 8 5 9 6 AM_V_CFA = $(am__v_CFA_@AM_V@) … … 22 19 $(am__mv) $$depbase.Tpo $$depbase.Plo 23 20 24 AM_V_JAVAC = $(am__v_JAVAC_@AM_V@)25 am__v_JAVAC_ = $(am__v_JAVAC_@AM_DEFAULT_V@)26 am__v_JAVAC_0 = @echo " JAVAC " $@;27 am__v_JAVAC_1 =28 29 AM_V_GOC = $(am__v_GOC_@AM_V@)30 am__v_GOC_ = $(am__v_GOC_@AM_DEFAULT_V@)31 am__v_GOC_0 = @echo " GOC " $@;32 am__v_GOC_1 =33 34 21 UPPCC = u++ 35 22 UPPCOMPILE = $(UPPCC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_UPPFLAGS) $(UPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_CFLAGS) $(CFLAGS) … … 39 26 am__v_UPP_0 = @echo " UPP " $@; 40 27 am__v_UPP_1 = 28 29 AM_V_GOC = $(am__v_GOC_@AM_V@) 30 am__v_GOC_ = $(am__v_GOC_@AM_DEFAULT_V@) 31 am__v_GOC_0 = @echo " GOC " $@; 32 am__v_GOC_1 = 33 34 AM_V_PY = $(am__v_PY_@AM_V@) 35 am__v_PY_ = $(am__v_PY_@AM_DEFAULT_V@) 36 am__v_PY_0 = @echo " PYTHON " $@; 37 am__v_PY_1 = 38 39 AM_V_RUST = $(am__v_RUST_@AM_V@) 40 am__v_RUST_ = $(am__v_RUST_@AM_DEFAULT_V@) 41 am__v_RUST_0 = @echo " RUST " $@; 42 am__v_RUST_1 = 43 44 AM_V_NODEJS = $(am__v_NODEJS_@AM_V@) 45 am__v_NODEJS_ = $(am__v_NODEJS_@AM_DEFAULT_V@) 46 am__v_NODEJS_0 = @echo " NODEJS " $@; 47 am__v_NODEJS_1 = 48 49 AM_V_JAVAC = $(am__v_JAVAC_@AM_V@) 50 am__v_JAVAC_ = $(am__v_JAVAC_@AM_DEFAULT_V@) 51 am__v_JAVAC_0 = @echo " JAVAC " $@; 52 am__v_JAVAC_1 = -
src/main.cc
r71d6bd8 r7030dab 10 10 // Created On : Fri May 15 23:12:02 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Aug 23 06:50:08 201913 // Update Count : 6 0712 // Last Modified On : Sat Feb 8 08:33:50 2020 13 // Update Count : 633 14 14 // 15 15 … … 20 20 #include <cstdio> // for fopen, FILE, fclose, stdin 21 21 #include <cstdlib> // for exit, free, abort, EXIT_F... 22 #include <csignal> // for signal, SIGABRT, SIGSEGV22 #include <csignal> // for signal, SIGABRT, SIGSEGV 23 23 #include <cstring> // for index 24 24 #include <fstream> // for ofstream … … 28 28 #include <list> // for list 29 29 #include <string> // for char_traits, operator<< 30 31 using namespace std; 30 32 31 33 #include "AST/Convert.hpp" … … 54 56 #include "InitTweak/GenInit.h" // for genInit 55 57 #include "MakeLibCfa.h" // for makeLibCfa 56 #include "Parser/LinkageSpec.h" // for Spec, Cforall, Intrinsic57 58 #include "Parser/ParseNode.h" // for DeclarationNode, buildList 58 59 #include "Parser/TypedefTable.h" // for TypedefTable … … 60 61 #include "ResolvExpr/Resolver.h" // for resolve 61 62 #include "SymTab/Validate.h" // for validate 63 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic 62 64 #include "SynTree/Declaration.h" // for Declaration 63 65 #include "SynTree/Visitor.h" // for acceptAll … … 65 67 #include "Virtual/ExpandCasts.h" // for expandCasts 66 68 67 68 using namespace std;69 69 70 70 static void NewPass( const char * const name ) { … … 98 98 static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start 99 99 100 static st d::string PreludeDirector = "";100 static string PreludeDirector = ""; 101 101 102 102 static void parse_cmdline( int argc, char *argv[] ); … … 105 105 106 106 static void backtrace( int start ) { // skip first N stack frames 107 enum { Frames = 50 };107 enum { Frames = 50, }; // maximum number of stack frames 108 108 void * array[Frames]; 109 int size = ::backtrace( array, Frames );109 size_t size = ::backtrace( array, Frames ); 110 110 char ** messages = ::backtrace_symbols( array, size ); // does not demangle names 111 111 … … 114 114 115 115 // skip last 2 stack frames after main 116 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {116 for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) { 117 117 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; 118 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset 118 119 for ( char * p = messages[i]; *p; p += 1 ) { // find parantheses and +offset 119 120 if ( *p == '(' ) { 120 121 mangled_name = p; … … 154 155 } // backtrace 155 156 156 static void sigSegvBusHandler( int sig_num ) { 157 cerr << "*CFA runtime error* program cfa-cpp terminated with " 158 << (sig_num == SIGSEGV ? "segment fault" : "bus error") 159 << "." << endl; 157 #define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused )) 158 159 static void Signal( int sig, void (*handler)(SIGPARMS), int flags ) { 160 struct sigaction act; 161 162 act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; 163 act.sa_flags = flags; 164 165 if ( sigaction( sig, &act, nullptr ) == -1 ) { 166 cerr << "*CFA runtime error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl; 167 _exit( EXIT_FAILURE ); 168 } // if 169 } // Signal 170 171 static void sigSegvBusHandler( SIGPARMS ) { 172 if ( sfp->si_addr == nullptr ) { 173 cerr << "Null pointer (nullptr) dereference." << endl; 174 } else { 175 cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl 176 << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl; 177 } // if 160 178 backtrace( 2 ); // skip first 2 stack frames 161 //_exit( EXIT_FAILURE );162 179 abort(); // cause core dump for debugging 163 180 } // sigSegvBusHandler 164 181 165 static void sigAbortHandler( __attribute__((unused)) int sig_num ) { 182 static void sigFpeHandler( SIGPARMS ) { 183 const char * msg; 184 185 switch ( sfp->si_code ) { 186 case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break; 187 case FPE_FLTOVF: msg = "overflow"; break; 188 case FPE_FLTUND: msg = "underflow"; break; 189 case FPE_FLTRES: msg = "inexact result"; break; 190 case FPE_FLTINV: msg = "invalid operation"; break; 191 default: msg = "unknown"; 192 } // choose 193 cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl 194 << "Possible cause is constant-expression evaluation invalid." << endl; 195 backtrace( 2 ); // skip first 2 stack frames 196 abort(); // cause core dump for debugging 197 } // sigFpeHandler 198 199 static void sigAbortHandler( SIGPARMS ) { 166 200 backtrace( 6 ); // skip first 6 stack frames 167 signal( SIGABRT, SIG_DFL);// reset default signal handler201 Signal( SIGABRT, (void (*)(SIGPARMS))SIG_DFL, SA_SIGINFO ); // reset default signal handler 168 202 raise( SIGABRT ); // reraise SIGABRT 169 203 } // sigAbortHandler … … 174 208 list< Declaration * > translationUnit; 175 209 176 signal( SIGSEGV, sigSegvBusHandler ); 177 signal( SIGBUS, sigSegvBusHandler ); 178 signal( SIGABRT, sigAbortHandler ); 179 180 // std::cout << "main" << std::endl; 210 Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); 211 Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO ); 212 Signal( SIGFPE, sigFpeHandler, SA_SIGINFO ); 213 Signal( SIGABRT, sigAbortHandler, SA_SIGINFO ); 214 215 // cout << "main" << endl; 181 216 // for ( int i = 0; i < argc; i += 1 ) { 182 // std::cout << '\t' << argv[i] << std::endl;217 // cout << '\t' << argv[i] << endl; 183 218 // } // for 184 219 … … 187 222 188 223 if ( waiting_for_gdb ) { 189 std::cerr << "Waiting for gdb" << std::endl;190 std::cerr << "run :" << std::endl;191 std::cerr << " gdb attach " << getpid() << std::endl;224 cerr << "Waiting for gdb" << endl; 225 cerr << "run :" << endl; 226 cerr << " gdb attach " << getpid() << endl; 192 227 raise(SIGSTOP); 193 228 } // if … … 395 430 return EXIT_FAILURE; 396 431 } catch ( ... ) { 397 std::exception_ptr eptr = std::current_exception();432 exception_ptr eptr = current_exception(); 398 433 try { 399 434 if (eptr) { 400 std::rethrow_exception(eptr);435 rethrow_exception(eptr); 401 436 } else { 402 std::cerr << "Exception Uncaught and Unknown" << std::endl;403 } // if 404 } catch(const std::exception& e) {405 std::cerr << "Uncaught Exception \"" << e.what() << "\"\n";437 cerr << "Exception Uncaught and Unknown" << endl; 438 } // if 439 } catch(const exception& e) { 440 cerr << "Uncaught Exception \"" << e.what() << "\"\n"; 406 441 } // try 407 442 return EXIT_FAILURE; … … 414 449 415 450 416 static const char optstring[] = ": hlLmNnpP:S:tgwW:D:";451 static const char optstring[] = ":c:ghlLmNnpP:S:twW:D:"; 417 452 418 453 enum { PreludeDir = 128 }; 419 454 static struct option long_opts[] = { 455 { "colors", required_argument, nullptr, 'c' }, 456 { "gdb", no_argument, nullptr, 'g' }, 420 457 { "help", no_argument, nullptr, 'h' }, 421 458 { "libcfa", no_argument, nullptr, 'l' }, … … 429 466 { "statistics", required_argument, nullptr, 'S' }, 430 467 { "tree", no_argument, nullptr, 't' }, 431 { "gdb", no_argument, nullptr, 'g' },432 468 { "", no_argument, nullptr, 0 }, // -w 433 469 { "", no_argument, nullptr, 0 }, // -W … … 437 473 438 474 static const char * description[] = { 439 "print help message", // -h 440 "generate libcfa.c", // -l 441 "generate line marks", // -L 442 "do not replace main", // -m 443 "do not generate line marks", // -N 444 "do not read prelude", // -n 475 "diagnostic color: never, always, or auto.", // -c 476 "wait for gdb to attach", // -g 477 "print help message", // -h 478 "generate libcfa.c", // -l 479 "generate line marks", // -L 480 "do not replace main", // -m 481 "do not generate line marks", // -N 482 "do not read prelude", // -n 445 483 "generate prototypes for prelude functions", // -p 446 "print", 484 "print", // -P 447 485 "<directory> prelude directory for debug/nodebug", // no flag 448 486 "<option-list> enable profiling information:\n counters,heap,time,all,none", // -S 449 "building cfa standard lib", // -t 450 "wait for gdb to attach", // -g 451 "", // -w 452 "", // -W 453 "", // -D 487 "building cfa standard lib", // -t 488 "", // -w 489 "", // -W 490 "", // -D 454 491 }; // description 455 492 … … 519 556 while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) { 520 557 switch ( c ) { 558 case 'c': // diagnostic colors 559 if ( strcmp( optarg, "always" ) == 0 ) { 560 ErrorHelpers::colors = ErrorHelpers::Colors::Always; 561 } else if ( strcmp( optarg, "never" ) == 0 ) { 562 ErrorHelpers::colors = ErrorHelpers::Colors::Never; 563 } else if ( strcmp( optarg, "auto" ) == 0 ) { 564 ErrorHelpers::colors = ErrorHelpers::Colors::Auto; 565 } // if 566 break; 521 567 case 'h': // help message 522 568 usage( argv ); // no return
Note:
See TracChangeset
for help on using the changeset viewer.