source: src/Parser/ParseNode.h @ 4c0b674

Last change on this file since 4c0b674 was 4c0b674, checked in by Andrew Beach <ajbeach@…>, 2 months ago

Moved ParseNode?'s name field down to DeclarationNode?, it is not used in any of the other child classes.

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