Changeset 7528ba1 for src/SymTab


Ignore:
Timestamp:
Feb 23, 2016, 11:02:53 AM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
a172972
Parents:
d63eeb0
Message:

autogen struct ctor/dtor first attempt

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    rd63eeb0 r7528ba1  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Feb 09 13:21:56 2016
    13 // Update Count     : 270
     12// Last Modified On : Mon Feb 22 12:26:37 2016
     13// Update Count     : 297
    1414//
    1515
     
    729729        }
    730730
     731
     732        void makeStructCtorDtor( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, std::list< Declaration * > & declsToAdd ) {
     733                FunctionType *ctorType = new FunctionType( Type::Qualifiers(), false );
     734
     735                // Make function polymorphic in same parameters as generic struct, if applicable
     736                bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
     737                std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
     738                std::list< Expression* > structParams;  // List of matching parameters to put on types
     739                for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
     740                        isGeneric = true;
     741                        TypeDecl *typeParam = (*param)->clone();
     742                        ctorType->get_forall().push_back( typeParam );
     743                        structParams.push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeParam->get_name(), typeParam ) ) );
     744                }
     745
     746                ObjectDecl *thisParam = new ObjectDecl( "_this", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), cloneWithParams( refType, structParams ) ), 0 );
     747                ctorType->get_parameters().push_back( thisParam );
     748
     749                // Routines at global scope marked "static" to prevent multiple definitions is separate translation units
     750                // because each unit generates copies of the default routines for each aggregate.
     751                FunctionDecl *ctorDecl = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, ctorType, 0, true, false );
     752                FunctionDecl *dtorDecl = new FunctionDecl( "^?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, ctorType, 0, true, false );
     753                ctorDecl->fixUniqueId();
     754                dtorDecl->fixUniqueId();
     755
     756                // add definitions
     757                // TODO: add in calls to default constructors and destructors for fields
     758                ctorDecl->set_statements( new CompoundStmt( noLabels ) );
     759                dtorDecl->set_statements( new CompoundStmt( noLabels ) );
     760                declsToAdd.push_back( ctorDecl );
     761                declsToAdd.push_back( dtorDecl );
     762
     763
     764                // for ( std::list< Declaration * >::const_iterator member = aggregateDecl->get_members().begin(); member != aggregateDecl->get_members().end(); ++member ) {
     765                //      if ( DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *member ) ) {
     766                //              // query the type qualifiers of this field and skip assigning it if it is marked const.
     767                //              // If it is an array type, we need to strip off the array layers to find its qualifiers.
     768                //              Type * type = dwt->get_type();
     769                //              while ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
     770                //                      type = at->get_base();
     771                //              }
     772
     773                //              if ( type->get_qualifiers().isConst ) {
     774                //                      // don't assign const members
     775                //                      continue;
     776                //              }
     777
     778                //              if ( ArrayType *array = dynamic_cast< ArrayType * >( dwt->get_type() ) ) {
     779                //                      makeArrayAssignment( srcParam, dstParam, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
     780                //                      if ( isGeneric ) makeArrayAssignment( srcParam, returnVal, dwt, array, back_inserter( assignDecl->get_statements()->get_kids() ) );
     781                //              } else {
     782                //                      makeScalarAssignment( srcParam, dstParam, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
     783                //                      if ( isGeneric ) makeScalarAssignment( srcParam, returnVal, dwt, back_inserter( assignDecl->get_statements()->get_kids() ) );
     784                //              } // if
     785                //      } // if
     786                // } // for
     787                // if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
     788
     789                // return assignDecl;
     790        }
     791
    731792        Declaration *makeUnionAssignment( UnionDecl *aggregateDecl, UnionInstType *refType, unsigned int functionNesting ) {
    732793                FunctionType *assignType = new FunctionType( Type::Qualifiers(), false );
     
    778839                        StructInstType structInst( Type::Qualifiers(), structDecl->get_name() );
    779840                        structInst.set_baseStruct( structDecl );
     841
    780842                        declsToAdd.push_back( makeStructAssignment( structDecl, &structInst, functionNesting ) );
     843                        makeStructCtorDtor( structDecl, &structInst, functionNesting, declsToAdd );
    781844                        structsDone.insert( structDecl->get_name() );
    782845                } // if
Note: See TracChangeset for help on using the changeset viewer.