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 | // |
---|
7 | // ParseNode.h -- |
---|
8 | // |
---|
9 | // Author : Rodolfo G. Esteves |
---|
10 | // Created On : Sat May 16 13:28:16 2015 |
---|
11 | // Last Modified By : Peter A. Buhr |
---|
12 | // Last Modified On : Sat Dec 9 17:39:34 2023 |
---|
13 | // Update Count : 945 |
---|
14 | // |
---|
15 | |
---|
16 | #pragma once |
---|
17 | |
---|
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.h" // for CodeLocation |
---|
30 | #include "Common/SemanticError.h" // for SemanticError |
---|
31 | #include "Common/UniqueName.h" // for UniqueName |
---|
32 | #include "Common/utility.h" // for maybeClone |
---|
33 | #include "Parser/parserutility.h" // for maybeBuild, maybeCopy |
---|
34 | |
---|
35 | struct DeclarationNode; |
---|
36 | class InitializerNode; |
---|
37 | class ExpressionNode; |
---|
38 | struct StatementNode; |
---|
39 | |
---|
40 | |
---|
41 | //############################################################################## |
---|
42 | |
---|
43 | typedef CodeLocation YYLTYPE; |
---|
44 | #define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */ |
---|
45 | |
---|
46 | extern YYLTYPE yylloc; |
---|
47 | |
---|
48 | class ParseNode { |
---|
49 | public: |
---|
50 | ParseNode() {}; |
---|
51 | virtual ~ParseNode() { delete next; delete name; }; |
---|
52 | virtual ParseNode * clone() const = 0; |
---|
53 | |
---|
54 | ParseNode * get_next() const { return next; } |
---|
55 | ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; } |
---|
56 | |
---|
57 | ParseNode * get_last() { |
---|
58 | ParseNode * current; |
---|
59 | for ( current = this; current->get_next() != nullptr; current = current->get_next() ); |
---|
60 | return current; |
---|
61 | } |
---|
62 | ParseNode * set_last( ParseNode * newlast ) { |
---|
63 | if ( newlast != nullptr ) get_last()->set_next( newlast ); |
---|
64 | return this; |
---|
65 | } |
---|
66 | |
---|
67 | virtual void print( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {} |
---|
68 | virtual void printList( std::ostream & os, int indent = 0 ) const { |
---|
69 | print( os, indent ); |
---|
70 | if ( next ) next->print( os, indent ); |
---|
71 | } |
---|
72 | |
---|
73 | static int indent_by; |
---|
74 | |
---|
75 | ParseNode * next = nullptr; |
---|
76 | const std::string * name = nullptr; |
---|
77 | CodeLocation location = yylloc; |
---|
78 | }; // ParseNode |
---|
79 | |
---|
80 | // Must harmonize with OperName. |
---|
81 | enum class OperKinds { |
---|
82 | // diadic |
---|
83 | SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And, |
---|
84 | BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq, |
---|
85 | Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn, |
---|
86 | Index, Range, |
---|
87 | // monadic |
---|
88 | UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost, |
---|
89 | Ctor, Dtor, |
---|
90 | }; // OperKinds |
---|
91 | |
---|
92 | enum class EnumHiding { Visible, Hide }; |
---|
93 | |
---|
94 | struct LabelNode { |
---|
95 | std::vector<ast::Label> labels; |
---|
96 | }; |
---|
97 | |
---|
98 | std::ostream & operator<<( std::ostream & out, const ParseNode * node ); |
---|
99 | |
---|
100 | __attribute__((noreturn)) static inline void SemanticError( const ParseNode * obj, const std::string & error ) { |
---|
101 | SemanticError( obj->location, toString( error, obj ) ); |
---|
102 | } |
---|
103 | |
---|
104 | // Local Variables: // |
---|
105 | // tab-width: 4 // |
---|
106 | // mode: c++ // |
---|
107 | // compile-command: "make install" // |
---|
108 | // End: // |
---|