aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r--gcc/go/gofrontend/expressions.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index 707c193..a1e3733 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -28,6 +28,7 @@ class Map_type;
class Struct_type;
class Struct_field;
class Expression_list;
+class Const_expression;
class Var_expression;
class Enclosed_var_expression;
class Temporary_reference_expression;
@@ -626,6 +627,20 @@ class Expression
is_type_expression() const
{ return this->classification_ == EXPRESSION_TYPE; }
+ // If this is a const reference, return the Const_expression
+ // structure. Otherwise, return NULL. This is a controlled dynamic
+ // cast.
+ Const_expression*
+ const_expression()
+ { return this->convert<Const_expression, EXPRESSION_CONST_REFERENCE>(); }
+
+ const Const_expression*
+ const_expression() const
+ {
+ return this->convert<const Const_expression,
+ EXPRESSION_CONST_REFERENCE>();
+ }
+
// If this is a variable reference, return the Var_expression
// structure. Otherwise, return NULL. This is a controlled dynamic
// cast.
@@ -1453,6 +1468,96 @@ class Parser_expression : public Expression
{ go_unreachable(); }
};
+// A reference to a const in an expression.
+
+class Const_expression : public Expression
+{
+ public:
+ Const_expression(Named_object* constant, Location location)
+ : Expression(EXPRESSION_CONST_REFERENCE, location),
+ constant_(constant), type_(NULL), seen_(false)
+ { }
+
+ Named_object*
+ named_object()
+ { return this->constant_; }
+
+ const Named_object*
+ named_object() const
+ { return this->constant_; }
+
+ // Check that the initializer does not refer to the constant itself.
+ void
+ check_for_init_loop();
+
+ protected:
+ int
+ do_traverse(Traverse*);
+
+ Expression*
+ do_lower(Gogo*, Named_object*, Statement_inserter*, int);
+
+ bool
+ do_is_constant() const
+ { return true; }
+
+ bool
+ do_is_zero_value() const;
+
+ bool
+ do_is_static_initializer() const
+ { return true; }
+
+ bool
+ do_numeric_constant_value(Numeric_constant* nc) const;
+
+ bool
+ do_string_constant_value(std::string* val) const;
+
+ bool
+ do_boolean_constant_value(bool* val) const;
+
+ Type*
+ do_type();
+
+ // The type of a const is set by the declaration, not the use.
+ void
+ do_determine_type(const Type_context*);
+
+ void
+ do_check_types(Gogo*);
+
+ Expression*
+ do_copy()
+ { return this; }
+
+ Bexpression*
+ do_get_backend(Translate_context* context);
+
+ int
+ do_inlining_cost() const
+ { return 1; }
+
+ // When exporting a reference to a const as part of a const
+ // expression, we export the value. We ignore the fact that it has
+ // a name.
+ void
+ do_export(Export_function_body* efb) const;
+
+ void
+ do_dump_expression(Ast_dump_context*) const;
+
+ private:
+ // The constant.
+ Named_object* constant_;
+ // The type of this reference. This is used if the constant has an
+ // abstract type.
+ Type* type_;
+ // Used to prevent infinite recursion when a constant incorrectly
+ // refers to itself.
+ mutable bool seen_;
+};
+
// An expression which is simply a variable.
class Var_expression : public Expression