diff options
author | John Hodge (sonata) <tpg@mutabah.net> | 2014-12-23 12:06:25 +0800 |
---|---|---|
committer | John Hodge (sonata) <tpg@mutabah.net> | 2014-12-23 12:06:25 +0800 |
commit | 04dd6b05f945c944c13431baa509ec628ac26f41 (patch) | |
tree | 5a3d67f4f875481057118a3c553abf5ae998a548 /src/convert/render.cpp | |
parent | 89771222961d699f5ca6f586033b5fb915ced431 (diff) | |
download | mrust-04dd6b05f945c944c13431baa509ec628ac26f41.tar.gz |
Move source files to src/ folder
Diffstat (limited to 'src/convert/render.cpp')
-rw-r--r-- | src/convert/render.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/convert/render.cpp b/src/convert/render.cpp new file mode 100644 index 00000000..6de8dc57 --- /dev/null +++ b/src/convert/render.cpp @@ -0,0 +1,52 @@ +/*
+ */
+#include "../ast/ast.hpp"
+
+void Render_Type(::std::ostream& os, const TypeRef& type, const char *name)
+{
+ /*
+ swicth(type.class())
+ {
+ case TYPECLASS_STRUCT:
+ os << "struct " << type.struct().mangled_name() << " " << name;
+ break;
+ }
+ */
+}
+
+void Render_CStruct(::std::ostream& os, const AST::CStruct& str)
+{
+ os << "struct " << str.name() << "{\n";
+ FOREACH(::std::vector<std::pair<std::string,TypeRef> >, f, str.fields())
+ {
+ os << "\t";
+ Render_Type(os, f->second(), f->first().c_str());
+ os << ";\n";
+ }
+ os << "}\n"
+}
+
+void Render_Crate(::std::ostream& os, const AST::Flat& crate)
+{
+ // First off, print forward declarations of all structs + enums
+ FOREACH(::std::vector<AST::CStruct>, s, crate.structs())
+ os << "struct " << s->mangled_name() << ";\n";
+
+ FOREACH(::std::vector<AST::Function>, fcn, crate.functions())
+ {
+ Render_Type(os, fcn->rettype(), nullptr);
+ os << " " << fcn->name() << "(";
+ bool is_first = true;
+ FOREACH(::std::vector<std::pair<std::string,TypeRef> >, f, fcn.args())
+ {
+ if( !is_first )
+ os << ", ";
+ is_first = false;
+ Render_Type(os, f->second(), f->first().c_str());
+ }
+ os << ")\n{\n";
+ // Dump expression AST
+ os << "}\n";
+ }
+}
+
|