source: src/Parser/ParseNode.h@ f2898df

Last change on this file since f2898df was 5bf685f, checked in by Andrew Beach <ajbeach@…>, 20 months ago

Replayed maybeClone with maybeCopy, removed unused helppers in utility.h and pushed some includes out of headers.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[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//
[974906e2]7// ParseNode.h --
[b87a5ed]8//
9// Author : Rodolfo G. Esteves
10// Created On : Sat May 16 13:28:16 2015
[b1f2007d]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
[51b73452]17
[d180746]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
[51b73452]25
[bb7422a]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
[21f0aa8]29#include "Common/CodeLocation.h" // for CodeLocation
[d180746]30#include "Common/SemanticError.h" // for SemanticError
[be9288a]31#include "Common/UniqueName.h" // for UniqueName
[bb7422a]32#include "Parser/parserutility.h" // for maybeBuild, maybeCopy
[d180746]33
[b2e0df3]34struct DeclarationNode;
[c468150]35class InitializerNode;
[a6e5091]36class ExpressionNode;
[b2e0df3]37struct StatementNode;
[51b73452]38
[b1f2007d]39
[7880579]40//##############################################################################
41
[d48e529]42typedef CodeLocation YYLTYPE;
43#define YYLTYPE_IS_DECLARED 1 /* alert the parser that we have our own definition */
44
45extern YYLTYPE yylloc;
[294647b]46
[51b73452]47class ParseNode {
[bdd516a]48 public:
[99cad3aa]49 ParseNode() {};
[2298f728]50 virtual ~ParseNode() { delete next; delete name; };
[b6424d9]51 virtual ParseNode * clone() const = 0;
[51b73452]52
[b6424d9]53 ParseNode * get_next() const { return next; }
54 ParseNode * set_next( ParseNode * newlink ) { next = newlink; return this; }
[1b772749]55
[b6424d9]56 ParseNode * get_last() {
57 ParseNode * current;
[2298f728]58 for ( current = this; current->get_next() != nullptr; current = current->get_next() );
[99cad3aa]59 return current;
60 }
[b6424d9]61 ParseNode * set_last( ParseNode * newlast ) {
[2298f728]62 if ( newlast != nullptr ) get_last()->set_next( newlast );
[99cad3aa]63 return this;
64 }
[51b73452]65
[f2f512ba]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 {
[e4bc986]68 print( os, indent );
69 if ( next ) next->print( os, indent );
70 }
[1b772749]71
[b87a5ed]72 static int indent_by;
[7880579]73
[b6424d9]74 ParseNode * next = nullptr;
[25bca42]75 const std::string * name = nullptr;
[d48e529]76 CodeLocation location = yylloc;
[7880579]77}; // ParseNode
[51b73452]78
[e5f2a67]79// Must harmonize with OperName.
[d9e2280]80enum class OperKinds {
81 // diadic
[e5f2a67]82 SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And,
[d9e2280]83 BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
[e5f2a67]84 Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
[d9e2280]85 Index, Range,
86 // monadic
[5809461]87 UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
[d9e2280]88 Ctor, Dtor,
[c1c1112]89}; // OperKinds
[51b73452]90
[7cf8006]91enum class EnumHiding { Visible, Hide };
92
[e82aa9df]93struct LabelNode {
[bb7422a]94 std::vector<ast::Label> labels;
[e82aa9df]95};
96
[c8dfcd3]97std::ostream & operator<<( std::ostream & out, const ParseNode * node );
[7ecbb7e]98
[b1f2007d]99__attribute__((noreturn)) static inline void SemanticError( const ParseNode * obj, const std::string & error ) {
100 SemanticError( obj->location, toString( error, obj ) );
101}
102
[51b73452]103// Local Variables: //
[b87a5ed]104// tab-width: 4 //
105// mode: c++ //
106// compile-command: "make install" //
[51b73452]107// End: //
Note: See TracBrowser for help on using the repository browser.