FunctionQualifiers
AstBuilder::fn_qualifiers ()
{
- return FunctionQualifiers (loc, AsyncConstStatus::NONE, false);
+ return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal);
}
PathExprSegment
// `const`? `async`? `unsafe`? (`extern` Abi?)?
// unsafe? (extern Abi?)?
- switch (qualifiers.get_const_status ())
- {
- case NONE:
- break;
- case CONST_FN:
- push (Rust::Token::make (CONST, qualifiers.get_locus ()));
- break;
- case ASYNC_FN:
- push (Rust::Token::make (ASYNC, qualifiers.get_locus ()));
- break;
- }
-
+ if (qualifiers.is_async ())
+ push (Rust::Token::make (ASYNC, qualifiers.get_locus ()));
+ if (qualifiers.is_const ())
+ push (Rust::Token::make (CONST, qualifiers.get_locus ()));
if (qualifiers.is_unsafe ())
push (Rust::Token::make (UNSAFE, qualifiers.get_locus ()));
if (qualifiers.is_extern ())
{
std::string str;
- switch (const_status)
- {
- case NONE:
- // do nothing
- break;
- case CONST_FN:
- str += "const ";
- break;
- case ASYNC_FN:
- str += "async ";
- break;
- default:
- return "ERROR_MARK_STRING: async-const status failure";
- }
-
- if (has_unsafe)
+ if (is_async ())
+ str += "async ";
+ if (is_const ())
+ str += "const ";
+ if (is_unsafe ())
str += "unsafe ";
if (has_extern)
// Qualifiers for function, i.e. const, unsafe, extern etc.
class FunctionQualifiers
{
- AsyncConstStatus const_status;
- bool has_unsafe;
+ Async async_status;
+ Const const_status;
+ Unsafety unsafe_status;
bool has_extern;
std::string extern_abi;
location_t locus;
public:
- FunctionQualifiers (location_t locus, AsyncConstStatus const_status,
- bool has_unsafe, bool has_extern = false,
+ FunctionQualifiers (location_t locus, Async async_status, Const const_status,
+ Unsafety unsafe_status, bool has_extern = false,
std::string extern_abi = std::string ())
- : const_status (const_status), has_unsafe (has_unsafe),
- has_extern (has_extern), extern_abi (std::move (extern_abi)),
- locus (locus)
+ : async_status (async_status), const_status (const_status),
+ unsafe_status (unsafe_status), has_extern (has_extern),
+ extern_abi (std::move (extern_abi)), locus (locus)
{
if (!this->extern_abi.empty ())
{
std::string as_string () const;
- AsyncConstStatus get_const_status () const { return const_status; }
- bool is_unsafe () const { return has_unsafe; }
+ bool is_unsafe () const { return unsafe_status == Unsafety::Unsafe; }
bool is_extern () const { return has_extern; }
+ bool is_const () const { return const_status == Const::Yes; }
+ bool is_async () const { return async_status == Async::Yes; }
std::string get_extern_abi () const { return extern_abi; }
bool has_abi () const { return !extern_abi.empty (); }
+ Const get_const_status () const { return const_status; }
+ Async get_async_status () const { return async_status; }
location_t get_locus () const { return locus; }
};
"invalid ABI: found %qs", extern_abi.c_str ());
}
- return HIR::FunctionQualifiers (qualifiers.get_const_status (), unsafety,
+ return HIR::FunctionQualifiers (qualifiers.get_async_status (),
+ qualifiers.get_const_status (), unsafety,
has_extern, abi);
}
struct FunctionQualifiers
{
private:
- AsyncConstStatus const_status;
+ Async async_status;
+ Const const_status;
Unsafety unsafety;
bool has_extern;
ABI abi;
public:
- FunctionQualifiers (AsyncConstStatus const_status, Unsafety unsafety,
+ FunctionQualifiers (Async async_status, Const const_status, Unsafety unsafety,
bool has_extern, ABI abi)
- : const_status (const_status), unsafety (unsafety), has_extern (has_extern),
- abi (abi)
+ : async_status (async_status), const_status (const_status),
+ unsafety (unsafety), has_extern (has_extern), abi (abi)
{}
std::string as_string () const;
- AsyncConstStatus get_status () const { return const_status; }
+ Const get_const_status () const { return const_status; }
- bool is_const () const { return const_status == AsyncConstStatus::CONST_FN; }
+ bool is_const () const { return const_status == Const::Yes; }
bool is_unsafe () const { return unsafety == Unsafety::Unsafe; }
+ bool is_async () const { return async_status == Async::Yes; }
ABI get_abi () const { return abi; }
};
{
std::string str;
- switch (const_status)
- {
- case NONE:
- // do nothing
- break;
- case CONST_FN:
- str += "const ";
- break;
- case ASYNC_FN:
- str += "async ";
- break;
- default:
- return "ERROR_MARK_STRING: async-const status failure";
- }
-
- if (unsafety == Unsafety::Unsafe)
- {
- str += "unsafe ";
- }
+ if (is_const ())
+ str += "const ";
+ if (is_async ())
+ str += "async ";
+ if (is_unsafe ())
+ str += "unsafe ";
if (has_extern)
{
#include "rust-common.h"
#include "rust-item.h"
+#include "rust-common.h"
#include "rust-token.h"
#define INCLUDE_ALGORITHM
#include "rust-diagnostics.h"
AST::FunctionQualifiers
Parser<ManagedTokenSource>::parse_function_qualifiers ()
{
- AsyncConstStatus const_status = NONE;
- bool has_unsafe = false;
+ Async async_status = Async::No;
+ Const const_status = Const::No;
+ Unsafety unsafe_status = Unsafety::Normal;
bool has_extern = false;
std::string abi;
+ const_TokenPtr t;
+ location_t locus;
// Check in order of const, unsafe, then extern
- const_TokenPtr t = lexer.peek_token ();
- location_t locus = t->get_locus ();
- switch (t->get_id ())
+ for (int i = 0; i < 2; i++)
{
- case CONST:
- lexer.skip_token ();
- const_status = CONST_FN;
- break;
- case ASYNC:
- lexer.skip_token ();
- const_status = ASYNC_FN;
- break;
- default:
- // const status is still none
- break;
+ t = lexer.peek_token ();
+ locus = t->get_locus ();
+
+ switch (t->get_id ())
+ {
+ case CONST:
+ lexer.skip_token ();
+ const_status = Const::Yes;
+ break;
+ case ASYNC:
+ lexer.skip_token ();
+ async_status = Async::Yes;
+ break;
+ default:
+ // const status is still none
+ break;
+ }
}
if (lexer.peek_token ()->get_id () == UNSAFE)
{
lexer.skip_token ();
- has_unsafe = true;
+ unsafe_status = Unsafety::Unsafe;
}
if (lexer.peek_token ()->get_id () == EXTERN_KW)
}
}
- return AST::FunctionQualifiers (locus, const_status, has_unsafe, has_extern,
- std::move (abi));
+ return AST::FunctionQualifiers (locus, async_status, const_status,
+ unsafe_status, has_extern, std::move (abi));
}
// Parses generic (lifetime or type) params inside angle brackets (optional).
namespace Rust {
-enum Mutability
+enum class Mutability
{
Imm,
Mut
};
-enum Unsafety
+enum class Unsafety
{
Unsafe,
Normal
};
+enum class Const
+{
+ Yes,
+ No,
+};
+
+enum class Async
+{
+ Yes,
+ No
+};
+
enum BoundPolarity
{
RegularBound,