source: src/Parser/ExpressionNode.h @ 924534e

Last change on this file since 924534e was dc3fbe5, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Factored out the ParseNode?'s next field into a new child type. This is only type safe when used in the given one level curiously reoccurring template pattern, as it is now. This allowed most of the intermedate helpers to be removed.

  • Property mode set to 100644
File size: 4.4 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
20struct InitializerNode;
21
22struct ExpressionNode final : public ParseList<ExpressionNode> {
23        ExpressionNode( ast::Expr * expr = nullptr ) : expr( expr ) {}
24        virtual ~ExpressionNode() {}
25        virtual ExpressionNode * clone() const override {
26                if ( nullptr == expr ) return nullptr;
27                ExpressionNode * node = new ExpressionNode( ast::shallowCopy( expr.get() ) );
28                node->set_next( maybeCopy( get_next() ) );
29                return node;
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() {
44                ast::Expr * node = 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// These 4 routines modify the string:
57ast::Expr * build_constantInteger( const CodeLocation &, std::string & );
58ast::Expr * build_constantFloat( const CodeLocation &, std::string & );
59ast::Expr * build_constantChar( const CodeLocation &, std::string & );
60ast::Expr * build_constantStr( const CodeLocation &, std::string & );
61ast::Expr * build_field_name_FLOATING_FRACTIONconstant( const CodeLocation &, const std::string & str );
62ast::Expr * build_field_name_FLOATING_DECIMALconstant( const CodeLocation &, const std::string & str );
63ast::Expr * build_field_name_FLOATINGconstant( const CodeLocation &, const std::string & str );
64ast::Expr * build_field_name_fraction_constants( const CodeLocation &, ast::Expr * fieldName, ExpressionNode * fracts );
65
66ast::NameExpr * build_varref( const CodeLocation &, const std::string * name );
67ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const DeclarationNode * decl_node, const ast::NameExpr * name );
68ast::QualifiedNameExpr * build_qualified_expr( const CodeLocation &, const ast::EnumDecl * decl, const ast::NameExpr * name );
69ast::DimensionExpr * build_dimensionref( const CodeLocation &, const std::string * name );
70
71ast::Expr * build_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node, ast::CastExpr::CastKind kind = ast::CastExpr::Default );
72ast::Expr * build_keyword_cast( const CodeLocation &, ast::AggregateDecl::Aggregate target, ExpressionNode * expr_node );
73ast::Expr * build_virtual_cast( const CodeLocation &, DeclarationNode * decl_node, ExpressionNode * expr_node );
74ast::Expr * build_fieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
75ast::Expr * build_pfieldSel( const CodeLocation &, ExpressionNode * expr_node, ast::Expr * member );
76ast::Expr * build_offsetOf( const CodeLocation &, DeclarationNode * decl_node, ast::NameExpr * member );
77ast::Expr * build_and( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
78ast::Expr * build_and_or( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ast::LogicalFlag flag );
79ast::Expr * build_unary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node );
80ast::Expr * build_binary_val( const CodeLocation &, OperKinds op, ExpressionNode * expr_node1, ExpressionNode * expr_node2 );
81ast::Expr * build_cond( const CodeLocation &, ExpressionNode * expr_node1, ExpressionNode * expr_node2, ExpressionNode * expr_node3 );
82ast::Expr * build_tuple( const CodeLocation &, ExpressionNode * expr_node = nullptr );
83ast::Expr * build_func( const CodeLocation &, ExpressionNode * function, ExpressionNode * expr_node );
84ast::Expr * build_compoundLiteral( const CodeLocation &, DeclarationNode * decl_node, InitializerNode * kids );
85
86ast::Expr * build_enum_pos_expr( const CodeLocation &, ast::Expr * expr_node );
Note: See TracBrowser for help on using the repository browser.