mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibCpp: Allow qualified names in AST Declaration nodes
Previously, the names of declarations where stored as a simple StringView. Because of that, we couldn't parse out-of-line function definitions, which have qualified names. For example, we couldn't parse the following snippet: ``` void MyClass::foo(){} ``` To fix this, we now store the name of a declaration with a ASTNode::Name node, which represents a qualified named.
This commit is contained in:
parent
604309327e
commit
7b42abccf2
4 changed files with 79 additions and 57 deletions
|
@ -248,7 +248,9 @@ String CppComprehensionEngine::type_of_property(const DocumentData& document, co
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
VERIFY(verify_cast<NamedType>(*type).name());
|
VERIFY(verify_cast<NamedType>(*type).name());
|
||||||
return verify_cast<NamedType>(*type).name()->full_name();
|
if (verify_cast<NamedType>(*type).name())
|
||||||
|
return verify_cast<NamedType>(*type).name()->full_name();
|
||||||
|
return String::empty();
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -260,9 +262,11 @@ String CppComprehensionEngine::type_of_variable(const Identifier& identifier) co
|
||||||
for (auto& decl : current->declarations()) {
|
for (auto& decl : current->declarations()) {
|
||||||
if (decl.is_variable_or_parameter_declaration()) {
|
if (decl.is_variable_or_parameter_declaration()) {
|
||||||
auto& var_or_param = verify_cast<VariableOrParameterDeclaration>(decl);
|
auto& var_or_param = verify_cast<VariableOrParameterDeclaration>(decl);
|
||||||
if (var_or_param.name() == identifier.name() && var_or_param.type()->is_named_type()) {
|
if (var_or_param.full_name() == identifier.name() && var_or_param.type()->is_named_type()) {
|
||||||
VERIFY(verify_cast<NamedType>(*var_or_param.type()).name());
|
VERIFY(verify_cast<NamedType>(*var_or_param.type()).name());
|
||||||
return verify_cast<NamedType>(*var_or_param.type()).name()->full_name();
|
if (verify_cast<NamedType>(*var_or_param.type()).name())
|
||||||
|
return verify_cast<NamedType>(*var_or_param.type()).name()->full_name();
|
||||||
|
return String::empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,14 +316,14 @@ Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::properties_of_typ
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& struct_or_class = verify_cast<StructOrClassDeclaration>(*decl);
|
auto& struct_or_class = verify_cast<StructOrClassDeclaration>(*decl);
|
||||||
VERIFY(struct_or_class.name() == type_symbol.name);
|
VERIFY(struct_or_class.full_name() == type_symbol.name);
|
||||||
|
|
||||||
Vector<Symbol> properties;
|
Vector<Symbol> properties;
|
||||||
for (auto& member : struct_or_class.members()) {
|
for (auto& member : struct_or_class.members()) {
|
||||||
Vector<StringView> scope(type_symbol.scope);
|
Vector<StringView> scope(type_symbol.scope);
|
||||||
scope.append(type_symbol.name);
|
scope.append(type_symbol.name);
|
||||||
// FIXME: We don't have to create the Symbol here, it should already exist in the 'm_symbol' table of some DocumentData we already parsed.
|
// FIXME: We don't have to create the Symbol here, it should already exist in the 'm_symbol' table of some DocumentData we already parsed.
|
||||||
properties.append(Symbol::create(member.name(), scope, member, Symbol::IsLocal::No));
|
properties.append(Symbol::create(member.full_name(), scope, member, Symbol::IsLocal::No));
|
||||||
}
|
}
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +343,7 @@ Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols
|
||||||
Vector<Symbol> symbols;
|
Vector<Symbol> symbols;
|
||||||
|
|
||||||
for (auto& decl : node.declarations()) {
|
for (auto& decl : node.declarations()) {
|
||||||
symbols.append(Symbol::create(decl.name(), scope, decl, is_local));
|
symbols.append(Symbol::create(decl.full_name(), scope, decl, is_local));
|
||||||
|
|
||||||
bool should_recurse = decl.is_namespace() || decl.is_struct_or_class() || decl.is_function();
|
bool should_recurse = decl.is_namespace() || decl.is_struct_or_class() || decl.is_function();
|
||||||
bool are_child_symbols_local = decl.is_function();
|
bool are_child_symbols_local = decl.is_function();
|
||||||
|
@ -348,7 +352,7 @@ Vector<CppComprehensionEngine::Symbol> CppComprehensionEngine::get_child_symbols
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto new_scope = scope;
|
auto new_scope = scope;
|
||||||
new_scope.append(decl.name());
|
new_scope.append(decl.full_name());
|
||||||
symbols.extend(get_child_symbols(decl, new_scope, are_child_symbols_local ? Symbol::IsLocal::Yes : is_local));
|
symbols.extend(get_child_symbols(decl, new_scope, are_child_symbols_local ? Symbol::IsLocal::Yes : is_local));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,11 +457,11 @@ static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.is_declaration()) {
|
if (node.is_declaration()) {
|
||||||
return get_target_declaration(node, verify_cast<Declaration>(node).name());
|
return get_target_declaration(node, verify_cast<Declaration>(node).full_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.is_type() && node.parent() && node.parent()->is_declaration()) {
|
if (node.is_type() && node.parent() && node.parent()->is_declaration()) {
|
||||||
return get_target_declaration(*node.parent(), verify_cast<Declaration>(node.parent())->name());
|
return get_target_declaration(*node.parent(), verify_cast<Declaration>(node.parent())->full_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgln("get_target_declaration: Invalid argument node of type: {}", node.class_name());
|
dbgln("get_target_declaration: Invalid argument node of type: {}", node.class_name());
|
||||||
|
@ -641,11 +645,11 @@ Vector<StringView> CppComprehensionEngine::scope_of_node(const ASTNode& node) co
|
||||||
|
|
||||||
StringView containing_scope;
|
StringView containing_scope;
|
||||||
if (parent_decl.is_namespace())
|
if (parent_decl.is_namespace())
|
||||||
containing_scope = static_cast<NamespaceDeclaration&>(parent_decl).name();
|
containing_scope = static_cast<NamespaceDeclaration&>(parent_decl).full_name();
|
||||||
if (parent_decl.is_struct_or_class())
|
if (parent_decl.is_struct_or_class())
|
||||||
containing_scope = static_cast<StructOrClassDeclaration&>(parent_decl).name();
|
containing_scope = static_cast<StructOrClassDeclaration&>(parent_decl).full_name();
|
||||||
if (parent_decl.is_function())
|
if (parent_decl.is_function())
|
||||||
containing_scope = static_cast<FunctionDeclaration&>(parent_decl).name();
|
containing_scope = static_cast<FunctionDeclaration&>(parent_decl).full_name();
|
||||||
|
|
||||||
parent_scope.append(containing_scope);
|
parent_scope.append(containing_scope);
|
||||||
return parent_scope;
|
return parent_scope;
|
||||||
|
|
|
@ -41,7 +41,7 @@ void FunctionDeclaration::dump(FILE* output, size_t indent) const
|
||||||
m_return_type->dump(output, indent + 1);
|
m_return_type->dump(output, indent + 1);
|
||||||
if (!m_name.is_null()) {
|
if (!m_name.is_null()) {
|
||||||
print_indent(output, indent + 1);
|
print_indent(output, indent + 1);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", m_name->full_name());
|
||||||
}
|
}
|
||||||
print_indent(output, indent + 1);
|
print_indent(output, indent + 1);
|
||||||
outln(output, "(");
|
outln(output, "(");
|
||||||
|
@ -125,9 +125,9 @@ String FunctionType::to_string() const
|
||||||
else
|
else
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
builder.append(parameter.type()->to_string());
|
builder.append(parameter.type()->to_string());
|
||||||
if (!parameter.name().is_empty()) {
|
if (parameter.name() && !parameter.full_name().is_empty()) {
|
||||||
builder.append(" ");
|
builder.append(" ");
|
||||||
builder.append(parameter.name());
|
builder.append(parameter.full_name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append(")");
|
builder.append(")");
|
||||||
|
@ -143,7 +143,7 @@ void Parameter::dump(FILE* output, size_t indent) const
|
||||||
}
|
}
|
||||||
if (!m_name.is_null()) {
|
if (!m_name.is_null()) {
|
||||||
print_indent(output, indent);
|
print_indent(output, indent);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", m_name->full_name());
|
||||||
}
|
}
|
||||||
if (m_type)
|
if (m_type)
|
||||||
m_type->dump(output, indent + 1);
|
m_type->dump(output, indent + 1);
|
||||||
|
@ -176,7 +176,7 @@ void VariableDeclaration::dump(FILE* output, size_t indent) const
|
||||||
if (m_type)
|
if (m_type)
|
||||||
m_type->dump(output, indent + 1);
|
m_type->dump(output, indent + 1);
|
||||||
print_indent(output, indent + 1);
|
print_indent(output, indent + 1);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", full_name());
|
||||||
if (m_initial_value)
|
if (m_initial_value)
|
||||||
m_initial_value->dump(output, indent + 1);
|
m_initial_value->dump(output, indent + 1);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ void EnumDeclaration::dump(FILE* output, size_t indent) const
|
||||||
{
|
{
|
||||||
ASTNode::dump(output, indent);
|
ASTNode::dump(output, indent);
|
||||||
print_indent(output, indent);
|
print_indent(output, indent);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", full_name());
|
||||||
for (auto& entry : m_entries) {
|
for (auto& entry : m_entries) {
|
||||||
print_indent(output, indent + 1);
|
print_indent(output, indent + 1);
|
||||||
outln(output, "{}", entry.name);
|
outln(output, "{}", entry.name);
|
||||||
|
@ -331,7 +331,7 @@ void StructOrClassDeclaration::dump(FILE* output, size_t indent) const
|
||||||
{
|
{
|
||||||
ASTNode::dump(output, indent);
|
ASTNode::dump(output, indent);
|
||||||
print_indent(output, indent);
|
print_indent(output, indent);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", full_name());
|
||||||
for (auto& member : m_members) {
|
for (auto& member : m_members) {
|
||||||
member.dump(output, indent + 1);
|
member.dump(output, indent + 1);
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ void NamespaceDeclaration::dump(FILE* output, size_t indent) const
|
||||||
{
|
{
|
||||||
ASTNode::dump(output, indent);
|
ASTNode::dump(output, indent);
|
||||||
print_indent(output, indent + 1);
|
print_indent(output, indent + 1);
|
||||||
outln(output, "{}", m_name);
|
outln(output, "{}", full_name());
|
||||||
for (auto& decl : m_declarations)
|
for (auto& decl : m_declarations)
|
||||||
decl.dump(output, indent + 1);
|
decl.dump(output, indent + 1);
|
||||||
}
|
}
|
||||||
|
@ -527,19 +527,26 @@ void Name::dump(FILE* output, size_t indent) const
|
||||||
outln(output, "{}", full_name());
|
outln(output, "{}", full_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
String Name::full_name() const
|
StringView Name::full_name() const
|
||||||
{
|
{
|
||||||
|
if (m_full_name.has_value())
|
||||||
|
return *m_full_name;
|
||||||
|
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
if (!m_scope.is_empty()) {
|
if (!m_scope.is_empty()) {
|
||||||
for (auto& scope : m_scope) {
|
for (auto& scope : m_scope) {
|
||||||
builder.appendff("{}::", scope.name());
|
builder.appendff("{}::", scope.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return String::formatted("{}{}", builder.to_string(), m_name.is_null() ? "" : m_name->name());
|
m_full_name = String::formatted("{}{}", builder.to_string(), m_name.is_null() ? "" : m_name->name());
|
||||||
|
return *m_full_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
String TemplatizedName::full_name() const
|
StringView TemplatizedName::full_name() const
|
||||||
{
|
{
|
||||||
|
if (m_full_name.has_value())
|
||||||
|
return *m_full_name;
|
||||||
|
|
||||||
StringBuilder name;
|
StringBuilder name;
|
||||||
name.append(Name::full_name());
|
name.append(Name::full_name());
|
||||||
name.append('<');
|
name.append('<');
|
||||||
|
@ -547,7 +554,8 @@ String TemplatizedName::full_name() const
|
||||||
name.append(type.to_string());
|
name.append(type.to_string());
|
||||||
}
|
}
|
||||||
name.append('>');
|
name.append('>');
|
||||||
return name.to_string();
|
m_full_name = name.to_string();
|
||||||
|
return *m_full_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppCastExpression::dump(FILE* output, size_t indent) const
|
void CppCastExpression::dump(FILE* output, size_t indent) const
|
||||||
|
@ -624,4 +632,16 @@ void Destructor::dump(FILE* output, size_t indent) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringView Declaration::full_name() const
|
||||||
|
{
|
||||||
|
if (!m_full_name.has_value()) {
|
||||||
|
if (m_name)
|
||||||
|
m_full_name = m_name->full_name();
|
||||||
|
else
|
||||||
|
m_full_name = String::empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *m_full_name;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,8 +125,9 @@ public:
|
||||||
virtual bool is_function() const { return false; }
|
virtual bool is_function() const { return false; }
|
||||||
virtual bool is_namespace() const { return false; }
|
virtual bool is_namespace() const { return false; }
|
||||||
bool is_member() const { return parent() != nullptr && parent()->is_declaration() && verify_cast<Declaration>(parent())->is_struct_or_class(); }
|
bool is_member() const { return parent() != nullptr && parent()->is_declaration() && verify_cast<Declaration>(parent())->is_struct_or_class(); }
|
||||||
StringView name() const { return m_name; }
|
const Name* name() const { return m_name; }
|
||||||
void set_name(StringView name) { m_name = move(name); }
|
StringView full_name() const;
|
||||||
|
void set_name(RefPtr<Name> name) { m_name = move(name); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Declaration(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
|
Declaration(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
|
||||||
|
@ -134,7 +135,8 @@ protected:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
StringView m_name;
|
RefPtr<Name> m_name;
|
||||||
|
mutable Optional<String> m_full_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InvalidDeclaration : public Declaration {
|
class InvalidDeclaration : public Declaration {
|
||||||
|
@ -204,7 +206,7 @@ public:
|
||||||
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
|
virtual void dump(FILE* = stdout, size_t indent = 0) const override;
|
||||||
virtual bool is_parameter() const override { return true; }
|
virtual bool is_parameter() const override { return true; }
|
||||||
|
|
||||||
Parameter(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename, StringView name)
|
Parameter(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename, RefPtr<Name> name)
|
||||||
: VariableOrParameterDeclaration(parent, start, end, filename)
|
: VariableOrParameterDeclaration(parent, start, end, filename)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
@ -436,7 +438,7 @@ public:
|
||||||
: Expression(parent, start, end, filename)
|
: Expression(parent, start, end, filename)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
virtual String full_name() const;
|
virtual StringView full_name() const;
|
||||||
|
|
||||||
const Identifier* name() const { return m_name.ptr(); }
|
const Identifier* name() const { return m_name.ptr(); }
|
||||||
void set_name(RefPtr<Identifier>&& name) { m_name = move(name); }
|
void set_name(RefPtr<Identifier>&& name) { m_name = move(name); }
|
||||||
|
@ -447,6 +449,7 @@ public:
|
||||||
private:
|
private:
|
||||||
RefPtr<Identifier> m_name;
|
RefPtr<Identifier> m_name;
|
||||||
NonnullRefPtrVector<Identifier> m_scope;
|
NonnullRefPtrVector<Identifier> m_scope;
|
||||||
|
mutable Optional<String> m_full_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TemplatizedName : public Name {
|
class TemplatizedName : public Name {
|
||||||
|
@ -454,7 +457,7 @@ public:
|
||||||
virtual ~TemplatizedName() override = default;
|
virtual ~TemplatizedName() override = default;
|
||||||
virtual const char* class_name() const override { return "TemplatizedName"; }
|
virtual const char* class_name() const override { return "TemplatizedName"; }
|
||||||
virtual bool is_templatized() const override { return true; }
|
virtual bool is_templatized() const override { return true; }
|
||||||
virtual String full_name() const override;
|
virtual StringView full_name() const override;
|
||||||
|
|
||||||
TemplatizedName(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
|
TemplatizedName(ASTNode* parent, Optional<Position> start, Optional<Position> end, const String& filename)
|
||||||
: Name(parent, start, end, filename)
|
: Name(parent, start, end, filename)
|
||||||
|
@ -465,6 +468,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NonnullRefPtrVector<Type> m_template_arguments;
|
NonnullRefPtrVector<Type> m_template_arguments;
|
||||||
|
mutable Optional<String> m_full_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NumericLiteral : public Expression {
|
class NumericLiteral : public Expression {
|
||||||
|
|
|
@ -104,8 +104,7 @@ NonnullRefPtr<FunctionDeclaration> Parser::parse_function_declaration(ASTNode& p
|
||||||
func->set_qualifiers(parse_function_qualifiers());
|
func->set_qualifiers(parse_function_qualifiers());
|
||||||
func->set_return_type(parse_type(*func));
|
func->set_return_type(parse_type(*func));
|
||||||
|
|
||||||
auto function_name = consume(Token::Type::Identifier);
|
func->set_name(parse_name(*func));
|
||||||
func->set_name(text_of_token(function_name));
|
|
||||||
|
|
||||||
consume(Token::Type::LeftParen);
|
consume(Token::Type::LeftParen);
|
||||||
auto parameters = parse_parameter_list(*func);
|
auto parameters = parse_parameter_list(*func);
|
||||||
|
@ -318,7 +317,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& p
|
||||||
return var;
|
return var;
|
||||||
}
|
}
|
||||||
var->set_type(parse_type(var));
|
var->set_type(parse_type(var));
|
||||||
auto identifier_token = consume(Token::Type::Identifier);
|
auto name = parse_name(*var);
|
||||||
RefPtr<Expression> initial_value;
|
RefPtr<Expression> initial_value;
|
||||||
|
|
||||||
if (match(Token::Type::Equals)) {
|
if (match(Token::Type::Equals)) {
|
||||||
|
@ -334,7 +333,7 @@ NonnullRefPtr<VariableDeclaration> Parser::parse_variable_declaration(ASTNode& p
|
||||||
consume(Token::Type::Semicolon);
|
consume(Token::Type::Semicolon);
|
||||||
|
|
||||||
var->set_end(position());
|
var->set_end(position());
|
||||||
var->set_name(text_of_token(identifier_token));
|
var->set_name(name);
|
||||||
var->set_initial_value(move(initial_value));
|
var->set_initial_value(move(initial_value));
|
||||||
|
|
||||||
return var;
|
return var;
|
||||||
|
@ -720,9 +719,10 @@ bool Parser::match_function_declaration()
|
||||||
VERIFY(m_root_node);
|
VERIFY(m_root_node);
|
||||||
(void)parse_type(get_dummy_node());
|
(void)parse_type(get_dummy_node());
|
||||||
|
|
||||||
if (!peek(Token::Type::Identifier).has_value())
|
if (!match_name())
|
||||||
return false;
|
return false;
|
||||||
consume();
|
|
||||||
|
(void)parse_name(get_dummy_node());
|
||||||
|
|
||||||
if (!peek(Token::Type::LeftParen).has_value())
|
if (!peek(Token::Type::LeftParen).has_value())
|
||||||
return false;
|
return false;
|
||||||
|
@ -750,7 +750,7 @@ Optional<NonnullRefPtrVector<Parameter>> Parser::parse_parameter_list(ASTNode& p
|
||||||
NonnullRefPtrVector<Parameter> parameters;
|
NonnullRefPtrVector<Parameter> parameters;
|
||||||
while (peek().type() != Token::Type::RightParen && !eof()) {
|
while (peek().type() != Token::Type::RightParen && !eof()) {
|
||||||
if (match_ellipsis()) {
|
if (match_ellipsis()) {
|
||||||
auto param = create_ast_node<Parameter>(parent, position(), {}, StringView {});
|
auto param = create_ast_node<Parameter>(parent, position(), {}, RefPtr<Name> {});
|
||||||
consume(Token::Type::Dot);
|
consume(Token::Type::Dot);
|
||||||
consume(Token::Type::Dot);
|
consume(Token::Type::Dot);
|
||||||
auto last_dot = consume(Token::Type::Dot);
|
auto last_dot = consume(Token::Type::Dot);
|
||||||
|
@ -760,15 +760,12 @@ Optional<NonnullRefPtrVector<Parameter>> Parser::parse_parameter_list(ASTNode& p
|
||||||
} else {
|
} else {
|
||||||
auto type = parse_type(parent);
|
auto type = parse_type(parent);
|
||||||
|
|
||||||
auto name_identifier = peek(Token::Type::Identifier);
|
RefPtr<Name> name;
|
||||||
if (name_identifier.has_value())
|
if (match_name()) {
|
||||||
consume(Token::Type::Identifier);
|
name = parse_name(parent);
|
||||||
|
}
|
||||||
|
|
||||||
StringView name;
|
auto param = create_ast_node<Parameter>(parent, type->start(), !name.is_null() ? name->end() : type->end(), name);
|
||||||
if (name_identifier.has_value())
|
|
||||||
name = text_of_token(name_identifier.value());
|
|
||||||
|
|
||||||
auto param = create_ast_node<Parameter>(parent, type->start(), name_identifier.has_value() ? name_identifier.value().end() : type->end(), name);
|
|
||||||
type->set_parent(*param.ptr());
|
type->set_parent(*param.ptr());
|
||||||
|
|
||||||
param->set_type(move(type));
|
param->set_type(move(type));
|
||||||
|
@ -1087,8 +1084,8 @@ NonnullRefPtr<EnumDeclaration> Parser::parse_enum_declaration(ASTNode& parent)
|
||||||
enum_decl->set_type(EnumDeclaration::Type::RegularEnum);
|
enum_decl->set_type(EnumDeclaration::Type::RegularEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto name_token = consume(Token::Type::Identifier);
|
auto name = parse_name(*enum_decl);
|
||||||
enum_decl->set_name(text_of_token(name_token));
|
enum_decl->set_name(name);
|
||||||
consume(Token::Type::LeftCurly);
|
consume(Token::Type::LeftCurly);
|
||||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||||
auto name = text_of_token(consume(Token::Type::Identifier));
|
auto name = text_of_token(consume(Token::Type::Identifier));
|
||||||
|
@ -1149,8 +1146,8 @@ NonnullRefPtr<StructOrClassDeclaration> Parser::parse_class_declaration(ASTNode&
|
||||||
|
|
||||||
auto decl = create_ast_node<StructOrClassDeclaration>(parent, position(), {}, type);
|
auto decl = create_ast_node<StructOrClassDeclaration>(parent, position(), {}, type);
|
||||||
|
|
||||||
auto name_token = consume(Token::Type::Identifier);
|
auto name = parse_name(*decl);
|
||||||
decl->set_name(text_of_token(name_token));
|
decl->set_name(name);
|
||||||
|
|
||||||
auto has_final = match_keyword("final");
|
auto has_final = match_keyword("final");
|
||||||
|
|
||||||
|
@ -1394,8 +1391,8 @@ NonnullRefPtr<NamespaceDeclaration> Parser::parse_namespace_declaration(ASTNode&
|
||||||
if (!is_nested_namespace)
|
if (!is_nested_namespace)
|
||||||
consume(Token::Type::Keyword);
|
consume(Token::Type::Keyword);
|
||||||
|
|
||||||
auto name_token = consume(Token::Type::Identifier);
|
auto name = parse_name(*namespace_decl);
|
||||||
namespace_decl->set_name(name_token.text());
|
namespace_decl->set_name(name);
|
||||||
|
|
||||||
if (peek().type() == Token::Type::ColonColon) {
|
if (peek().type() == Token::Type::ColonColon) {
|
||||||
consume(Token::Type::ColonColon);
|
consume(Token::Type::ColonColon);
|
||||||
|
@ -1565,7 +1562,7 @@ NonnullRefPtr<BracedInitList> Parser::parse_braced_init_list(ASTNode& parent)
|
||||||
}
|
}
|
||||||
NonnullRefPtrVector<Declaration> Parser::parse_class_members(StructOrClassDeclaration& parent)
|
NonnullRefPtrVector<Declaration> Parser::parse_class_members(StructOrClassDeclaration& parent)
|
||||||
{
|
{
|
||||||
auto class_name = parent.name();
|
auto class_name = parent.full_name();
|
||||||
|
|
||||||
NonnullRefPtrVector<Declaration> members;
|
NonnullRefPtrVector<Declaration> members;
|
||||||
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
while (!eof() && peek().type() != Token::Type::RightCurly) {
|
||||||
|
@ -1652,11 +1649,8 @@ void Parser::parse_constructor_or_destructor_impl(FunctionDeclaration& func, Cto
|
||||||
consume(Token::Type::Tilde);
|
consume(Token::Type::Tilde);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto name_token = consume();
|
auto name = parse_name(func);
|
||||||
if (name_token.type() != Token::Type::Identifier && name_token.type() != Token::Type::KnownType) {
|
func.set_name(name);
|
||||||
error("Unexpected constructor name");
|
|
||||||
}
|
|
||||||
func.set_name(name_token.text());
|
|
||||||
|
|
||||||
consume(Token::Type::LeftParen);
|
consume(Token::Type::LeftParen);
|
||||||
auto parameters = parse_parameter_list(func);
|
auto parameters = parse_parameter_list(func);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue