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 | |
---|
20 | class InitializerNode; |
---|
21 | |
---|
22 | class ExpressionNode final : public ParseNode { |
---|
23 | public: |
---|
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; |
---|
52 | private: |
---|
53 | bool extension = false; |
---|
54 | }; // ExpressionNode |
---|
55 | |
---|
56 | /* |
---|
57 | // Must harmonize with OperName. |
---|
58 | enum 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 | |
---|
69 | enum class EnumHiding { Visible, Hide }; |
---|
70 | |
---|
71 | struct LabelNode { |
---|
72 | std::vector<ast::Label> labels; |
---|
73 | }; |
---|
74 | */ |
---|
75 | |
---|
76 | // These 4 routines modify the string: |
---|
77 | ast::Expr * build_constantInteger( const CodeLocation &, std::string & ); |
---|
78 | ast::Expr * build_constantFloat( const CodeLocation &, std::string & ); |
---|
79 | ast::Expr * build_constantChar( const CodeLocation &, std::string & ); |
---|
80 | ast::Expr * build_constantStr( const CodeLocation &, std::string & ); |
---|
81 | ast::Expr * build_field_name_FLOATING_FRACTIONconstant( const CodeLocation &, const std::string & str ); |
---|
82 | ast::Expr * build_field_name_FLOATING_DECIMALconstant( const CodeLocation &, const std::string & str ); |
---|
83 | ast::Expr * build_field_name_FLOATINGconstant( const CodeLocation &, const std::string & str ); |
---|
84 | ast::Expr * build_field_name_fraction_constants( const CodeLocation &, ast::Expr * fieldName, ExpressionNode * fracts ); |
---|
85 | |
---|
86 | ast::NameExpr * build_varref( const CodeLocation &, const std::string * name ); |
---|
87 | ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const DeclarationNode * decl_node, const ast::NameExpr * name ); |
---|
88 | ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const ast::EnumDecl * decl, const ast::NameExpr * name ); |
---|
89 | ast::DimensionExpr * build_dimensionref( const CodeLocation &, const std::string * name ); |
---|
90 | |
---|
91 | ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node ); |
---|
92 | ast::Expr * build_keyword_cast( const CodeLocation &, ast::AggregateDecl::Aggregate target, ExpressionNode * expr_node ); |
---|
93 | ast::Expr * build_virtual_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node ); |
---|
94 | ast::Expr * build_fieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member ); |
---|
95 | ast::Expr * build_pfieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member ); |
---|
96 | ast::Expr * build_offsetOf( const CodeLocation &, DeclarationNode * decl_node, ast::NameExpr * member ); |
---|
97 | ast::Expr * build_and( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); |
---|
98 | ast::Expr * build_and_or( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ast::LogicalFlag flag ); |
---|
99 | ast::Expr * build_unary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node ); |
---|
100 | ast::Expr * build_binary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); |
---|
101 | ast::Expr * build_binary_ptr( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 ); |
---|
102 | ast::Expr * build_cond( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 ); |
---|
103 | ast::Expr * build_tuple( const CodeLocation &, ExpressionNode * expr_node = nullptr ); |
---|
104 | ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node ); |
---|
105 | ast::Expr * build_compoundLiteral( const CodeLocation &, DeclarationNode * decl_node, InitializerNode * kids ); |
---|