* Go patch committed: export String_index_expression
@ 2016-04-28 19:12 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2016-04-28 19:12 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 243 bytes --]
This patch to the Go frontend by Chris Manghane makes
String_index_expression accessible outside of expressions.cc. This is
a step toward future patches. Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu. Committed to mainline.
Ian
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 4844 bytes --]
Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE (revision 235452)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -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.
Index: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc (revision 235452)
+++ gcc/go/gofrontend/expressions.cc (working copy)
@@ -10380,66 +10380,7 @@ Expression::make_array_index(Expression*
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.
Index: gcc/go/gofrontend/expressions.h
===================================================================
--- gcc/go/gofrontend/expressions.h (revision 235452)
+++ gcc/go/gofrontend/expressions.h (working copy)
@@ -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 Ex
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-04-28 19:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-28 19:12 Go patch committed: export String_index_expression Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).