[c468150] | 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 |
|
---|
[6611177] | 43 | ast::Expr * build() {
|
---|
| 44 | ast::Expr * node = expr.release();
|
---|
[c468150] | 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 | // These 4 routines modify the string:
|
---|
| 57 | ast::Expr * build_constantInteger( const CodeLocation &, std::string & );
|
---|
| 58 | ast::Expr * build_constantFloat( const CodeLocation &, std::string & );
|
---|
| 59 | ast::Expr * build_constantChar( const CodeLocation &, std::string & );
|
---|
| 60 | ast::Expr * build_constantStr( const CodeLocation &, std::string & );
|
---|
| 61 | ast::Expr * build_field_name_FLOATING_FRACTIONconstant( const CodeLocation &, const std::string & str );
|
---|
| 62 | ast::Expr * build_field_name_FLOATING_DECIMALconstant( const CodeLocation &, const std::string & str );
|
---|
| 63 | ast::Expr * build_field_name_FLOATINGconstant( const CodeLocation &, const std::string & str );
|
---|
| 64 | ast::Expr * build_field_name_fraction_constants( const CodeLocation &, ast::Expr * fieldName, ExpressionNode * fracts );
|
---|
| 65 |
|
---|
| 66 | ast::NameExpr * build_varref( const CodeLocation &, const std::string * name );
|
---|
| 67 | ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const DeclarationNode * decl_node, const ast::NameExpr * name );
|
---|
| 68 | ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const ast::EnumDecl * decl, const ast::NameExpr * name );
|
---|
| 69 | ast::DimensionExpr * build_dimensionref( const CodeLocation &, const std::string * name );
|
---|
| 70 |
|
---|
| 71 | ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
|
---|
| 72 | ast::Expr * build_keyword_cast( const CodeLocation &, ast::AggregateDecl::Aggregate target, ExpressionNode * expr_node );
|
---|
| 73 | ast::Expr * build_virtual_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
|
---|
| 74 | ast::Expr * build_fieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
|
---|
| 75 | ast::Expr * build_pfieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
|
---|
| 76 | ast::Expr * build_offsetOf( const CodeLocation &, DeclarationNode * decl_node, ast::NameExpr * member );
|
---|
| 77 | ast::Expr * build_and( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
---|
| 78 | ast::Expr * build_and_or( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ast::LogicalFlag flag );
|
---|
| 79 | ast::Expr * build_unary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node );
|
---|
| 80 | ast::Expr * build_binary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
|
---|
| 81 | ast::Expr * build_cond( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
|
---|
| 82 | ast::Expr * build_tuple( const CodeLocation &, ExpressionNode * expr_node = nullptr );
|
---|
| 83 | ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node );
|
---|
| 84 | ast::Expr * build_compoundLiteral( const CodeLocation &, DeclarationNode * decl_node, InitializerNode * kids );
|
---|