@@ -2084,31 +2084,6 @@ TokenCollector::visit (ExternalStaticItem &item)
push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
}
-void
-TokenCollector::visit (ExternalFunctionItem &function)
-{
- visit_items_as_lines (function.get_outer_attrs ());
- visit (function.get_visibility ());
-
- auto id = function.get_identifier ().as_string ();
-
- push (Rust::Token::make (FN_KW, function.get_locus ()));
- push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id)));
- if (function.has_generics ())
- visit (function.get_generic_params ());
- push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION));
-
- visit_items_joined_by_separator (function.get_function_params ());
-
- push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION));
- if (function.has_return_type ())
- {
- push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION));
- visit (function.get_return_type ());
- }
- push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION));
-}
-
void
TokenCollector::visit (ExternBlock &block)
{
@@ -333,7 +333,6 @@ public:
void visit (TraitImpl &impl);
void visit (ExternalTypeItem &item);
void visit (ExternalStaticItem &item);
- void visit (ExternalFunctionItem &item);
void visit (ExternBlock &block);
// rust-macro.h
@@ -203,7 +203,6 @@ class ExternalItem;
class ExternalTypeItem;
class ExternalStaticItem;
class NamedFunctionParam;
-class ExternalFunctionItem;
class ExternBlock;
// rust-macro.h
@@ -1004,24 +1004,6 @@ DefaultASTVisitor::visit (AST::NamedFunctionParam ¶m)
visit (param.get_type ());
}
-void
-DefaultASTVisitor::visit (AST::ExternalFunctionItem &item)
-{
- visit_outer_attrs (item);
- visit (item.get_visibility ());
- for (auto &generic : item.get_generic_params ())
- visit (generic);
-
- if (item.has_where_clause ())
- visit (item.get_where_clause ());
-
- for (auto ¶m : item.get_function_params ())
- visit (param);
-
- if (item.has_return_type ())
- visit (item.get_return_type ());
-}
-
void
DefaultASTVisitor::visit (AST::ExternBlock &block)
{
@@ -164,7 +164,6 @@ public:
// virtual void visit(ExternalItem& item) = 0;
virtual void visit (ExternalTypeItem &type) = 0;
virtual void visit (ExternalStaticItem &item) = 0;
- virtual void visit (ExternalFunctionItem &item) = 0;
virtual void visit (ExternBlock &block) = 0;
// rust-macro.h
@@ -338,7 +337,6 @@ protected:
virtual void visit (AST::TraitImpl &impl) override;
virtual void visit (AST::ExternalTypeItem &item) override;
virtual void visit (AST::ExternalStaticItem &item) override;
- virtual void visit (AST::ExternalFunctionItem &item) override;
virtual void visit (AST::ExternBlock &block) override;
virtual void visit (AST::MacroMatchFragment &match) override;
virtual void visit (AST::MacroMatchRepetition &match) override;
@@ -2974,69 +2974,6 @@ ExternalStaticItem::as_string () const
return str;
}
-std::string
-ExternalFunctionItem::as_string () const
-{
- // outer attributes
- std::string str = append_attributes (outer_attrs, OUTER);
-
- // start visibility on new line and with a space
- str += "\n" + visibility.as_string () + " ";
-
- str += "fn ";
-
- // add name
- str += item_name.as_string ();
-
- // generic params
- str += "\n Generic params: ";
- if (generic_params.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto ¶m : generic_params)
- {
- // DEBUG: null pointer check
- if (param == nullptr)
- {
- rust_debug (
- "something really terrible has gone wrong - null pointer "
- "generic param in external function item.");
- return "NULL_POINTER_MARK";
- }
-
- str += "\n " + param->as_string ();
- }
- }
-
- // function params
- str += "\n Function params: ";
- if (function_params.empty ())
- {
- str += "none";
- }
- else
- {
- for (const auto ¶m : function_params)
- str += "\n " + param.as_string ();
- }
-
- // add type on new line
- str += "\n (return) Type: "
- + (has_return_type () ? return_type->as_string () : "()");
-
- // where clause
- str += "\n Where clause: ";
- if (has_where_clause ())
- str += where_clause.as_string ();
- else
- str += "none";
-
- return str;
-}
-
std::string
NamedFunctionParam::as_string () const
{
@@ -4866,12 +4803,6 @@ ExternalStaticItem::accept_vis (ASTVisitor &vis)
vis.visit (*this);
}
-void
-ExternalFunctionItem::accept_vis (ASTVisitor &vis)
-{
- vis.visit (*this);
-}
-
void
ExternBlock::accept_vis (ASTVisitor &vis)
{
@@ -64,25 +64,6 @@ ASTValidation::visit (AST::ConstantItem &const_item)
AST::ContextualASTVisitor::visit (const_item);
}
-void
-ASTValidation::visit (AST::ExternalFunctionItem &item)
-{
- auto ¶ms = item.get_function_params ();
-
- if (params.size () == 1 && params[0].is_variadic ())
- rust_error_at (
- params[0].get_locus (),
- "C-variadic function must be declared with at least one named argument");
-
- for (auto it = params.begin (); it != params.end (); it++)
- if (it->is_variadic () && it + 1 != params.end ())
- rust_error_at (
- it->get_locus (),
- "%<...%> must be the last argument of a C-variadic function");
-
- AST::ContextualASTVisitor::visit (item);
-}
-
void
ASTValidation::visit (AST::Union &item)
{
@@ -38,7 +38,6 @@ public:
virtual void visit (AST::ConstantItem &const_item);
virtual void visit (AST::Lifetime &lifetime);
virtual void visit (AST::LoopLabel &label);
- virtual void visit (AST::ExternalFunctionItem &item);
virtual void visit (AST::Union &item);
virtual void visit (AST::Function &function);
virtual void visit (AST::Trait &trait);
@@ -130,7 +130,6 @@ public:
void visit (AST::Trait &trait) override {}
void visit (AST::ExternalTypeItem &item) override;
void visit (AST::ExternalStaticItem &item) override {}
- void visit (AST::ExternalFunctionItem &item) override {}
void visit (AST::ExternBlock &block) override;
void visit (AST::MacroMatchFragment &match) override {}
void visit (AST::MacroMatchRepetition &match) override {}
@@ -2195,62 +2195,6 @@ CfgStrip::visit (AST::ExternalStaticItem &item)
rust_error_at (type->get_locus (), "cannot strip type in this position");
}
-void
-CfgStrip::visit (AST::ExternalFunctionItem &item)
-{
- // strip test based on outer attrs
- expand_cfg_attrs (item.get_outer_attrs ());
- if (fails_cfg_with_expand (item.get_outer_attrs ()))
- {
- item.mark_for_strip ();
- return;
- }
-
- AST::DefaultASTVisitor::visit (item);
-
- /* strip function parameters if required - this is specifically
- * allowed by spec */
- auto ¶ms = item.get_function_params ();
- for (auto it = params.begin (); it != params.end ();)
- {
- auto ¶m = *it;
-
- auto ¶m_attrs = param.get_outer_attrs ();
- expand_cfg_attrs (param_attrs);
- if (fails_cfg_with_expand (param_attrs))
- {
- it = params.erase (it);
- continue;
- }
-
- if (!param.is_variadic ())
- {
- auto &type = param.get_type ();
- if (type->is_marked_for_strip ())
- rust_error_at (type->get_locus (),
- "cannot strip type in this position");
- }
-
- // increment if nothing else happens
- ++it;
- }
- /* NOTE: these are extern function params, which may have different
- * rules and restrictions to "normal" function params. So expansion
- * handled separately. */
-
- /* TODO: assuming that variadic nature cannot be stripped. If this
- * is not true, then have code here to do so. */
-
- if (item.has_return_type ())
- {
- auto &return_type = item.get_return_type ();
-
- if (return_type->is_marked_for_strip ())
- rust_error_at (return_type->get_locus (),
- "cannot strip type in this position");
- }
-}
-
void
CfgStrip::visit (AST::ExternBlock &block)
{
@@ -150,7 +150,6 @@ public:
void visit (AST::TraitImpl &impl) override;
void visit (AST::ExternalTypeItem &item) override;
void visit (AST::ExternalStaticItem &item) override;
- void visit (AST::ExternalFunctionItem &item) override;
void visit (AST::ExternBlock &block) override;
// I don't think it would be possible to strip macros without expansion
@@ -166,7 +166,6 @@ private:
virtual void visit (TraitImpl &impl) override final{};
virtual void visit (ExternalTypeItem &type) override final{};
virtual void visit (ExternalStaticItem &item) override final{};
- virtual void visit (ExternalFunctionItem &item) override final{};
virtual void visit (ExternBlock &block) override final{};
virtual void visit (MacroMatchFragment &match) override final{};
virtual void visit (MacroMatchRepetition &match) override final{};
@@ -922,23 +922,6 @@ ExpandVisitor::visit (AST::ExternalStaticItem &static_item)
maybe_expand_type (static_item.get_type ());
}
-void
-ExpandVisitor::visit (AST::ExternalFunctionItem &item)
-{
- for (auto ¶m : item.get_generic_params ())
- visit (param);
-
- for (auto ¶m : item.get_function_params ())
- if (!param.is_variadic ())
- maybe_expand_type (param.get_type ());
-
- if (item.has_return_type ())
- maybe_expand_type (item.get_return_type ());
-
- if (item.has_where_clause ())
- expand_where_clause (item.get_where_clause ());
-}
-
void
ExpandVisitor::visit (AST::ExternBlock &block)
{
@@ -252,7 +252,6 @@ public:
void visit (AST::TraitImpl &impl) override;
void visit (AST::ExternalTypeItem &item) override;
void visit (AST::ExternalStaticItem &item) override;
- void visit (AST::ExternalFunctionItem &item) override;
void visit (AST::ExternBlock &block) override;
// I don't think it would be possible to strip macros without expansion
@@ -345,9 +345,6 @@ void
ASTLoweringBase::visit (AST::ExternalStaticItem &)
{}
void
-ASTLoweringBase::visit (AST::ExternalFunctionItem &)
-{}
-void
ASTLoweringBase::visit (AST::ExternBlock &)
{}
@@ -186,7 +186,6 @@ public:
// virtual void visit(ExternalItem& item);
virtual void visit (AST::ExternalTypeItem &item);
virtual void visit (AST::ExternalStaticItem &item);
- virtual void visit (AST::ExternalFunctionItem &item);
virtual void visit (AST::ExternBlock &block);
// rust-macro.h
@@ -93,46 +93,9 @@ ExportContext::emit_function (const HIR::Function &fn)
// FIXME assert that this is actually an AST::Function
AST::Function &function = static_cast<AST::Function &> (vis_item);
- // we can emit an extern block with abi of "rust"
- Identifier item_name = function.get_function_name ();
-
- // always empty for extern linkage
- AST::WhereClause where_clause = AST::WhereClause::create_empty ();
- std::vector<std::unique_ptr<AST::GenericParam>> generic_params;
-
- AST::Visibility vis = function.get_visibility ();
- std::unique_ptr<AST::Type> return_type
- = std::unique_ptr<AST::Type> (nullptr);
- if (function.has_return_type ())
- {
- return_type = function.get_return_type ()->clone_type ();
- }
-
- std::vector<AST::NamedFunctionParam> function_params;
- for (auto &p : function.get_function_params ())
- {
- if (p->is_variadic () || p->is_self ())
- rust_unreachable ();
- auto param = static_cast<AST::FunctionParam *> (p.get ());
- std::string name = param->get_pattern ()->as_string ();
- std::unique_ptr<AST::Type> param_type
- = param->get_type ()->clone_type ();
-
- AST::NamedFunctionParam np (name, std::move (param_type), {},
- param->get_locus ());
- function_params.push_back (std::move (np));
- }
-
- AST::ExternalItem *external_item
- = new AST::ExternalFunctionItem (item_name, {} /* generic_params */,
- std::move (return_type), where_clause,
- std::move (function_params), vis,
- function.get_outer_attrs (),
- function.get_locus ());
-
std::vector<std::unique_ptr<AST::ExternalItem>> external_items;
- external_items.push_back (
- std::unique_ptr<AST::ExternalItem> (external_item));
+ external_items.push_back (std::unique_ptr<AST::ExternalItem> (
+ static_cast<AST::ExternalItem *> (&function)));
AST::ExternBlock extern_block (get_string_from_abi (Rust::ABI::RUST),
std::move (external_items),
@@ -6034,68 +6034,6 @@ Parser<ManagedTokenSource>::parse_named_function_params (
return params;
}
-template <typename ManagedTokenSource>
-std::unique_ptr<AST::ExternalFunctionItem>
-Parser<ManagedTokenSource>::parse_external_function_item (
- AST::Visibility vis, AST::AttrVec outer_attrs)
-{
- location_t locus = lexer.peek_token ()->get_locus ();
-
- // parse extern function declaration item
- // skip function token
- lexer.skip_token ();
-
- // parse identifier
- const_TokenPtr ident_tok = expect_token (IDENTIFIER);
- if (ident_tok == nullptr)
- {
- skip_after_semicolon ();
- return nullptr;
- }
- Identifier ident{ident_tok};
-
- // parse (optional) generic params
- std::vector<std::unique_ptr<AST::GenericParam>> generic_params
- = parse_generic_params_in_angles ();
-
- if (!skip_token (LEFT_PAREN))
- {
- skip_after_semicolon ();
- return nullptr;
- }
-
- // parse parameters
- std::vector<AST::NamedFunctionParam> function_params
- = parse_named_function_params (
- [] (TokenId id) { return id == RIGHT_PAREN; });
-
- if (!skip_token (RIGHT_PAREN))
- {
- skip_after_semicolon ();
- return nullptr;
- }
-
- // parse (optional) return type
- std::unique_ptr<AST::Type> return_type = parse_function_return_type ();
-
- // parse (optional) where clause
- AST::WhereClause where_clause = parse_where_clause ();
-
- if (!skip_token (SEMICOLON))
- {
- // skip somewhere?
- return nullptr;
- }
-
- function_params.shrink_to_fit ();
-
- return std::unique_ptr<AST::ExternalFunctionItem> (
- new AST::ExternalFunctionItem (
- std::move (ident), std::move (generic_params), std::move (return_type),
- std::move (where_clause), std::move (function_params), std::move (vis),
- std::move (outer_attrs), locus));
-}
-
// Parses a single extern block item (static or function declaration).
template <typename ManagedTokenSource>
std::unique_ptr<AST::ExternalItem>
@@ -310,8 +310,6 @@ private:
AST::Lifetime lifetime_from_token (const_TokenPtr tok);
std::unique_ptr<AST::ExternalTypeItem>
parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs);
- std::unique_ptr<AST::ExternalFunctionItem>
- parse_external_function_item (AST::Visibility vis, AST::AttrVec outer_attrs);
AST::NamedFunctionParam parse_named_function_param ();
template <typename EndTokenPred>
std::vector<AST::NamedFunctionParam>
@@ -430,10 +430,6 @@ void
ResolverBase::visit (AST::ExternalStaticItem &)
{}
-void
-ResolverBase::visit (AST::ExternalFunctionItem &)
-{}
-
void
ResolverBase::visit (AST::ExternBlock &)
{}
@@ -135,7 +135,6 @@ public:
void visit (AST::ExternalTypeItem &);
void visit (AST::ExternalStaticItem &);
- void visit (AST::ExternalFunctionItem &);
void visit (AST::ExternBlock &);
void visit (AST::MacroMatchFragment &);
@@ -492,10 +492,6 @@ void
DefaultResolver::visit (AST::ExternalStaticItem &)
{}
-void
-DefaultResolver::visit (AST::ExternalFunctionItem &)
-{}
-
void
DefaultResolver::visit (AST::MacroMatchRepetition &)
{}
@@ -118,7 +118,6 @@ public:
void visit (AST::TraitItemType &);
void visit (AST::ExternalTypeItem &);
void visit (AST::ExternalStaticItem &);
- void visit (AST::ExternalFunctionItem &);
void visit (AST::MacroMatchRepetition &);
void visit (AST::MacroMatcher &);
void visit (AST::MacroRulesDefinition &);
@@ -766,10 +766,6 @@ void
AttributeChecker::visit (AST::ExternalStaticItem &)
{}
-void
-AttributeChecker::visit (AST::ExternalFunctionItem &)
-{}
-
void
AttributeChecker::visit (AST::ExternBlock &block)
{
@@ -199,7 +199,6 @@ private:
void visit (AST::TraitImpl &impl) override;
void visit (AST::ExternalTypeItem &item) override;
void visit (AST::ExternalStaticItem &item) override;
- void visit (AST::ExternalFunctionItem &item) override;
void visit (AST::ExternBlock &block) override;
// rust-macro.h
new file mode 100644
@@ -0,0 +1,5 @@
+extern "C" {
+ fn myfun0(a:i32,...) {}
+ // { dg-error "cannot have a body" "" { target *-*-* } .-1 }
+}
+