[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 | // |
---|
[c92bdcc] | 7 | // ParseNode.hpp -- |
---|
[b87a5ed] | 8 | // |
---|
| 9 | // Author : Rodolfo G. Esteves |
---|
| 10 | // Created On : Sat May 16 13:28:16 2015 |
---|
[b1f2007] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Sat Dec 9 17:39:34 2023 |
---|
| 13 | // Update Count : 945 |
---|
[b87a5ed] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[c92bdcc] | 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 |
---|
| 25 | |
---|
| 26 | #include "AST/Expr.hpp" // for Expr, NameExpr, LogicalFlag |
---|
| 27 | #include "AST/Fwd.hpp" // for ptr, Decl, DeclWithType, |
---|
| 28 | #include "AST/Stmt.hpp" // for Stmt |
---|
| 29 | #include "Common/CodeLocation.hpp" // for CodeLocation |
---|
| 30 | #include "Common/SemanticError.hpp" // for SemanticError |
---|
| 31 | #include "Common/UniqueName.hpp" // for UniqueName |
---|
| 32 | #include "Parser/ParserUtility.hpp" // for maybeBuild, maybeCopy |
---|
[d180746] | 33 | |
---|
[b2e0df3] | 34 | struct DeclarationNode; |
---|
[dc3fbe5] | 35 | struct InitializerNode; |
---|
| 36 | struct ExpressionNode; |
---|
[b2e0df3] | 37 | struct StatementNode; |
---|
[51b7345] | 38 | |
---|
[b1f2007] | 39 | |
---|
[7880579] | 40 | //############################################################################## |
---|
| 41 | |
---|
[d48e529] | 42 | typedef CodeLocation YYLTYPE; |
---|
| 43 | #define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */ |
---|
| 44 | |
---|
| 45 | extern YYLTYPE yylloc; |
---|
[294647b] | 46 | |
---|
[dc3fbe5] | 47 | struct ParseNode { |
---|
| 48 | ParseNode() {} |
---|
| 49 | virtual ~ParseNode() {} |
---|
[b6424d9] | 50 | virtual ParseNode * clone() const = 0; |
---|
[51b7345] | 51 | |
---|
[dc3fbe5] | 52 | virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} |
---|
| 53 | |
---|
| 54 | static int indent_by; |
---|
| 55 | |
---|
| 56 | CodeLocation location = yylloc; |
---|
| 57 | }; // ParseNode |
---|
| 58 | |
---|
| 59 | /// Only ever use in the form `struct NAME final : public ParseList<NAME>`! |
---|
| 60 | template<typename Next> |
---|
| 61 | struct ParseList : public ParseNode { |
---|
| 62 | ParseList() {} |
---|
| 63 | virtual ~ParseList() { delete next; }; |
---|
| 64 | virtual ParseList<Next> * clone() const = 0; |
---|
[1b772749] | 65 | |
---|
[dc3fbe5] | 66 | Next * get_last() { |
---|
| 67 | Next * current = static_cast<Next *>( this ); |
---|
| 68 | while ( current->next != nullptr ) current = current->next; |
---|
[99cad3aa] | 69 | return current; |
---|
| 70 | } |
---|
[dc3fbe5] | 71 | Next * set_last( Next * newlast ) { |
---|
| 72 | if ( newlast != nullptr ) get_last()->next = newlast; |
---|
| 73 | return static_cast<Next *>( this ); |
---|
[99cad3aa] | 74 | } |
---|
[51b7345] | 75 | |
---|
[f2f512ba] | 76 | virtual void printList( std::ostream & os, int indent = 0 ) const { |
---|
[e4bc986] | 77 | print( os, indent ); |
---|
| 78 | if ( next ) next->print( os, indent ); |
---|
| 79 | } |
---|
[1b772749] | 80 | |
---|
[dc3fbe5] | 81 | Next * next = nullptr; |
---|
| 82 | }; |
---|
[51b7345] | 83 | |
---|
[4a72fef] | 84 | template<typename Node> |
---|
| 85 | void extend( Node *& list, Node * value ) { |
---|
| 86 | if ( list ) { |
---|
| 87 | extend( list->next, value ); |
---|
| 88 | } else { |
---|
| 89 | list = value; |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | |
---|
[e5f2a67] | 93 | // Must harmonize with OperName. |
---|
[d9e2280] | 94 | enum class OperKinds { |
---|
| 95 | // diadic |
---|
[e5f2a67] | 96 | SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And, |
---|
[d9e2280] | 97 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, |
---|
[e5f2a67] | 98 | Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, |
---|
[d9e2280] | 99 | Index, Range, |
---|
| 100 | // monadic |
---|
[5809461] | 101 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, |
---|
[d9e2280] | 102 | Ctor, Dtor, |
---|
[c1c1112] | 103 | }; // OperKinds |
---|
[51b7345] | 104 | |
---|
[7cf8006] | 105 | enum class EnumHiding { Visible, Hide }; |
---|
| 106 | |
---|
[e82aa9df] | 107 | struct LabelNode { |
---|
[bb7422a] | 108 | std::vector<ast::Label> labels; |
---|
[e82aa9df] | 109 | }; |
---|
| 110 | |
---|
[c8dfcd3] | 111 | std::ostream & operator<<( std::ostream & out, const ParseNode * node ); |
---|
[7ecbb7e] | 112 | |
---|
[b1f2007] | 113 | __attribute__((noreturn)) static inline void SemanticError( const ParseNode * obj, const std::string & error ) { |
---|
| 114 | SemanticError( obj->location, toString( error, obj ) ); |
---|
| 115 | } |
---|
| 116 | |
---|
[51b7345] | 117 | // Local Variables: // |
---|
[b87a5ed] | 118 | // tab-width: 4 // |
---|
| 119 | // mode: c++ // |
---|
| 120 | // compile-command: "make install" // |
---|
[51b7345] | 121 | // End: // |
---|