Changeset 2bfc6b2 for src


Ignore:
Timestamp:
Aug 30, 2018, 1:00:41 PM (6 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

Refactor FindSpecialDeclarations? and associated special declarations

Location:
src
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Lvalue.cc

    ra715b5c r2bfc6b2  
    2121#include "Lvalue.h"
    2222
     23#include "InitTweak/InitTweak.h"
    2324#include "Parser/LinkageSpec.h"          // for Spec, isBuiltin, Intrinsic
    2425#include "ResolvExpr/TypeEnvironment.h"  // for AssertionSet, OpenVarSet
    2526#include "ResolvExpr/Unify.h"            // for unify
    2627#include "ResolvExpr/typeops.h"
    27 #include "SymTab/Autogen.h"
    2828#include "SymTab/Indexer.h"              // for Indexer
    2929#include "SynTree/Declaration.h"         // for Declaration, FunctionDecl
     
    3333#include "SynTree/Type.h"                // for PointerType, Type, FunctionType
    3434#include "SynTree/Visitor.h"             // for Visitor, acceptAll
     35#include "Validate/FindSpecialDecls.h"   // for dereferenceOperator
    3536
    3637#if 0
     
    4445                // TODO: fold this into the general createDeref function??
    4546                Expression * mkDeref( Expression * arg ) {
    46                         if ( SymTab::dereferenceOperator ) {
     47                        if ( Validate::dereferenceOperator ) {
    4748                                // 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 );
    4950                                deref->result = new PointerType( Type::Qualifiers(), deref->result );
    5051                                Type * base = InitTweak::getPointerBase( arg->result );
  • src/InitTweak/FixInit.cc

    ra715b5c r2bfc6b2  
    5656#include "SynTree/DeclReplacer.h"      // for DeclReplacer
    5757#include "SynTree/Visitor.h"           // for acceptAll, maybeAccept
     58#include "Validate/FindSpecialDecls.h" // for dtorStmt, dtorStructDestroy
    5859
    5960bool ctordtorp = false; // print all debug
     
    204205                        static void generate( std::list< Declaration * > & translationUnit );
    205206
    206                         void premutate( StructDecl * structDecl );
    207 
    208207                        void premutate( FunctionDecl * funcDecl );
    209208                        DeclarationWithType * postmutate( FunctionDecl * funcDecl );
     
    227226                        bool isCtor = false; // true if current function is a constructor
    228227                        StructDecl * structDecl = nullptr;
    229 
    230                         // special built-in functions necessary for this to work
    231                         StructDecl * dtorStruct = nullptr;
    232                         FunctionDecl * dtorStructDestroy = nullptr;
    233228                };
    234229
     
    10191014                }
    10201015
    1021                 void GenStructMemberCalls::premutate( StructDecl * structDecl ) {
    1022                         if ( ! dtorStruct && structDecl->name == "__Destructor" ) {
    1023                                 dtorStruct = structDecl;
    1024                         }
    1025                 }
    1026 
    10271016                void GenStructMemberCalls::premutate( FunctionDecl * funcDecl ) {
    10281017                        GuardValue( function );
     
    10371026                        unhandled.clear();
    10381027                        usedUninit.clear();
    1039 
    1040                         if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {
    1041                                 dtorStructDestroy = funcDecl;
    1042                                 return;
    1043                         }
    10441028
    10451029                        function = funcDecl;
     
    10531037                                if ( structType ) {
    10541038                                        structDecl = structType->get_baseStruct();
    1055                                         if ( structDecl == dtorStruct ) return;
    10561039                                        for ( Declaration * member : structDecl->get_members() ) {
    10571040                                                if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
     
    11271110                                                                // function->get_statements()->push_back( callStmt );
    11281111
     1112                                                                // Optimization: do not need to call intrinsic destructors on members
     1113                                                                if ( isIntrinsicSingleArgCallStmt( callStmt ) ) continue;;
     1114
    11291115                                                                // __Destructor _dtor0 = { (void *)&b.a1, (void (*)(void *)_destroy_A };
    11301116                                                                std::list< Statement * > stmtsToAdd;
    11311117
    11321118                                                                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." );
    11351121
    11361122                                                                Expression * thisExpr = new CastExpr( new AddressExpr( new VariableExpr( thisParam ) ), new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ) );
     
    11421128                                                                Type * dtorType = new PointerType( Type::Qualifiers(), dtorFtype );
    11431129
    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 ) ) } ) );
    11451131                                                                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 ) } ) );
    11471133
    11481134                                                                function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd );
  • src/InitTweak/GenInit.cc

    ra715b5c r2bfc6b2  
    1515#include "GenInit.h"
    1616
    17 #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
     17#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
    2222
    2323#include "CodeGen/OperatorTable.h"
    24 #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
     24#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
    3232#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
    4445
    4546namespace InitTweak {
     
    186187
    187188                        // 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 );
    189190                        // array is variable-length when the dimension is not constexpr
    190191                        arrayType->isVarLen = ! isConstExpr( arrayType->dimension );
     
    192193                        if ( ! Tuples::maybeImpure( arrayType->dimension ) ) return;
    193194
    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() ) );
    195196                        arrayDimension->get_type()->set_const( true );
    196197
  • src/Makefile.am

    ra715b5c r2bfc6b2  
    5151AM_LDFLAGS  = @HOST_FLAGS@ -Xlinker -export-dynamic
    5252
    53 demangler_SOURCES = SymTab/demangler.cc
     53demangler_SOURCES = SymTab/demangler.cc # test driver for the demangler, also useful as a sanity check that libdemangle.a is complete
    5454
    5555demangler_LDADD = libdemangle.a     # yywrap
     
    138138  Tuples/TupleAssignment.cc \
    139139  Tuples/TupleExpansion.cc \
    140   Validate/HandleAttributes.cc
     140  Validate/HandleAttributes.cc \
     141  Validate/FindSpecialDecls.cc
    141142
    142143MAINTAINERCLEANFILES += ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}}
  • src/Makefile.in

    ra715b5c r2bfc6b2  
    212212        Tuples/Explode.$(OBJEXT) Tuples/TupleAssignment.$(OBJEXT) \
    213213        Tuples/TupleExpansion.$(OBJEXT) \
    214         Validate/HandleAttributes.$(OBJEXT)
     214        Validate/HandleAttributes.$(OBJEXT) \
     215        Validate/FindSpecialDecls.$(OBJEXT)
    215216libdemangle_a_OBJECTS = $(am_libdemangle_a_OBJECTS)
    216217am__installdirs = "$(DESTDIR)$(cfa_cpplibdir)"
     
    285286        Tuples/TupleExpansion.$(OBJEXT) Tuples/Explode.$(OBJEXT) \
    286287        Validate/HandleAttributes.$(OBJEXT) \
     288        Validate/FindSpecialDecls.$(OBJEXT) \
    287289        Virtual/ExpandCasts.$(OBJEXT)
    288290am____driver_cfa_cpp_OBJECTS = $(am__objects_1)
     
    566568        Tuples/TupleAssignment.cc Tuples/TupleExpansion.cc \
    567569        Tuples/Explode.cc Validate/HandleAttributes.cc \
    568         Virtual/ExpandCasts.cc
     570        Validate/FindSpecialDecls.cc Virtual/ExpandCasts.cc
    569571MAINTAINERCLEANFILES = ${libdir}/${notdir ${cfa_cpplib_PROGRAMS}}
    570572MOSTLYCLEANFILES = Parser/parser.hh Parser/parser.output
     
    580582AM_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
    581583AM_LDFLAGS = @HOST_FLAGS@ -Xlinker -export-dynamic
    582 demangler_SOURCES = SymTab/demangler.cc
     584demangler_SOURCES = SymTab/demangler.cc # test driver for the demangler, also useful as a sanity check that libdemangle.a is complete
    583585demangler_LDADD = libdemangle.a     # yywrap
    584586noinst_LIBRARIES = libdemangle.a
     
    665667  Tuples/TupleAssignment.cc \
    666668  Tuples/TupleExpansion.cc \
    667   Validate/HandleAttributes.cc
     669  Validate/HandleAttributes.cc \
     670  Validate/FindSpecialDecls.cc
    668671
    669672all: $(BUILT_SOURCES)
     
    942945        @: > Validate/$(DEPDIR)/$(am__dirstamp)
    943946Validate/HandleAttributes.$(OBJEXT): Validate/$(am__dirstamp) \
     947        Validate/$(DEPDIR)/$(am__dirstamp)
     948Validate/FindSpecialDecls.$(OBJEXT): Validate/$(am__dirstamp) \
    944949        Validate/$(DEPDIR)/$(am__dirstamp)
    945950
     
    12031208@AMDEP_TRUE@@am__include@ @am__quote@Tuples/$(DEPDIR)/TupleAssignment.Po@am__quote@
    12041209@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@
    12051211@AMDEP_TRUE@@am__include@ @am__quote@Validate/$(DEPDIR)/HandleAttributes.Po@am__quote@
    12061212@AMDEP_TRUE@@am__include@ @am__quote@Virtual/$(DEPDIR)/ExpandCasts.Po@am__quote@
  • src/ResolvExpr/Resolver.cc

    ra715b5c r2bfc6b2  
    3131#include "ResolvExpr/TypeEnvironment.h"  // for TypeEnvironment
    3232#include "Resolver.h"
    33 #include "SymTab/Autogen.h"              // for SizeType
    3433#include "SymTab/Indexer.h"              // for Indexer
    3534#include "SynTree/Declaration.h"         // for ObjectDecl, TypeDecl, Declar...
     
    4342#include "typeops.h"                     // for extractResultType
    4443#include "Unify.h"                       // for unify
     44#include "Validate/FindSpecialDecls.h"   // for SizeType
    4545
    4646using namespace std;
     
    374374        void Resolver::handlePtrType( PtrType * type ) {
    375375                if ( type->get_dimension() ) {
    376                         findSingleExpression( type->dimension, SymTab::SizeType->clone(), indexer );
     376                        findSingleExpression( type->dimension, Validate::SizeType->clone(), indexer );
    377377                }
    378378        }
  • src/SymTab/Autogen.cc

    ra715b5c r2bfc6b2  
    4141
    4242namespace SymTab {
    43         Type * SizeType = 0;
    44 
    4543        /// Data used to generate functions generically. Specifically, the name of the generated function and a function which generates the routine protoype
    4644        struct FuncData {
  • src/SymTab/Autogen.h

    ra715b5c r2bfc6b2  
    3636        /// returns true if obj's name is the empty string and it has a bitfield width
    3737        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 type
    41         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;
    4638
    4739        /// generate the type of an assignment function for paramType.
  • src/SymTab/Validate.cc

    ra715b5c r2bfc6b2  
    7575#include "SynTree/Visitor.h"           // for Visitor
    7676#include "Validate/HandleAttributes.h" // for handleAttributes
     77#include "Validate/FindSpecialDecls.h" // for FindSpecialDecls
    7778
    7879class CompoundStmt;
     
    287288        };
    288289
    289         FunctionDecl * dereferenceOperator = nullptr;
    290         struct FindSpecialDeclarations final {
    291                 void previsit( FunctionDecl * funcDecl );
    292         };
    293 
    294290        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    295291                PassVisitor<EnumAndPointerDecay> epc;
     
    298294                PassVisitor<CompoundLiteral> compoundliteral;
    299295                PassVisitor<ValidateGenericParameters> genericParams;
    300                 PassVisitor<FindSpecialDeclarations> finder;
    301296                PassVisitor<LabelAddressFixer> labelAddrFixer;
    302297                PassVisitor<HoistTypeDecls> hoistDecls;
     
    325320                FixObjectType::fix( translationUnit );
    326321                ArrayLength::computeLength( translationUnit );
    327                 acceptAll( translationUnit, finder ); // xxx - remove this pass soon
     322                Validate::findSpecialDecls( translationUnit );
    328323                mutateAll( translationUnit, labelAddrFixer );
    329324                Validate::handleAttributes( translationUnit );
     
    901896                if ( eliminator.pass.typedefNames.count( "size_t" ) ) {
    902897                        // 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();
    904899                } else {
    905900                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
    906901                        // 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 );
    908903                }
    909904        }
     
    12931288                        // need to resolve array dimensions early so that constructor code can correctly determine
    12941289                        // 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 );
    12961291
    12971292                        // must re-evaluate whether a type is a VLA, now that more information is available
     
    13301325                return addrExpr;
    13311326        }
    1332 
    1333         void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
    1334                 if ( ! dereferenceOperator ) {
    1335                         // find and remember the intrinsic dereference operator for object pointers
    1336                         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         }
    13501327} // namespace SymTab
    13511328
  • src/Validate/module.mk

    ra715b5c r2bfc6b2  
    1515###############################################################################
    1616
    17 SRC += Validate/HandleAttributes.cc
     17SRC += Validate/HandleAttributes.cc \
     18        Validate/FindSpecialDecls.cc
Note: See TracChangeset for help on using the changeset viewer.