Changeset 9939dc3
- Timestamp:
- May 17, 2022, 3:44:08 PM (2 years ago)
- Branches:
- ADT, ast-experimental, master, pthread-emulation, qualifiedEnum
- Children:
- 767a8ef
- Parents:
- fa2a3b1
- Location:
- src
- Files:
-
- 6 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 49 49 50 50 } 51 52 bool FixMain::replace_main = false;53 51 54 52 template<typename container> -
src/CodeGen/module.mk
rfa2a3b1 r9939dc3 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/Common/Indenter.h
rfa2a3b1 r9939dc3 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/module.mk
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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/module.mk
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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/module.mk
rfa2a3b1 r9939dc3 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/ResolvExpr/AlternativeFinder.cc
rfa2a3b1 r9939dc3 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/SymTab/Validate.cc
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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/module.mk
rfa2a3b1 r9939dc3 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) 30 SRC += $(SRC_SYMTAB) \ 31 SymTab/Validate.cc \ 32 SymTab/Validate.h 33 31 34 SRCDEMANGLE += $(SRC_SYMTAB) \ 32 35 SymTab/Demangle.cc \ -
src/SynTree/module.mk
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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/module.mk
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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
rfa2a3b1 r9939dc3 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.