diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-20 16:16:20 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-20 16:16:20 +0800 |
commit | 508fe45737e08a6749ddc5f903523dc7b3aaba1a (patch) | |
tree | e6d5dbd24e89086feb136e81c42000482d7f8e76 | |
parent | 1c50e757b45f64ead016d6cd2bf27585ba5dce04 (diff) | |
download | mrust-508fe45737e08a6749ddc5f903523dc7b3aaba1a.tar.gz |
Parse - Cleanup TODOs
-rw-r--r-- | src/macro_rules/eval.cpp | 3 | ||||
-rw-r--r-- | src/parse/expr.cpp | 21 | ||||
-rw-r--r-- | src/parse/root.cpp | 31 | ||||
-rw-r--r-- | src/parse/token.cpp | 18 | ||||
-rw-r--r-- | src/parse/tokenstream.cpp | 2 |
5 files changed, 39 insertions, 36 deletions
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp index b2f5e409..a393ba46 100644 --- a/src/macro_rules/eval.cpp +++ b/src/macro_rules/eval.cpp @@ -715,12 +715,13 @@ InterpolatedFragment Macro_HandlePatternCap(TokenStream& lex, MacroPatEnt::Type return InterpolatedFragment( Parse_Mod_Item_S(lex, cur_mod.m_file_info, cur_mod.path(), AST::AttributeList{}) ); } break; case MacroPatEnt::PAT_IDENT: - // TODO: Any reserved word is also valid as an ident + // NOTE: Any reserved word is also valid as an ident GET_TOK(tok, lex); if( tok.type() == TOK_IDENT || is_reserved_word(tok.type()) ) ; else CHECK_TOK(tok, TOK_IDENT); + // TODO: TOK_INTERPOLATED_IDENT return InterpolatedFragment( TokenTree(lex.getHygiene(), tok) ); } throw ""; diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp index 22bf9afc..5194e1d8 100644 --- a/src/parse/expr.cpp +++ b/src/parse/expr.cpp @@ -20,7 +20,7 @@ using AST::ExprNode; using AST::ExprNodeP; -// TODO: Use a ProtoSpan +// TODO: Use a ProtoSpan instead of a point span? static inline ExprNodeP mk_exprnodep(const TokenStream& lex, AST::ExprNode* en){en->set_span(lex.point_span()); return ExprNodeP(en); } #define NEWNODE(type, ...) mk_exprnodep(lex, new type(__VA_ARGS__)) @@ -66,9 +66,10 @@ ExprNodeP Parse_ExprBlockNode(TokenStream& lex, bool is_unsafe/*=false*/) DEBUG("tok = " << tok); // NOTE: Doc comments can appear within a function and apply to the function - ::AST::AttributeList node_attrs; - Parse_ParentAttrs(lex, node_attrs); - (void)node_attrs; // TODO: Use these attributes + if( lex.parse_state().parent_attrs ) + { + Parse_ParentAttrs(lex, *lex.parse_state().parent_attrs); + } if( LOOK_AHEAD(lex) == TOK_BRACE_CLOSE ) break; @@ -162,6 +163,7 @@ ExprNodeP Parse_ExprBlockLine_WithItems(TokenStream& lex, ::std::shared_ptr<AST: } else if( item_attrs.m_items.size() > 0 ) { // TODO: Is this an error? - Attributes on a expression that didn't yeild a node. + // - They should have applied to the item that was parsed? } else { } @@ -740,7 +742,6 @@ ExprNodeP Parse_Expr1_1(TokenStream& lex) return NEWNODE( AST::ExprNode_BinOp, AST::ExprNode_BinOp::RANGE, ::std::move(left), ::std::move(right) ); } -// TODO: Is this left associative? LEFTASSOC(Parse_Expr1_2, Parse_Expr1_5, case TOK_TRIPLE_DOT: rv = NEWNODE( AST::ExprNode_BinOp, AST::ExprNode_BinOp::RANGE_INC, mv$(rv), next(lex) ); @@ -915,8 +916,7 @@ ExprNodeP Parse_ExprFC(TokenStream& lex) GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE); break; case TOK_DOT: - // Field access / method call - // TODO: What about tuple indexing? + // Field access / method call / tuple index switch(GET_TOK(tok, lex)) { case TOK_IDENT: { @@ -1097,7 +1097,7 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) return tok.take_frag_node(); - // TODO: Return/break/continue/... here? + // Return/break/continue/... also parsed here (but recurses back up to actually handle them) case TOK_RWORD_RETURN: case TOK_RWORD_CONTINUE: case TOK_RWORD_BREAK: @@ -1177,7 +1177,6 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) return NEWNODE( AST::ExprNode_NamedValue, ::std::move(path) ); } case TOK_RWORD_MOVE: - // TODO: Annotate closure as move GET_TOK(tok, lex); if(tok.type() == TOK_PIPE) return Parse_ExprVal_Closure(lex, true); @@ -1271,7 +1270,9 @@ ExprNodeP Parse_ExprVal(TokenStream& lex) } ExprNodeP Parse_ExprMacro(TokenStream& lex, AST::Path path) { - ASSERT_BUG(lex.point_span(), path.is_trivial(), "TODO: Support path macros - " << path); + if( !path.is_trivial() ) { + TODO(lex.point_span(), "Support path macros - " << path); + } Token tok; ::std::string name = path.m_class.is_Local() ? path.m_class.as_Local().name : path.nodes()[0].name(); diff --git a/src/parse/root.cpp b/src/parse/root.cpp index a57d6844..35da3a76 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -346,9 +346,9 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ if( tok.type() == TOK_AMP ) { // By-reference method? - // TODO: If a lifetime is seen (and not a prototype), it is definitely a self binding unsigned int ofs = 0; + // Handle a lifetime parameter name if( lex.lookahead(0) == TOK_LIFETIME ) ofs ++; @@ -362,22 +362,16 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ } auto ty_sp = lex.end_span(ps); + bool is_mut = false; if( tok.type() == TOK_RWORD_MUT ) { - GET_CHECK_TOK(tok, lex, TOK_RWORD_SELF); - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, true, TypeRef(ty_sp, "Self", 0xFFFF))) ); - } - else - { - args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, false, TypeRef(ty_sp, "Self", 0xFFFF))) ); + is_mut = true; + GET_TOK(tok, lex); } - DEBUG("TODO: UFCS / self lifetimes"); + CHECK_TOK(tok, TOK_RWORD_SELF); + args.push_back( ::std::make_pair( AST::Pattern(AST::Pattern::TagBind(), "self"), TypeRef(TypeRef::TagReference(), ty_sp, is_mut, TypeRef(ty_sp, "Self", 0xFFFF))) ); if( allow_self == false ) throw ParseError::Generic(lex, "Self binding not expected"); - //args.push_back( ::std::make_pair( - // AST::Pattern(), - // TypeRef(TypeRef::TagReference(), lifetime, (fcn_class == AST::Function::CLASS_MUTMETHOD), ) - //) ); // Prime tok for next step GET_TOK(tok, lex); @@ -486,7 +480,7 @@ AST::Function Parse_FunctionDefWithCode(TokenStream& lex, ::std::string abi, boo Token tok; auto ret = Parse_FunctionDef(lex, abi, allow_self, false, is_unsafe, is_const); GET_CHECK_TOK(tok, lex, TOK_BRACE_OPEN); - // Enter a new hygine scope (TODO: Should this be in Parse_ExprBlock?) + // Enter a new hygine scope for the function (TODO: Should this be in Parse_ExprBlock?) lex.push_hygine(); PUTBACK(tok, lex); ret.set_code( Parse_ExprBlock(lex) ); @@ -645,7 +639,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items } while( GET_TOK(tok, lex) == TOK_PLUS ); } - // TODO: Support "for Sized?" if(tok.type() == TOK_RWORD_WHERE) { //if( params.ty_params().size() == 0 ) @@ -747,7 +740,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items break; } // Functions (possibly unsafe) - // TODO: Const? case TOK_RWORD_UNSAFE: fn_is_unsafe = true; if( GET_TOK(tok, lex) == TOK_RWORD_EXTERN ) @@ -770,8 +762,7 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items if( GET_TOK(tok, lex) == TOK_BRACE_OPEN ) { PUTBACK(tok, lex); - // Enter a new hygine scope for the function body. - // - TODO: Should this just happen in Parse_ExprBlock? + // Enter a new hygine scope for the function body. (TODO: Should this be in Parse_ExprBlock?) lex.push_hygine(); fcn.set_code( Parse_ExprBlock(lex) ); lex.pop_hygine(); @@ -784,7 +775,6 @@ AST::Trait Parse_TraitDef(TokenStream& lex, const AST::AttributeList& meta_items { throw ParseError::Unexpected(lex, tok); } - // TODO: Store `item_attrs` trait.add_function( ::std::move(name), mv$(item_attrs), ::std::move(fcn) ); break; } default: @@ -842,7 +832,7 @@ AST::Enum Parse_EnumDef(TokenStream& lex, const AST::AttributeList& meta_items) } auto field_attrs = Parse_ItemAttrs(lex); - (void)field_attrs; // TODO^ + (void)field_attrs; // TODO: Store field_attrs types.push_back( Parse_Type(lex) ); } while( GET_TOK(tok, lex) == TOK_COMMA ); @@ -1176,8 +1166,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); auto i = ::AST::Static(AST::Static::CONST, mv$(ty), mv$(val)); - // TODO: Attributes on associated constants - impl.add_static( is_public, is_specialisable, mv$(name), mv$(i) /*, mv$(item_attrs)*/ ); + impl.add_static( is_public, is_specialisable, mv$(name), mv$(i) ); break ; } else if( tok.type() == TOK_RWORD_UNSAFE ) diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 6f3bafd9..eb5830a2 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -297,7 +297,7 @@ struct EscapedString { reinterpret_cast<const ::AST::Path*>(m_data.as_Fragment())->print_pretty(ss, true); return ss.str(); case TOK_INTERPOLATED_PATTERN: - // TODO: Use a configurable print + // TODO: Use a pretty printer too? return FMT( *reinterpret_cast<const ::AST::Pattern*>(m_data.as_Fragment()) ); case TOK_INTERPOLATED_STMT: case TOK_INTERPOLATED_BLOCK: @@ -312,9 +312,21 @@ struct EscapedString { // Value tokens case TOK_IDENT: return m_data.as_String(); case TOK_LIFETIME: return "'" + m_data.as_String(); - case TOK_INTEGER: return FMT(m_data.as_Integer().m_intval); // TODO: suffix for type + case TOK_INTEGER: + if( m_data.as_Integer().m_datatype == CORETYPE_ANY ) { + return FMT(m_data.as_Integer().m_intval); + } + else { + return FMT(m_data.as_Integer().m_intval << "_" << m_data.as_Integer().m_datatype); + } case TOK_CHAR: return FMT("'\\u{"<< ::std::hex << m_data.as_Integer().m_intval << "}"); - case TOK_FLOAT: return FMT(m_data.as_Float().m_floatval); + case TOK_FLOAT: + if( m_data.as_Float().m_datatype == CORETYPE_ANY ) { + return FMT(m_data.as_Float().m_floatval); + } + else { + return FMT(m_data.as_Float().m_floatval << "_" << m_data.as_Float().m_datatype); + } case TOK_STRING: return FMT("\"" << EscapedString(m_data.as_String()) << "\""); case TOK_BYTESTRING:return FMT("b\"" << m_data.as_String() << "\""); case TOK_HASH: return "#"; diff --git a/src/parse/tokenstream.cpp b/src/parse/tokenstream.cpp index 901312a3..625f12db 100644 --- a/src/parse/tokenstream.cpp +++ b/src/parse/tokenstream.cpp @@ -141,7 +141,7 @@ Ident TokenStream::get_ident(Token tok) const return Ident(getHygiene(), tok.str()); } else if( tok.type() == TOK_INTERPOLATED_IDENT ) { - TODO(getPosition(), ""); + TODO(getPosition(), "get_ident from TOK_INTERPOLATED_IDENT"); } else { throw ParseError::Unexpected(*this, tok); |