source: src/Parser/ExpressionNode.h @ 16dff44

ADTast-experimental
Last change on this file since 16dff44 was c468150, checked in by Andrew Beach <ajbeach@…>, 18 months ago

Split up ParseNode?.h so that headers match implementation. May have a bit less to include total because of it.

  • Property mode set to 100644
File size: 5.0 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// ExpressionNode.h --
8//
9// Author           : Andrew Beach
10// Created On       : Wed Apr  5 11:34:00 2023
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Apr  5 11:50:00 2023
13// Update Count     : 0
14//
15
16#pragma once
17
18#include "ParseNode.h"
19
20class InitializerNode;
21
22class ExpressionNode final : public ParseNode {
23public:
24        ExpressionNode( ast::Expr * expr = nullptr ) : expr( expr ) {}
25        virtual ~ExpressionNode() {}
26        virtual ExpressionNode * clone() const override {
27                if ( nullptr == expr ) return nullptr;
28                return static_cast<ExpressionNode*>(
29                        (new ExpressionNode( ast::shallowCopy( expr.get() ) ))->set_next( maybeCopy( get_next() ) ));
30        }
31
32        bool get_extension() const { return extension; }
33        ExpressionNode * set_extension( bool exten ) { extension = exten; return this; }
34
35        virtual void print( std::ostream & os, __attribute__((unused)) int indent = 0 ) const override {
36                os << expr.get();
37        }
38        void printOneLine( __attribute__((unused)) std::ostream & os, __attribute__((unused)) int indent = 0 ) const {}
39
40        template<typename T>
41        bool isExpressionType() const {  return nullptr != dynamic_cast<T>(expr.get()); }
42
43        ast::Expr * build() const {
44                ast::Expr * node = const_cast<ExpressionNode *>(this)->expr.release();
45                node->set_extension( this->get_extension() );
46                node->location = this->location;
47                return node;
48        }
49
50        // Public because of lifetime implications (what lifetime implications?)
51        std::unique_ptr<ast::Expr> expr;
52private:
53        bool extension = false;
54}; // ExpressionNode
55
56/*
57// Must harmonize with OperName.
58enum class OperKinds {
59    // diadic
60    SizeOf, AlignOf, OffsetOf, Plus, Minus, Exp, Mul, Div, Mod, Or, And,
61    BitOr, BitAnd, Xor, Cast, LShift, RShift, LThan, GThan, LEThan, GEThan, Eq, Neq,
62    Assign, AtAssn, ExpAssn, MulAssn, DivAssn, ModAssn, PlusAssn, MinusAssn, LSAssn, RSAssn, AndAssn, ERAssn, OrAssn,
63    Index, Range,
64    // monadic
65    UnPlus, UnMinus, AddressOf, PointTo, Neg, BitNeg, Incr, IncrPost, Decr, DecrPost,
66    Ctor, Dtor,
67}; // OperKinds
68
69enum class EnumHiding { Visible, Hide };
70
71struct LabelNode {
72    std::vector<ast::Label> labels;
73};
74*/
75
76// These 4 routines modify the string:
77ast::Expr * build_constantInteger( const CodeLocation &, std::string & );
78ast::Expr * build_constantFloat( const CodeLocation &, std::string & );
79ast::Expr * build_constantChar( const CodeLocation &, std::string & );
80ast::Expr * build_constantStr( const CodeLocation &, std::string & );
81ast::Expr * build_field_name_FLOATING_FRACTIONconstant( const CodeLocation &, const std::string & str );
82ast::Expr * build_field_name_FLOATING_DECIMALconstant( const CodeLocation &, const std::string & str );
83ast::Expr * build_field_name_FLOATINGconstant( const CodeLocation &, const std::string & str );
84ast::Expr * build_field_name_fraction_constants( const CodeLocation &, ast::Expr * fieldName, ExpressionNode * fracts );
85
86ast::NameExpr * build_varref( const CodeLocation &, const std::string * name );
87ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const DeclarationNode * decl_node, const ast::NameExpr * name );
88ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const ast::EnumDecl * decl, const ast::NameExpr * name );
89ast::DimensionExpr * build_dimensionref( const CodeLocation &, const std::string * name );
90
91ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
92ast::Expr * build_keyword_cast( const CodeLocation &, ast::AggregateDecl::Aggregate target, ExpressionNode * expr_node );
93ast::Expr * build_virtual_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
94ast::Expr * build_fieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
95ast::Expr * build_pfieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
96ast::Expr * build_offsetOf( const CodeLocation &, DeclarationNode * decl_node, ast::NameExpr * member );
97ast::Expr * build_and( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
98ast::Expr * build_and_or( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ast::LogicalFlag flag );
99ast::Expr * build_unary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node );
100ast::Expr * build_binary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
101ast::Expr * build_binary_ptr( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
102ast::Expr * build_cond( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
103ast::Expr * build_tuple( const CodeLocation &, ExpressionNode * expr_node = nullptr );
104ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node );
105ast::Expr * build_compoundLiteral( const CodeLocation &, DeclarationNode * decl_node, InitializerNode * kids );
Note: See TracBrowser for help on using the repository browser.