source: src/Parser/ParseNode.h @ 647e2ea

Last change on this file since 647e2ea was dc3fbe5, checked in by Andrew Beach <ajbeach@…>, 3 months ago

Factored out the ParseNode?'s next field into a new child type. This is only type safe when used in the given one level curiously reoccurring template pattern, as it is now. This allowed most of the intermedate helpers to be removed.

  • Property mode set to 100644
File size: 3.5 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;
35struct InitializerNode;
36struct 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
47struct ParseNode {
48        ParseNode() {}
49        virtual ~ParseNode() {}
50        virtual ParseNode * clone() const = 0;
51
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>`!
60template<typename Next>
61struct ParseList : public ParseNode {
62        ParseList() {}
63        virtual ~ParseList() { delete next; };
64        virtual ParseList<Next> * clone() const = 0;
65
66        Next * get_next() const { return next; }
67        void set_next( Next * newlink ) { next = newlink; }
68
69        Next * get_last() {
70                Next * current = static_cast<Next *>( this );
71                while ( current->next != nullptr ) current = current->next;
72                return current;
73        }
74        Next * set_last( Next * newlast ) {
75                if ( newlast != nullptr ) get_last()->next = newlast;
76                return static_cast<Next *>( this );
77        }
78
79        virtual void printList( std::ostream & os, int indent = 0 ) const {
80                print( os, indent );
81                if ( next ) next->print( os, indent );
82        }
83
84        Next * next = nullptr;
85};
86
87// Must harmonize with OperName.
88enum class OperKinds {
89        // diadic
90        SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And,
91        BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
92        Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
93        Index, Range,
94        // monadic
95        UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
96        Ctor, Dtor,
97}; // OperKinds
98
99enum class EnumHiding { Visible, Hide };
100
101struct LabelNode {
102        std::vector<ast::Label> labels;
103};
104
105std::ostream & operator<<( std::ostream & out, const ParseNode * node );
106
107__attribute__((noreturn)) static inline void SemanticError( const ParseNode * obj, const std::string & error ) {
108        SemanticError( obj->location, toString( error, obj ) );
109}
110
111// Local Variables: //
112// tab-width: 4 //
113// mode: c++ //
114// compile-command: "make install" //
115// End: //
Note: See TracBrowser for help on using the repository browser.