source: src/Parser/ParseNode.h@ dd16dd5

ADT ast-experimental
Last change on this file since dd16dd5 was 9a533ba, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Remove the unused DeclarationNode::Attr_t type and support.

  • Property mode set to 100644
File size: 21.6 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[974906e2]7// ParseNode.h --
[b87a5ed]8//
9// Author : Rodolfo G. Esteves
10// Created On : Sat May 16 13:28:16 2015
[76c62b2]11// Last Modified By : Peter A. Buhr
[44a0ca2]12// Last Modified On : Sun Feb 19 09:02:37 2023
13// Update Count : 940
[b87a5ed]14//
15
[6b0b624]16#pragma once
[51b73452]17
[d180746]18#include <algorithm> // for move
19#include <cassert> // for assert, assertf
20#include <iosfwd> // for ostream
21#include <iterator> // for back_insert_iterator
22#include <list> // for list
23#include <memory> // for unique_ptr, pointer_traits
24#include <string> // for string
[51b73452]25
[21f0aa8]26#include "Common/CodeLocation.h" // for CodeLocation
[d180746]27#include "Common/SemanticError.h" // for SemanticError
[be9288a]28#include "Common/UniqueName.h" // for UniqueName
[4b60b28]29#include "Common/utility.h" // for maybeClone
30#include "Parser/parserutility.h" // for maybeBuild
[07de76b]31#include "SynTree/LinkageSpec.h" // for Spec
[312029a]32#include "SynTree/Declaration.h" // for Aggregate
[d180746]33#include "SynTree/Expression.h" // for Expression, ConstantExpr (ptr only)
34#include "SynTree/Label.h" // for Label
35#include "SynTree/Statement.h" // for Statement, BranchStmt, BranchStmt:...
36#include "SynTree/Type.h" // for Type, Type::FuncSpecifiers, Type::...
37
38class Attribute;
39class Declaration;
[b2e0df3]40struct DeclarationNode;
[d180746]41class DeclarationWithType;
42class Initializer;
[a6e5091]43class ExpressionNode;
[b2e0df3]44struct StatementNode;
[51b73452]45
[7880579]46//##############################################################################
47
[d48e529]48typedef CodeLocation YYLTYPE;
49#define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
50
51extern YYLTYPE yylloc;
[294647b]52
[51b73452]53class ParseNode {
[bdd516a]54 public:
[99cad3aa]55 ParseNode() {};
[2298f728]56 virtual ~ParseNode() { delete next; delete name; };
[b6424d9]57 virtual ParseNode * clone() const = 0;
[51b73452]58
[b6424d9]59 ParseNode * get_next() const { return next; }
60 ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; }
[1b772749]61
[b6424d9]62 ParseNode * get_last() {
63 ParseNode * current;
[2298f728]64 for ( current = this; current->get_next() != nullptr; current = current->get_next() );
[99cad3aa]65 return current;
66 }
[b6424d9]67 ParseNode * set_last( ParseNode * newlast ) {
[2298f728]68 if ( newlast != nullptr ) get_last()->set_next( newlast );
[99cad3aa]69 return this;
70 }
[51b73452]71
[f2f512ba]72 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}
73 virtual void printList( std::ostream & os, int indent = 0 ) const {
[e4bc986]74 print( os, indent );
75 if ( next ) next->print( os, indent );
76 }
[1b772749]77
[b87a5ed]78 static int indent_by;
[7880579]79
[b6424d9]80 ParseNode * next = nullptr;
[25bca42]81 const std::string * name = nullptr;
[d48e529]82 CodeLocation location = yylloc;
[7880579]83}; // ParseNode
[51b73452]84
[7bf7fb9]85//##############################################################################
86
[d1625f8]87class InitializerNode : public ParseNode {
88 public:
[82bbaf4]89 InitializerNode( ExpressionNode *, bool aggrp = false, ExpressionNode * des = nullptr );
[2298f728]90 InitializerNode( InitializerNode *, bool aggrp = false, ExpressionNode * des = nullptr );
[3ed994e]91 InitializerNode( bool isDelete );
[d1625f8]92 ~InitializerNode();
[a7741435]93 virtual InitializerNode * clone() const { assert( false ); return nullptr; }
[d1625f8]94
[b6424d9]95 ExpressionNode * get_expression() const { return expr; }
[d1625f8]96
[b6424d9]97 InitializerNode * set_designators( ExpressionNode * des ) { designator = des; return this; }
98 ExpressionNode * get_designators() const { return designator; }
[d1625f8]99
[b6424d9]100 InitializerNode * set_maybeConstructed( bool value ) { maybeConstructed = value; return this; }
[d1625f8]101 bool get_maybeConstructed() const { return maybeConstructed; }
102
[3ed994e]103 bool get_isDelete() const { return isDelete; }
104
[b6424d9]105 InitializerNode * next_init() const { return kids; }
[d1625f8]106
[f2f512ba]107 void print( std::ostream & os, int indent = 0 ) const;
[d1625f8]108 void printOneLine( std::ostream & ) const;
109
[b6424d9]110 virtual Initializer * build() const;
[d1625f8]111 private:
[b6424d9]112 ExpressionNode * expr;
[d1625f8]113 bool aggregate;
[b6424d9]114 ExpressionNode * designator; // may be list
115 InitializerNode * kids;
[d1625f8]116 bool maybeConstructed;
[3ed994e]117 bool isDelete;
[c1c1112]118}; // InitializerNode
[d1625f8]119
120//##############################################################################
121
[ac71a86]122class ExpressionNode final : public ParseNode {
[bdd516a]123 public:
[d1625f8]124 ExpressionNode( Expression * expr = nullptr ) : expr( expr ) {}
125 virtual ~ExpressionNode() {}
[6eb4398]126 virtual ExpressionNode * clone() const override { return expr ? static_cast<ExpressionNode*>((new ExpressionNode( expr->clone() ))->set_next( maybeClone( get_next() ) )) : nullptr; }
[51b73452]127
[e04ef3a]128 bool get_extension() const { return extension; }
[b6424d9]129 ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
[51b73452]130
[f2f512ba]131 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
132 os << expr.get();
[e4bc986]133 }
[f2f512ba]134 void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}
[ac71a86]135
136 template<typename T>
[513e165]137 bool isExpressionType() const { return nullptr != dynamic_cast<T>(expr.get()); }
[51b73452]138
[a7c90d4]139 Expression * build() const { return const_cast<ExpressionNode *>(this)->expr.release(); }
[67d4e37]140
141 std::unique_ptr<Expression> expr; // public because of lifetime implications
[bdd516a]142 private:
[e04ef3a]143 bool extension = false;
[c1c1112]144}; // ExpressionNode
[e04ef3a]145
146template< typename T >
[7880579]147struct maybeBuild_t< Expression, T > {
[b6424d9]148 static inline Expression * doit( const T * orig ) {
[e04ef3a]149 if ( orig ) {
[b6424d9]150 Expression * p = orig->build();
[e04ef3a]151 p->set_extension( orig->get_extension() );
[64ac636]152 p->location = orig->location;
[e04ef3a]153 return p;
154 } else {
[7880579]155 return nullptr;
[e04ef3a]156 } // if
157 }
[51b73452]158};
159
[e5f2a67]160// Must harmonize with OperName.
[d9e2280]161enum class OperKinds {
162 // diadic
[e5f2a67]163 SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And,
[d9e2280]164 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
[e5f2a67]165 Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
[d9e2280]166 Index, Range,
167 // monadic
[5809461]168 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
[d9e2280]169 Ctor, Dtor,
[c1c1112]170}; // OperKinds
[51b73452]171
[7cf8006]172enum class EnumHiding { Visible, Hide };
173
[e82aa9df]174struct LabelNode {
175 std::list< Label > labels;
176};
177
[25bca42]178Expression * build_constantInteger( std::string & str ); // these 4 routines modify the string
179Expression * build_constantFloat( std::string & str );
180Expression * build_constantChar( std::string & str );
181Expression * build_constantStr( std::string & str );
[930f69e]182Expression * build_field_name_FLOATING_FRACTIONconstant( const std::string & str );
183Expression * build_field_name_FLOATING_DECIMALconstant( const std::string & str );
[8780e30]184Expression * build_field_name_FLOATINGconstant( const std::string & str );
185Expression * build_field_name_fraction_constants( Expression * fieldName, ExpressionNode * fracts );
[b6424d9]186
[d7dc824]187NameExpr * build_varref( const std::string * name );
[4e2befe3]188QualifiedNameExpr * build_qualified_expr( const DeclarationNode * decl_node, const NameExpr * name );
[b0d9ff7]189QualifiedNameExpr * build_qualified_expr( const EnumDecl * decl, const NameExpr * name );
[6e50a6b]190DimensionExpr * build_dimensionref( const std::string * name );
[b6424d9]191
192Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
[312029a]193Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node );
[a5f0529]194Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
[fd782b2]195Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
196Expression * build_pfieldSel( ExpressionNode * expr_node, Expression * member );
[b6424d9]197Expression * build_offsetOf( DeclarationNode * decl_node, NameExpr * member );
198Expression * build_and( ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
199Expression * build_and_or( ExpressionNode * expr_node1, ExpressionNode * expr_node2, bool kind );
200Expression * build_unary_val( OperKinds op, ExpressionNode * expr_node );
201Expression * build_unary_ptr( OperKinds op, ExpressionNode * expr_node );
202Expression * build_binary_val( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
203Expression * build_binary_ptr( OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
204Expression * build_cond( ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
[2298f728]205Expression * build_tuple( ExpressionNode * expr_node = nullptr );
[b6424d9]206Expression * build_func( ExpressionNode * function, ExpressionNode * expr_node );
207Expression * build_compoundLiteral( DeclarationNode * decl_node, InitializerNode * kids );
[51b73452]208
[7bf7fb9]209//##############################################################################
210
[62e5546]211struct TypeData;
[51b73452]212
[a025ea8]213struct DeclarationNode : public ParseNode {
[ba01b14]214 // These enumerations must harmonize with their names in DeclarationNode.cc.
215 enum BasicType { Void, Bool, Char, Int, Int128,
[e15853c]216 Float, Double, LongDouble, uuFloat80, uuFloat128,
217 uFloat16, uFloat32, uFloat32x, uFloat64, uFloat64x, uFloat128, uFloat128x, NoBasicType };
[dd020c0]218 static const char * basicTypeNames[];
[ba01b14]219 enum ComplexType { Complex, NoComplexType, Imaginary }; // Imaginary unsupported => parse, but make invisible and print error message
[dd020c0]220 static const char * complexTypeNames[];
[201aeb9]221 enum Signedness { Signed, Unsigned, NoSignedness };
[dd020c0]222 static const char * signednessNames[];
[201aeb9]223 enum Length { Short, Long, LongLong, NoLength };
[dd020c0]224 static const char * lengthNames[];
[f673c13c]225 enum BuiltinType { Valist, AutoType, Zero, One, NoBuiltinType };
[dd020c0]226 static const char * builtinTypeNames[];
[b6424d9]227
[68fe077a]228 static DeclarationNode * newStorageClass( Type::StorageClasses );
[ddfd945]229 static DeclarationNode * newFuncSpecifier( Type::FuncSpecifiers );
[738e304]230 static DeclarationNode * newTypeQualifier( Type::Qualifiers );
[b6424d9]231 static DeclarationNode * newBasicType( BasicType );
[5b639ee]232 static DeclarationNode * newComplexType( ComplexType );
[dd020c0]233 static DeclarationNode * newSignedNess( Signedness );
234 static DeclarationNode * newLength( Length );
[b6424d9]235 static DeclarationNode * newBuiltinType( BuiltinType );
[dd020c0]236 static DeclarationNode * newForall( DeclarationNode * );
[25bca42]237 static DeclarationNode * newFromTypedef( const std::string * );
[47498bd]238 static DeclarationNode * newFromGlobalScope();
[c5d7701]239 static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
[25bca42]240 static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
[312029a]241 static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
[e4d7c1c]242 static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body, bool typed, DeclarationNode * base = nullptr, EnumHiding hiding = EnumHiding::Visible );
[25bca42]243 static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
[374cb117]244 static DeclarationNode * newEnumValueGeneric( const std::string * name, InitializerNode * init );
[1e30df7]245 static DeclarationNode * newEnumInLine( const std::string name );
[25bca42]246 static DeclarationNode * newName( const std::string * );
247 static DeclarationNode * newFromTypeGen( const std::string *, ExpressionNode * params );
[07de76b]248 static DeclarationNode * newTypeParam( TypeDecl::Kind, const std::string * );
[2298f728]249 static DeclarationNode * newTrait( const std::string * name, DeclarationNode * params, DeclarationNode * asserts );
250 static DeclarationNode * newTraitUse( const std::string * name, ExpressionNode * params );
[25bca42]251 static DeclarationNode * newTypeDecl( const std::string * name, DeclarationNode * typeParams );
[ce8c12f]252 static DeclarationNode * newPointer( DeclarationNode * qualifiers, OperKinds kind );
[b6424d9]253 static DeclarationNode * newArray( ExpressionNode * size, DeclarationNode * qualifiers, bool isStatic );
254 static DeclarationNode * newVarArray( DeclarationNode * qualifiers );
255 static DeclarationNode * newBitfield( ExpressionNode * size );
256 static DeclarationNode * newTuple( DeclarationNode * members );
[f855545]257 static DeclarationNode * newTypeof( ExpressionNode * expr, bool basetypeof = false );
[93bbbc4]258 static DeclarationNode * newVtableType( DeclarationNode * expr );
[25bca42]259 static DeclarationNode * newAttribute( const std::string *, ExpressionNode * expr = nullptr ); // gcc attributes
[2d019af]260 static DeclarationNode * newDirectiveStmt( StatementNode * stmt ); // gcc external directive statement
[e994912]261 static DeclarationNode * newAsmStmt( StatementNode * stmt ); // gcc external asm statement
[f6e3e34]262 static DeclarationNode * newStaticAssert( ExpressionNode * condition, Expression * message );
[b87a5ed]263
[7880579]264 DeclarationNode();
265 ~DeclarationNode();
[6a0d4d61]266 DeclarationNode * clone() const override;
[7880579]267
[2298f728]268 DeclarationNode * addQualifiers( DeclarationNode * );
[413ad05]269 void checkQualifiers( const TypeData *, const TypeData * );
[a7c90d4]270 void checkSpecifiers( DeclarationNode * );
271 DeclarationNode * copySpecifiers( DeclarationNode * );
[2298f728]272 DeclarationNode * addType( DeclarationNode * );
[b6424d9]273 DeclarationNode * addTypedef();
[f135b50]274 DeclarationNode * addEnumBase( DeclarationNode * );
[2298f728]275 DeclarationNode * addAssertions( DeclarationNode * );
276 DeclarationNode * addName( std::string * );
[c0aa336]277 DeclarationNode * addAsmName( DeclarationNode * );
[b6424d9]278 DeclarationNode * addBitfield( ExpressionNode * size );
279 DeclarationNode * addVarArgs();
[c453ac4]280 DeclarationNode * addFunctionBody( StatementNode * body, ExpressionNode * with = nullptr );
[b6424d9]281 DeclarationNode * addOldDeclList( DeclarationNode * list );
[c0aa336]282 DeclarationNode * setBase( TypeData * newType );
283 DeclarationNode * copyAttribute( DeclarationNode * attr );
[b6424d9]284 DeclarationNode * addPointer( DeclarationNode * qualifiers );
285 DeclarationNode * addArray( DeclarationNode * array );
286 DeclarationNode * addNewPointer( DeclarationNode * pointer );
287 DeclarationNode * addNewArray( DeclarationNode * array );
288 DeclarationNode * addParamList( DeclarationNode * list );
289 DeclarationNode * addIdList( DeclarationNode * list ); // old-style functions
290 DeclarationNode * addInitializer( InitializerNode * init );
[67cf18c]291 DeclarationNode * addTypeInitializer( DeclarationNode * init );
[b6424d9]292
293 DeclarationNode * cloneType( std::string * newName );
294 DeclarationNode * cloneBaseType( DeclarationNode * newdecl );
295
296 DeclarationNode * appendList( DeclarationNode * node ) {
[99cad3aa]297 return (DeclarationNode *)set_last( node );
298 }
[b87a5ed]299
[f2f512ba]300 virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;
301 virtual void printList( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const override;
[b87a5ed]302
[b6424d9]303 Declaration * build() const;
[a7c90d4]304 Type * buildType() const;
[b87a5ed]305
[8b7ee09]306 LinkageSpec::Spec get_linkage() const { return linkage; }
[b6424d9]307 DeclarationNode * extractAggregate() const;
[4f147cc]308 bool has_enumeratorValue() const { return (bool)enumeratorValue; }
[a7c90d4]309 ExpressionNode * consume_enumeratorValue() const { return const_cast<DeclarationNode *>(this)->enumeratorValue.release(); }
[b87a5ed]310
[7305915]311 bool get_extension() const { return extension; }
[b6424d9]312 DeclarationNode * set_extension( bool exten ) { extension = exten; return this; }
[e07caa2]313
314 bool get_inLine() const { return inLine; }
315 DeclarationNode * set_inLine( bool inL ) { inLine = inL; return this; }
[a025ea8]316
[481115f]317 DeclarationNode * get_last() { return (DeclarationNode *)ParseNode::get_last(); }
318
[28307be]319 struct Variable_t {
[faddbd8]320// const std::string * name;
[07de76b]321 TypeDecl::Kind tyClass;
[28307be]322 DeclarationNode * assertions;
[67cf18c]323 DeclarationNode * initializer;
[28307be]324 };
325 Variable_t variable;
326
[f6e3e34]327 struct StaticAssert_t {
328 ExpressionNode * condition;
329 Expression * message;
330 };
331 StaticAssert_t assert;
332
[e07caa2]333 BuiltinType builtin = NoBuiltinType;
[8f6f47d7]334
[e07caa2]335 TypeData * type = nullptr;
[dd020c0]336
[e07caa2]337 bool inLine = false;
[44a0ca2]338 bool enumInLine = false;
[ddfd945]339 Type::FuncSpecifiers funcSpecs;
[68fe077a]340 Type::StorageClasses storageClasses;
[dd020c0]341
[e07caa2]342 ExpressionNode * bitfieldWidth = nullptr;
[4f147cc]343 std::unique_ptr<ExpressionNode> enumeratorValue;
[e07caa2]344 bool hasEllipsis = false;
[8b7ee09]345 LinkageSpec::Spec linkage;
[e07caa2]346 Expression * asmName = nullptr;
[44a81853]347 std::list< Attribute * > attributes;
[e07caa2]348 InitializerNode * initializer = nullptr;
[7305915]349 bool extension = false;
[13e3b50]350 std::string error;
[e07caa2]351 StatementNode * asmStmt = nullptr;
[2d019af]352 StatementNode * directiveStmt = nullptr;
[b87a5ed]353
354 static UniqueName anonymous;
[1db21619]355}; // DeclarationNode
[51b73452]356
[b6424d9]357Type * buildType( TypeData * type );
[d1625f8]358
[b6424d9]359static inline Type * maybeMoveBuildType( const DeclarationNode * orig ) {
[a7c90d4]360 Type * ret = orig ? orig->buildType() : nullptr;
[4f147cc]361 delete orig;
362 return ret;
363}
364
[7bf7fb9]365//##############################################################################
366
[a025ea8]367struct StatementNode final : public ParseNode {
[e82aa9df]368 StatementNode() { stmt = nullptr; }
[b6424d9]369 StatementNode( Statement * stmt ) : stmt( stmt ) {}
370 StatementNode( DeclarationNode * decl );
[e82aa9df]371 virtual ~StatementNode() {}
[51b73452]372
[b6424d9]373 virtual StatementNode * clone() const final { assert( false ); return nullptr; }
[a7c90d4]374 Statement * build() const { return const_cast<StatementNode *>(this)->stmt.release(); }
[2f22cc4]375
[44a81853]376 virtual StatementNode * add_label( const std::string * name, DeclarationNode * attr = nullptr ) {
377 stmt->get_labels().emplace_back( * name, nullptr, attr ? std::move( attr->attributes ) : std::list< Attribute * > {} );
378 delete attr;
[ac71a86]379 delete name;
[2f22cc4]380 return this;
381 }
382
[b6424d9]383 virtual StatementNode * append_last_case( StatementNode * );
[1d4580a]384
[f2f512ba]385 virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
[e4bc986]386 os << stmt.get() << std::endl;
387 }
[a025ea8]388
[ac71a86]389 std::unique_ptr<Statement> stmt;
[2f22cc4]390}; // StatementNode
391
[b6424d9]392Statement * build_expr( ExpressionNode * ctl );
[1d4580a]393
[473d1da0]394struct CondCtl {
395 CondCtl( DeclarationNode * decl, ExpressionNode * condition ) :
[936e9f4]396 init( decl ? new StatementNode( decl ) : nullptr ), condition( condition ) {}
397
398 StatementNode * init;
399 ExpressionNode * condition;
400};
401
[f271bdd]402struct ForCtrl {
403 ForCtrl( ExpressionNode * expr, ExpressionNode * condition, ExpressionNode * change ) :
[e82aa9df]404 init( new StatementNode( build_expr( expr ) ) ), condition( condition ), change( change ) {}
[f271bdd]405 ForCtrl( DeclarationNode * decl, ExpressionNode * condition, ExpressionNode * change ) :
[e82aa9df]406 init( new StatementNode( decl ) ), condition( condition ), change( change ) {}
[2f22cc4]407
[b6424d9]408 StatementNode * init;
409 ExpressionNode * condition;
410 ExpressionNode * change;
[2f22cc4]411};
412
[473d1da0]413Expression * build_if_control( CondCtl * ctl, std::list< Statement * > & init );
[436bbe5]414Statement * build_if( CondCtl * ctl, StatementNode * then, StatementNode * else_ );
[6a276a0]415Statement * build_switch( bool isSwitch, ExpressionNode * ctl, StatementNode * stmt );
[b6424d9]416Statement * build_case( ExpressionNode * ctl );
417Statement * build_default();
[436bbe5]418Statement * build_while( CondCtl * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
419Statement * build_do_while( ExpressionNode * ctl, StatementNode * stmt, StatementNode * else_ = nullptr );
420Statement * build_for( ForCtrl * forctl, StatementNode * stmt, StatementNode * else_ = nullptr );
[b6424d9]421Statement * build_branch( BranchStmt::Type kind );
422Statement * build_branch( std::string * identifier, BranchStmt::Type kind );
423Statement * build_computedgoto( ExpressionNode * ctl );
424Statement * build_return( ExpressionNode * ctl );
425Statement * build_throw( ExpressionNode * ctl );
[daf1af8]426Statement * build_resume( ExpressionNode * ctl );
427Statement * build_resume_at( ExpressionNode * ctl , ExpressionNode * target );
[436bbe5]428Statement * build_try( StatementNode * try_, StatementNode * catch_, StatementNode * finally_ );
429Statement * build_catch( CatchStmt::Kind kind, DeclarationNode * decl, ExpressionNode * cond, StatementNode * body );
[b6424d9]430Statement * build_finally( StatementNode * stmt );
431Statement * build_compound( StatementNode * first );
[a025ea8]432StatementNode * maybe_build_compound( StatementNode * first );
[6d539f83]433Statement * build_asm( bool voltile, Expression * instruction, ExpressionNode * output = nullptr, ExpressionNode * input = nullptr, ExpressionNode * clobber = nullptr, LabelNode * gotolabels = nullptr );
434Statement * build_directive( std::string * directive );
[427854b]435SuspendStmt * build_suspend( StatementNode *, SuspendStmt::Type = SuspendStmt::None);
[135b431]436WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when );
437WaitForStmt * build_waitfor( ExpressionNode * target, StatementNode * stmt, ExpressionNode * when, WaitForStmt * existing );
438WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when );
439WaitForStmt * build_waitfor_timeout( ExpressionNode * timeout, StatementNode * stmt, ExpressionNode * when, StatementNode * else_stmt, ExpressionNode * else_when );
[e67991f]440Statement * build_with( ExpressionNode * exprs, StatementNode * stmt );
[6cebfef]441Statement * build_mutex( ExpressionNode * exprs, StatementNode * stmt );
[7f5566b]442
[7bf7fb9]443//##############################################################################
444
[aefcc3b]445template< typename SynTreeType, typename NodeType, template< typename, typename...> class Container, typename... Args >
[f2f512ba]446void buildList( const NodeType * firstNode, Container< SynTreeType *, Args... > & outputList ) {
[a16764a6]447 SemanticErrorException errors;
[aefcc3b]448 std::back_insert_iterator< Container< SynTreeType *, Args... > > out( outputList );
[b6424d9]449 const NodeType * cur = firstNode;
[b87a5ed]450
451 while ( cur ) {
452 try {
[b6424d9]453 SynTreeType * result = dynamic_cast< SynTreeType * >( maybeBuild< typename std::pointer_traits< decltype(cur->build())>::element_type >( cur ) );
[b87a5ed]454 if ( result ) {
[294647b]455 result->location = cur->location;
[b6424d9]456 * out++ = result;
[046e04a]457 } else {
[3e274ab]458 SemanticError( cur->location, "type specifier declaration in forall clause is currently unimplemented." );
[b87a5ed]459 } // if
[f2f512ba]460 } catch( SemanticErrorException & e ) {
[b87a5ed]461 errors.append( e );
462 } // try
[4678c1ec]463 const ParseNode * temp = (cur->get_next());
464 cur = dynamic_cast< const NodeType * >( temp ); // should not return nullptr
465 if ( ! cur && temp ) { // non-homogeneous nodes ?
[82ff4ed1]466 SemanticError( temp->location, "internal error, non-homogeneous nodes founds in buildList processing." );
[4678c1ec]467 } // if
[b87a5ed]468 } // while
[a32b204]469 if ( ! errors.isEmpty() ) {
[b87a5ed]470 throw errors;
471 } // if
[51b73452]472}
473
474// in DeclarationNode.cc
[f2f512ba]475void buildList( const DeclarationNode * firstNode, std::list< Declaration * > & outputList );
476void buildList( const DeclarationNode * firstNode, std::list< DeclarationWithType * > & outputList );
477void buildTypeList( const DeclarationNode * firstNode, std::list< Type * > & outputList );
[51b73452]478
[7ecbb7e]479template< typename SynTreeType, typename NodeType >
[f2f512ba]480void buildMoveList( const NodeType * firstNode, std::list< SynTreeType * > & outputList ) {
[3a5131ed]481 buildList( firstNode, outputList );
[7ecbb7e]482 delete firstNode;
483}
484
[c8dfcd3]485// in ParseNode.cc
486std::ostream & operator<<( std::ostream & out, const ParseNode * node );
[7ecbb7e]487
[51b73452]488// Local Variables: //
[b87a5ed]489// tab-width: 4 //
490// mode: c++ //
491// compile-command: "make install" //
[51b73452]492// End: //
Note: See TracBrowser for help on using the repository browser.