Changeset 2bfc6b2
- Timestamp:
- Aug 30, 2018, 1:00:41 PM (7 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- bcc0946
- Parents:
- a715b5c
- Location:
- src
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/GenPoly/Lvalue.cc ¶
ra715b5c r2bfc6b2 21 21 #include "Lvalue.h" 22 22 23 #include "InitTweak/InitTweak.h" 23 24 #include "Parser/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic 24 25 #include "ResolvExpr/TypeEnvironment.h" // for AssertionSet, OpenVarSet 25 26 #include "ResolvExpr/Unify.h" // for unify 26 27 #include "ResolvExpr/typeops.h" 27 #include "SymTab/Autogen.h"28 28 #include "SymTab/Indexer.h" // for Indexer 29 29 #include "SynTree/Declaration.h" // for Declaration, FunctionDecl … … 33 33 #include "SynTree/Type.h" // for PointerType, Type, FunctionType 34 34 #include "SynTree/Visitor.h" // for Visitor, acceptAll 35 #include "Validate/FindSpecialDecls.h" // for dereferenceOperator 35 36 36 37 #if 0 … … 44 45 // TODO: fold this into the general createDeref function?? 45 46 Expression * mkDeref( Expression * arg ) { 46 if ( SymTab::dereferenceOperator ) {47 if ( Validate::dereferenceOperator ) { 47 48 // note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass 48 VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator );49 VariableExpr * deref = new VariableExpr( Validate::dereferenceOperator ); 49 50 deref->result = new PointerType( Type::Qualifiers(), deref->result ); 50 51 Type * base = InitTweak::getPointerBase( arg->result ); -
TabularUnified src/InitTweak/FixInit.cc ¶
ra715b5c r2bfc6b2 56 56 #include "SynTree/DeclReplacer.h" // for DeclReplacer 57 57 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 58 #include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy 58 59 59 60 bool ctordtorp = false; // print all debug … … 204 205 static void generate( std::list< Declaration * > & translationUnit ); 205 206 206 void premutate( StructDecl * structDecl );207 208 207 void premutate( FunctionDecl * funcDecl ); 209 208 DeclarationWithType * postmutate( FunctionDecl * funcDecl ); … … 227 226 bool isCtor = false; // true if current function is a constructor 228 227 StructDecl * structDecl = nullptr; 229 230 // special built-in functions necessary for this to work231 StructDecl * dtorStruct = nullptr;232 FunctionDecl * dtorStructDestroy = nullptr;233 228 }; 234 229 … … 1019 1014 } 1020 1015 1021 void GenStructMemberCalls::premutate( StructDecl * structDecl ) {1022 if ( ! dtorStruct && structDecl->name == "__Destructor" ) {1023 dtorStruct = structDecl;1024 }1025 }1026 1027 1016 void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) { 1028 1017 GuardValue( function ); … … 1037 1026 unhandled.clear(); 1038 1027 usedUninit.clear(); 1039 1040 if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {1041 dtorStructDestroy = funcDecl;1042 return;1043 }1044 1028 1045 1029 function = funcDecl; … … 1053 1037 if ( structType ) { 1054 1038 structDecl = structType->get_baseStruct(); 1055 if ( structDecl == dtorStruct ) return;1056 1039 for ( Declaration * member : structDecl->get_members() ) { 1057 1040 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) { … … 1127 1110 // function->get_statements()->push_back( callStmt ); 1128 1111 1112 // Optimization: do not need to call intrinsic destructors on members 1113 if ( isIntrinsicSingleArgCallStmt( callStmt ) ) continue;; 1114 1129 1115 // __Destructor _dtor0 = { (void *)&b.a1, (void (*)(void *)_destroy_A }; 1130 1116 std::list< Statement * > stmtsToAdd; 1131 1117 1132 1118 static UniqueName memberDtorNamer = { "__memberDtor" }; 1133 assertf( dtorStruct, "builtin __Destructor not found." );1134 assertf( dtorStructDestroy, "builtin __destroy_Destructor not found." );1119 assertf( Validate::dtorStruct, "builtin __Destructor not found." ); 1120 assertf( Validate::dtorStructDestroy, "builtin __destroy_Destructor not found." ); 1135 1121 1136 1122 Expression * thisExpr = new CastExpr( new AddressExpr( new VariableExpr( thisParam ) ), new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ) ); … … 1142 1128 Type * dtorType = new PointerType( Type::Qualifiers(), dtorFtype ); 1143 1129 1144 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) );1130 ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), Validate::dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( new CastExpr( dtorExpr, dtorType ) ) } ) ); 1145 1131 function->statements->push_front( new DeclStmt( destructor ) ); 1146 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorStructDestroy ) } ) );1132 destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( Validate::dtorStructDestroy ) } ) ); 1147 1133 1148 1134 function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd ); -
TabularUnified src/InitTweak/GenInit.cc ¶
ra715b5c r2bfc6b2 15 15 #include "GenInit.h" 16 16 17 #include <stddef.h> // for NULL18 #include <algorithm> // for any_of19 #include <cassert> // for assert, strict_dynamic_cast, assertf20 #include <iterator> // for back_inserter, inserter, back_inse...21 #include <list> // for _List_iterator, list17 #include <stddef.h> // for NULL 18 #include <algorithm> // for any_of 19 #include <cassert> // for assert, strict_dynamic_cast, assertf 20 #include <iterator> // for back_inserter, inserter, back_inse... 21 #include <list> // for _List_iterator, list 22 22 23 23 #include "CodeGen/OperatorTable.h" 24 #include "Common/PassVisitor.h" // for PassVisitor, WithGuards, WithShort...25 #include "Common/SemanticError.h" // for SemanticError26 #include "Common/UniqueName.h" // for UniqueName27 #include "Common/utility.h" // for ValueGuard, maybeClone28 #include "GenPoly/GenPoly.h" // for getFunctionType, isPolyType29 #include "GenPoly/ScopedSet.h" // for ScopedSet, ScopedSet<>::const_iter...30 #include "InitTweak.h" // for isConstExpr, InitExpander, checkIn...31 #include "Parser/LinkageSpec.h" // for isOverridable, C24 #include "Common/PassVisitor.h" // for PassVisitor, WithGuards, WithShort... 25 #include "Common/SemanticError.h" // for SemanticError 26 #include "Common/UniqueName.h" // for UniqueName 27 #include "Common/utility.h" // for ValueGuard, maybeClone 28 #include "GenPoly/GenPoly.h" // for getFunctionType, isPolyType 29 #include "GenPoly/ScopedSet.h" // for ScopedSet, ScopedSet<>::const_iter... 30 #include "InitTweak.h" // for isConstExpr, InitExpander, checkIn... 31 #include "Parser/LinkageSpec.h" // for isOverridable, C 32 32 #include "ResolvExpr/Resolver.h" 33 #include "SymTab/Autogen.h" // for genImplicitCall, SizeType 34 #include "SymTab/Mangler.h" // for Mangler 35 #include "SynTree/Declaration.h" // for ObjectDecl, DeclarationWithType 36 #include "SynTree/Expression.h" // for VariableExpr, UntypedExpr, Address... 37 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit, Initi... 38 #include "SynTree/Label.h" // for Label 39 #include "SynTree/Mutator.h" // for mutateAll 40 #include "SynTree/Statement.h" // for CompoundStmt, ImplicitCtorDtorStmt 41 #include "SynTree/Type.h" // for Type, ArrayType, Type::Qualifiers 42 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 43 #include "Tuples/Tuples.h" // for maybeImpure 33 #include "SymTab/Autogen.h" // for genImplicitCall 34 #include "SymTab/Mangler.h" // for Mangler 35 #include "SynTree/Declaration.h" // for ObjectDecl, DeclarationWithType 36 #include "SynTree/Expression.h" // for VariableExpr, UntypedExpr, Address... 37 #include "SynTree/Initializer.h" // for ConstructorInit, SingleInit, Initi... 38 #include "SynTree/Label.h" // for Label 39 #include "SynTree/Mutator.h" // for mutateAll 40 #include "SynTree/Statement.h" // for CompoundStmt, ImplicitCtorDtorStmt 41 #include "SynTree/Type.h" // for Type, ArrayType, Type::Qualifiers 42 #include "SynTree/Visitor.h" // for acceptAll, maybeAccept 43 #include "Tuples/Tuples.h" // for maybeImpure 44 #include "Validate/FindSpecialDecls.h" // for SizeType 44 45 45 46 namespace InitTweak { … … 186 187 187 188 // need to resolve array dimensions in order to accurately determine if constexpr 188 ResolvExpr::findSingleExpression( arrayType->dimension, SymTab::SizeType->clone(), indexer );189 ResolvExpr::findSingleExpression( arrayType->dimension, Validate::SizeType->clone(), indexer ); 189 190 // array is variable-length when the dimension is not constexpr 190 191 arrayType->isVarLen = ! isConstExpr( arrayType->dimension ); … … 192 193 if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return; 193 194 194 ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );195 ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageClasses, LinkageSpec::C, 0, Validate::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) ); 195 196 arrayDimension->get_type()->set_const( true ); 196 197 -
TabularUnified src/Makefile.am ¶
ra715b5c r2bfc6b2 51 51 AM_LDFLAGS = @HOST_FLAGS@ -Xlinker -export-dynamic 52 52 53 demangler_SOURCES = SymTab/demangler.cc 53 demangler_SOURCES = SymTab/demangler.cc # test driver for the demangler, also useful as a sanity check that libdemangle.a is complete 54 54 55 55 demangler_LDADD = libdemangle.a # yywrap … … 138 138 Tuples/TupleAssignment.cc \ 139 139 Tuples/TupleExpansion.cc \ 140 Validate/HandleAttributes.cc 140 Validate/HandleAttributes.cc \ 141 Validate/FindSpecialDecls.cc 141 142 142 143 MAINTAINERCLEANFILES += ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}} -
TabularUnified src/Makefile.in ¶
ra715b5c r2bfc6b2 212 212 Tuples/Explode.$(OBJEXT) Tuples/TupleAssignment.$(OBJEXT) \ 213 213 Tuples/TupleExpansion.$(OBJEXT) \ 214 Validate/HandleAttributes.$(OBJEXT) 214 Validate/HandleAttributes.$(OBJEXT) \ 215 Validate/FindSpecialDecls.$(OBJEXT) 215 216 libdemangle_a_OBJECTS = $(am_libdemangle_a_OBJECTS) 216 217 am__installdirs = "$(DESTDIR)$(cfa_cpplibdir)" … … 285 286 Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \ 286 287 Validate/HandleAttributes.$(OBJEXT) \ 288 Validate/FindSpecialDecls.$(OBJEXT) \ 287 289 Virtual/ExpandCasts.$(OBJEXT) 288 290 am____driver_cfa_cpp_OBJECTS = $(am__objects_1) … … 566 568 Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \ 567 569 Tuples/Explode.cc Validate/HandleAttributes.cc \ 568 V irtual/ExpandCasts.cc570 Validate/FindSpecialDecls.cc Virtual/ExpandCasts.cc 569 571 MAINTAINERCLEANFILES = ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}} 570 572 MOSTLYCLEANFILES = Parser/parser.hh Parser/parser.output … … 580 582 AM_CXXFLAGS = @HOST_FLAGS@ -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I./Parser -I$(srcdir)/Parser -I$(srcdir)/include -DYY_NO_INPUT -O2 -g -std=c++14 581 583 AM_LDFLAGS = @HOST_FLAGS@ -Xlinker -export-dynamic 582 demangler_SOURCES = SymTab/demangler.cc 584 demangler_SOURCES = SymTab/demangler.cc # test driver for the demangler, also useful as a sanity check that libdemangle.a is complete 583 585 demangler_LDADD = libdemangle.a # yywrap 584 586 noinst_LIBRARIES = libdemangle.a … … 665 667 Tuples/TupleAssignment.cc \ 666 668 Tuples/TupleExpansion.cc \ 667 Validate/HandleAttributes.cc 669 Validate/HandleAttributes.cc \ 670 Validate/FindSpecialDecls.cc 668 671 669 672 all: $(BUILT_SOURCES) … … 942 945 @: > Validate/$(DEPDIR)/$(am__dirstamp) 943 946 Validate/HandleAttributes.$(OBJEXT): Validate/$(am__dirstamp) \ 947 Validate/$(DEPDIR)/$(am__dirstamp) 948 Validate/FindSpecialDecls.$(OBJEXT): Validate/$(am__dirstamp) \ 944 949 Validate/$(DEPDIR)/$(am__dirstamp) 945 950 … … 1203 1208 @AMDEP_TRUE@@am__include@ @am__quote@Tuples/$(DEPDIR)/TupleAssignment.Po@am__quote@ 1204 1209 @AMDEP_TRUE@@am__include@ @am__quote@Tuples/$(DEPDIR)/TupleExpansion.Po@am__quote@ 1210 @AMDEP_TRUE@@am__include@ @am__quote@Validate/$(DEPDIR)/FindSpecialDecls.Po@am__quote@ 1205 1211 @AMDEP_TRUE@@am__include@ @am__quote@Validate/$(DEPDIR)/HandleAttributes.Po@am__quote@ 1206 1212 @AMDEP_TRUE@@am__include@ @am__quote@Virtual/$(DEPDIR)/ExpandCasts.Po@am__quote@ -
TabularUnified src/ResolvExpr/Resolver.cc ¶
ra715b5c r2bfc6b2 31 31 #include "ResolvExpr/TypeEnvironment.h" // for TypeEnvironment 32 32 #include "Resolver.h" 33 #include "SymTab/Autogen.h" // for SizeType34 33 #include "SymTab/Indexer.h" // for Indexer 35 34 #include "SynTree/Declaration.h" // for ObjectDecl, TypeDecl, Declar... … … 43 42 #include "typeops.h" // for extractResultType 44 43 #include "Unify.h" // for unify 44 #include "Validate/FindSpecialDecls.h" // for SizeType 45 45 46 46 using namespace std; … … 374 374 void Resolver::handlePtrType( PtrType * type ) { 375 375 if ( type->get_dimension() ) { 376 findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );376 findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer ); 377 377 } 378 378 } -
TabularUnified src/SymTab/Autogen.cc ¶
ra715b5c r2bfc6b2 41 41 42 42 namespace SymTab { 43 Type * SizeType = 0;44 45 43 /// Data used to generate functions generically. Specifically, the name of the generated function and a function which generates the routine protoype 46 44 struct FuncData { -
TabularUnified src/SymTab/Autogen.h ¶
ra715b5c r2bfc6b2 36 36 /// returns true if obj's name is the empty string and it has a bitfield width 37 37 bool isUnnamedBitfield( ObjectDecl * obj ); 38 39 /// size_t type - set when size_t typedef is seen. Useful in a few places,40 /// such as in determining array dimension type41 extern Type * SizeType;42 43 /// intrinsic dereference operator for unqualified types - set when *? function is seen in FindSpecialDeclarations.44 /// Useful for creating dereference ApplicationExprs without a full resolver pass.45 extern FunctionDecl * dereferenceOperator;46 38 47 39 /// generate the type of an assignment function for paramType. -
TabularUnified src/SymTab/Validate.cc ¶
ra715b5c r2bfc6b2 75 75 #include "SynTree/Visitor.h" // for Visitor 76 76 #include "Validate/HandleAttributes.h" // for handleAttributes 77 #include "Validate/FindSpecialDecls.h" // for FindSpecialDecls 77 78 78 79 class CompoundStmt; … … 287 288 }; 288 289 289 FunctionDecl * dereferenceOperator = nullptr;290 struct FindSpecialDeclarations final {291 void previsit( FunctionDecl * funcDecl );292 };293 294 290 void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) { 295 291 PassVisitor<EnumAndPointerDecay> epc; … … 298 294 PassVisitor<CompoundLiteral> compoundliteral; 299 295 PassVisitor<ValidateGenericParameters> genericParams; 300 PassVisitor<FindSpecialDeclarations> finder;301 296 PassVisitor<LabelAddressFixer> labelAddrFixer; 302 297 PassVisitor<HoistTypeDecls> hoistDecls; … … 325 320 FixObjectType::fix( translationUnit ); 326 321 ArrayLength::computeLength( translationUnit ); 327 acceptAll( translationUnit, finder ); // xxx - remove this pass soon322 Validate::findSpecialDecls( translationUnit ); 328 323 mutateAll( translationUnit, labelAddrFixer ); 329 324 Validate::handleAttributes( translationUnit ); … … 901 896 if ( eliminator.pass.typedefNames.count( "size_t" ) ) { 902 897 // grab and remember declaration of size_t 903 SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone();898 Validate::SizeType = eliminator.pass.typedefNames["size_t"].first->base->clone(); 904 899 } else { 905 900 // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong 906 901 // eventually should have a warning for this case. 907 SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );902 Validate::SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ); 908 903 } 909 904 } … … 1293 1288 // need to resolve array dimensions early so that constructor code can correctly determine 1294 1289 // if a type is a VLA (and hence whether its elements need to be constructed) 1295 ResolvExpr::findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );1290 ResolvExpr::findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer ); 1296 1291 1297 1292 // must re-evaluate whether a type is a VLA, now that more information is available … … 1330 1325 return addrExpr; 1331 1326 } 1332 1333 void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {1334 if ( ! dereferenceOperator ) {1335 // find and remember the intrinsic dereference operator for object pointers1336 if ( funcDecl->name == "*?" && funcDecl->linkage == LinkageSpec::Intrinsic ) {1337 FunctionType * ftype = funcDecl->type;1338 if ( ftype->parameters.size() == 1 ) {1339 PointerType * ptrType = strict_dynamic_cast<PointerType *>( ftype->parameters.front()->get_type() );1340 if ( ptrType->base->get_qualifiers() == Type::Qualifiers() ) {1341 TypeInstType * inst = dynamic_cast<TypeInstType *>( ptrType->base );1342 if ( inst && ! inst->get_isFtype() ) {1343 dereferenceOperator = funcDecl;1344 }1345 }1346 }1347 }1348 }1349 }1350 1327 } // namespace SymTab 1351 1328 -
TabularUnified src/Validate/module.mk ¶
ra715b5c r2bfc6b2 15 15 ############################################################################### 16 16 17 SRC += Validate/HandleAttributes.cc 17 SRC += Validate/HandleAttributes.cc \ 18 Validate/FindSpecialDecls.cc
Note: See TracChangeset
for help on using the changeset viewer.