aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/export.h
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-11-26 21:44:20 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-11-26 21:44:20 +0000
commit1e4cc1d4b097f346b4cda611782fe83eda0df18f (patch)
tree2d4e3368b005eaf1e957c8b3437f6e03d7026f42 /gcc/go/gofrontend/export.h
parent50e99db39196a0567e844f35ce1cd0f36d066b8f (diff)
downloadgcc-1e4cc1d4b097f346b4cda611782fe83eda0df18f.zip
gcc-1e4cc1d4b097f346b4cda611782fe83eda0df18f.tar.gz
gcc-1e4cc1d4b097f346b4cda611782fe83eda0df18f.tar.bz2
compiler: initial support for exporting function bodies
Create a framework for putting function bodies in export data. At present only empty functions will be put there, and they will be ignored on import. Later patches will get this to the point of supporting inlining of (some) functions defined in other packages. Reviewed-on: https://go-review.googlesource.com/c/150061 From-SVN: r266490
Diffstat (limited to 'gcc/go/gofrontend/export.h')
-rw-r--r--gcc/go/gofrontend/export.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index 84077a2..5751488 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -286,4 +286,60 @@ class Stream_to_string : public Export::Stream
std::string string_;
};
+// Class to manage exporting a function body. This is passed around
+// to Statements and Expressions. It builds up the export data for
+// the function.
+
+class Export_function_body
+{
+ public:
+ Export_function_body(int indent)
+ : indent_(indent)
+ { }
+
+ // Write a character to the body.
+ void
+ write_char(char c)
+ { this->body_.append(1, c); }
+
+ // Write a NUL terminated string to the body.
+ void
+ write_c_string(const char* str)
+ { this->body_.append(str); }
+
+ // Write a string to the body.
+ void
+ write_string(const std::string& str)
+ { this->body_.append(str); }
+
+ // Append as many spaces as the current indentation level.
+ void
+ indent()
+ {
+ for (int i = this->indent_; i > 0; i--)
+ this->write_char(' ');
+ }
+
+ // Increment the indentation level.
+ void
+ increment_indent()
+ { ++this->indent_; }
+
+ // Decrement the indentation level.
+ void
+ decrement_indent()
+ { --this->indent_; }
+
+ // Return a reference to the completed body.
+ const std::string&
+ body() const
+ { return this->body_; }
+
+ private:
+ // The body we are building.
+ std::string body_;
+ // Current indentation level: the number of spaces before each statement.
+ int indent_;
+};
+
#endif // !defined(GO_EXPORT_H)