diff options
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r-- | gcc/go/gofrontend/expressions.h | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 9de734e..a4f6558 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -39,6 +39,7 @@ class Unary_expression; class Binary_expression; class String_concat_expression; class Call_expression; +class Builtin_call_expression; class Call_result_expression; class Func_expression; class Func_descriptor_expression; @@ -2246,6 +2247,15 @@ class Call_expression : public Expression set_is_multi_value_arg() { this->is_multi_value_arg_ = true; } + // Whether this is a call to builtin function. + virtual bool + is_builtin() + { return false; } + + // Convert to a Builtin_call_expression, or return NULL. + inline Builtin_call_expression* + builtin_call_expression(); + protected: int do_traverse(Traverse*); @@ -2351,6 +2361,133 @@ class Call_expression : public Expression bool is_flattened_; }; +// A call expression to a builtin function. + +class Builtin_call_expression : public Call_expression +{ + public: + Builtin_call_expression(Gogo* gogo, Expression* fn, Expression_list* args, + bool is_varargs, Location location); + + // The builtin functions. + enum Builtin_function_code + { + BUILTIN_INVALID, + + // Predeclared builtin functions. + BUILTIN_APPEND, + BUILTIN_CAP, + BUILTIN_CLOSE, + BUILTIN_COMPLEX, + BUILTIN_COPY, + BUILTIN_DELETE, + BUILTIN_IMAG, + BUILTIN_LEN, + BUILTIN_MAKE, + BUILTIN_NEW, + BUILTIN_PANIC, + BUILTIN_PRINT, + BUILTIN_PRINTLN, + BUILTIN_REAL, + BUILTIN_RECOVER, + + // Builtin functions from the unsafe package. + BUILTIN_ALIGNOF, + BUILTIN_OFFSETOF, + BUILTIN_SIZEOF + }; + + Builtin_function_code + code() + { return this->code_; } + + // This overrides Call_expression::is_builtin. + bool + is_builtin() + { return true; } + + protected: + // This overrides Call_expression::do_lower. + Expression* + do_lower(Gogo*, Named_object*, Statement_inserter*, int); + + Expression* + do_flatten(Gogo*, Named_object*, Statement_inserter*); + + bool + do_is_constant() const; + + bool + do_numeric_constant_value(Numeric_constant*) const; + + bool + do_discarding_value(); + + Type* + do_type(); + + void + do_determine_type(const Type_context*); + + void + do_check_types(Gogo*); + + Expression* + do_copy(); + + Bexpression* + do_get_backend(Translate_context*); + + void + do_export(Export*) const; + + virtual bool + do_is_recover_call() const; + + virtual void + do_set_recover_arg(Expression*); + + private: + Expression* + one_arg() const; + + bool + check_one_arg(); + + static Type* + real_imag_type(Type*); + + static Type* + complex_type(Type*); + + Expression* + lower_make(Statement_inserter*); + + Expression* flatten_append(Gogo*, Named_object*, Statement_inserter*); + + bool + check_int_value(Expression*, bool is_length, bool* small); + + // A pointer back to the general IR structure. This avoids a global + // variable, or passing it around everywhere. + Gogo* gogo_; + // The builtin function being called. + Builtin_function_code code_; + // Used to stop endless loops when the length of an array uses len + // or cap of the array itself. + mutable bool seen_; + // Whether the argument is set for calls to BUILTIN_RECOVER. + bool recover_arg_is_set_; +}; + +inline Builtin_call_expression* +Call_expression::builtin_call_expression() +{ + return (this->is_builtin() + ? static_cast<Builtin_call_expression*>(this) + : NULL); +} + // A single result from a call which returns multiple results. class Call_result_expression : public Expression |