#include "group.h"
namespace ProcMacro {
-namespace Group {
Group
-Group::make_group (TokenStream::TokenStream stream, Delimiter delim)
+Group::make_group (TokenStream stream, Delimiter delim)
{
return {delim, stream};
}
TokenStream::TokenStream::drop (&g->stream);
}
-} // namespace Group
} // namespace ProcMacro
#include "tokenstream.h"
namespace ProcMacro {
-namespace Group {
enum Delimiter
{
- Parenthesis,
- Brace,
- Bracket,
- None,
+ PARENTHESIS,
+ BRACE,
+ BRACKET,
+ NONE,
};
struct Group
{
Delimiter delimiter;
- TokenStream::TokenStream stream;
+ TokenStream stream;
public:
- static Group make_group (TokenStream::TokenStream stream, Delimiter delim);
+ static Group make_group (TokenStream stream, Delimiter delim);
static void drop (Group *g);
};
-} // namespace Group
} // namespace ProcMacro
#endif /* ! GROUP_H */
#include <cstring>
namespace ProcMacro {
-namespace Ident {
extern "C" {
ident->len = 0;
}
-} // namespace Ident
} // namespace ProcMacro
#include <string>
namespace ProcMacro {
-namespace Ident {
struct Ident
{
Ident__clone (const Ident *ident);
}
-} // namespace Ident
} // namespace ProcMacro
#endif /* ! IDENT_H */
#include <cstdlib>
namespace ProcMacro {
-namespace Literal {
void
Literal::drop (Literal *lit)
return {ISIZE, payload};
}
-} // namespace Literal
} // namespace ProcMacro
#include <vector>
namespace ProcMacro {
-namespace Literal {
enum UnsignedTag
{
UNSIGNED_8,
static Literal make_usize (std::uint64_t value, bool suffixed = false);
static Literal make_isize (std::int64_t value, bool suffixed = false);
+ static void drop (Literal *lit);
+
+private:
static Literal make_unsigned (UnsignedSuffixPayload p);
static Literal make_signed (SignedSuffixPayload p);
-
- static void drop (Literal *lit);
};
extern "C" {
Literal__from_string (const unsigned char *str, std::uint64_t len,
Literal *lit);
}
-} // namespace Literal
} // namespace ProcMacro
#endif /* ! LITERAL_H */
#include <cstdlib>
namespace ProcMacro {
-namespace Punct {
Punct
Punct::make_punct (std::uint32_t ch, Spacing spacing)
return {ch, spacing};
}
-} // namespace Punct
} // namespace ProcMacro
#include <cstdint>
namespace ProcMacro {
-namespace Punct {
enum Spacing
{
- Alone,
- Joint
+ ALONE,
+ JOINT
};
struct Punct
Spacing spacing;
public:
- static Punct make_punct (std::uint32_t ch, Spacing spacing = Spacing::Alone);
+ static Punct make_punct (std::uint32_t ch, Spacing spacing = Spacing::ALONE);
};
-} // namespace Punct
} // namespace ProcMacro
#endif /* ! PUNCT_H */
#include <cstring>
namespace ProcMacro {
-namespace TokenStream {
TokenStream
-TokenStream::make_tokenstream (std::vector<TokenTree::TokenTree> vec)
+TokenStream::make_tokenstream (std::vector<TokenTree> vec)
{
auto stream = make_tokenstream (vec.size ());
for (auto tt : vec)
TokenStream
TokenStream::make_tokenstream (std::uint64_t capacity)
{
- auto *data = new TokenTree::TokenTree[capacity];
+ auto *data = new TokenTree[capacity];
return {data, 0, capacity};
}
TokenStream::grow (std::uint64_t delta)
{
auto new_capacity = capacity + delta;
- auto *new_data = new TokenTree::TokenTree[new_capacity];
+ auto *new_data = new TokenTree[new_capacity];
std::memcpy (new_data, data, size);
delete[] data;
data = new_data;
}
void
-TokenStream::push (TokenTree::TokenTree tree)
+TokenStream::push (TokenTree tree)
{
if (size == capacity)
grow (capacity);
}
extern "C" void
-TokenSream__push (TokenStream *stream, TokenTree::TokenTree tree)
+TokenSream__push (TokenStream *stream, TokenTree tree)
{
stream->push (tree);
}
extern "C" TokenStream
TokenStream__clone (const TokenStream *ts)
{
- auto *data = new TokenTree::TokenTree[ts->capacity];
+ auto *data = new TokenTree[ts->capacity];
std::memcpy (data, ts->data, ts->size);
return {data, ts->size, ts->capacity};
}
TokenStream::drop (stream);
}
-} // namespace TokenStream
} // namespace ProcMacro
#include <vector>
namespace ProcMacro {
-namespace TokenTree {
struct TokenTree;
-}
-
-namespace TokenStream {
-
-const std::int64_t DEFAULT_CAPACITY = 0;
struct TokenStream
{
- TokenTree::TokenTree *data;
+ TokenTree *data;
std::uint64_t size;
std::uint64_t capacity;
public:
void grow (std::uint64_t delta);
- void push (TokenTree::TokenTree tree);
+ void push (TokenTree tree);
TokenStream clone () const;
- static TokenStream make_tokenstream (std::vector<TokenTree::TokenTree> vec);
- static TokenStream make_tokenstream (std::uint64_t capacity
- = DEFAULT_CAPACITY);
+ static TokenStream make_tokenstream (std::vector<TokenTree> vec);
+ static TokenStream make_tokenstream (std::uint64_t capacity = 1);
static void drop (TokenStream *stream);
};
TokenStream__with_capacity (std::uint64_t capacity);
extern "C" void
-TokenSream__push (TokenStream *stream, TokenTree::TokenTree tree);
+TokenSream__push (TokenStream *stream, TokenTree tree);
extern "C" bool
TokenStream__from_string (unsigned char *str, std::uint64_t len,
extern "C" void
TokenStream__drop (TokenStream *stream);
-} // namespace TokenStream
} // namespace ProcMacro
#endif /* ! TOKENSTREAM_H */
#include "tokentree.h"
namespace ProcMacro {
-namespace TokenTree {
TokenTree
-TokenTree::make_tokentree (Group::Group group)
+TokenTree::make_tokentree (Group group)
{
TokenTreePayload payload;
payload.group = group;
}
TokenTree
-TokenTree::make_tokentree (Ident::Ident ident)
+TokenTree::make_tokentree (Ident ident)
{
TokenTreePayload payload;
payload.ident = ident;
}
TokenTree
-TokenTree::make_tokentree (Punct::Punct punct)
+TokenTree::make_tokentree (Punct punct)
{
TokenTreePayload payload;
payload.punct = punct;
}
TokenTree
-TokenTree::make_tokentree (Literal::Literal literal)
+TokenTree::make_tokentree (Literal literal)
{
TokenTreePayload payload;
payload.literal = literal;
}
}
-} // namespace TokenTree
} // namespace ProcMacro
#include "literal.h"
namespace ProcMacro {
-namespace TokenTree {
enum TokenTreeTag
{
union TokenTreePayload
{
- Group::Group group;
- Ident::Ident ident;
- Punct::Punct punct;
- Literal::Literal literal;
+ Group group;
+ Ident ident;
+ Punct punct;
+ Literal literal;
};
struct TokenTree
TokenTreePayload payload;
public:
- static TokenTree make_tokentree (Group::Group group);
- static TokenTree make_tokentree (Ident::Ident ident);
- static TokenTree make_tokentree (Punct::Punct punct);
- static TokenTree make_tokentree (Literal::Literal literal);
+ static TokenTree make_tokentree (Group group);
+ static TokenTree make_tokentree (Ident ident);
+ static TokenTree make_tokentree (Punct punct);
+ static TokenTree make_tokentree (Literal literal);
static void drop (TokenTree *tt);
};
-} // namespace TokenTree
} // namespace ProcMacro
#endif /* ! TOKENTREE_H */