source: src/Parser/ParseNode.h @ 0a6d2045

Last change on this file since 0a6d2045 was b1f2007, checked in by Peter A. Buhr <pabuhr@…>, 7 months ago

first attempt at simplifying SemanticError? and its usage

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