- Timestamp:
- Jun 2, 2022, 3:11:21 PM (3 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- ced5e2a
- Parents:
- 015925a (diff), fc134a48 (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:
-
- 7 added
- 1 deleted
- 41 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Expr.cpp
r015925a re5d9274 10 10 // Created On : Wed May 15 17:00:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Created On : Tue Nov 30 14:23:00 202113 // Update Count : 712 // Created On : Wed May 18 13:56:00 2022 13 // Update Count : 8 14 14 // 15 15 … … 21 21 22 22 #include "Copy.hpp" // for shallowCopy 23 #include "Eval.hpp" // for call24 23 #include "GenericSubstitution.hpp" 25 24 #include "LinkageSpec.hpp" … … 67 66 // --- UntypedExpr 68 67 68 bool UntypedExpr::get_lvalue() const { 69 std::string fname = InitTweak::getFunctionName( this ); 70 return lvalueFunctionNames.count( fname ); 71 } 72 69 73 UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, const Expr * arg ) { 70 74 assert( arg ); 71 75 72 UntypedExpr * ret = c all( loc, "*?", arg);76 UntypedExpr * ret = createCall( loc, "*?", { arg } ); 73 77 if ( const Type * ty = arg->result ) { 74 78 const Type * base = InitTweak::getPointerBase( ty ); … … 87 91 } 88 92 89 bool UntypedExpr::get_lvalue() const {90 std::string fname = InitTweak::getFunctionName( this );91 return lvalueFunctionNames.count( fname );92 }93 94 93 UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) { 95 94 assert( lhs && rhs ); 96 95 97 UntypedExpr * ret = c all( loc, "?=?", lhs, rhs);96 UntypedExpr * ret = createCall( loc, "?=?", { lhs, rhs } ); 98 97 if ( lhs->result && rhs->result ) { 99 98 // if both expressions are typed, assumes that this assignment is a C bitwise assignment, … … 102 101 } 103 102 return ret; 103 } 104 105 UntypedExpr * UntypedExpr::createCall( const CodeLocation & loc, 106 const std::string & name, std::vector<ptr<Expr>> && args ) { 107 return new UntypedExpr( loc, 108 new NameExpr( loc, name ), std::move( args ) ); 104 109 } 105 110 -
src/AST/Expr.hpp
r015925a re5d9274 230 230 /// Creates a new assignment expression 231 231 static UntypedExpr * createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ); 232 /// Creates a new call of a variable. 233 static UntypedExpr * createCall( const CodeLocation & loc, 234 const std::string & name, std::vector<ptr<Expr>> && args ); 232 235 233 236 const Expr * accept( Visitor & v ) const override { return v.visit( this ); } -
src/AST/module.mk
r015925a re5d9274 29 29 AST/DeclReplacer.cpp \ 30 30 AST/DeclReplacer.hpp \ 31 AST/Eval.hpp \32 31 AST/Expr.cpp \ 33 32 AST/Expr.hpp \ -
src/CodeGen/CodeGenerator.cc
r015925a re5d9274 1238 1238 } // namespace CodeGen 1239 1239 1240 1241 unsigned Indenter::tabsize = 2;1242 1243 std::ostream & operator<<( std::ostream & out, const BaseSyntaxNode * node ) {1244 if ( node ) {1245 node->print( out );1246 } else {1247 out << "nullptr";1248 }1249 return out;1250 }1251 1252 1240 // Local Variables: // 1253 1241 // tab-width: 4 // -
src/CodeGen/FixMain.cc
r015925a re5d9274 49 49 50 50 } 51 52 bool FixMain::replace_main = false;53 51 54 52 template<typename container> -
src/CodeGen/GenType.cc
r015925a re5d9274 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 1 15:24:00 201913 // Update Count : 2 312 // Last Modified On : Fri May 20 11:18:00 2022 13 // Update Count : 24 14 14 // 15 15 #include "GenType.h" … … 50 50 void postvisit( TraitInstType * inst ); 51 51 void postvisit( TypeofType * typeof ); 52 void postvisit( VTableType * vtable ); 52 53 void postvisit( QualifiedType * qualType ); 53 54 … … 259 260 if ( options.genC ) { 260 261 typeString = "enum " + typeString; 261 } 262 } 262 } 263 } 263 264 handleQualifiers( enumInst ); 264 265 } 265 266 266 267 void GenType::postvisit( TypeInstType * typeInst ) { 268 assertf( ! options.genC, "Type instance types should not reach code generation." ); 267 269 typeString = typeInst->name + " " + typeString; 268 270 handleQualifiers( typeInst ); … … 320 322 } 321 323 324 void GenType::postvisit( VTableType * vtable ) { 325 assertf( ! options.genC, "Virtual table types should not reach code generation." ); 326 std::ostringstream os; 327 os << "vtable(" << genType( vtable->base, "", options ) << ") " << typeString; 328 typeString = os.str(); 329 handleQualifiers( vtable ); 330 } 331 322 332 void GenType::postvisit( QualifiedType * qualType ) { 323 333 assertf( ! options.genC, "Qualified types should not reach code generation." ); -
src/CodeGen/LinkOnce.cc
r015925a re5d9274 53 53 new ConstantExpr( Constant::from_string( section_name ) ) 54 54 ); 55 56 // Unconditionnaly add "visibility(default)" to anything with gnu.linkonce 57 // visibility is a mess otherwise 58 attributes.push_back(new Attribute("visibility", {new ConstantExpr( Constant::from_string( "default" ) )})); 59 55 60 } 56 61 visit_children = false; -
src/CodeGen/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Peter A. Buhr13 ## Last Modified On : Sat Dec 14 07:29:42 201914 ## Update Count : 412 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:26:00 2022 14 ## Update Count : 5 15 15 ############################################################################### 16 16 17 #SRC += ArgTweak/Rewriter.cc \ 18 # ArgTweak/Mutate.cc 17 SRC_CODEGEN = \ 18 CodeGen/FixMain2.cc \ 19 CodeGen/FixMain.h \ 20 CodeGen/OperatorTable.cc \ 21 CodeGen/OperatorTable.h 19 22 20 SRC _CODEGEN =\23 SRC += $(SRC_CODEGEN) \ 21 24 CodeGen/CodeGenerator.cc \ 22 25 CodeGen/CodeGenerator.h \ 26 CodeGen/Generate.cc \ 27 CodeGen/Generate.h \ 23 28 CodeGen/FixMain.cc \ 24 CodeGen/FixMain.h \ 29 CodeGen/FixNames.cc \ 30 CodeGen/FixNames.h \ 25 31 CodeGen/GenType.cc \ 26 32 CodeGen/GenType.h \ 27 33 CodeGen/LinkOnce.cc \ 28 34 CodeGen/LinkOnce.h \ 29 CodeGen/OperatorTable.cc \30 CodeGen/OperatorTable.h \31 35 CodeGen/Options.h 32 36 33 SRC += $(SRC_CODEGEN) CodeGen/Generate.cc CodeGen/Generate.h CodeGen/FixNames.cc CodeGen/FixNames.h34 37 SRCDEMANGLE += $(SRC_CODEGEN) -
src/CodeTools/ResolvProtoDump.cc
r015925a re5d9274 304 304 305 305 // replace enums with int 306 void previsit( EnumInstType* ) { ss << (int)BasicType::SignedInt; } 306 void previsit( EnumInstType* ) { 307 // TODO: add the meaningful representation of typed int 308 ss << (int)BasicType::SignedInt; 309 } 307 310 308 311 void previsit( TypeInstType* vt ) { -
src/Common/Indenter.h
r015925a re5d9274 10 10 // Created On : Fri Jun 30 16:55:23 2017 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Aug 11 11:15:00 201713 // Update Count : 112 // Last Modified On : Fri May 13 14:10:00 2022 13 // Update Count : 2 14 14 // 15 15 16 #ifndef INDENTER_H 17 #define INDENTER_H 16 #pragma once 17 18 #include <ostream> 18 19 19 20 struct Indenter { … … 37 38 return out << std::string(indent.indent * indent.amt, ' '); 38 39 } 39 40 #endif // INDENTER_H -
src/Common/ResolvProtoDump.cpp
r015925a re5d9274 227 227 } 228 228 229 void previsit( const ast::EnumInstType * ) { 229 void previsit( const ast::EnumInstType * enumInst) { 230 // TODO: Add the meaningful text representation of typed enum 230 231 ss << (int)ast::BasicType::SignedInt; 231 232 } -
src/Common/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Peter A. Buhr13 ## Last Modified On : Tue Sep 27 11:06:38 201614 ## Update Count : 412 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:27:00 2022 14 ## Update Count : 5 15 15 ############################################################################### 16 16 17 17 SRC_COMMON = \ 18 Common/Assert.cc \ 19 Common/CodeLocation.h \ 20 Common/CodeLocationTools.hpp \ 21 Common/CodeLocationTools.cpp \ 22 Common/CompilerError.h \ 23 Common/Debug.h \ 24 Common/DeclStats.hpp \ 25 Common/DeclStats.cpp \ 26 Common/ErrorObjects.h \ 27 Common/Eval.cc \ 28 Common/Examine.cc \ 29 Common/Examine.h \ 30 Common/FilterCombos.h \ 31 Common/Indenter.h \ 32 Common/PassVisitor.cc \ 33 Common/PassVisitor.h \ 34 Common/PassVisitor.impl.h \ 35 Common/PassVisitor.proto.h \ 36 Common/PersistentMap.h \ 37 Common/ResolvProtoDump.hpp \ 38 Common/ResolvProtoDump.cpp \ 39 Common/ScopedMap.h \ 40 Common/SemanticError.cc \ 41 Common/SemanticError.h \ 42 Common/Stats.h \ 43 Common/Stats/Base.h \ 44 Common/Stats/Counter.cc \ 45 Common/Stats/Counter.h \ 46 Common/Stats/Heap.cc \ 47 Common/Stats/Heap.h \ 48 Common/Stats/ResolveTime.cc \ 49 Common/Stats/ResolveTime.h \ 50 Common/Stats/Stats.cc \ 51 Common/Stats/Time.cc \ 52 Common/Stats/Time.h \ 53 Common/UnimplementedError.h \ 54 Common/UniqueName.cc \ 55 Common/UniqueName.h \ 56 Common/utility.h \ 57 Common/VectorMap.h 18 Common/Assert.cc \ 19 Common/CodeLocation.h \ 20 Common/CodeLocationTools.hpp \ 21 Common/CodeLocationTools.cpp \ 22 Common/CompilerError.h \ 23 Common/Debug.h \ 24 Common/DeclStats.hpp \ 25 Common/DeclStats.cpp \ 26 Common/ErrorObjects.h \ 27 Common/Eval.cc \ 28 Common/Examine.cc \ 29 Common/Examine.h \ 30 Common/FilterCombos.h \ 31 Common/Indenter.h \ 32 Common/Indenter.cc \ 33 Common/PassVisitor.cc \ 34 Common/PassVisitor.h \ 35 Common/PassVisitor.impl.h \ 36 Common/PassVisitor.proto.h \ 37 Common/PersistentMap.h \ 38 Common/ResolvProtoDump.hpp \ 39 Common/ResolvProtoDump.cpp \ 40 Common/ScopedMap.h \ 41 Common/SemanticError.cc \ 42 Common/SemanticError.h \ 43 Common/Stats.h \ 44 Common/Stats/Base.h \ 45 Common/Stats/Counter.cc \ 46 Common/Stats/Counter.h \ 47 Common/Stats/Heap.cc \ 48 Common/Stats/Heap.h \ 49 Common/Stats/ResolveTime.cc \ 50 Common/Stats/ResolveTime.h \ 51 Common/Stats/Stats.cc \ 52 Common/Stats/Time.cc \ 53 Common/Stats/Time.h \ 54 Common/UnimplementedError.h \ 55 Common/UniqueName.cc \ 56 Common/UniqueName.h \ 57 Common/utility.h \ 58 Common/VectorMap.h 58 59 59 SRC += $(SRC_COMMON) Common/DebugMalloc.cc 60 SRC += $(SRC_COMMON) \ 61 Common/DebugMalloc.cc 62 60 63 SRCDEMANGLE += $(SRC_COMMON) -
src/Concurrency/module.mk
r015925a re5d9274 10 10 ## Author : Thierry Delisle 11 11 ## Created On : Mon Mar 13 12:48:40 2017 12 ## Last Modified By : 13 ## Last Modified On : 14 ## Update Count : 012 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 13:28:00 2022 14 ## Update Count : 1 15 15 ############################################################################### 16 16 17 SRC _CONCURRENCY= \17 SRC += \ 18 18 Concurrency/KeywordsNew.cpp \ 19 Concurrency/Keywords.cc 20 21 SRC += $(SRC_CONCURRENCY) \ 19 Concurrency/Keywords.cc \ 22 20 Concurrency/Keywords.h \ 23 21 Concurrency/Waitfor.cc \ 24 22 Concurrency/Waitfor.h 25 26 SRCDEMANGLE += $(SRC_CONCURRENCY)27 -
src/ControlStruct/ExceptDecl.cc
r015925a re5d9274 9 9 // Author : Henry Xue 10 10 // Created On : Tue Jul 20 04:10:50 2021 11 // Last Modified By : Henry Xue12 // Last Modified On : Tue Aug 03 10:42:26 202113 // Update Count : 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Wed May 25 16:43:00 2022 13 // Update Count : 5 14 14 // 15 15 … … 39 39 } 40 40 41 TypeInstType * makeExceptInstType(42 const std::string & exceptionName, 43 const std::list< Expression *> & parameters 44 ) { 45 TypeInstType * exceptInstType = new TypeInstType(41 StructInstType * makeExceptInstType( 42 const std::string & exceptionName, 43 const std::list< Expression *> & parameters 44 ) { 45 StructInstType * exceptInstType = new StructInstType( 46 46 noQualifiers, 47 exceptionName, 48 false 47 exceptionName 49 48 ); 50 49 cloneAll( parameters, exceptInstType->parameters ); … … 151 150 nullptr, 152 151 new PointerType( noQualifiers, 153 new TypeInstType( Type::Const, "__cfavir_type_info", false) ),152 new StructInstType( Type::Const, "__cfavir_type_info" ) ), 154 153 nullptr 155 154 ) ); … … 257 256 const std::string & exceptionName, 258 257 const std::list< TypeDecl *> & forallClause, 259 const std::list< Expression *> & parameters, 258 const std::list< Expression *> & parameters, 260 259 const std::list< Declaration *> & members 261 260 ) { … … 302 301 ObjectDecl * ehmExternVtable( 303 302 const std::string & exceptionName, 304 const std::list< Expression *> & parameters, 303 const std::list< Expression *> & parameters, 305 304 const std::string & tableName 306 305 ) { … … 457 456 } 458 457 458 class VTableCore : public WithDeclsToAdd { 459 public: 460 // Remove any remaining vtable type nodes in the tree. 461 Type * postmutate( VTableType * vtableType ); 462 }; 463 464 Type * VTableCore::postmutate( VTableType * vtableType ) { 465 auto inst = strict_dynamic_cast<ReferenceToType *>( vtableType->base ); 466 467 std::string vtableName = Virtual::vtableTypeName( inst->name ); 468 StructInstType * newType = new StructInstType( noQualifiers, vtableName ); 469 cloneAll( inst->parameters, newType->parameters ); 470 471 delete vtableType; 472 return newType; 473 } 474 459 475 void translateExcept( std::list< Declaration *> & translationUnit ) { 460 476 PassVisitor<ExceptDeclCore> translator; 461 477 mutateAll( translationUnit, translator ); 462 } 463 464 } 478 PassVisitor<VTableCore> typeTranslator; 479 mutateAll( translationUnit, typeTranslator ); 480 } 481 482 } -
src/ControlStruct/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Peter A. Buhr13 ## Last Modified On : Sat Jan 29 12:04:19202214 ## Update Count : 712 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:30:00 2022 14 ## Update Count : 8 15 15 ############################################################################### 16 16 17 SRC _CONTROLSTRUCT= \17 SRC += \ 18 18 ControlStruct/ExceptDecl.cc \ 19 19 ControlStruct/ExceptDecl.h \ 20 ControlStruct/ExceptTranslateNew.cpp \ 21 ControlStruct/ExceptTranslate.cc \ 22 ControlStruct/ExceptTranslate.h \ 20 23 ControlStruct/FixLabels.cpp \ 21 24 ControlStruct/FixLabels.hpp \ … … 37 40 ControlStruct/Mutate.h 38 41 39 SRC += $(SRC_CONTROLSTRUCT) \40 ControlStruct/ExceptTranslateNew.cpp \41 ControlStruct/ExceptTranslate.cc \42 ControlStruct/ExceptTranslate.h43 44 SRCDEMANGLE += $(SRC_CONTROLSTRUCT)45 -
src/GenPoly/Lvalue.cc
r015925a re5d9274 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 : Fri Dec 13 23:14:38 201913 // Update Count : 711 // Last Modified By : Andrew Beach 12 // Last Modified On : Mon May 16 14:09:00 2022 13 // Update Count : 8 14 14 // 15 15 … … 125 125 } // namespace 126 126 127 static bool referencesEliminated = false; 128 // used by UntypedExpr::createDeref to determine whether result type of dereference should be ReferenceType or value type. 129 bool referencesPermissable() { 130 return ! referencesEliminated; 131 } 127 // Stored elsewhere (Lvalue2, initially false). 128 extern bool referencesEliminated; 132 129 133 130 void convertLvalue( std::list< Declaration* > & translationUnit ) { -
src/GenPoly/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Peter A. Buhr13 ## Last Modified On : Mon Jun 1 17:52:30 201514 ## Update Count : 112 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:31:00 2022 14 ## Update Count : 2 15 15 ############################################################################### 16 16 17 SRC += GenPoly/Box.cc \ 18 GenPoly/Box.h \ 19 GenPoly/ErasableScopedMap.h \ 20 GenPoly/FindFunction.cc \ 21 GenPoly/FindFunction.h \ 22 GenPoly/GenPoly.cc \ 23 GenPoly/GenPoly.h \ 24 GenPoly/InstantiateGeneric.cc \ 25 GenPoly/InstantiateGeneric.h \ 26 GenPoly/Lvalue.cc \ 27 GenPoly/Lvalue.h \ 28 GenPoly/ScopedSet.h \ 29 GenPoly/ScrubTyVars.cc \ 30 GenPoly/ScrubTyVars.h \ 31 GenPoly/Specialize.cc \ 32 GenPoly/Specialize.h 17 SRC_GENPOLY = \ 18 GenPoly/GenPoly.cc \ 19 GenPoly/GenPoly.h \ 20 GenPoly/Lvalue2.cc \ 21 GenPoly/Lvalue.h 33 22 34 SRCDEMANGLE += GenPoly/GenPoly.cc GenPoly/GenPoly.h GenPoly/Lvalue.cc GenPoly/Lvalue.h 23 SRC += $(SRC_GENPOLY) \ 24 GenPoly/Box.cc \ 25 GenPoly/Box.h \ 26 GenPoly/ErasableScopedMap.h \ 27 GenPoly/FindFunction.cc \ 28 GenPoly/FindFunction.h \ 29 GenPoly/InstantiateGeneric.cc \ 30 GenPoly/InstantiateGeneric.h \ 31 GenPoly/Lvalue.cc \ 32 GenPoly/ScopedSet.h \ 33 GenPoly/ScrubTyVars.cc \ 34 GenPoly/ScrubTyVars.h \ 35 GenPoly/Specialize.cc \ 36 GenPoly/Specialize.h 35 37 38 SRCDEMANGLE += $(SRC_GENPOLY) -
src/InitTweak/FixInitNew.cpp
r015925a re5d9274 454 454 455 455 auto expr = new ast::ImplicitCopyCtorExpr( appExpr->location, mutExpr ); 456 // Move the type substitution to the new top-level, if it is attached to the appExpr. 457 // Ensure it is not deleted with the ImplicitCopyCtorExpr by removing it before deletion. 458 // The substitution is needed to obtain the type of temporary variables so that copy constructor 459 // calls can be resolved. 456 // Move the type substitution to the new top-level. The substitution 457 // is needed to obtain the type of temporary variables so that copy 458 // constructor calls can be resolved. 460 459 assert( typeSubs ); 461 // assert (mutExpr->env);462 460 expr->env = tmp; 463 // mutExpr->env = nullptr;464 //std::swap( expr->env, appExpr->env );465 461 return expr; 466 462 } 467 463 468 464 void ResolveCopyCtors::previsit(const ast::Expr * expr) { 469 if (expr->env) { 470 GuardValue(env); 471 GuardValue(envModified); 472 env = expr->env->clone(); 473 envModified = false; 474 } 465 if ( nullptr == expr->env ) { 466 return; 467 } 468 GuardValue( env ) = expr->env->clone(); 469 GuardValue( envModified ) = false; 475 470 } 476 471 477 472 const ast::Expr * ResolveCopyCtors::postvisit(const ast::Expr * expr) { 478 if (expr->env) { 479 if (envModified) { 480 auto mutExpr = mutate(expr); 481 mutExpr->env = env; 482 return mutExpr; 483 } 484 else { 485 // env was not mutated, skip and delete the shallow copy 486 delete env; 487 return expr; 488 } 489 } 490 else { 473 // No local environment, skip. 474 if ( nullptr == expr->env ) { 475 return expr; 476 // Environment was modified, mutate and replace. 477 } else if ( envModified ) { 478 auto mutExpr = mutate(expr); 479 mutExpr->env = env; 480 return mutExpr; 481 // Environment was not mutated, delete the shallow copy before guard. 482 } else { 483 delete env; 491 484 return expr; 492 485 } … … 497 490 const ast::Expr * ResolveCopyCtors::makeCtorDtor( const std::string & fname, const ast::ObjectDecl * var, const ast::Expr * cpArg ) { 498 491 assert( var ); 499 assert (var->isManaged());500 assert (!cpArg || cpArg->isManaged());492 assert( var->isManaged() ); 493 assert( !cpArg || cpArg->isManaged() ); 501 494 // arrays are not copy constructed, so this should always be an ExprStmt 502 495 ast::ptr< ast::Stmt > stmt = genCtorDtor(var->location, fname, var, cpArg ); … … 504 497 auto exprStmt = stmt.strict_as<ast::ImplicitCtorDtorStmt>()->callStmt.strict_as<ast::ExprStmt>(); 505 498 ast::ptr<ast::Expr> untyped = exprStmt->expr; // take ownership of expr 506 // exprStmt->expr = nullptr;507 499 508 500 // resolve copy constructor … … 516 508 env->add( *resolved->env ); 517 509 envModified = true; 518 // delete resolved->env;519 510 auto mut = mutate(resolved.get()); 520 511 assertf(mut == resolved.get(), "newly resolved expression must be unique"); 521 512 mut->env = nullptr; 522 513 } // if 523 // delete stmt;524 514 if ( auto assign = resolved.as<ast::TupleAssignExpr>() ) { 525 515 // fix newly generated StmtExpr -
src/InitTweak/GenInit.cc
r015925a re5d9274 368 368 369 369 struct ReturnFixer_New final : 370 public ast::WithStmtsToAdd<>, ast::WithGuards {370 public ast::WithStmtsToAdd<>, ast::WithGuards, ast::WithShortCircuiting { 371 371 void previsit( const ast::FunctionDecl * decl ); 372 372 const ast::ReturnStmt * previsit( const ast::ReturnStmt * stmt ); … … 376 376 377 377 void ReturnFixer_New::previsit( const ast::FunctionDecl * decl ) { 378 if (decl->linkage == ast::Linkage::Intrinsic) visit_children = false; 378 379 GuardValue( funcDecl ) = decl; 379 380 } -
src/InitTweak/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Rob Schluntz13 ## Last Modified On : Fri May 13 11:36:24 201614 ## Update Count : 312 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:31:00 2022 14 ## Update Count : 4 15 15 ############################################################################### 16 16 17 SRC += \ 18 InitTweak/FixGlobalInit.cc \ 19 InitTweak/FixGlobalInit.h \ 20 InitTweak/FixInit.cc \ 21 InitTweak/FixInit.h \ 22 InitTweak/GenInit.cc \ 23 InitTweak/GenInit.h \ 24 InitTweak/InitTweak.cc \ 25 InitTweak/InitTweak.h \ 26 InitTweak/FixInitNew.cpp 27 28 SRCDEMANGLE += \ 17 SRC_INITTWEAK = \ 29 18 InitTweak/GenInit.cc \ 30 19 InitTweak/GenInit.h \ … … 32 21 InitTweak/InitTweak.h 33 22 23 SRC += $(SRC_INITTWEAK) \ 24 InitTweak/FixGlobalInit.cc \ 25 InitTweak/FixGlobalInit.h \ 26 InitTweak/FixInit.cc \ 27 InitTweak/FixInit.h \ 28 InitTweak/FixInitNew.cpp 29 30 SRCDEMANGLE += $(SRC_INITTWEAK) -
src/Parser/parser.yy
r015925a re5d9274 10 10 // Created On : Sat Sep 1 20:22:55 2001 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 4 17:22:48202213 // Update Count : 5 27912 // Last Modified On : Sat May 14 09:16:22 2022 13 // Update Count : 5401 14 14 // 15 15 … … 54 54 #include "Common/SemanticError.h" // error_str 55 55 #include "Common/utility.h" // for maybeMoveBuild, maybeBuild, CodeLo... 56 57 #include "SynTree/Attribute.h" // for Attribute 56 58 57 59 extern DeclarationNode * parseTree; … … 93 95 } // appendStr 94 96 95 DeclarationNode * distAttr( DeclarationNode * specifier, DeclarationNode * declList ) { 96 // distribute declaration_specifier across all declared variables, e.g., static, const, __attribute__. 97 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( specifier ); 97 DeclarationNode * distAttr( DeclarationNode * typeSpec, DeclarationNode * declList ) { 98 // distribute declaration_specifier across all declared variables, e.g., static, const, but not __attribute__. 99 assert( declList ); 100 // printf( "distAttr1 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout ); 101 DeclarationNode * cur = declList, * cl = (new DeclarationNode)->addType( typeSpec ); 102 // printf( "distAttr2 cl %p\n", cl ); cl->type->print( std::cout ); 103 // cl->type->aggregate.name = cl->type->aggInst.aggregate->aggregate.name; 104 98 105 for ( cur = dynamic_cast<DeclarationNode *>( cur->get_next() ); cur != nullptr; cur = dynamic_cast<DeclarationNode *>( cur->get_next() ) ) { 99 106 cl->cloneBaseType( cur ); 100 107 } // for 101 108 declList->addType( cl ); 109 // printf( "distAttr3 declList %p\n", declList ); declList->print( std::cout, 0 ); 102 110 return declList; 103 111 } // distAttr … … 171 179 if ( ! ( typeSpec->type && (typeSpec->type->kind == TypeData::Aggregate || typeSpec->type->kind == TypeData::Enum) ) ) { 172 180 stringstream ss; 173 typeSpec->type->print( ss);181 // printf( "fieldDecl1 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout ); 174 182 SemanticWarning( yylloc, Warning::SuperfluousDecl, ss.str().c_str() ); 175 183 return nullptr; 176 184 } // if 185 // printf( "fieldDecl2 typeSpec %p\n", typeSpec ); typeSpec->type->print( std::cout ); 177 186 fieldList = DeclarationNode::newName( nullptr ); 178 187 } // if 179 return distAttr( typeSpec, fieldList ); // mark all fields in list 188 // return distAttr( typeSpec, fieldList ); // mark all fields in list 189 190 // printf( "fieldDecl3 typeSpec %p\n", typeSpec ); typeSpec->print( std::cout, 0 ); 191 DeclarationNode * temp = distAttr( typeSpec, fieldList ); // mark all fields in list 192 // printf( "fieldDecl4 temp %p\n", temp ); temp->print( std::cout, 0 ); 193 return temp; 180 194 } // fieldDecl 181 195 … … 1620 1634 declaration: // old & new style declarations 1621 1635 c_declaration ';' 1636 { 1637 // printf( "C_DECLARATION1 %p %s\n", $$, $$->name ? $$->name->c_str() : "(nil)" ); 1638 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 1639 // printf( "\tattr %s\n", attr->name.c_str() ); 1640 // } // for 1641 } 1622 1642 | cfa_declaration ';' // CFA 1623 1643 | static_assert // C11 … … 1825 1845 basic_type_specifier 1826 1846 | sue_type_specifier 1847 { 1848 // printf( "sue_type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 1849 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 1850 // printf( "\tattr %s\n", attr->name.c_str() ); 1851 // } // for 1852 } 1827 1853 | type_type_specifier 1828 1854 ; … … 2041 2067 sue_declaration_specifier: // struct, union, enum + storage class + type specifier 2042 2068 sue_type_specifier 2069 { 2070 // printf( "sue_declaration_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2071 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2072 // printf( "\tattr %s\n", attr->name.c_str() ); 2073 // } // for 2074 } 2043 2075 | declaration_qualifier_list sue_type_specifier 2044 2076 { $$ = $2->addQualifiers( $1 ); } … … 2051 2083 sue_type_specifier: // struct, union, enum + type specifier 2052 2084 elaborated_type 2085 { 2086 // printf( "sue_type_specifier %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2087 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2088 // printf( "\tattr %s\n", attr->name.c_str() ); 2089 // } // for 2090 } 2053 2091 | type_qualifier_list 2054 2092 { if ( $1->type != nullptr && $1->type->forall ) forall = true; } // remember generic type … … 2123 2161 elaborated_type: // struct, union, enum 2124 2162 aggregate_type 2163 { 2164 // printf( "elaborated_type %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2165 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2166 // printf( "\tattr %s\n", attr->name.c_str() ); 2167 // } // for 2168 } 2125 2169 | enum_type 2126 2170 ; … … 2142 2186 } 2143 2187 '{' field_declaration_list_opt '}' type_parameters_opt 2144 { $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); } 2188 { 2189 // printf( "aggregate_type1 %s\n", $3.str->c_str() ); 2190 // if ( $2 ) 2191 // for ( Attribute * attr: reverseIterate( $2->attributes ) ) { 2192 // printf( "copySpecifiers12 %s\n", attr->name.c_str() ); 2193 // } // for 2194 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); 2195 // printf( "aggregate_type2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2196 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2197 // printf( "aggregate_type3 %s\n", attr->name.c_str() ); 2198 // } // for 2199 } 2145 2200 | aggregate_key attribute_list_opt TYPEDEFname // unqualified type name 2146 2201 { … … 2150 2205 '{' field_declaration_list_opt '}' type_parameters_opt 2151 2206 { 2207 // printf( "AGG3\n" ); 2152 2208 DeclarationNode::newFromTypedef( $3 ); 2153 2209 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2160 2216 '{' field_declaration_list_opt '}' type_parameters_opt 2161 2217 { 2218 // printf( "AGG4\n" ); 2162 2219 DeclarationNode::newFromTypeGen( $3, nullptr ); 2163 2220 $$ = DeclarationNode::newAggregate( $1, $3, $8, $6, true )->addQualifiers( $2 ); … … 2236 2293 field_declaration: 2237 2294 type_specifier field_declaring_list_opt ';' 2238 { $$ = fieldDecl( $1, $2 ); } 2295 { 2296 // printf( "type_specifier1 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2297 $$ = fieldDecl( $1, $2 ); 2298 // printf( "type_specifier2 %p %s\n", $$, $$->type->aggregate.name ? $$->type->aggregate.name->c_str() : "(nil)" ); 2299 // for ( Attribute * attr: reverseIterate( $$->attributes ) ) { 2300 // printf( "\tattr %s\n", attr->name.c_str() ); 2301 // } // for 2302 } 2239 2303 | EXTENSION type_specifier field_declaring_list_opt ';' // GCC 2240 2304 { $$ = fieldDecl( $2, $3 ); distExt( $$ ); } … … 2845 2909 // empty 2846 2910 { $$ = nullptr; forall = false; } 2847 | WITH '(' tuple_expression_list ')' 2848 { $$ = $3; forall = false; } 2911 | WITH '(' tuple_expression_list ')' attribute_list_opt 2912 { 2913 $$ = $3; forall = false; 2914 if ( $5 ) { 2915 SemanticError( yylloc, "Attributes cannot be associated with function body. Move attribute(s) before \"with\" clause." ); 2916 $$ = nullptr; 2917 } // if 2918 } 2849 2919 ; 2850 2920 -
src/ResolvExpr/AlternativeFinder.cc
r015925a re5d9274 42 42 #include "SymTab/Indexer.h" // for Indexer 43 43 #include "SymTab/Mangler.h" // for Mangler 44 #include "SymTab/Validate .h"// for validateType44 #include "SymTab/ValidateType.h" // for validateType 45 45 #include "SynTree/Constant.h" // for Constant 46 46 #include "SynTree/Declaration.h" // for DeclarationWithType, TypeDecl, Dec... -
src/ResolvExpr/CandidateFinder.cpp
r015925a re5d9274 899 899 900 900 if (argType.as<ast::PointerType>()) funcFinder.otypeKeys.insert(Mangle::Encoding::pointer); 901 else if (const ast::EnumInstType * enumInst = argType.as<ast::EnumInstType>()) { 902 const ast::EnumDecl * enumDecl = enumInst->base; 903 if ( const ast::Type* enumType = enumDecl->base ) { 904 // instance of enum (T) is a instance of type (T) 905 funcFinder.otypeKeys.insert(Mangle::mangle(enumType, Mangle::NoGenericParams | Mangle::Type)); 906 } else { 907 // instance of an untyped enum is techically int 908 funcFinder.otypeKeys.insert(Mangle::mangle(enumDecl, Mangle::NoGenericParams | Mangle::Type)); 909 } 910 } 901 911 else funcFinder.otypeKeys.insert(Mangle::mangle(argType, Mangle::NoGenericParams | Mangle::Type)); 902 912 } … … 918 928 919 929 // find function operators 920 ast::ptr< ast::Expr > opExpr = new ast::NameExpr{ untypedExpr->location, "?()" }; 930 ast::ptr< ast::Expr > opExpr = new ast::NameExpr{ untypedExpr->location, "?()" }; // ??? why not ?{} 921 931 CandidateFinder opFinder( context, tenv ); 922 932 // okay if there aren't any function operations -
src/ResolvExpr/CommonType.cc
r015925a re5d9274 497 497 result = new BasicType( basicType->tq | otherBasic->tq, newType ); 498 498 } // if 499 } else if ( dynamic_cast< EnumInstType * > ( type2 ) ||dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) {499 } else if ( dynamic_cast< ZeroType * >( type2 ) || dynamic_cast< OneType * >( type2 ) ) { 500 500 // use signed int in lieu of the enum/zero/one type 501 501 BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ]; … … 503 503 result = new BasicType( basicType->tq | type2->tq, newType ); 504 504 } // if 505 } // if 505 } else if ( const EnumInstType * enumInst = dynamic_cast< const EnumInstType * > ( type2 ) ) { 506 const EnumDecl* enumDecl = enumInst->baseEnum; 507 if ( const Type* baseType = enumDecl->base ) { 508 result = baseType->clone(); 509 } else { 510 BasicType::Kind newType = commonTypes[ basicType->get_kind() ][ BasicType::SignedInt ]; 511 if ( ( ( newType == basicType->get_kind() && basicType->tq >= type2->tq ) || widenFirst ) && ( ( newType != basicType->get_kind() && basicType->tq <= type2->tq ) || widenSecond ) ) { 512 result = new BasicType( basicType->tq | type2->tq, newType ); 513 } // if 514 } 515 } 506 516 } 507 517 … … 691 701 } 692 702 } else if ( 693 dynamic_cast< const ast::EnumInstType * >( type2 ) 694 || dynamic_cast< const ast::ZeroType * >( type2 ) 703 dynamic_cast< const ast::ZeroType * >( type2 ) 695 704 || dynamic_cast< const ast::OneType * >( type2 ) 696 705 ) { … … 705 714 result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers }; 706 715 } 716 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 717 #warning remove casts when `commonTypes` moved to new AST 718 const ast::EnumDecl* enumDecl = enumInst->base; 719 if ( enumDecl->base ) { 720 result = enumDecl->base.get(); 721 } else { 722 ast::BasicType::Kind kind = (ast::BasicType::Kind)(int)commonTypes[ (BasicType::Kind)(int)basic->kind ][ (BasicType::Kind)(int)ast::BasicType::SignedInt ]; 723 if ( 724 ( ( kind == basic->kind && basic->qualifiers >= type2->qualifiers ) 725 || widen.first ) 726 && ( ( kind != basic->kind && basic->qualifiers <= type2->qualifiers ) 727 || widen.second ) 728 ) { 729 result = new ast::BasicType{ kind, basic->qualifiers | type2->qualifiers }; 730 } 731 } 707 732 } 708 733 } … … 723 748 result = voidPtr; 724 749 add_qualifiers( result, oPtr->qualifiers ); 750 } 751 752 // For a typed enum, we want to unify type1 with the base type of the enum 753 bool tryResolveWithTypedEnum( const ast::Type * type1 ) { 754 if (auto enumInst = dynamic_cast<const ast::EnumInstType *> (type2) ) { 755 ast::AssertionSet have, need; // unused 756 ast::OpenVarSet newOpen{ open }; 757 if (enumInst->base->base 758 && unifyExact(type1, enumInst->base->base, tenv, need, have, newOpen, widen, symtab)) { 759 result = type1; 760 return true; 761 } 762 } 763 return false; 725 764 } 726 765 … … 768 807 result = pointer; 769 808 add_qualifiers( result, type2->qualifiers ); 770 } 771 } 772 773 void postvisit( const ast::ArrayType * ) {} 809 } else { 810 tryResolveWithTypedEnum( pointer ); 811 } 812 } 813 814 void postvisit( const ast::ArrayType * arr ) { 815 // xxx - does it make sense? 816 tryResolveWithTypedEnum( arr ); 817 } 774 818 775 819 void postvisit( const ast::ReferenceType * ref ) { … … 810 854 result = ref; 811 855 add_qualifiers( result, type2->qualifiers ); 812 } 813 } 814 815 void postvisit( const ast::FunctionType * ) {} 816 817 void postvisit( const ast::StructInstType * ) {} 818 819 void postvisit( const ast::UnionInstType * ) {} 856 } else { 857 // xxx - does unifying a ref with typed enumInst makes sense? 858 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 859 result = commonType( type2, ref, widen, symtab, tenv, open ); 860 } 861 } 862 863 void postvisit( const ast::FunctionType * func) { 864 tryResolveWithTypedEnum( func ); 865 } 866 867 void postvisit( const ast::StructInstType * inst ) { 868 tryResolveWithTypedEnum( inst ); 869 } 870 871 void postvisit( const ast::UnionInstType * inst ) { 872 tryResolveWithTypedEnum( inst ); 873 } 820 874 821 875 void postvisit( const ast::EnumInstType * enumInst ) { 822 if ( 823 dynamic_cast< const ast::BasicType * >( type2 ) 824 || dynamic_cast< const ast::ZeroType * >( type2 ) 825 || dynamic_cast< const ast::OneType * >( type2 ) 826 ) { 827 // reuse BasicType/EnumInstType common type by swapping 876 // reuse BasicType/EnumInstType common type by swapping 877 // xxx - is this already handled by unify? 878 if (!dynamic_cast<const ast::EnumInstType *>(type2)) 828 879 result = commonType( type2, enumInst, widen, symtab, tenv, open ); 829 }830 880 } 831 881 … … 850 900 result = type2; 851 901 reset_qualifiers( result, q1 | q2 ); 902 } else { 903 tryResolveWithTypedEnum( t1 ); 852 904 } 853 905 } … … 855 907 } 856 908 857 void postvisit( const ast::TupleType * ) {} 909 void postvisit( const ast::TupleType * tuple) { 910 tryResolveWithTypedEnum( tuple ); 911 } 858 912 859 913 void postvisit( const ast::VarArgsType * ) {} … … 861 915 void postvisit( const ast::ZeroType * zero ) { 862 916 if ( ! widen.first ) return; 863 if ( 864 dynamic_cast< const ast::BasicType * >( type2 ) 865 || dynamic_cast< const ast::PointerType * >( type2 ) 866 || dynamic_cast< const ast::EnumInstType * >( type2 ) 867 ) { 917 if ( dynamic_cast< const ast::BasicType * >( type2 ) 918 || dynamic_cast< const ast::PointerType * >( type2 ) ) { 868 919 if ( widen.second || zero->qualifiers <= type2->qualifiers ) { 869 920 result = type2; … … 873 924 result = new ast::BasicType{ 874 925 ast::BasicType::SignedInt, zero->qualifiers | type2->qualifiers }; 926 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 927 const ast::EnumDecl * enumDecl = enumInst->base; 928 if ( enumDecl->base ) { 929 if ( tryResolveWithTypedEnum( zero ) ) 930 add_qualifiers( result, zero->qualifiers ); 931 } else { 932 if ( widen.second || zero->qualifiers <= type2->qualifiers ) { 933 result = type2; 934 add_qualifiers( result, zero->qualifiers ); 935 } 936 } 875 937 } 876 938 } … … 878 940 void postvisit( const ast::OneType * one ) { 879 941 if ( ! widen.first ) return; 880 if ( 881 dynamic_cast< const ast::BasicType * >( type2 ) 882 || dynamic_cast< const ast::EnumInstType * >( type2 ) 883 ) { 942 if ( dynamic_cast< const ast::BasicType * >( type2 ) ) { 884 943 if ( widen.second || one->qualifiers <= type2->qualifiers ) { 885 944 result = type2; … … 889 948 result = new ast::BasicType{ 890 949 ast::BasicType::SignedInt, one->qualifiers | type2->qualifiers }; 950 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( type2 ) ) { 951 const ast::EnumDecl * enumBase = enumInst->base; 952 if ( enumBase->base ) { 953 if ( tryResolveWithTypedEnum( one )) 954 add_qualifiers( result, one->qualifiers ); 955 } else { 956 if ( widen.second || one->qualifiers <= type2->qualifiers ) { 957 result = type2; 958 add_qualifiers( result, one->qualifiers ); 959 } 960 } 891 961 } 892 962 } -
src/ResolvExpr/ConversionCost.cc
r015925a re5d9274 321 321 } 322 322 323 // refactor for code resue 324 void ConversionCost::conversionCostFromBasicToBasic(const BasicType * src, const BasicType * dest) { 325 int tableResult = costMatrix[ src->kind ][ dest->kind ]; 326 if ( tableResult == -1 ) { 327 cost = Cost::unsafe; 328 } else { 329 cost = Cost::zero; 330 cost.incSafe( tableResult ); 331 cost.incSign( signMatrix[ src->kind ][ dest->kind ] ); 332 } // if 333 } // ConversionCost::conversionCostFromBasicToBasic 334 323 335 void ConversionCost::postvisit(const BasicType * basicType) { 324 336 if ( const BasicType * destAsBasic = dynamic_cast< const BasicType * >( dest ) ) { 325 int tableResult = costMatrix[ basicType->kind ][ destAsBasic->kind ]; 326 if ( tableResult == -1 ) { 327 cost = Cost::unsafe; 328 } else { 329 cost = Cost::zero; 330 cost.incSafe( tableResult ); 331 cost.incSign( signMatrix[ basicType->kind ][ destAsBasic->kind ] ); 332 } // if 333 } else if ( dynamic_cast< const EnumInstType * >( dest ) ) { 334 // xxx - not positive this is correct, but appears to allow casting int => enum 335 // TODO 336 EnumDecl * decl = dynamic_cast< const EnumInstType * >( dest )->baseEnum; 337 if ( decl->base ) { 338 cost = Cost::infinity; 337 conversionCostFromBasicToBasic(basicType, destAsBasic); 338 } else if ( const EnumInstType * enumInst = dynamic_cast< const EnumInstType * >( dest ) ) { 339 const EnumDecl * base_enum = enumInst->baseEnum; 340 if ( const Type * base = base_enum->base ) { // if the base enum has a base (if it is typed) 341 if ( const BasicType * enumBaseAstBasic = dynamic_cast< const BasicType *> (base) ) { 342 conversionCostFromBasicToBasic(basicType, enumBaseAstBasic); 343 } else { 344 cost = Cost::infinity; 345 } // if 339 346 } else { 340 347 cost = Cost::unsafe; … … 398 405 void ConversionCost::postvisit( const FunctionType * ) {} 399 406 400 void ConversionCost::postvisit( const EnumInstType * ) { 401 static Type::Qualifiers q; 402 static BasicType integer( q, BasicType::SignedInt ); 403 cost = costFunc( &integer, dest, srcIsLvalue, indexer, env ); // safe if dest >= int 407 void ConversionCost::postvisit( const EnumInstType * enumInst) { 408 const EnumDecl * enumDecl = enumInst -> baseEnum; 409 if ( const Type * enumType = enumDecl -> base ) { // if it is a typed enum 410 cost = costFunc( enumType, dest, srcIsLvalue, indexer, env ); 411 } else { 412 static Type::Qualifiers q; 413 static BasicType integer( q, BasicType::SignedInt ); 414 cost = costFunc( &integer, dest, srcIsLvalue, indexer, env ); // safe if dest >= int 415 } // if 404 416 if ( cost < Cost::unsafe ) { 405 cost.incSafe();417 cost.incSafe(); 406 418 } // if 407 419 } … … 604 616 } 605 617 618 void ConversionCost_new::conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ) { 619 int tableResult = costMatrix[ src->kind ][ dest->kind ]; 620 if ( tableResult == -1 ) { 621 cost = Cost::unsafe; 622 } else { 623 cost = Cost::zero; 624 cost.incSafe( tableResult ); 625 cost.incSign( signMatrix[ src->kind ][ dest->kind ] ); 626 } 627 } 628 606 629 void ConversionCost_new::postvisit( const ast::BasicType * basicType ) { 607 630 if ( const ast::BasicType * dstAsBasic = dynamic_cast< const ast::BasicType * >( dst ) ) { 608 int tableResult = costMatrix[ basicType->kind ][ dstAsBasic->kind ]; 609 if ( tableResult == -1 ) { 610 cost = Cost::unsafe; 611 } else { 612 cost = Cost::zero; 613 cost.incSafe( tableResult ); 614 cost.incSign( signMatrix[ basicType->kind ][ dstAsBasic->kind ] ); 615 } 616 } else if ( dynamic_cast< const ast::EnumInstType * >( dst ) ) { 617 // xxx - not positive this is correct, but appears to allow casting int => enum 618 const ast::EnumDecl * decl = (dynamic_cast< const ast::EnumInstType * >( dst ))->base.get(); 619 if ( decl->base ) { 620 cost = Cost::infinity; 621 } else { 622 cost = Cost::unsafe; 623 } // if 631 conversionCostFromBasicToBasic( basicType, dstAsBasic ); 632 } else if ( const ast::EnumInstType * enumInst = dynamic_cast< const ast::EnumInstType * >( dst ) ) { 633 const ast::EnumDecl * enumDecl = enumInst->base.get(); 634 if ( const ast::Type * enumType = enumDecl->base.get() ) { 635 if ( const ast::BasicType * enumTypeAsBasic = dynamic_cast<const ast::BasicType *>(enumType) ) { 636 conversionCostFromBasicToBasic( basicType, enumTypeAsBasic ); 637 } else { 638 cost = Cost::infinity; 639 } 640 } else { 641 cost = Cost::unsafe; 642 } 624 643 } 625 644 } … … 673 692 674 693 void ConversionCost_new::postvisit( const ast::EnumInstType * enumInstType ) { 675 (void)enumInstType; 676 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 677 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 694 const ast::EnumDecl * baseEnum = enumInstType->base; 695 if ( const ast::Type * baseType = baseEnum->base ) { 696 cost = costCalc( baseType, dst, srcIsLvalue, symtab, env ); 697 } else { 698 (void)enumInstType; 699 static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) }; 700 cost = costCalc( integer, dst, srcIsLvalue, symtab, env ); 701 } 678 702 if ( cost < Cost::unsafe ) { 679 703 cost.incSafe(); -
src/ResolvExpr/ConversionCost.h
r015925a re5d9274 65 65 const TypeEnvironment &env; 66 66 CostFunction costFunc; 67 private: 68 // refactor for code resue 69 void conversionCostFromBasicToBasic( const BasicType * src, const BasicType* dest ); 67 70 }; 68 71 … … 111 114 void postvisit( const ast::ZeroType * zeroType ); 112 115 void postvisit( const ast::OneType * oneType ); 116 private: 117 // refactor for code resue 118 void conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ); 113 119 }; 114 120 -
src/SymTab/Autogen.h
r015925a re5d9274 21 21 22 22 #include "AST/Decl.hpp" 23 #include "AST/Eval.hpp"24 23 #include "AST/Expr.hpp" 25 24 #include "AST/Init.hpp" … … 71 70 template< typename OutIter > 72 71 ast::ptr< ast::Stmt > genCall( 73 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 74 const CodeLocation & loc, const std::string & fname, OutIter && out, 72 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 73 const CodeLocation & loc, const std::string & fname, OutIter && out, 75 74 const ast::Type * type, const ast::Type * addCast, LoopDirection forward = LoopForward ); 76 75 … … 128 127 } 129 128 130 /// inserts into out a generated call expression to function fname with arguments dstParam and 129 /// inserts into out a generated call expression to function fname with arguments dstParam and 131 130 /// srcParam. Should only be called with non-array types. 132 /// optionally returns a statement which must be inserted prior to the containing loop, if 131 /// optionally returns a statement which must be inserted prior to the containing loop, if 133 132 /// there is one 134 133 template< typename OutIter > 135 ast::ptr< ast::Stmt > genScalarCall( 136 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 137 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 134 ast::ptr< ast::Stmt > genScalarCall( 135 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 136 const CodeLocation & loc, std::string fname, OutIter && out, const ast::Type * type, 138 137 const ast::Type * addCast = nullptr 139 138 ) { … … 153 152 154 153 if ( addCast ) { 155 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 156 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 157 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 154 // cast to T& with qualifiers removed, so that qualified objects can be constructed and 155 // destructed with the same functions as non-qualified objects. Unfortunately, lvalue 156 // is considered a qualifier - for AddressExpr to resolve, its argument must have an 158 157 // lvalue-qualified type, so remove all qualifiers except lvalue. 159 158 // xxx -- old code actually removed lvalue too... 160 159 ast::ptr< ast::Type > guard = addCast; // prevent castType from mutating addCast 161 160 ast::ptr< ast::Type > castType = addCast; 162 ast::remove_qualifiers( 163 castType, 161 ast::remove_qualifiers( 162 castType, 164 163 ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Atomic ); 165 164 dstParam = new ast::CastExpr{ dstParam, new ast::ReferenceType{ castType } }; … … 181 180 182 181 srcParam.clearArrayIndices(); 183 182 184 183 return listInit; 185 184 } … … 249 248 } 250 249 251 /// Store in out a loop which calls fname on each element of the array with srcParam and 250 /// Store in out a loop which calls fname on each element of the array with srcParam and 252 251 /// dstParam as arguments. If forward is true, loop goes from 0 to N-1, else N-1 to 0 253 252 template< typename OutIter > 254 253 void genArrayCall( 255 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 256 const CodeLocation & loc, const std::string & fname, OutIter && out, 257 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 258 LoopDirection forward = LoopForward 254 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 255 const CodeLocation & loc, const std::string & fname, OutIter && out, 256 const ast::ArrayType * array, const ast::Type * addCast = nullptr, 257 LoopDirection forward = LoopForward 259 258 ) { 260 259 static UniqueName indexName( "_index" ); … … 279 278 } else { 280 279 // generate: for ( int i = N-1; i >= 0; --i ) 281 begin = ast:: call(282 loc, "?-?", array->dimension, ast::ConstantExpr::from_int( loc, 1 ));280 begin = ast::UntypedExpr::createCall( loc, "?-?", 281 { array->dimension, ast::ConstantExpr::from_int( loc, 1 ) } ); 283 282 end = ast::ConstantExpr::from_int( loc, 0 ); 284 283 cmp = "?>=?"; … … 286 285 } 287 286 288 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 289 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 287 ast::ptr< ast::DeclWithType > index = new ast::ObjectDecl{ 288 loc, indexName.newName(), new ast::BasicType{ ast::BasicType::SignedInt }, 290 289 new ast::SingleInit{ loc, begin } }; 291 290 ast::ptr< ast::Expr > indexVar = new ast::VariableExpr{ loc, index }; 292 293 ast::ptr< ast::Expr > cond = ast::call( loc, cmp, indexVar, end ); 294 295 ast::ptr< ast::Expr > inc = ast::call( loc, update, indexVar ); 296 297 ast::ptr< ast::Expr > dstIndex = ast::call( loc, "?[?]", dstParam, indexVar ); 298 299 // srcParam must keep track of the array indices to build the source parameter and/or 291 292 ast::ptr< ast::Expr > cond = ast::UntypedExpr::createCall( 293 loc, cmp, { indexVar, end } ); 294 295 ast::ptr< ast::Expr > inc = ast::UntypedExpr::createCall( 296 loc, update, { indexVar } ); 297 298 ast::ptr< ast::Expr > dstIndex = ast::UntypedExpr::createCall( 299 loc, "?[?]", { dstParam, indexVar } ); 300 301 // srcParam must keep track of the array indices to build the source parameter and/or 300 302 // array list initializer 301 303 srcParam.addArrayIndex( indexVar, array->dimension ); … … 303 305 // for stmt's body, eventually containing call 304 306 ast::CompoundStmt * body = new ast::CompoundStmt{ loc }; 305 ast::ptr< ast::Stmt > listInit = genCall( 306 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 307 ast::ptr< ast::Stmt > listInit = genCall( 308 srcParam, dstIndex, loc, fname, std::back_inserter( body->kids ), array->base, addCast, 307 309 forward ); 308 310 309 311 // block containing the stmt and index variable 310 312 ast::CompoundStmt * block = new ast::CompoundStmt{ loc }; … … 328 330 template< typename OutIter > 329 331 ast::ptr< ast::Stmt > genCall( 330 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 331 const CodeLocation & loc, const std::string & fname, OutIter && out, 332 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 333 const CodeLocation & loc, const std::string & fname, OutIter && out, 332 334 const ast::Type * type, const ast::Type * addCast, LoopDirection forward 333 335 ) { 334 336 if ( auto at = dynamic_cast< const ast::ArrayType * >( type ) ) { 335 genArrayCall( 336 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 337 genArrayCall( 338 srcParam, dstParam, loc, fname, std::forward< OutIter >(out), at, addCast, 337 339 forward ); 338 340 return {}; 339 341 } else { 340 return genScalarCall( 342 return genScalarCall( 341 343 srcParam, dstParam, loc, fname, std::forward< OutIter >( out ), type, addCast ); 342 344 } … … 377 379 } 378 380 379 static inline ast::ptr< ast::Stmt > genImplicitCall( 380 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 381 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 382 LoopDirection forward = LoopForward 381 static inline ast::ptr< ast::Stmt > genImplicitCall( 382 InitTweak::InitExpander_new & srcParam, const ast::Expr * dstParam, 383 const CodeLocation & loc, const std::string & fname, const ast::ObjectDecl * obj, 384 LoopDirection forward = LoopForward 383 385 ) { 384 386 // unnamed bit fields are not copied as they cannot be accessed … … 392 394 393 395 std::vector< ast::ptr< ast::Stmt > > stmts; 394 genCall( 396 genCall( 395 397 srcParam, dstParam, loc, fname, back_inserter( stmts ), obj->type, addCast, forward ); 396 398 … … 400 402 const ast::Stmt * callStmt = stmts.front(); 401 403 if ( addCast ) { 402 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 404 // implicitly generated ctor/dtor calls should be wrapped so that later passes are 403 405 // aware they were generated. 404 406 callStmt = new ast::ImplicitCtorDtorStmt{ callStmt->location, callStmt }; … … 417 419 // compile-command: "make install" // 418 420 // End: // 419 -
src/SymTab/Demangle.cc
r015925a re5d9274 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // Demangle r.cc --7 // Demangle.cc -- Convert a mangled name into a human readable name. 8 8 // 9 9 // Author : Rob Schluntz -
src/SymTab/Mangler.h
r015925a re5d9274 111 111 } 112 112 113 extern "C" {114 char * cforall_demangle(const char *, int);115 }116 117 113 // Local Variables: // 118 114 // tab-width: 4 // -
src/SymTab/Validate.cc
r015925a re5d9274 10 10 // Created On : Sun May 17 21:50:04 2015 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Fri Apr 29 9:45:00 202213 // Update Count : 36 512 // Last Modified On : Tue May 17 14:36:00 2022 13 // Update Count : 366 14 14 // 15 15 … … 74 74 #include "ResolvExpr/ResolveTypeof.h" // for resolveTypeof 75 75 #include "SymTab/Autogen.h" // for SizeType 76 #include "SymTab/ValidateType.h" // for decayEnumsAndPointers, decayFo... 76 77 #include "SynTree/LinkageSpec.h" // for C 77 78 #include "SynTree/Attribute.h" // for noAttributes, Attribute … … 134 135 }; 135 136 136 /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.137 struct EnumAndPointerDecay_old {138 void previsit( EnumDecl * aggregateDecl );139 void previsit( FunctionType * func );140 };141 142 /// Associates forward declarations of aggregates with their definitions143 struct LinkReferenceToTypes_old final : public WithIndexer, public WithGuards, public WithVisitorRef<LinkReferenceToTypes_old>, public WithShortCircuiting {144 LinkReferenceToTypes_old( const Indexer * indexer );145 146 void postvisit( TypeInstType * typeInst );147 148 void postvisit( EnumInstType * enumInst );149 void postvisit( StructInstType * structInst );150 void postvisit( UnionInstType * unionInst );151 void postvisit( TraitInstType * traitInst );152 void previsit( QualifiedType * qualType );153 void postvisit( QualifiedType * qualType );154 155 void postvisit( EnumDecl * enumDecl );156 void postvisit( StructDecl * structDecl );157 void postvisit( UnionDecl * unionDecl );158 void postvisit( TraitDecl * traitDecl );159 160 void previsit( StructDecl * structDecl );161 void previsit( UnionDecl * unionDecl );162 163 void renameGenericParams( std::list< TypeDecl * > & params );164 165 private:166 const Indexer * local_indexer;167 168 typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;169 typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;170 typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;171 ForwardEnumsType forwardEnums;172 ForwardStructsType forwardStructs;173 ForwardUnionsType forwardUnions;174 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately175 bool inGeneric = false;176 };177 178 137 /// Does early resolution on the expressions that give enumeration constants their values 179 138 struct ResolveEnumInitializers final : public WithIndexer, public WithGuards, public WithVisitorRef<ResolveEnumInitializers>, public WithShortCircuiting { … … 193 152 void previsit( StructDecl * aggrDecl ); 194 153 void previsit( UnionDecl * aggrDecl ); 195 };196 197 // These structs are the sub-sub-passes of ForallPointerDecay_old.198 199 struct TraitExpander_old final {200 void previsit( FunctionType * );201 void previsit( StructDecl * );202 void previsit( UnionDecl * );203 };204 205 struct AssertionFixer_old final {206 void previsit( FunctionType * );207 void previsit( StructDecl * );208 void previsit( UnionDecl * );209 };210 211 struct CheckOperatorTypes_old final {212 void previsit( ObjectDecl * );213 };214 215 struct FixUniqueIds_old final {216 void previsit( DeclarationWithType * );217 154 }; 218 155 … … 358 295 359 296 void validate_A( std::list< Declaration * > & translationUnit ) { 360 PassVisitor<EnumAndPointerDecay_old> epc;361 297 PassVisitor<HoistTypeDecls> hoistDecls; 362 298 { … … 367 303 ReplaceTypedef::replaceTypedef( translationUnit ); 368 304 ReturnTypeFixer::fix( translationUnit ); // must happen before autogen 369 acceptAll( translationUnit, epc ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling 370 } 371 } 372 373 void linkReferenceToTypes( std::list< Declaration * > & translationUnit ) { 374 PassVisitor<LinkReferenceToTypes_old> lrt( nullptr ); 375 acceptAll( translationUnit, lrt ); // must happen before autogen, because sized flag needs to propagate to generated functions 305 decayEnumsAndPointers( translationUnit ); // must happen before VerifyCtorDtorAssign, because void return objects should not exist; before LinkReferenceToTypes_old because it is an indexer and needs correct types for mangling 306 } 376 307 } 377 308 … … 412 343 }); 413 344 } 414 }415 416 static void decayForallPointers( std::list< Declaration * > & translationUnit ) {417 PassVisitor<TraitExpander_old> te;418 acceptAll( translationUnit, te );419 PassVisitor<AssertionFixer_old> af;420 acceptAll( translationUnit, af );421 PassVisitor<CheckOperatorTypes_old> cot;422 acceptAll( translationUnit, cot );423 PassVisitor<FixUniqueIds_old> fui;424 acceptAll( translationUnit, fui );425 345 } 426 346 … … 501 421 } 502 422 503 void validateType( Type * type, const Indexer * indexer ) {504 PassVisitor<EnumAndPointerDecay_old> epc;505 PassVisitor<LinkReferenceToTypes_old> lrt( indexer );506 PassVisitor<TraitExpander_old> te;507 PassVisitor<AssertionFixer_old> af;508 PassVisitor<CheckOperatorTypes_old> cot;509 PassVisitor<FixUniqueIds_old> fui;510 type->accept( epc );511 type->accept( lrt );512 type->accept( te );513 type->accept( af );514 type->accept( cot );515 type->accept( fui );516 }517 518 423 void HoistTypeDecls::handleType( Type * type ) { 519 424 // some type declarations are buried in expressions and not easy to hoist during parsing; hoist them here … … 708 613 } 709 614 710 void EnumAndPointerDecay_old::previsit( EnumDecl * enumDecl ) {711 // Set the type of each member of the enumeration to be EnumConstant712 for ( std::list< Declaration * >::iterator i = enumDecl->members.begin(); i != enumDecl->members.end(); ++i ) {713 ObjectDecl * obj = dynamic_cast< ObjectDecl * >( * i );714 assert( obj );715 obj->set_type( new EnumInstType( Type::Qualifiers( Type::Const ), enumDecl->name ) );716 } // for717 }718 719 namespace {720 template< typename DWTList >721 void fixFunctionList( DWTList & dwts, bool isVarArgs, FunctionType * func ) {722 auto nvals = dwts.size();723 bool containsVoid = false;724 for ( auto & dwt : dwts ) {725 // fix each DWT and record whether a void was found726 containsVoid |= fixFunction( dwt );727 }728 729 // the only case in which "void" is valid is where it is the only one in the list730 if ( containsVoid && ( nvals > 1 || isVarArgs ) ) {731 SemanticError( func, "invalid type void in function type " );732 }733 734 // one void is the only thing in the list; remove it.735 if ( containsVoid ) {736 delete dwts.front();737 dwts.clear();738 }739 }740 }741 742 void EnumAndPointerDecay_old::previsit( FunctionType * func ) {743 // Fix up parameters and return types744 fixFunctionList( func->parameters, func->isVarArgs, func );745 fixFunctionList( func->returnVals, false, func );746 }747 748 LinkReferenceToTypes_old::LinkReferenceToTypes_old( const Indexer * other_indexer ) : WithIndexer( false ) {749 if ( other_indexer ) {750 local_indexer = other_indexer;751 } else {752 local_indexer = &indexer;753 } // if754 }755 756 void LinkReferenceToTypes_old::postvisit( EnumInstType * enumInst ) {757 const EnumDecl * st = local_indexer->lookupEnum( enumInst->name );758 // it's not a semantic error if the enum is not found, just an implicit forward declaration759 if ( st ) {760 enumInst->baseEnum = const_cast<EnumDecl *>(st); // Just linking in the node761 } // if762 if ( ! st || ! st->body ) {763 // use of forward declaration764 forwardEnums[ enumInst->name ].push_back( enumInst );765 } // if766 }767 void LinkReferenceToTypes_old::postvisit( StructInstType * structInst ) {768 const StructDecl * st = local_indexer->lookupStruct( structInst->name );769 // it's not a semantic error if the struct is not found, just an implicit forward declaration770 if ( st ) {771 structInst->baseStruct = const_cast<StructDecl *>(st); // Just linking in the node772 } // if773 if ( ! st || ! st->body ) {774 // use of forward declaration775 forwardStructs[ structInst->name ].push_back( structInst );776 } // if777 }778 779 void LinkReferenceToTypes_old::postvisit( UnionInstType * unionInst ) {780 const UnionDecl * un = local_indexer->lookupUnion( unionInst->name );781 // it's not a semantic error if the union is not found, just an implicit forward declaration782 if ( un ) {783 unionInst->baseUnion = const_cast<UnionDecl *>(un); // Just linking in the node784 } // if785 if ( ! un || ! un->body ) {786 // use of forward declaration787 forwardUnions[ unionInst->name ].push_back( unionInst );788 } // if789 }790 791 void LinkReferenceToTypes_old::previsit( QualifiedType * ) {792 visit_children = false;793 }794 795 void LinkReferenceToTypes_old::postvisit( QualifiedType * qualType ) {796 // linking only makes sense for the 'oldest ancestor' of the qualified type797 qualType->parent->accept( * visitor );798 }799 800 template< typename Decl >801 void normalizeAssertions( std::list< Decl * > & assertions ) {802 // ensure no duplicate trait members after the clone803 auto pred = [](Decl * d1, Decl * d2) {804 // only care if they're equal805 DeclarationWithType * dwt1 = dynamic_cast<DeclarationWithType *>( d1 );806 DeclarationWithType * dwt2 = dynamic_cast<DeclarationWithType *>( d2 );807 if ( dwt1 && dwt2 ) {808 if ( dwt1->name == dwt2->name && ResolvExpr::typesCompatible( dwt1->get_type(), dwt2->get_type(), SymTab::Indexer() ) ) {809 // std::cerr << "=========== equal:" << std::endl;810 // std::cerr << "d1: " << d1 << std::endl;811 // std::cerr << "d2: " << d2 << std::endl;812 return false;813 }814 }815 return d1 < d2;816 };817 std::set<Decl *, decltype(pred)> unique_members( assertions.begin(), assertions.end(), pred );818 // if ( unique_members.size() != assertions.size() ) {819 // std::cerr << "============different" << std::endl;820 // std::cerr << unique_members.size() << " " << assertions.size() << std::endl;821 // }822 823 std::list< Decl * > order;824 order.splice( order.end(), assertions );825 std::copy_if( order.begin(), order.end(), back_inserter( assertions ), [&]( Decl * decl ) {826 return unique_members.count( decl );827 });828 }829 830 615 // expand assertions from trait instance, performing the appropriate type variable substitutions 831 616 template< typename Iterator > … … 838 623 // substitute trait decl parameters for instance parameters 839 624 applySubstitution( inst->baseTrait->parameters.begin(), inst->baseTrait->parameters.end(), inst->parameters.begin(), asserts.begin(), asserts.end(), out ); 840 }841 842 void LinkReferenceToTypes_old::postvisit( TraitDecl * traitDecl ) {843 if ( traitDecl->name == "sized" ) {844 // "sized" is a special trait - flick the sized status on for the type variable845 assertf( traitDecl->parameters.size() == 1, "Built-in trait 'sized' has incorrect number of parameters: %zd", traitDecl->parameters.size() );846 TypeDecl * td = traitDecl->parameters.front();847 td->set_sized( true );848 }849 850 // move assertions from type parameters into the body of the trait851 for ( TypeDecl * td : traitDecl->parameters ) {852 for ( DeclarationWithType * assert : td->assertions ) {853 if ( TraitInstType * inst = dynamic_cast< TraitInstType * >( assert->get_type() ) ) {854 expandAssertions( inst, back_inserter( traitDecl->members ) );855 } else {856 traitDecl->members.push_back( assert->clone() );857 }858 }859 deleteAll( td->assertions );860 td->assertions.clear();861 } // for862 }863 864 void LinkReferenceToTypes_old::postvisit( TraitInstType * traitInst ) {865 // handle other traits866 const TraitDecl * traitDecl = local_indexer->lookupTrait( traitInst->name );867 if ( ! traitDecl ) {868 SemanticError( traitInst->location, "use of undeclared trait " + traitInst->name );869 } // if870 if ( traitDecl->parameters.size() != traitInst->parameters.size() ) {871 SemanticError( traitInst, "incorrect number of trait parameters: " );872 } // if873 traitInst->baseTrait = const_cast<TraitDecl *>(traitDecl); // Just linking in the node874 875 // need to carry over the 'sized' status of each decl in the instance876 for ( auto p : group_iterate( traitDecl->parameters, traitInst->parameters ) ) {877 TypeExpr * expr = dynamic_cast< TypeExpr * >( std::get<1>(p) );878 if ( ! expr ) {879 SemanticError( std::get<1>(p), "Expression parameters for trait instances are currently unsupported: " );880 }881 if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {882 TypeDecl * formalDecl = std::get<0>(p);883 TypeDecl * instDecl = inst->baseType;884 if ( formalDecl->get_sized() ) instDecl->set_sized( true );885 }886 }887 // normalizeAssertions( traitInst->members );888 }889 890 void LinkReferenceToTypes_old::postvisit( EnumDecl * enumDecl ) {891 // visit enum members first so that the types of self-referencing members are updated properly892 // Replace the enum base; right now it works only for StructEnum893 if ( enumDecl->base && dynamic_cast<TypeInstType*>(enumDecl->base) ) {894 std::string baseName = static_cast<TypeInstType*>(enumDecl->base)->name;895 const StructDecl * st = local_indexer->lookupStruct( baseName );896 if ( st ) {897 enumDecl->base = new StructInstType(Type::Qualifiers(),const_cast<StructDecl *>(st)); // Just linking in the node898 }899 }900 if ( enumDecl->body ) {901 ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->name );902 if ( fwds != forwardEnums.end() ) {903 for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {904 (* inst)->baseEnum = enumDecl;905 } // for906 forwardEnums.erase( fwds );907 } // if908 } // if909 }910 911 void LinkReferenceToTypes_old::renameGenericParams( std::list< TypeDecl * > & params ) {912 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g.913 // forall(otype T)914 // struct Box {915 // T x;916 // };917 // forall(otype T)918 // void f(Box(T) b) {919 // ...920 // }921 // The T in Box and the T in f are different, so internally the naming must reflect that.922 GuardValue( inGeneric );923 inGeneric = ! params.empty();924 for ( TypeDecl * td : params ) {925 td->name = "__" + td->name + "_generic_";926 }927 }928 929 void LinkReferenceToTypes_old::previsit( StructDecl * structDecl ) {930 renameGenericParams( structDecl->parameters );931 }932 933 void LinkReferenceToTypes_old::previsit( UnionDecl * unionDecl ) {934 renameGenericParams( unionDecl->parameters );935 }936 937 void LinkReferenceToTypes_old::postvisit( StructDecl * structDecl ) {938 // visit struct members first so that the types of self-referencing members are updated properly939 // xxx - need to ensure that type parameters match up between forward declarations and definition (most importantly, number of type parameters and their defaults)940 if ( structDecl->body ) {941 ForwardStructsType::iterator fwds = forwardStructs.find( structDecl->name );942 if ( fwds != forwardStructs.end() ) {943 for ( std::list< StructInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {944 (* inst)->baseStruct = structDecl;945 } // for946 forwardStructs.erase( fwds );947 } // if948 } // if949 }950 951 void LinkReferenceToTypes_old::postvisit( UnionDecl * unionDecl ) {952 if ( unionDecl->body ) {953 ForwardUnionsType::iterator fwds = forwardUnions.find( unionDecl->name );954 if ( fwds != forwardUnions.end() ) {955 for ( std::list< UnionInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {956 (* inst)->baseUnion = unionDecl;957 } // for958 forwardUnions.erase( fwds );959 } // if960 } // if961 }962 963 void LinkReferenceToTypes_old::postvisit( TypeInstType * typeInst ) {964 // ensure generic parameter instances are renamed like the base type965 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name;966 if ( const NamedTypeDecl * namedTypeDecl = local_indexer->lookupType( typeInst->name ) ) {967 if ( const TypeDecl * typeDecl = dynamic_cast< const TypeDecl * >( namedTypeDecl ) ) {968 typeInst->set_isFtype( typeDecl->kind == TypeDecl::Ftype );969 } // if970 } // if971 625 } 972 626 … … 997 651 } 998 652 } 999 1000 653 } 1001 654 } … … 1085 738 void ForallPointerDecay_old::previsit( UnionDecl * aggrDecl ) { 1086 739 forallFixer( aggrDecl->parameters, aggrDecl ); 1087 }1088 1089 void TraitExpander_old::previsit( FunctionType * ftype ) {1090 expandTraits( ftype->forall );1091 }1092 1093 void TraitExpander_old::previsit( StructDecl * aggrDecl ) {1094 expandTraits( aggrDecl->parameters );1095 }1096 1097 void TraitExpander_old::previsit( UnionDecl * aggrDecl ) {1098 expandTraits( aggrDecl->parameters );1099 }1100 1101 void AssertionFixer_old::previsit( FunctionType * ftype ) {1102 fixAssertions( ftype->forall, ftype );1103 }1104 1105 void AssertionFixer_old::previsit( StructDecl * aggrDecl ) {1106 fixAssertions( aggrDecl->parameters, aggrDecl );1107 }1108 1109 void AssertionFixer_old::previsit( UnionDecl * aggrDecl ) {1110 fixAssertions( aggrDecl->parameters, aggrDecl );1111 }1112 1113 void CheckOperatorTypes_old::previsit( ObjectDecl * object ) {1114 // ensure that operator names only apply to functions or function pointers1115 if ( CodeGen::isOperator( object->name ) && ! dynamic_cast< FunctionType * >( object->type->stripDeclarator() ) ) {1116 SemanticError( object->location, toCString( "operator ", object->name.c_str(), " is not a function or function pointer." ) );1117 }1118 }1119 1120 void FixUniqueIds_old::previsit( DeclarationWithType * decl ) {1121 decl->fixUniqueId();1122 740 } 1123 741 -
src/SymTab/Validate.h
r015925a re5d9274 10 10 // Author : Richard C. Bilson 11 11 // Created On : Sun May 17 21:53:34 2015 12 // Last Modified By : Peter A. Buhr13 // Last Modified On : Sat Jul 22 09:46:07 201714 // Update Count : 412 // Last Modified By : Andrew Beach 13 // Last Modified On : Tue May 17 14:35:00 2022 14 // Update Count : 5 15 15 // 16 16 … … 33 33 /// Normalizes struct and function declarations 34 34 void validate( std::list< Declaration * > &translationUnit, bool doDebug = false ); 35 void validateType( Type *type, const Indexer *indexer );36 35 37 36 // Sub-passes of validate. … … 42 41 void validate_E( std::list< Declaration * > &translationUnit ); 43 42 void validate_F( std::list< Declaration * > &translationUnit ); 44 void linkReferenceToTypes( std::list< Declaration * > &translationUnit );45 46 const ast::Type * validateType(47 const CodeLocation & loc, const ast::Type * type, const ast::SymbolTable & symtab );48 43 } // namespace SymTab 49 44 -
src/SymTab/demangler.cc
r015925a re5d9274 1 #include " Mangler.h"1 #include "Demangle.h" 2 2 #include <iostream> 3 3 #include <fstream> -
src/SymTab/module.mk
r015925a re5d9274 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 12 ## Last Modified By : Andrew Beach 13 ## Last Modified On : T hr Aug 10 16:08:00 201714 ## Update Count : 413 ## Last Modified On : Tue May 17 14:46:00 2022 14 ## Update Count : 5 15 15 ############################################################################### 16 16 17 17 SRC_SYMTAB = \ 18 19 20 21 22 23 24 25 26 27 SymTab/Validate.cc \28 SymTab/Validate.h18 SymTab/Autogen.cc \ 19 SymTab/Autogen.h \ 20 SymTab/FixFunction.cc \ 21 SymTab/FixFunction.h \ 22 SymTab/Indexer.cc \ 23 SymTab/Indexer.h \ 24 SymTab/Mangler.cc \ 25 SymTab/ManglerCommon.cc \ 26 SymTab/Mangler.h \ 27 SymTab/ValidateType.cc \ 28 SymTab/ValidateType.h 29 29 30 SRC += $(SRC_SYMTAB) 31 SRCDEMANGLE += $(SRC_SYMTAB) SymTab/Demangle.cc 30 SRC += $(SRC_SYMTAB) \ 31 SymTab/Validate.cc \ 32 SymTab/Validate.h 33 34 SRCDEMANGLE += $(SRC_SYMTAB) \ 35 SymTab/Demangle.cc \ 36 SymTab/Demangle.h -
src/SynTree/module.mk
r015925a re5d9274 24 24 SynTree/AttrType.cc \ 25 25 SynTree/BaseSyntaxNode.h \ 26 SynTree/BaseSyntaxNode.cc \ 26 27 SynTree/BasicType.cc \ 27 28 SynTree/CommaExpr.cc \ -
src/Tuples/TupleExpansion.cc
r015925a re5d9274 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 : Fri Dec 13 23:45:51 201913 // Update Count : 2 411 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue May 17 15:02:00 2022 13 // Update Count : 25 14 14 // 15 15 … … 367 367 return nullptr; 368 368 } 369 370 namespace {371 /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure372 struct ImpurityDetector : public WithShortCircuiting {373 ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}374 375 void previsit( const ApplicationExpr * appExpr ) {376 visit_children = false;377 if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {378 if ( function->linkage == LinkageSpec::Intrinsic ) {379 if ( function->name == "*?" || function->name == "?[?]" ) {380 // intrinsic dereference, subscript are pure, but need to recursively look for impurity381 visit_children = true;382 return;383 }384 }385 }386 maybeImpure = true;387 }388 void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }389 void previsit( const UniqueExpr * ) {390 if ( ignoreUnique ) {391 // bottom out at unique expression.392 // The existence of a unique expression doesn't change the purity of an expression.393 // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression.394 visit_children = false;395 return;396 }397 }398 399 bool maybeImpure = false;400 bool ignoreUnique;401 };402 } // namespace403 404 bool maybeImpure( const Expression * expr ) {405 PassVisitor<ImpurityDetector> detector( false );406 expr->accept( detector );407 return detector.pass.maybeImpure;408 }409 410 bool maybeImpureIgnoreUnique( const Expression * expr ) {411 PassVisitor<ImpurityDetector> detector( true );412 expr->accept( detector );413 return detector.pass.maybeImpure;414 }415 369 } // namespace Tuples 416 370 -
src/Tuples/Tuples.cc
r015925a re5d9274 10 10 // Created On : Mon Jun 17 14:41:00 2019 11 11 // Last Modified By : Andrew Beach 12 // Last Modified On : Tue Jun 18 9:31:00 201913 // Update Count : 112 // Last Modified On : Mon May 16 16:15:00 2022 13 // Update Count : 2 14 14 // 15 15 … … 18 18 #include "AST/Pass.hpp" 19 19 #include "AST/LinkageSpec.hpp" 20 #include "Common/PassVisitor.h" 20 21 #include "InitTweak/InitTweak.h" 21 22 … … 23 24 24 25 namespace { 26 /// Checks if impurity (read: side-effects) may exist in a piece of code. 27 /// Currently gives a very crude approximation, wherein any function 28 /// call expression means the code may be impure. 29 struct ImpurityDetector_old : public WithShortCircuiting { 30 bool const ignoreUnique; 31 bool maybeImpure; 32 33 ImpurityDetector_old( bool ignoreUnique ) : 34 ignoreUnique( ignoreUnique ), maybeImpure( false ) 35 {} 36 37 void previsit( const ApplicationExpr * appExpr ) { 38 visit_children = false; 39 if ( const DeclarationWithType * function = 40 InitTweak::getFunction( appExpr ) ) { 41 if ( function->linkage == LinkageSpec::Intrinsic ) { 42 if ( function->name == "*?" || function->name == "?[?]" ) { 43 // intrinsic dereference, subscript are pure, 44 // but need to recursively look for impurity 45 visit_children = true; 46 return; 47 } 48 } 49 } 50 maybeImpure = true; 51 } 52 53 void previsit( const UntypedExpr * ) { 54 maybeImpure = true; 55 visit_children = false; 56 } 57 58 void previsit( const UniqueExpr * ) { 59 if ( ignoreUnique ) { 60 // bottom out at unique expression. 61 // The existence of a unique expression doesn't change the purity of an expression. 62 // That is, even if the wrapped expression is impure, the wrapper protects the rest of the expression. 63 visit_children = false; 64 return; 65 } 66 } 67 }; 68 69 bool detectImpurity( const Expression * expr, bool ignoreUnique ) { 70 PassVisitor<ImpurityDetector_old> detector( ignoreUnique ); 71 expr->accept( detector ); 72 return detector.pass.maybeImpure; 73 } 74 25 75 /// Determines if impurity (read: side-effects) may exist in a piece of code. Currently gives 26 76 /// a very crude approximation, wherein any function call expression means the code may be 27 77 /// impure. 28 78 struct ImpurityDetector : public ast::WithShortCircuiting { 29 bool maybeImpure= false;79 bool result = false; 30 80 31 81 void previsit( ast::ApplicationExpr const * appExpr ) { … … 36 86 } 37 87 } 38 maybeImpure= true; visit_children = false;88 result = true; visit_children = false; 39 89 } 40 90 void previsit( ast::UntypedExpr const * ) { 41 maybeImpure= true; visit_children = false;91 result = true; visit_children = false; 42 92 } 43 93 }; 94 44 95 struct ImpurityDetectorIgnoreUnique : public ImpurityDetector { 45 96 using ImpurityDetector::previsit; … … 48 99 } 49 100 }; 50 51 template<typename Detector>52 bool detectImpurity( const ast::Expr * expr ) {53 ast::Pass<Detector> detector;54 expr->accept( detector );55 return detector.core.maybeImpure;56 }57 101 } // namespace 58 102 59 103 bool maybeImpure( const ast::Expr * expr ) { 60 return detectImpurity<ImpurityDetector>( expr );104 return ast::Pass<ImpurityDetector>::read( expr ); 61 105 } 62 106 63 107 bool maybeImpureIgnoreUnique( const ast::Expr * expr ) { 64 return detectImpurity<ImpurityDetectorIgnoreUnique>( expr ); 108 return ast::Pass<ImpurityDetectorIgnoreUnique>::read( expr ); 109 } 110 111 bool maybeImpure( const Expression * expr ) { 112 return detectImpurity( expr, false ); 113 } 114 115 bool maybeImpureIgnoreUnique( const Expression * expr ) { 116 return detectImpurity( expr, true ); 65 117 } 66 118 -
src/Tuples/module.mk
r015925a re5d9274 10 10 ## Author : Richard C. Bilson 11 11 ## Created On : Mon Jun 1 17:49:17 2015 12 ## Last Modified By : Henry Xue13 ## Last Modified On : Mon Aug 23 15:36:09 202114 ## Update Count : 212 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Mon May 17 15:00:00 2022 14 ## Update Count : 3 15 15 ############################################################################### 16 16 … … 24 24 Tuples/Tuples.h 25 25 26 SRC += $(SRC_TUPLES) 26 27 27 SRC += $(SRC_TUPLES)28 28 SRCDEMANGLE += $(SRC_TUPLES) -
src/Validate/Autogen.cpp
r015925a re5d9274 402 402 auto retval = srcParam(); 403 403 retval->name = "_ret"; 404 // xxx - Adding this unused attribute can slience unused variable warning 405 // However, some code might not be compiled as expected 406 // Temporarily disabled 407 // retval->attributes.push_back(new ast::Attribute("unused")); 404 408 return genProto( "?=?", { dstParam(), srcParam() }, { retval } ); 405 409 } -
src/Validate/module.mk
r015925a re5d9274 10 10 ## Author : Rob Schluntz 11 11 ## Created On : Fri Jul 27 10:10:10 2018 12 ## Last Modified By : Rob Schluntz13 ## Last Modified On : Fri Jul 27 10:10:26 201814 ## Update Count : 212 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tue May 17 14:59:00 2022 14 ## Update Count : 3 15 15 ############################################################################### 16 16 17 17 SRC_VALIDATE = \ 18 Validate/FindSpecialDecls.cc \ 19 Validate/FindSpecialDecls.h 20 21 SRC += $(SRC_VALIDATE) \ 18 22 Validate/Autogen.cpp \ 19 23 Validate/Autogen.hpp \ … … 22 26 Validate/EliminateTypedef.cpp \ 23 27 Validate/EliminateTypedef.hpp \ 28 Validate/FindSpecialDeclsNew.cpp \ 24 29 Validate/FixQualifiedTypes.cpp \ 25 30 Validate/FixQualifiedTypes.hpp \ … … 38 43 Validate/NoIdSymbolTable.hpp \ 39 44 Validate/ReturnCheck.cpp \ 40 Validate/ReturnCheck.hpp \ 41 Validate/FindSpecialDeclsNew.cpp \ 42 Validate/FindSpecialDecls.cc \ 43 Validate/FindSpecialDecls.h 45 Validate/ReturnCheck.hpp 44 46 45 SRC += $(SRC_VALIDATE)46 47 SRCDEMANGLE += $(SRC_VALIDATE) -
src/Virtual/module.mk
r015925a re5d9274 11 11 ## Created On : Tus Jul 25 10:18:00 2017 12 12 ## Last Modified By : Andrew Beach 13 ## Last Modified On : Tus Jul 25 10:18:00 201714 ## Update Count : 013 ## Last Modified On : Tus May 17 14:59:00 2022 14 ## Update Count : 1 15 15 ############################################################################### 16 16 17 SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h \ 18 Virtual/Tables.cc Virtual/Tables.h 19 20 SRCDEMANGLE += Virtual/Tables.cc 17 SRC += \ 18 Virtual/ExpandCasts.cc \ 19 Virtual/ExpandCasts.h \ 20 Virtual/Tables.cc \ 21 Virtual/Tables.h -
src/main.cc
r015925a re5d9274 70 70 #include "ResolvExpr/Resolver.h" // for resolve 71 71 #include "SymTab/Validate.h" // for validate 72 #include "SymTab/ValidateType.h" // for linkReferenceToTypes 72 73 #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic 73 74 #include "SynTree/Declaration.h" // for Declaration
Note:
See TracChangeset
for help on using the changeset viewer.