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