From 6411b7c7d220ae9af5e54d0fdae66e4e44faf01f Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 21 Mar 2015 14:21:00 +0800 Subject: Fix minor lexing and dump issues --- src/dump_as_rust.cpp | 27 +++++++++++++++++++++------ src/main.cpp | 28 +++++++++++++++------------- src/parse/lex.cpp | 4 ++-- src/types.cpp | 10 ++++++++-- 4 files changed, 46 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/dump_as_rust.cpp b/src/dump_as_rust.cpp index e1c32a69..a1fac249 100644 --- a/src/dump_as_rust.cpp +++ b/src/dump_as_rust.cpp @@ -132,9 +132,22 @@ public: } m_os << ")"; } - virtual void visit(AST::ExprNode_CallObject&) override { + virtual void visit(AST::ExprNode_CallObject& n) override { m_expr_root = false; - throw ::std::runtime_error("unimplemented ExprNode_CallObject"); + m_os << "("; + AST::NodeVisitor::visit(n.m_val); + m_os << ")("; + bool is_first = true; + for( auto& arg : n.m_args ) + { + if(is_first) { + is_first = false; + } else { + m_os << ", "; + } + AST::NodeVisitor::visit(arg); + } + m_os << ")"; } virtual void visit(AST::ExprNode_Loop& n) override { bool expr_root = m_expr_root; @@ -408,9 +421,11 @@ public: AST::NodeVisitor::visit(n.m_idx); m_os << "]"; } - virtual void visit(AST::ExprNode_Deref&) override { + virtual void visit(AST::ExprNode_Deref& n) override { m_expr_root = false; - throw ::std::runtime_error("unimplemented ExprNode_Deref"); + m_os << "*("; + AST::NodeVisitor::visit(n.m_value); + m_os << ")"; } virtual void visit(AST::ExprNode_Cast& n) override { m_expr_root = false; @@ -644,7 +659,7 @@ void RustPrinter::print_bounds(const AST::TypeParams& params) for( const auto& b : params.bounds() ) { if( !is_first ) - m_os << ", "; + m_os << ",\n"; is_first = false; m_os << indent() << b.test() << ": "; @@ -652,8 +667,8 @@ void RustPrinter::print_bounds(const AST::TypeParams& params) m_os << b.bound(); else m_os << b.lifetime(); - m_os << "\n"; } + m_os << "\n"; dec_indent(); } diff --git a/src/main.cpp b/src/main.cpp index 6aeba895..760f8566 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,12 +15,12 @@ int g_debug_indent_level = 0; bool debug_enabled() { - - return true; + + return true; } ::std::ostream& debug_output(int indent, const char* function) { - return ::std::cout << g_cur_phase << "- " << RepeatLitStr { " ", indent } << function << ": "; + return ::std::cout << g_cur_phase << "- " << RepeatLitStr { " ", indent } << function << ": "; } /// main! @@ -90,35 +90,37 @@ int main(int argc, char *argv[]) //Serialiser& s = s_tt; try { - g_cur_phase = "Parse"; + g_cur_phase = "Parse"; AST::Crate crate = Parse_Crate(infile); - g_cur_phase = "PostParse"; + g_cur_phase = "PostParse"; crate.post_parse(); //s << crate; + g_cur_phase = "Temp output"; + Dump_Rust( FMT(outfile << ".rs").c_str(), crate ); // Resolve names to be absolute names (include references to the relevant struct/global/function) - g_cur_phase = "Resolve"; + g_cur_phase = "Resolve"; ResolvePaths(crate); //s << crate; // Typecheck / type propagate module (type annotations of all values) // - Check all generic conditions (ensure referenced trait is valid) // > Also mark parameter with applicable traits - #if 0 - g_cur_phase = "TypecheckBounds"; + #if 0 + g_cur_phase = "TypecheckBounds"; Typecheck_GenericBounds(crate); // - Check all generic parameters match required conditions - g_cur_phase = "TypecheckParams"; + g_cur_phase = "TypecheckParams"; Typecheck_GenericParams(crate); // - Typecheck statics and consts // - Typecheck + propagate functions // > Forward pass first - //g_cur_phase = "TypecheckExpr"; + //g_cur_phase = "TypecheckExpr"; //Typecheck_Expr(crate); - #endif + #endif - g_cur_phase = "Output"; + g_cur_phase = "Output"; Dump_Rust( FMT(outfile << ".rs").c_str(), crate ); if( strcmp(emit_type, "ast") == 0 ) @@ -129,7 +131,7 @@ int main(int argc, char *argv[]) return 0; } // Flatten modules into "mangled" set - g_cur_phase = "Flatten"; + g_cur_phase = "Flatten"; AST::Flat flat_crate = Convert_Flatten(crate); // Convert structures to C structures / tagged enums diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index 78d2aa7e..d09bc2d8 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -311,7 +311,7 @@ Token Lexer::getTokenInt() } else { while( isdigit(ch) ) { - val *= val * 10; + val *= 10; val += ch - '0'; ch = this->getc(); } @@ -703,7 +703,7 @@ SERIALISE_TYPE_S(Token, { os << "\"" << tok.str() << "\""; break; case TOK_INTEGER: - os << tok.intval(); + os << ":" << tok.intval(); break; default: break; diff --git a/src/types.cpp b/src/types.cpp index b1f4735e..abf6b2da 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -393,7 +393,10 @@ bool TypeRef::operator==(const TypeRef& x) const os << "*" << (tr.m_is_inner_mutable ? "mut" : "const") << " " << tr.m_inner_types[0]; break; case TypeRef::ARRAY: - os << "[" << tr.m_inner_types[0] << "; " << tr.m_size_expr << "]"; + os << "[" << tr.m_inner_types[0]; + if( tr.m_size_expr.get() ) + os << "; " << *tr.m_size_expr; + os << "]"; break; case TypeRef::GENERIC: os << "/* arg */ " << tr.m_path[0].name(); @@ -499,6 +502,9 @@ SERIALISE_TYPE(TypeRef::, "TypeRef", { void PrettyPrintType::print(::std::ostream& os) const { + #if 1 + os << m_type; + #else switch(m_type.m_class) { case TypeRef::ANY: @@ -546,7 +552,7 @@ void PrettyPrintType::print(::std::ostream& os) const os << "<" << m_type.m_inner_types[0].print_pretty() << " as " << m_type.m_inner_types[1].print_pretty() << ">::" << m_type.m_path[0].name(); break; } - + #endif } ::std::ostream& operator<<(::std::ostream& os, const PrettyPrintType& v) -- cgit v1.2.3