aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2016-04-28 19:12:13 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-04-28 19:12:13 +0000
commit913a9fbb4fa4dde21e2f8071352f5f548b73f181 (patch)
tree66ab4e8f808963572df8a20a15f966f75e9667ff /gcc/go
parent9fae9ece6abc4212cbdd21c7fe334b43f78eb3a0 (diff)
downloadgcc-913a9fbb4fa4dde21e2f8071352f5f548b73f181.zip
gcc-913a9fbb4fa4dde21e2f8071352f5f548b73f181.tar.gz
gcc-913a9fbb4fa4dde21e2f8071352f5f548b73f181.tar.bz2
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
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/expressions.cc61
-rw-r--r--gcc/go/gofrontend/expressions.h74
3 files changed, 76 insertions, 61 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 5f24f22..ced2068 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-ba520fdcbea95531ebb9ef3d5be2de405ca90df3
+b17e404f5b8954e008b512741296d238ab7b2ef9
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 05425bc..da7b4e0 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10380,66 +10380,7 @@ Expression::make_array_index(Expression* array, Expression* start,
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 : 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_;
-};
+// Class String_index_expression.
// String index traversal.
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index c1e8191..a953bbd 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -44,6 +44,7 @@ class Func_descriptor_expression;
class Unknown_expression;
class Index_expression;
class Array_index_expression;
+class String_index_expression;
class Map_index_expression;
class Bound_method_expression;
class Field_reference_expression;
@@ -675,6 +676,13 @@ class Expression
array_index_expression()
{ 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,
// return the Map_index_expression structure. Otherwise, return
// NULL.
@@ -2583,6 +2591,72 @@ class Array_index_expression : public Expression
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.
class Map_index_expression : public Expression