public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ian Lance Taylor <iant@golang.org>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
		"gofrontend-dev@googlegroups.com"
	<gofrontend-dev@googlegroups.com>
Subject: Go patch committed: export String_index_expression
Date: Thu, 28 Apr 2016 19:12:00 -0000	[thread overview]
Message-ID: <CAOyqgcWEPY3h9tth1ejJSUERZhWHyVEUky=HrBjJnRpN0QUJkA@mail.gmail.com> (raw)

[-- 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

                 reply	other threads:[~2016-04-28 19:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOyqgcWEPY3h9tth1ejJSUERZhWHyVEUky=HrBjJnRpN0QUJkA@mail.gmail.com' \
    --to=iant@golang.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gofrontend-dev@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).