Changes in / [80722d0:d30790f]


Ignore:
Location:
src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src/Common/utility.h

    r80722d0 rd30790f  
    5656}
    5757
    58 
    5958template< typename Input_iterator >
    6059void printEnums( Input_iterator begin, Input_iterator end, const char * const *name_array, std::ostream &os ) {
  • src/Parser/DeclarationNode.cc

    r80722d0 rd30790f  
    230230        DeclarationNode *newnode = new DeclarationNode;
    231231        newnode->name = assign_strptr( name );
    232         newnode->enumeratorValue = constant;
     232        newnode->enumeratorValue.reset( constant );
    233233        typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID );
    234234        return newnode;
  • src/Parser/ExpressionNode.cc

    r80722d0 rd30790f  
    183183
    184184Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) {
    185         Type *targetType = decl_node->buildType();
     185        Type *targetType = maybeMoveBuildType( decl_node );
    186186        if ( dynamic_cast< VoidType * >( targetType ) ) {
    187187                delete targetType;
     
    213213}
    214214Expression *build_sizeOftype( DeclarationNode *decl_node ) {
    215         Expression* ret = new SizeofExpr( decl_node->buildType() );
    216         delete decl_node;
    217         return ret;
     215        return new SizeofExpr( maybeMoveBuildType( decl_node ) );
    218216}
    219217Expression *build_alignOfexpr( ExpressionNode *expr_node ) {
     
    221219}
    222220Expression *build_alignOftype( DeclarationNode *decl_node ) {
    223         return new AlignofExpr( decl_node->buildType() );
     221        return new AlignofExpr( maybeMoveBuildType( decl_node) );
    224222}
    225223Expression *build_offsetOf( DeclarationNode *decl_node, NameExpr *member ) {
    226         Expression* ret = new UntypedOffsetofExpr( decl_node->buildType(), member->get_name() );
    227         delete decl_node;
     224        Expression* ret = new UntypedOffsetofExpr( maybeMoveBuildType( decl_node ), member->get_name() );
    228225        delete member;
    229226        return ret;
     
    269266}
    270267Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) {
    271         return new AttrExpr( var, decl_node->buildType() );
     268        return new AttrExpr( var, maybeMoveBuildType( decl_node ) );
    272269}
    273270
     
    296293}
    297294Expression *build_typevalue( DeclarationNode *decl ) {
    298         return new TypeExpr( decl->buildType() );
     295        return new TypeExpr( maybeMoveBuildType( decl ) );
    299296}
    300297
  • src/Parser/InitializerNode.cc

    r80722d0 rd30790f  
    4545InitializerNode::~InitializerNode() {
    4646        delete expr;
     47        delete designator;
     48        delete kids;
    4749}
    4850
  • src/Parser/ParseNode.h

    r80722d0 rd30790f  
    280280        LinkageSpec::Spec get_linkage() const { return linkage; }
    281281        DeclarationNode *extractAggregate() const;
    282         ExpressionNode *get_enumeratorValue() const { return enumeratorValue; }
     282        bool has_enumeratorValue() const { return (bool)enumeratorValue; }
     283        ExpressionNode *consume_enumeratorValue() const { return const_cast<DeclarationNode*>(this)->enumeratorValue.release(); }
    283284
    284285        bool get_extension() const { return extension; }
     
    295296        std::list< std::string > attributes;
    296297        ExpressionNode *bitfieldWidth;
    297         ExpressionNode *enumeratorValue;
     298        std::unique_ptr<ExpressionNode> enumeratorValue;
    298299        InitializerNode *initializer;
    299300        bool hasEllipsis;
     
    306307
    307308Type *buildType( TypeData *type );
     309
     310static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) {
     311        Type* ret = orig ? orig->buildType() : nullptr;
     312        delete orig;
     313        return ret;
     314}
    308315
    309316//##############################################################################
  • src/Parser/StatementNode.cc

    r80722d0 rd30790f  
    5454        // find end of list and maintain previous pointer
    5555        for ( StatementNode * curr = prev; curr != nullptr; curr = (StatementNode *)curr->get_next() ) {
    56                 StatementNode *node = dynamic_cast< StatementNode * >(curr);
    57                 assert( node );
     56                StatementNode *node = safe_dynamic_cast< StatementNode * >(curr);
    5857                assert( dynamic_cast< CaseStmt * >(node->stmt.get()) );
    5958                prev = curr;
     
    160159        std::list< Statement * > branches;
    161160        buildMoveList< Statement, StatementNode >( catch_stmt, branches );
    162         CompoundStmt *tryBlock = dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    163         assert( tryBlock );
     161        CompoundStmt *tryBlock = safe_dynamic_cast< CompoundStmt * >(maybeMoveBuild< Statement >(try_stmt));
    164162        FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) );
    165163        return new TryStmt( noLabels, tryBlock, branches, finallyBlock );
  • src/Parser/TypeData.cc

    r80722d0 rd30790f  
    909909        std::list< Declaration * >::iterator members = ret->get_members().begin();
    910910        for ( const DeclarationNode *cur = enumeration->constants; cur != nullptr; cur = dynamic_cast< DeclarationNode * >( cur->get_next() ), ++members ) {
    911                 if ( cur->get_enumeratorValue() != nullptr ) {
     911                if ( cur->has_enumeratorValue() ) {
    912912                        ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members);
    913                         member->set_init( new SingleInit( maybeBuild< Expression >( cur->get_enumeratorValue() ), std::list< Expression * >() ) );
     913                        member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) );
    914914                } // if
    915915        } // for
  • src/include/assert.h

    r80722d0 rd30790f  
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // assert.h -- 
    8 // 
     6//
     7// assert.h --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Aug 18 13:19:26 2016
     
    1212// Last Modified On : Thu Aug 18 13:25:55 2016
    1313// Update Count     : 4
    14 //
     14//
     15
     16#pragma once
    1517
    1618#include_next <assert.h>
     
    2224void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... );
    2325
     26template<typename T, typename U>
     27static inline T safe_dynamic_cast(const U& src) {
     28        T ret = dynamic_cast<T>(src);
     29        assert(ret);
     30        return ret;
     31}
     32
    2433// Local Variables: //
    2534// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.