Changeset 90152a4 for src/Parser/ParseNode.h
- Timestamp:
- Aug 27, 2018, 4:40:34 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:
- b7c89aa
- Parents:
- f9feab8 (diff), 305581d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/ParseNode.h
rf9feab8 r90152a4 10 10 // Created On : Sat May 16 13:28:16 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Nov 27 17:33:35 201713 // Update Count : 8 2412 // Last Modified On : Sat Aug 4 09:39:40 2018 13 // Update Count : 853 14 14 // 15 15 … … 68 68 } 69 69 70 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}71 virtual void printList( std::ostream & os, int indent = 0 ) const {70 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} 71 virtual void printList( std::ostream & os, int indent = 0 ) const { 72 72 print( os, indent ); 73 73 if ( next ) next->print( os, indent ); … … 77 77 78 78 ParseNode * next = nullptr; 79 std::string * name = nullptr;79 const std::string * name = nullptr; 80 80 CodeLocation location = yylloc; 81 81 }; // ParseNode … … 87 87 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 88 88 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr ); 89 InitializerNode( bool isDelete ); 89 90 ~InitializerNode(); 90 91 virtual InitializerNode * clone() const { assert( false ); return nullptr; } … … 98 99 bool get_maybeConstructed() const { return maybeConstructed; } 99 100 101 bool get_isDelete() const { return isDelete; } 102 100 103 InitializerNode * next_init() const { return kids; } 101 104 102 void print( std::ostream & os, int indent = 0 ) const;105 void print( std::ostream & os, int indent = 0 ) const; 103 106 void printOneLine( std::ostream & ) const; 104 107 … … 110 113 InitializerNode * kids; 111 114 bool maybeConstructed; 115 bool isDelete; 112 116 }; // InitializerNode 113 117 … … 123 127 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; } 124 128 125 virtual void print( std::ostream &os, __attribute__((unused)) int indent = 0 ) const override { 126 os << expr.get() << std::endl; 127 } 128 void printOneLine( __attribute__((unused)) std::ostream &os, __attribute__((unused)) int indent = 0 ) const {} 129 129 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override { 130 os << expr.get(); 131 } 132 void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} 133 134 Expression *get_expr() const { return expr.get(); } 130 135 template<typename T> 131 136 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); } … … 167 172 }; 168 173 169 Expression * build_constantInteger( std::string & str );170 Expression * build_constantFloat( std::string & str );171 Expression * build_constantChar( std::string & str );172 Expression * build_constantStr( std::string & str );174 Expression * build_constantInteger( std::string & str ); // these 4 routines modify the string 175 Expression * build_constantFloat( std::string & str ); 176 Expression * build_constantChar( std::string & str ); 177 Expression * build_constantStr( std::string & str ); 173 178 Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str ); 174 179 Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str ); … … 179 184 180 185 Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 186 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ); 181 187 Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node ); 182 188 Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member ); … … 209 215 enum Length { Short, Long, LongLong, NoLength }; 210 216 static const char * lengthNames[]; 211 enum Aggregate { Struct, Union, Trait, Coroutine, Monitor, Thread, NoAggregate };217 enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate }; 212 218 static const char * aggregateNames[]; 213 219 enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass }; … … 225 231 static DeclarationNode * newBuiltinType( BuiltinType ); 226 232 static DeclarationNode * newForall( DeclarationNode * ); 227 static DeclarationNode * newFromTypedef( std::string * ); 228 static DeclarationNode * newFunction( std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body, bool newStyle = false ); 233 static DeclarationNode * newFromTypedef( const std::string * ); 234 static DeclarationNode * newFromGlobalScope(); 235 static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * ); 236 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body ); 229 237 static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ); 230 static DeclarationNode * newEnum( std::string * name, DeclarationNode * constants, bool body );231 static DeclarationNode * newEnumConstant( std::string * name, ExpressionNode * constant );232 static DeclarationNode * newName( std::string * );233 static DeclarationNode * newFromTypeGen( std::string *, ExpressionNode * params );234 static DeclarationNode * newTypeParam( TypeClass, std::string * );238 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body ); 239 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant ); 240 static DeclarationNode * newName( const std::string * ); 241 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params ); 242 static DeclarationNode * newTypeParam( TypeClass, const std::string * ); 235 243 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts ); 236 244 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params ); 237 static DeclarationNode * newTypeDecl( std::string * name, DeclarationNode * typeParams );245 static DeclarationNode * newTypeDecl( const std::string * name, DeclarationNode * typeParams ); 238 246 static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind ); 239 247 static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic ); … … 242 250 static DeclarationNode * newTuple( DeclarationNode * members ); 243 251 static DeclarationNode * newTypeof( ExpressionNode * expr ); 244 static DeclarationNode * newAttr( std::string *, ExpressionNode * expr ); // @ attributes245 static DeclarationNode * newAttr( std::string *, DeclarationNode * type ); // @ attributes246 static DeclarationNode * newAttribute( std::string *, ExpressionNode * expr = nullptr ); // gcc attributes252 static DeclarationNode * newAttr( const std::string *, ExpressionNode * expr ); // @ attributes 253 static DeclarationNode * newAttr( const std::string *, DeclarationNode * type ); // @ attributes 254 static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes 247 255 static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement 256 static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message ); 248 257 249 258 DeclarationNode(); … … 262 271 DeclarationNode * addBitfield( ExpressionNode * size ); 263 272 DeclarationNode * addVarArgs(); 264 DeclarationNode * addFunctionBody( StatementNode * body, StatementNode * with = nullptr );273 DeclarationNode * addFunctionBody( StatementNode * body, ExpressionNode * with = nullptr ); 265 274 DeclarationNode * addOldDeclList( DeclarationNode * list ); 266 275 DeclarationNode * setBase( TypeData * newType ); … … 282 291 } 283 292 284 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;285 virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;293 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override; 294 virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override; 286 295 287 296 Declaration * build() const; 288 297 Type * buildType() const; 289 298 290 bool get_hasEllipsis() const;291 299 LinkageSpec::Spec get_linkage() const { return linkage; } 292 300 DeclarationNode * extractAggregate() const; … … 296 304 bool get_extension() const { return extension; } 297 305 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; } 306 307 bool get_inLine() const { return inLine; } 308 DeclarationNode * set_inLine( bool inL ) { inLine = inL; return this; } 298 309 public: 299 310 DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); } … … 314 325 Attr_t attr; 315 326 316 BuiltinType builtin; 317 318 TypeData * type; 319 327 struct StaticAssert_t { 328 ExpressionNode * condition; 329 Expression * message; 330 }; 331 StaticAssert_t assert; 332 333 BuiltinType builtin = NoBuiltinType; 334 335 TypeData * type = nullptr; 336 337 bool inLine = false; 320 338 Type::FuncSpecifiers funcSpecs; 321 339 Type::StorageClasses storageClasses; 322 340 323 ExpressionNode * bitfieldWidth ;341 ExpressionNode * bitfieldWidth = nullptr; 324 342 std::unique_ptr<ExpressionNode> enumeratorValue; 325 bool hasEllipsis ;343 bool hasEllipsis = false; 326 344 LinkageSpec::Spec linkage; 327 Expression * asmName;345 Expression * asmName = nullptr; 328 346 std::list< Attribute * > attributes; 329 InitializerNode * initializer ;347 InitializerNode * initializer = nullptr; 330 348 bool extension = false; 331 349 std::string error; 332 StatementNode * asmStmt ;350 StatementNode * asmStmt = nullptr; 333 351 334 352 static UniqueName anonymous; … … 364 382 virtual StatementNode * append_last_case( StatementNode * ); 365 383 366 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {384 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override { 367 385 os << stmt.get() << std::endl; 368 386 } … … 373 391 Statement * build_expr( ExpressionNode * ctl ); 374 392 375 struct IfCt l {376 IfCt l( DeclarationNode * decl, ExpressionNode * condition ) :393 struct IfCtrl { 394 IfCtrl( DeclarationNode * decl, ExpressionNode * condition ) : 377 395 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {} 378 396 … … 381 399 }; 382 400 383 struct ForCt l {384 ForCt l( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :401 struct ForCtrl { 402 ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) : 385 403 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {} 386 ForCt l( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :404 ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) : 387 405 init( new StatementNode( decl ) ), condition( condition ), change( change ) {} 388 406 … … 392 410 }; 393 411 394 Statement * build_if( IfCtl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 395 Statement * build_switch( ExpressionNode * ctl, StatementNode * stmt ); 412 Expression * build_if_control( IfCtrl * ctl, std::list< Statement * > & init ); 413 Statement * build_if( IfCtrl * ctl, StatementNode * then_stmt, StatementNode * else_stmt ); 414 Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt ); 396 415 Statement * build_case( ExpressionNode * ctl ); 397 416 Statement * build_default(); 398 Statement * build_while( ExpressionNode * ctl, StatementNode * stmt, bool kind = false ); 399 Statement * build_for( ForCtl * forctl, StatementNode * stmt ); 417 Statement * build_while( IfCtrl * ctl, StatementNode * stmt ); 418 Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt ); 419 Statement * build_for( ForCtrl * forctl, StatementNode * stmt ); 400 420 Statement * build_branch( BranchStmt::Type kind ); 401 421 Statement * build_branch( std::string * identifier, BranchStmt::Type kind ); … … 409 429 Statement * build_finally( StatementNode * stmt ); 410 430 Statement * build_compound( StatementNode * first ); 411 Statement * build_asmstmt( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 431 Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr ); 432 Statement * build_directive( std::string * directive ); 412 433 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when ); 413 434 WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing ); … … 419 440 420 441 template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args > 421 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) {422 SemanticError errors;442 void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) { 443 SemanticErrorException errors; 423 444 std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList ); 424 445 const NodeType * cur = firstNode; … … 433 454 assertf(false, "buildList unknown type"); 434 455 } // if 435 } catch( SemanticError &e ) { 436 e.set_location( cur->location ); 456 } catch( SemanticErrorException & e ) { 437 457 errors.append( e ); 438 458 } // try … … 445 465 446 466 // in DeclarationNode.cc 447 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList );448 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList );449 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList );467 void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList ); 468 void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList ); 469 void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList ); 450 470 451 471 template< typename SynTreeType, typename NodeType > 452 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) {472 void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) { 453 473 buildList( firstNode, outputList ); 454 474 delete firstNode;
Note:
See TracChangeset
for help on using the changeset viewer.