| 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 : Andrew Beach
 | 
|---|
| 12 | // Last Modified On : Mon Apr  3 17:55:00 2023
 | 
|---|
| 13 | // Update Count     : 942
 | 
|---|
| 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 | class Attribute;
 | 
|---|
| 36 | class Declaration;
 | 
|---|
| 37 | struct DeclarationNode;
 | 
|---|
| 38 | class DeclarationWithType;
 | 
|---|
| 39 | class Initializer;
 | 
|---|
| 40 | class InitializerNode;
 | 
|---|
| 41 | class ExpressionNode;
 | 
|---|
| 42 | struct StatementNode;
 | 
|---|
| 43 | 
 | 
|---|
| 44 | //##############################################################################
 | 
|---|
| 45 | 
 | 
|---|
| 46 | typedef CodeLocation YYLTYPE;
 | 
|---|
| 47 | #define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
 | 
|---|
| 48 | 
 | 
|---|
| 49 | extern YYLTYPE yylloc;
 | 
|---|
| 50 | 
 | 
|---|
| 51 | class ParseNode {
 | 
|---|
| 52 |   public:
 | 
|---|
| 53 |         ParseNode() {};
 | 
|---|
| 54 |         virtual ~ParseNode() { delete next; delete name; };
 | 
|---|
| 55 |         virtual ParseNode * clone() const = 0;
 | 
|---|
| 56 | 
 | 
|---|
| 57 |         ParseNode * get_next() const { return next; }
 | 
|---|
| 58 |         ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; }
 | 
|---|
| 59 | 
 | 
|---|
| 60 |         ParseNode * get_last() {
 | 
|---|
| 61 |                 ParseNode * current;
 | 
|---|
| 62 |                 for ( current = this; current->get_next() != nullptr; current = current->get_next() );
 | 
|---|
| 63 |                 return current;
 | 
|---|
| 64 |         }
 | 
|---|
| 65 |         ParseNode * set_last( ParseNode * newlast ) {
 | 
|---|
| 66 |                 if ( newlast != nullptr ) get_last()->set_next( newlast );
 | 
|---|
| 67 |                 return this;
 | 
|---|
| 68 |         }
 | 
|---|
| 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 {
 | 
|---|
| 72 |                 print( os, indent );
 | 
|---|
| 73 |                 if ( next ) next->print( os, indent );
 | 
|---|
| 74 |         }
 | 
|---|
| 75 | 
 | 
|---|
| 76 |         static int indent_by;
 | 
|---|
| 77 | 
 | 
|---|
| 78 |         ParseNode * next = nullptr;
 | 
|---|
| 79 |         const std::string * name = nullptr;
 | 
|---|
| 80 |         CodeLocation location = yylloc;
 | 
|---|
| 81 | }; // ParseNode
 | 
|---|
| 82 | 
 | 
|---|
| 83 | // Must harmonize with OperName.
 | 
|---|
| 84 | enum class OperKinds {
 | 
|---|
| 85 |         // diadic
 | 
|---|
| 86 |         SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And,
 | 
|---|
| 87 |         BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
 | 
|---|
| 88 |         Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
 | 
|---|
| 89 |         Index, Range,
 | 
|---|
| 90 |         // monadic
 | 
|---|
| 91 |         UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
 | 
|---|
| 92 |         Ctor, Dtor,
 | 
|---|
| 93 | }; // OperKinds
 | 
|---|
| 94 | 
 | 
|---|
| 95 | enum class EnumHiding { Visible, Hide };
 | 
|---|
| 96 | 
 | 
|---|
| 97 | struct LabelNode {
 | 
|---|
| 98 |         std::vector<ast::Label> labels;
 | 
|---|
| 99 | };
 | 
|---|
| 100 | 
 | 
|---|
| 101 | std::ostream & operator<<( std::ostream & out, const ParseNode * node );
 | 
|---|
| 102 | 
 | 
|---|
| 103 | // Local Variables: //
 | 
|---|
| 104 | // tab-width: 4 //
 | 
|---|
| 105 | // mode: c++ //
 | 
|---|
| 106 | // compile-command: "make install" //
 | 
|---|
| 107 | // End: //
 | 
|---|