diff options
author | John Hodge <tpg@mutabah.net> | 2015-03-17 12:44:16 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2015-03-17 12:44:16 +0800 |
commit | 80e44173b4abef7238304fbaf1182862144b62b1 (patch) | |
tree | d468ce61ffa2c3ed5a5ceaffb909fb0798bf5161 /src | |
parent | 6c571b2d3f99f5e209986dc00710d3fb86caafad (diff) | |
download | mrust-80e44173b4abef7238304fbaf1182862144b62b1.tar.gz |
Clean up handling of TokenTrees, allowing empty but valid TTs
Diffstat (limited to 'src')
-rw-r--r-- | src/macros.cpp | 21 | ||||
-rw-r--r-- | src/parse/lex.cpp | 2 | ||||
-rw-r--r-- | src/parse/root.cpp | 10 | ||||
-rw-r--r-- | src/parse/tokentree.hpp | 3 |
4 files changed, 28 insertions, 8 deletions
diff --git a/src/macros.cpp b/src/macros.cpp index b2528755..3b6147e3 100644 --- a/src/macros.cpp +++ b/src/macros.cpp @@ -419,11 +419,20 @@ Token MacroExpander::realGetToken() else if( ent.subpats.size() != 0 )
{
// New layer
- // - Push an offset
- m_offsets.push_back( ::std::make_pair(0, 0) );
- // - Save the current layer
- m_cur_ents = getCurLayer();
- // - Restart loop for new layer
+ DEBUG("- NL = " << layer+1 << ", count = " << m_layer_counts.size() );
+ if( layer+1 < m_layer_counts.size() && m_layer_counts.at(layer+1) > 0 )
+ {
+ // - Push an offset
+ m_offsets.push_back( ::std::make_pair(0, 0) );
+ // - Save the current layer
+ m_cur_ents = getCurLayer();
+ // - Restart loop for new layer
+ }
+ else
+ {
+ // Layer empty
+ DEBUG("Layer " << layer+1 << " is empty");
+ }
}
else
{
@@ -435,7 +444,7 @@ Token MacroExpander::realGetToken() else
{
// - Otherwise, restart/end loop and fall through
- unsigned int layer_max = m_layer_counts.at(layer);
+ unsigned int layer_max = (layer < m_layer_counts.size() ? m_layer_counts.at(layer) : 0);
if( m_offsets.back().second + 1 < layer_max )
{
DEBUG("Restart layer");
diff --git a/src/parse/lex.cpp b/src/parse/lex.cpp index d469d46d..17eb4f30 100644 --- a/src/parse/lex.cpp +++ b/src/parse/lex.cpp @@ -637,7 +637,7 @@ Token TTStream::realGetToken() unsigned int& idx = m_stack.back().first; const TokenTree& tree = *m_stack.back().second; - if(idx == 0 && tree.size() == 0) { + if(idx == 0 && tree.is_token()) { idx ++; return tree.tok(); } diff --git a/src/parse/root.cpp b/src/parse/root.cpp index f84b11f6..55f6f21c 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -173,6 +173,8 @@ TypeRef Parse_Type(TokenStream& lex) switch( GET_TOK(tok, lex) )
{
+ case TOK_UNDERSCORE:
+ return TypeRef();
case TOK_RWORD_EXTERN: {
GET_CHECK_TOK(tok, lex, TOK_STRING);
::std::string abi = tok.str();
@@ -211,6 +213,10 @@ TypeRef Parse_Type(TokenStream& lex) case TOK_DOUBLE_COLON:
// Path with generics
return TypeRef(TypeRef::TagPath(), Parse_Path(lex, true, PATH_GENERIC_TYPE));
+
+ // HACK! Convert && into & &
+ case TOK_DOUBLE_AMP:
+ lex.putback(Token(TOK_AMP));
case TOK_AMP: {
::std::string lifetime;
// Reference
@@ -1424,8 +1430,10 @@ void Parse_ModRoot_Items(TokenStream& lex, AST::Crate& crate, AST::Module& mod, }
else
{
+ DEBUG("Invoke macro '"<<tok.str()<<"'");
TokenTree tt = Parse_TT(lex, true);
- if( tt.size() == 0 ) {
+ if( tt.is_token() ) {
+ DEBUG("TT was a single token (not a sub-tree)");
throw ParseError::Unexpected(lex, tt.tok());
}
::std::string name = tok.str();
diff --git a/src/parse/tokentree.hpp b/src/parse/tokentree.hpp index eaaf6623..2eb967ac 100644 --- a/src/parse/tokentree.hpp +++ b/src/parse/tokentree.hpp @@ -19,6 +19,9 @@ public: {
}
+ bool is_token() const {
+ return m_tok.type() != TOK_NULL;
+ }
const unsigned int size() const {
return m_subtrees.size();
}
|