diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ast/expr.cpp | 3 | ||||
-rw-r--r-- | src/expand/crate_tags.cpp | 8 | ||||
-rw-r--r-- | src/expand/format_args.cpp | 58 | ||||
-rw-r--r-- | src/expand/lang_item.cpp | 4 | ||||
-rw-r--r-- | src/expand/stringify.cpp | 1 |
5 files changed, 58 insertions, 16 deletions
diff --git a/src/ast/expr.cpp b/src/ast/expr.cpp index 1525ed12..5111bad6 100644 --- a/src/ast/expr.cpp +++ b/src/ast/expr.cpp @@ -358,7 +358,8 @@ NODE(ExprNode_Tuple, { }) NODE(ExprNode_NamedValue, { - os << m_path; + m_path.print_pretty(os, false); + //os << m_path; },{ return NEWNODE(ExprNode_NamedValue, AST::Path(m_path)); }) diff --git a/src/expand/crate_tags.cpp b/src/expand/crate_tags.cpp index 0e7d8447..1a2abf83 100644 --- a/src/expand/crate_tags.cpp +++ b/src/expand/crate_tags.cpp @@ -62,6 +62,14 @@ public: // TODO: Check for an existing allocator crate crate.m_lang_items.insert(::std::make_pair( "mrustc-allocator", AST::Path("",{}) )); } + + void handle(const Span& sp, const AST::Attribute& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + if( ! i.is_Function() ) { + ERROR(sp, E0000, "#[allocator] can only be put on functions and the crate - found on " << i.tag_str()); + } + // TODO: Ensure that this is an extern { fn } + // TODO: Does this need to do anything? + } }; class Decorator_PanicRuntime: public ExpandDecorator diff --git a/src/expand/format_args.cpp b/src/expand/format_args.cpp index 915af2af..fe2bdfb4 100644 --- a/src/expand/format_args.cpp +++ b/src/expand/format_args.cpp @@ -431,27 +431,18 @@ namespace { toks.push_back( mv$(t3) ); toks.push_back( mv$(t4) ); } -} -class CFormatArgsExpander: - public ExpandProcMacro -{ - ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override + ::std::unique_ptr<TokenStream> expand_format_args(const Span& sp, const ::AST::Crate& crate, TTStream& lex, bool add_newline) { Token tok; - auto lex = TTStream(sp, tt); - lex.parse_state().module = &mod; - if( ident != "" ) - ERROR(sp, E0000, "format_args! doesn't take an ident"); - - auto n = Parse_ExprVal(lex); - ASSERT_BUG(sp, n, "No expression returned"); - Expand_BareExpr(crate, mod, n); + auto format_string_node = Parse_ExprVal(lex); + ASSERT_BUG(sp, format_string_node, "No expression returned"); + Expand_BareExpr(crate, lex.parse_state().get_current_mod(), format_string_node); - auto* format_string_np = dynamic_cast<AST::ExprNode_String*>(&*n); + auto* format_string_np = dynamic_cast<AST::ExprNode_String*>(&*format_string_node); if( !format_string_np ) { - ERROR(sp, E0000, "format_args! requires a string literal - got " << *n); + ERROR(sp, E0000, "format_args! requires a string literal - got " << *format_string_node); } const auto& format_string_sp = format_string_np->span(); const auto& format_string = format_string_np->m_value; @@ -497,6 +488,10 @@ class CFormatArgsExpander: ::std::vector< FmtFrag> fragments; ::std::string tail; ::std::tie( fragments, tail ) = parse_format_string(format_string_sp, format_string, named_args_index, free_args.size()); + if( add_newline ) + { + tail += "\n"; + } bool is_simple = true; for(unsigned int i = 0; i < fragments.size(); i ++) @@ -719,7 +714,40 @@ class CFormatArgsExpander: return box$( TTStreamO(sp, TokenTree(Ident::Hygiene::new_scope(), mv$(toks))) ); } +} + +class CFormatArgsExpander: + public ExpandProcMacro +{ + ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override + { + Token tok; + + auto lex = TTStream(sp, tt); + lex.parse_state().module = &mod; + if( ident != "" ) + ERROR(sp, E0000, "format_args! doesn't take an ident"); + + return expand_format_args(sp, crate, lex, /*add_newline=*/false); + } +}; + +class CFormatArgsNlExpander: + public ExpandProcMacro +{ + ::std::unique_ptr<TokenStream> expand(const Span& sp, const ::AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) override + { + Token tok; + + auto lex = TTStream(sp, tt); + lex.parse_state().module = &mod; + if( ident != "" ) + ERROR(sp, E0000, "format_args_nl! doesn't take an ident"); + + return expand_format_args(sp, crate, lex, /*add_newline=*/true); + } }; STATIC_MACRO("format_args", CFormatArgsExpander); +STATIC_MACRO("format_args_nl", CFormatArgsNlExpander); diff --git a/src/expand/lang_item.cpp b/src/expand/lang_item.cpp index 55bde52f..8dd481f3 100644 --- a/src/expand/lang_item.cpp +++ b/src/expand/lang_item.cpp @@ -78,6 +78,8 @@ void handle_lang_item(const Span& sp, AST::Crate& crate, const AST::Path& path, else if( name == "debug_trait" ) { /* TODO: Poke derive() with this */ } + else if( TARGETVER_1_29 && name == "termination" ) { } // 1.29 - trait used for non-() main + // Structs else if( name == "non_zero" ) { } else if( name == "phantom_data" ) { } @@ -222,6 +224,8 @@ public: // std - interestingly else if( name == "f32" ) {} else if( name == "f64" ) {} + else if( TARGETVER_1_29 && name == "f32_runtime" ) {} + else if( TARGETVER_1_29 && name == "f64_runtime" ) {} else { ERROR(sp, E0000, "Unknown lang item '" << name << "' on impl"); } diff --git a/src/expand/stringify.cpp b/src/expand/stringify.cpp index 06c65c02..b85c23c6 100644 --- a/src/expand/stringify.cpp +++ b/src/expand/stringify.cpp @@ -22,6 +22,7 @@ class CExpander: { if(!rv.empty()) rv += " "; + DEBUG(" += " << tok); rv += tok.to_str(); } |