template <typename T>
AST::Fragment expand_derive_proc_macro (T &item, AST::SimplePath &path)
{
- CustomDeriveProcMacro macro;
- if (!mappings->lookup_derive_proc_macro_invocation (path, macro))
+ tl::optional<CustomDeriveProcMacro &> macro
+ = mappings->lookup_derive_proc_macro_invocation (path);
+ if (!macro.has_value ())
{
rust_error_at (path.get_locus (), "Macro not found");
return AST::Fragment::create_error ();
auto c = collector.collect_tokens ();
std::vector<const_TokenPtr> vec (c.cbegin (), c.cend ());
- return parse_proc_macro_output (macro.get_handle () (convert (vec)));
+ return parse_proc_macro_output (
+ macro.value ().get_handle () (convert (vec)));
}
template <typename T>
AST::Fragment expand_bang_proc_macro (T &item,
AST::MacroInvocation &invocation)
{
- BangProcMacro macro;
- if (!mappings->lookup_bang_proc_macro_invocation (invocation, macro))
+ tl::optional<BangProcMacro &> macro
+ = mappings->lookup_bang_proc_macro_invocation (invocation);
+ if (!macro.has_value ())
{
rust_error_at (invocation.get_locus (), "Macro not found");
return AST::Fragment::create_error ();
auto c = collector.collect_tokens ();
std::vector<const_TokenPtr> vec (c.cbegin (), c.cend ());
- return parse_proc_macro_output (macro.get_handle () (convert (vec)));
+ return parse_proc_macro_output (
+ macro.value ().get_handle () (convert (vec)));
}
template <typename T>
AST::Fragment expand_attribute_proc_macro (T &item, AST::SimplePath &path)
{
- AttributeProcMacro macro;
- if (!mappings->lookup_attribute_proc_macro_invocation (path, macro))
+ tl::optional<AttributeProcMacro &> macro
+ = mappings->lookup_attribute_proc_macro_invocation (path);
+ if (!macro.has_value ())
{
rust_error_at (path.get_locus (), "Macro not found");
return AST::Fragment::create_error ();
// FIXME: Handle attributes
return parse_proc_macro_output (
- macro.get_handle () (ProcMacro::TokenStream::make_tokenstream (),
- convert (vec)));
+ macro.value ().get_handle () (ProcMacro::TokenStream::make_tokenstream (),
+ convert (vec)));
}
/**
procmacroDeriveInvocations[invoc.get_node_id ()] = def;
}
-bool
-Mappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc,
- CustomDeriveProcMacro &def)
+tl::optional<CustomDeriveProcMacro &>
+Mappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc)
{
auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
if (it == procmacroDeriveInvocations.end ())
- return false;
+ return tl::nullopt;
- def = it->second;
- return true;
+ return it->second;
}
void
procmacroBangInvocations[invoc.get_macro_node_id ()] = def;
}
-bool
-Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
- BangProcMacro &def)
+tl::optional<BangProcMacro &>
+Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc)
{
auto it = procmacroBangInvocations.find (invoc.get_macro_node_id ());
if (it == procmacroBangInvocations.end ())
- return false;
+ return tl::nullopt;
- def = it->second;
- return true;
+ return it->second;
}
void
procmacroAttributeInvocations[invoc.get_node_id ()] = def;
}
-bool
-Mappings::lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc,
- AttributeProcMacro &def)
+tl::optional<AttributeProcMacro &>
+Mappings::lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc)
{
auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
if (it == procmacroAttributeInvocations.end ())
- return false;
+ return tl::nullopt;
- def = it->second;
- return true;
+ return it->second;
}
void
bool lookup_bang_proc_macro_def (NodeId id, BangProcMacro ¯o);
bool lookup_attribute_proc_macro_def (NodeId id, AttributeProcMacro ¯o);
+ tl::optional<CustomDeriveProcMacro &>
+ lookup_derive_proc_macro_invocation (AST::SimplePath &invoc);
+ tl::optional<BangProcMacro &>
+ lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc_id);
+ tl::optional<AttributeProcMacro &>
+ lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc);
void insert_derive_proc_macro_invocation (AST::SimplePath &invoc,
CustomDeriveProcMacro def);
-
- bool lookup_derive_proc_macro_invocation (AST::SimplePath &invoc,
- CustomDeriveProcMacro &def);
void insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
BangProcMacro def);
- bool lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc_id,
- BangProcMacro &def);
void insert_attribute_proc_macro_invocation (AST::SimplePath &invoc,
AttributeProcMacro def);
- bool lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc,
- AttributeProcMacro &def);
void insert_visibility (NodeId id, Privacy::ModuleVisibility visibility);
bool lookup_visibility (NodeId id, Privacy::ModuleVisibility &def);