Changes in / [80722d0:d30790f]
- Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/utility.h
r80722d0 rd30790f 56 56 } 57 57 58 59 58 template< typename Input_iterator > 60 59 void printEnums( Input_iterator begin, Input_iterator end, const char * const *name_array, std::ostream &os ) { -
src/Parser/DeclarationNode.cc
r80722d0 rd30790f 230 230 DeclarationNode *newnode = new DeclarationNode; 231 231 newnode->name = assign_strptr( name ); 232 newnode->enumeratorValue = constant;232 newnode->enumeratorValue.reset( constant ); 233 233 typedefTable.addToEnclosingScope( newnode->name, TypedefTable::ID ); 234 234 return newnode; -
src/Parser/ExpressionNode.cc
r80722d0 rd30790f 183 183 184 184 Expression *build_cast( DeclarationNode *decl_node, ExpressionNode *expr_node ) { 185 Type *targetType = decl_node->buildType();185 Type *targetType = maybeMoveBuildType( decl_node ); 186 186 if ( dynamic_cast< VoidType * >( targetType ) ) { 187 187 delete targetType; … … 213 213 } 214 214 Expression *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 ) ); 218 216 } 219 217 Expression *build_alignOfexpr( ExpressionNode *expr_node ) { … … 221 219 } 222 220 Expression *build_alignOftype( DeclarationNode *decl_node ) { 223 return new AlignofExpr( decl_node->buildType() );221 return new AlignofExpr( maybeMoveBuildType( decl_node) ); 224 222 } 225 223 Expression *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() ); 228 225 delete member; 229 226 return ret; … … 269 266 } 270 267 Expression *build_attrtype( NameExpr *var, DeclarationNode * decl_node ) { 271 return new AttrExpr( var, decl_node->buildType() );268 return new AttrExpr( var, maybeMoveBuildType( decl_node ) ); 272 269 } 273 270 … … 296 293 } 297 294 Expression *build_typevalue( DeclarationNode *decl ) { 298 return new TypeExpr( decl->buildType() );295 return new TypeExpr( maybeMoveBuildType( decl ) ); 299 296 } 300 297 -
src/Parser/InitializerNode.cc
r80722d0 rd30790f 45 45 InitializerNode::~InitializerNode() { 46 46 delete expr; 47 delete designator; 48 delete kids; 47 49 } 48 50 -
src/Parser/ParseNode.h
r80722d0 rd30790f 280 280 LinkageSpec::Spec get_linkage() const { return linkage; } 281 281 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(); } 283 284 284 285 bool get_extension() const { return extension; } … … 295 296 std::list< std::string > attributes; 296 297 ExpressionNode *bitfieldWidth; 297 ExpressionNode *enumeratorValue;298 std::unique_ptr<ExpressionNode> enumeratorValue; 298 299 InitializerNode *initializer; 299 300 bool hasEllipsis; … … 306 307 307 308 Type *buildType( TypeData *type ); 309 310 static inline Type * maybeMoveBuildType( const DeclarationNode *orig ) { 311 Type* ret = orig ? orig->buildType() : nullptr; 312 delete orig; 313 return ret; 314 } 308 315 309 316 //############################################################################## -
src/Parser/StatementNode.cc
r80722d0 rd30790f 54 54 // find end of list and maintain previous pointer 55 55 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); 58 57 assert( dynamic_cast< CaseStmt * >(node->stmt.get()) ); 59 58 prev = curr; … … 160 159 std::list< Statement * > branches; 161 160 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)); 164 162 FinallyStmt *finallyBlock = dynamic_cast< FinallyStmt * >(maybeMoveBuild< Statement >(finally_stmt) ); 165 163 return new TryStmt( noLabels, tryBlock, branches, finallyBlock ); -
src/Parser/TypeData.cc
r80722d0 rd30790f 909 909 std::list< Declaration * >::iterator members = ret->get_members().begin(); 910 910 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() ) { 912 912 ObjectDecl *member = dynamic_cast< ObjectDecl * >(*members); 913 member->set_init( new SingleInit( maybe Build< Expression >( cur->get_enumeratorValue() ), std::list< Expression * >() ) );913 member->set_init( new SingleInit( maybeMoveBuild< Expression >( cur->consume_enumeratorValue() ), std::list< Expression * >() ) ); 914 914 } // if 915 915 } // for -
src/include/assert.h
r80722d0 rd30790f 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // assert.h -- 8 // 6 // 7 // assert.h -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Aug 18 13:19:26 2016 … … 12 12 // Last Modified On : Thu Aug 18 13:25:55 2016 13 13 // Update Count : 4 14 // 14 // 15 16 #pragma once 15 17 16 18 #include_next <assert.h> … … 22 24 void __assert_fail_f( const char *assertion, const char *file, unsigned int line, const char *function, const char *fmt, ... ); 23 25 26 template<typename T, typename U> 27 static inline T safe_dynamic_cast(const U& src) { 28 T ret = dynamic_cast<T>(src); 29 assert(ret); 30 return ret; 31 } 32 24 33 // Local Variables: // 25 34 // tab-width: 4 //
Note: See TracChangeset
for help on using the changeset viewer.