Commit 913a9fbb by Ian Lance Taylor

compiler: Export String_index_expression.

    
    Exports String_index_expression and adds the getter `string` that
    returns the underlying string.  This will be used to handle string
    indexing different from array indexing in escape analysis.
    
    Reviewed-on: https://go-review.googlesource.com/18545

From-SVN: r235602
parent 9fae9ece
ba520fdcbea95531ebb9ef3d5be2de405ca90df3 b17e404f5b8954e008b512741296d238ab7b2ef9
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.
...@@ -10380,66 +10380,7 @@ Expression::make_array_index(Expression* array, Expression* start, ...@@ -10380,66 +10380,7 @@ Expression::make_array_index(Expression* array, Expression* start,
return new Array_index_expression(array, start, end, cap, location); return new Array_index_expression(array, start, end, cap, location);
} }
// A string index. This is used for both indexing and slicing. // Class String_index_expression.
class String_index_expression : public Expression
{
public:
String_index_expression(Expression* string, Expression* start,
Expression* end, Location location)
: Expression(EXPRESSION_STRING_INDEX, location),
string_(string), start_(start), end_(end)
{ }
protected:
int
do_traverse(Traverse*);
Expression*
do_flatten(Gogo*, Named_object*, Statement_inserter*);
Type*
do_type();
void
do_determine_type(const Type_context*);
void
do_check_types(Gogo*);
Expression*
do_copy()
{
return Expression::make_string_index(this->string_->copy(),
this->start_->copy(),
(this->end_ == NULL
? NULL
: this->end_->copy()),
this->location());
}
bool
do_must_eval_subexpressions_in_order(int* skip) const
{
*skip = 1;
return true;
}
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
private:
// The string we are getting a value from.
Expression* string_;
// The start or only index.
Expression* start_;
// The end index of a slice. This may be NULL for a single index,
// or it may be a nil expression for the length of the string.
Expression* end_;
};
// String index traversal. // String index traversal.
......
...@@ -44,6 +44,7 @@ class Func_descriptor_expression; ...@@ -44,6 +44,7 @@ class Func_descriptor_expression;
class Unknown_expression; class Unknown_expression;
class Index_expression; class Index_expression;
class Array_index_expression; class Array_index_expression;
class String_index_expression;
class Map_index_expression; class Map_index_expression;
class Bound_method_expression; class Bound_method_expression;
class Field_reference_expression; class Field_reference_expression;
...@@ -675,6 +676,13 @@ class Expression ...@@ -675,6 +676,13 @@ class Expression
array_index_expression() array_index_expression()
{ return this->convert<Array_index_expression, EXPRESSION_ARRAY_INDEX>(); } { return this->convert<Array_index_expression, EXPRESSION_ARRAY_INDEX>(); }
// If this is an expression which refers to indexing in a string,
// return the String_index_expression structure. Otherwise, return
// NULL.
String_index_expression*
string_index_expression()
{ return this->convert<String_index_expression, EXPRESSION_STRING_INDEX>(); }
// If this is an expression which refers to indexing in a map, // If this is an expression which refers to indexing in a map,
// return the Map_index_expression structure. Otherwise, return // return the Map_index_expression structure. Otherwise, return
// NULL. // NULL.
...@@ -2583,6 +2591,72 @@ class Array_index_expression : public Expression ...@@ -2583,6 +2591,72 @@ class Array_index_expression : public Expression
Type* type_; Type* type_;
}; };
// A string index. This is used for both indexing and slicing.
class String_index_expression : public Expression
{
public:
String_index_expression(Expression* string, Expression* start,
Expression* end, Location location)
: Expression(EXPRESSION_STRING_INDEX, location),
string_(string), start_(start), end_(end)
{ }
// Return the string being indexed.
Expression*
string() const
{ return this->string_; }
protected:
int
do_traverse(Traverse*);
Expression*
do_flatten(Gogo*, Named_object*, Statement_inserter*);
Type*
do_type();
void
do_determine_type(const Type_context*);
void
do_check_types(Gogo*);
Expression*
do_copy()
{
return Expression::make_string_index(this->string_->copy(),
this->start_->copy(),
(this->end_ == NULL
? NULL
: this->end_->copy()),
this->location());
}
bool
do_must_eval_subexpressions_in_order(int* skip) const
{
*skip = 1;
return true;
}
Bexpression*
do_get_backend(Translate_context*);
void
do_dump_expression(Ast_dump_context*) const;
private:
// The string we are getting a value from.
Expression* string_;
// The start or only index.
Expression* start_;
// The end index of a slice. This may be NULL for a single index,
// or it may be a nil expression for the length of the string.
Expression* end_;
};
// An index into a map. // An index into a map.
class Map_index_expression : public Expression class Map_index_expression : public Expression
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment