Commit 2f9399c7 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] IdentifierExpression, NameAndType and Signature use Identifier

This CL changes a few AST nodes and one internal structure to use "Identifier"
instead of a simple std::string, allowing the use of the exact source position
of such a name.

Drive-by change: Add new constructor to Binding that allows creation from
an Identifier. It sets the declaration_position to the source position of
the name instead of using "CurrentSourcePosition".

R=tebbi@chromium.org

Bug: v8:7793
Change-Id: I456d20822b6528d2e96400c28ebfebea3ca80613
Reviewed-on: https://chromium-review.googlesource.com/c/1491223
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59899}
parent a6f226e8
......@@ -207,17 +207,17 @@ struct IdentifierExpression : LocationExpression {
DEFINE_AST_NODE_LEAF_BOILERPLATE(IdentifierExpression)
IdentifierExpression(SourcePosition pos,
std::vector<std::string> namespace_qualification,
std::string name, std::vector<TypeExpression*> args = {})
Identifier* name, std::vector<TypeExpression*> args = {})
: LocationExpression(kKind, pos),
namespace_qualification(std::move(namespace_qualification)),
name(std::move(name)),
name(name),
generic_arguments(std::move(args)) {}
IdentifierExpression(SourcePosition pos, std::string name,
IdentifierExpression(SourcePosition pos, Identifier* name,
std::vector<TypeExpression*> args = {})
: IdentifierExpression(pos, {}, std::move(name), std::move(args)) {}
bool IsThis() const { return name == kThisParameterName; }
: IdentifierExpression(pos, {}, name, std::move(args)) {}
bool IsThis() const { return name->value == kThisParameterName; }
std::vector<std::string> namespace_qualification;
std::string name;
Identifier* name;
std::vector<TypeExpression*> generic_arguments;
};
......@@ -419,7 +419,7 @@ struct NewExpression : Expression {
};
struct ParameterList {
std::vector<std::string> names;
std::vector<Identifier*> names;
std::vector<TypeExpression*> types;
size_t implicit_count;
bool has_varargs;
......@@ -693,7 +693,7 @@ struct TypeAliasDeclaration : Declaration {
};
struct NameAndTypeExpression {
std::string name;
Identifier* name;
TypeExpression* type;
};
......
......@@ -246,7 +246,7 @@ void DeclarationVisitor::DeclareMethods(
AggregateType* container_type, const std::vector<Declaration*>& methods) {
// Declare the class' methods
IdentifierExpression* constructor_this = MakeNode<IdentifierExpression>(
std::vector<std::string>{}, kThisParameterName);
std::vector<std::string>{}, MakeNode<Identifier>(kThisParameterName));
AggregateType* constructor_this_type =
container_type->IsStructType()
? container_type
......@@ -261,7 +261,7 @@ void DeclarationVisitor::DeclareMethods(
Signature signature = MakeSignature(method->signature.get());
signature.parameter_names.insert(
signature.parameter_names.begin() + signature.implicit_count,
kThisParameterName);
MakeNode<Identifier>(kThisParameterName));
Statement* body = *(standard_declaration->body);
std::string method_name(method->name);
if (method->name == kConstructMethodName) {
......@@ -304,21 +304,23 @@ void DeclarationVisitor::DeclareMethods(
std::vector<Statement*> initializer_statements;
size_t parameter_number = 0;
constructor_signature.parameter_names.push_back(kThisParameterName);
constructor_signature.parameter_names.push_back(
MakeNode<Identifier>(kThisParameterName));
constructor_signature.parameter_types.types.push_back(constructor_this_type);
std::vector<Expression*> super_arguments;
for (auto current_type : hierarchy) {
for (auto& f : current_type->fields()) {
DCHECK(!f.index);
std::string parameter_name("p" + std::to_string(parameter_number++));
constructor_signature.parameter_names.push_back(parameter_name);
constructor_signature.parameter_names.push_back(
MakeNode<Identifier>(parameter_name));
constructor_signature.parameter_types.types.push_back(
f.name_and_type.type);
IdentifierExpression* value = MakeNode<IdentifierExpression>(
std::vector<std::string>{}, parameter_name);
std::vector<std::string>{}, MakeNode<Identifier>(parameter_name));
if (container_type != current_type) {
super_arguments.push_back(MakeNode<IdentifierExpression>(
std::vector<std::string>{}, parameter_name));
std::vector<std::string>{}, MakeNode<Identifier>(parameter_name)));
} else {
LocationExpression* location = MakeNode<FieldAccessExpression>(
constructor_this, f.name_and_type.name);
......@@ -331,7 +333,7 @@ void DeclarationVisitor::DeclareMethods(
if (hierarchy.size() > 1) {
IdentifierExpression* super_identifier = MakeNode<IdentifierExpression>(
std::vector<std::string>{}, kSuperMethodName);
std::vector<std::string>{}, MakeNode<Identifier>(kSuperMethodName));
Statement* statement =
MakeNode<ExpressionStatement>(MakeNode<CallMethodExpression>(
constructor_this, super_identifier, super_arguments,
......@@ -543,7 +545,7 @@ void DeclarationVisitor::FinalizeStructFieldsAndMethods(
struct_type->RegisterField({field.name_and_type.type->pos,
struct_type,
base::nullopt,
{field.name_and_type.name, field_type},
{field.name_and_type.name->value, field_type},
offset,
false});
offset += LoweredSlotCount(field_type);
......@@ -583,7 +585,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
{field_expression.name_and_type.type->pos,
class_type,
index_field,
{field_expression.name_and_type.name, field_type},
{field_expression.name_and_type.name->value, field_type},
class_offset,
field_expression.weak});
} else {
......@@ -597,7 +599,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
{field_expression.name_and_type.type->pos,
class_type,
base::nullopt,
{field_expression.name_and_type.name, field_type},
{field_expression.name_and_type.name->value, field_type},
class_offset,
field_expression.weak});
size_t field_size;
......@@ -659,7 +661,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
if (field.index) continue;
CurrentSourcePosition::Scope position_activator(field.pos);
IdentifierExpression* parameter =
MakeNode<IdentifierExpression>(std::string{"o"});
MakeNode<IdentifierExpression>(MakeNode<Identifier>(std::string{"o"}));
// Load accessor
std::string camel_field_name = CamelifyString(field.name_and_type.name);
......@@ -667,7 +669,7 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
"Load" + class_type->name() + camel_field_name;
std::string load_operator_name = "." + field.name_and_type.name;
Signature load_signature;
load_signature.parameter_names.push_back("o");
load_signature.parameter_names.push_back(MakeNode<Identifier>("o"));
load_signature.parameter_types.types.push_back(class_type);
load_signature.parameter_types.var_args = false;
load_signature.return_type = field.name_and_type.type;
......@@ -679,13 +681,13 @@ void DeclarationVisitor::FinalizeClassFieldsAndMethods(
// Store accessor
IdentifierExpression* value = MakeNode<IdentifierExpression>(
std::vector<std::string>{}, std::string{"v"});
std::vector<std::string>{}, MakeNode<Identifier>(std::string{"v"}));
std::string store_macro_name =
"Store" + class_type->name() + camel_field_name;
std::string store_operator_name = "." + field.name_and_type.name + "=";
Signature store_signature;
store_signature.parameter_names.push_back("o");
store_signature.parameter_names.push_back("v");
store_signature.parameter_names.push_back(MakeNode<Identifier>("o"));
store_signature.parameter_names.push_back(MakeNode<Identifier>("v"));
store_signature.parameter_types.types.push_back(class_type);
store_signature.parameter_types.types.push_back(field.name_and_type.type);
store_signature.parameter_types.var_args = false;
......
......@@ -251,7 +251,7 @@ VisitResult ImplementationVisitor::InlineMacro(
size_t i = 0;
for (auto arg : arguments) {
if (this_reference && i == signature.implicit_count) i++;
const std::string& name = macro->parameter_names()[i++];
const Identifier* name = macro->parameter_names()[i++];
parameter_bindings.Add(name, LocalValue{true, arg});
}
......@@ -368,7 +368,7 @@ void ImplementationVisitor::VisitMacroCommon(Macro* macro) {
for (size_t i = 0; i < macro->signature().parameter_names.size(); ++i) {
if (this_reference && i == macro->signature().implicit_count) continue;
const std::string& name = macro->parameter_names()[i];
const std::string& name = macro->parameter_names()[i]->value;
std::string external_name = ExternalParameterName(name);
const Type* type = macro->signature().types()[i];
......@@ -449,7 +449,7 @@ std::string AddParameter(size_t i, Builtin* builtin,
Stack<std::string>* parameters,
Stack<const Type*>* parameter_types,
BlockBindings<LocalValue>* parameter_bindings) {
const std::string& name = builtin->signature().parameter_names[i];
const Identifier* name = builtin->signature().parameter_names[i];
const Type* type = builtin->signature().types()[i];
std::string external_name = "parameter" + std::to_string(i);
parameters->Push(external_name);
......@@ -512,7 +512,7 @@ void ImplementationVisitor::Visit(Builtin* builtin) {
for (size_t i = 0; i < signature.parameter_names.size(); ++i) {
if (i < first) continue;
const std::string& parameter_name = signature.parameter_names[i];
const std::string& parameter_name = signature.parameter_names[i]->value;
const Type* type = signature.types()[i];
std::string var = AddParameter(i, builtin, &parameters, &parameter_types,
&parameter_bindings);
......@@ -579,7 +579,7 @@ const Type* ImplementationVisitor::Visit(
init_result =
VisitResult(*type, assembler().TopRange(lowered_types.size()));
}
block_bindings->Add(stmt->name->value,
block_bindings->Add(stmt->name,
LocalValue{stmt->const_qualified, *init_result});
return TypeOracle::GetVoidType();
}
......@@ -1445,14 +1445,14 @@ void ImplementationVisitor::GenerateFunctionDeclaration(
DCHECK_EQ(signature.types().size(), parameter_names.size());
auto type_iterator = signature.types().begin();
bool first = true;
for (const std::string& name : parameter_names) {
for (const Identifier* name : parameter_names) {
if (!first) {
o << ", ";
}
const Type* parameter_type = *type_iterator;
const std::string& generated_type_name =
parameter_type->GetGeneratedTypeName();
o << generated_type_name << " " << ExternalParameterName(name);
o << generated_type_name << " " << ExternalParameterName(name->value);
type_iterator++;
first = false;
}
......@@ -1760,14 +1760,14 @@ LocationReference ImplementationVisitor::GetLocationReference(
IdentifierExpression* expr) {
if (expr->namespace_qualification.empty()) {
if (base::Optional<Binding<LocalValue>*> value =
TryLookupLocalValue(expr->name)) {
TryLookupLocalValue(expr->name->value)) {
if (expr->generic_arguments.size() != 0) {
ReportError("cannot have generic parameters on local name ",
expr->name);
}
if ((*value)->is_const) {
return LocationReference::Temporary((*value)->value,
"constant value " + expr->name);
return LocationReference::Temporary(
(*value)->value, "constant value " + expr->name->value);
}
return LocationReference::VariableAccess((*value)->value);
}
......@@ -1776,10 +1776,11 @@ LocationReference ImplementationVisitor::GetLocationReference(
if (expr->IsThis()) {
ReportError("\"this\" cannot be qualified");
}
QualifiedName name = QualifiedName(expr->namespace_qualification, expr->name);
QualifiedName name =
QualifiedName(expr->namespace_qualification, expr->name->value);
if (base::Optional<Builtin*> builtin = Declarations::TryLookupBuiltin(name)) {
return LocationReference::Temporary(GetBuiltinCode(*builtin),
"builtin " + expr->name);
"builtin " + expr->name->value);
}
if (expr->generic_arguments.size() != 0) {
Generic* generic = Declarations::LookupUniqueGeneric(name);
......@@ -1788,7 +1789,7 @@ LocationReference ImplementationVisitor::GetLocationReference(
if (Builtin* builtin = Builtin::DynamicCast(specialization)) {
DCHECK(!builtin->IsExternal());
return LocationReference::Temporary(GetBuiltinCode(builtin),
"builtin " + expr->name);
"builtin " + expr->name->value);
} else {
ReportError("cannot create function pointer for non-builtin ",
generic->name());
......@@ -1801,18 +1802,18 @@ LocationReference ImplementationVisitor::GetLocationReference(
VisitResult(constant->type(), constant->ExternalAssemblerName() +
"(state_)." +
constant->constant_name() + "()"),
"namespace constant " + expr->name);
"namespace constant " + expr->name->value);
}
assembler().Emit(NamespaceConstantInstruction{constant});
StackRange stack_range =
assembler().TopRange(LoweredSlotCount(constant->type()));
return LocationReference::Temporary(
VisitResult(constant->type(), stack_range),
"namespace constant " + expr->name);
"namespace constant " + expr->name->value);
}
ExternConstant* constant = ExternConstant::cast(value);
return LocationReference::Temporary(constant->value(),
"extern value " + expr->name);
"extern value " + expr->name->value);
}
VisitResult ImplementationVisitor::GenerateFetchFromLocation(
......@@ -1952,7 +1953,8 @@ VisitResult ImplementationVisitor::GenerateCall(
size_t current = 0;
for (; current < callable->signature().implicit_count; ++current) {
std::string implicit_name = callable->signature().parameter_names[current];
std::string implicit_name =
callable->signature().parameter_names[current]->value;
base::Optional<Binding<LocalValue>*> val =
TryLookupLocalValue(implicit_name);
if (!val) {
......@@ -2181,8 +2183,8 @@ VisitResult ImplementationVisitor::Visit(CallExpression* expr,
bool is_tailcall) {
StackScope scope(this);
Arguments arguments;
QualifiedName name =
QualifiedName(expr->callee->namespace_qualification, expr->callee->name);
QualifiedName name = QualifiedName(expr->callee->namespace_qualification,
expr->callee->name->value);
TypeVector specialization_types =
GetTypeVector(expr->callee->generic_arguments);
bool has_template_arguments = !specialization_types.empty();
......@@ -2202,7 +2204,7 @@ VisitResult ImplementationVisitor::Visit(CallExpression* expr,
VisitResult ImplementationVisitor::Visit(CallMethodExpression* expr) {
StackScope scope(this);
Arguments arguments;
std::string method_name = expr->method->name;
std::string method_name = expr->method->name->value;
TypeVector specialization_types =
GetTypeVector(expr->method->generic_arguments);
LocationReference target = GetLocationReference(expr->target);
......@@ -2543,7 +2545,7 @@ void ImplementationVisitor::GenerateBuiltinDefinitions(std::string& file_name) {
int index = 0;
for (const auto& parameter : builtin->parameter_names()) {
if (index >= firstParameterIndex) {
new_contents_stream << ", k" << CamelifyString(parameter);
new_contents_stream << ", k" << CamelifyString(parameter->value);
}
index++;
}
......
......@@ -166,6 +166,11 @@ class Binding : public T {
previous_binding_(this) {
std::swap(previous_binding_, manager_->current_bindings_[name]);
}
template <class... Args>
Binding(BindingsManager<T>* manager, const Identifier* name, Args&&... args)
: Binding(manager, name->value, std::forward<Args>(args)...) {
declaration_position_ = name->pos;
}
~Binding() { manager_->current_bindings_[name_] = previous_binding_; }
const std::string& name() const { return name_; }
......@@ -184,18 +189,17 @@ class BlockBindings {
public:
explicit BlockBindings(BindingsManager<T>* manager) : manager_(manager) {}
void Add(std::string name, T value) {
for (const auto& binding : bindings_) {
if (binding->name() == name) {
ReportError(
"redeclaration of name \"", name,
"\" in the same block is illegal, previous declaration at: ",
binding->declaration_position());
}
}
ReportErrorIfAlreadyBound(name);
bindings_.push_back(base::make_unique<Binding<T>>(manager_, std::move(name),
std::move(value)));
}
void Add(const Identifier* name, T value) {
ReportErrorIfAlreadyBound(name->value);
bindings_.push_back(
base::make_unique<Binding<T>>(manager_, name, std::move(value)));
}
std::vector<Binding<T>*> bindings() const {
std::vector<Binding<T>*> result;
result.reserve(bindings_.size());
......@@ -206,6 +210,17 @@ class BlockBindings {
}
private:
void ReportErrorIfAlreadyBound(const std::string& name) {
for (const auto& binding : bindings_) {
if (binding->name() == name) {
ReportError(
"redeclaration of name \"", name,
"\" in the same block is illegal, previous declaration at: ",
binding->declaration_position());
}
}
}
BindingsManager<T>* manager_;
std::vector<std::unique_ptr<Binding<T>>> bindings_;
};
......
......@@ -208,7 +208,7 @@ Expression* MakeCall(IdentifierExpression* callee,
if (id->generic_arguments.size() != 0) {
ReportError("An otherwise label cannot have generic parameters");
}
labels.push_back(id->name);
labels.push_back(id->name->value);
continue;
}
}
......@@ -238,7 +238,8 @@ Expression* MakeCall(const std::string& callee,
const std::vector<TypeExpression*>& generic_arguments,
const std::vector<Expression*>& arguments,
const std::vector<Statement*>& otherwise) {
return MakeCall(MakeNode<IdentifierExpression>(callee, generic_arguments),
return MakeCall(MakeNode<IdentifierExpression>(MakeNode<Identifier>(callee),
generic_arguments),
base::nullopt, arguments, otherwise);
}
......@@ -247,15 +248,17 @@ base::Optional<ParseResult> MakeCall(ParseResultIterator* child_results) {
auto args = child_results->NextAs<std::vector<Expression*>>();
auto otherwise = child_results->NextAs<std::vector<Statement*>>();
IdentifierExpression* target = IdentifierExpression::cast(callee);
if (target->name == kSuperMethodName) {
if (target->name->value == kSuperMethodName) {
if (target->namespace_qualification.size() != 0) {
ReportError(
"\"super\" invocation cannot be used with namespace qualification");
}
target = MakeNode<IdentifierExpression>(kSuperMethodName);
return ParseResult{
MakeCall(target, MakeNode<IdentifierExpression>(kThisParameterName),
args, otherwise)};
target =
MakeNode<IdentifierExpression>(MakeNode<Identifier>(kSuperMethodName));
return ParseResult{MakeCall(target,
MakeNode<IdentifierExpression>(
MakeNode<Identifier>(kThisParameterName)),
args, otherwise)};
} else {
return ParseResult{MakeCall(target, base::nullopt, args, otherwise)};
}
......@@ -266,8 +269,9 @@ base::Optional<ParseResult> MakeMethodCall(ParseResultIterator* child_results) {
auto callee = child_results->NextAs<std::string>();
auto args = child_results->NextAs<std::vector<Expression*>>();
auto otherwise = child_results->NextAs<std::vector<Statement*>>();
return ParseResult{MakeCall(MakeNode<IdentifierExpression>(callee), this_arg,
args, otherwise)};
return ParseResult{
MakeCall(MakeNode<IdentifierExpression>(MakeNode<Identifier>(callee)),
this_arg, args, otherwise)};
}
base::Optional<ParseResult> MakeNew(ParseResultIterator* child_results) {
......@@ -316,8 +320,9 @@ base::Optional<ParseResult> MakeParameterListFromTypes(
result.has_varargs = has_varargs;
result.implicit_count = implicit_params.size();
for (NameAndTypeExpression& implicit_param : implicit_params) {
if (!IsLowerCamelCase(implicit_param.name)) {
NamingConventionError("Parameter", implicit_param.name, "lowerCamelCase");
if (!IsLowerCamelCase(implicit_param.name->value)) {
NamingConventionError("Parameter", implicit_param.name->value,
"lowerCamelCase");
}
result.names.push_back(implicit_param.name);
result.types.push_back(implicit_param.type);
......@@ -341,19 +346,19 @@ base::Optional<ParseResult> MakeParameterListFromNameAndTypeList(
}
ParameterList result;
for (NameAndTypeExpression& pair : implicit_params) {
if (!IsLowerCamelCase(pair.name)) {
NamingConventionError("Parameter", pair.name, "lowerCamelCase");
if (!IsLowerCamelCase(pair.name->value)) {
NamingConventionError("Parameter", pair.name->value, "lowerCamelCase");
}
result.names.push_back(std::move(pair.name));
result.types.push_back(pair.type);
}
for (NameAndTypeExpression& pair : explicit_params) {
if (!IsLowerCamelCase(pair.name)) {
NamingConventionError("Parameter", pair.name, "lowerCamelCase");
if (!IsLowerCamelCase(pair.name->value)) {
NamingConventionError("Parameter", pair.name->value, "lowerCamelCase");
}
result.names.push_back(std::move(pair.name));
result.names.push_back(pair.name);
result.types.push_back(pair.type);
}
result.implicit_count = implicit_params.size();
......@@ -759,7 +764,8 @@ base::Optional<ParseResult> MakeTypeswitchStatement(
TypeExpression* accumulated_types;
for (size_t i = 0; i < cases.size(); ++i) {
CurrentSourcePosition::Scope current_source_position(cases[i].pos);
Expression* value = MakeNode<IdentifierExpression>("_value");
Expression* value =
MakeNode<IdentifierExpression>(MakeNode<Identifier>("_value"));
if (i >= 1) {
value =
MakeNode<AssumeTypeImpossibleExpression>(accumulated_types, value);
......@@ -769,7 +775,8 @@ base::Optional<ParseResult> MakeTypeswitchStatement(
value = MakeCall("Cast", std::vector<TypeExpression*>{cases[i].type},
std::vector<Expression*>{value},
std::vector<Statement*>{MakeNode<ExpressionStatement>(
MakeNode<IdentifierExpression>("_NextCase"))});
MakeNode<IdentifierExpression>(
MakeNode<Identifier>("_NextCase")))});
case_block = MakeNode<BlockStatement>();
} else {
case_block = current_block;
......@@ -945,7 +952,7 @@ base::Optional<ParseResult> MakeCatchBlock(ParseResultIterator* child_results) {
NamingConventionError("Exception", variable, "lowerCamelCase");
}
ParameterList parameters;
parameters.names.push_back(variable);
parameters.names.push_back(MakeNode<Identifier>(variable));
parameters.types.push_back(MakeNode<BasicTypeExpression>(
std::vector<std::string>{}, false, "Object"));
parameters.has_varargs = false;
......@@ -979,12 +986,11 @@ base::Optional<ParseResult> MakeIdentifierExpression(
ParseResultIterator* child_results) {
auto namespace_qualification =
child_results->NextAs<std::vector<std::string>>();
auto name = child_results->NextAs<std::string>();
auto name = child_results->NextAs<Identifier*>();
auto generic_arguments =
child_results->NextAs<std::vector<TypeExpression*>>();
LocationExpression* result = MakeNode<IdentifierExpression>(
std::move(namespace_qualification), std::move(name),
std::move(generic_arguments));
std::move(namespace_qualification), name, std::move(generic_arguments));
return ParseResult{result};
}
......@@ -1097,25 +1103,24 @@ base::Optional<ParseResult> MakeLabelAndTypes(
base::Optional<ParseResult> MakeNameAndType(
ParseResultIterator* child_results) {
auto name = child_results->NextAs<std::string>();
auto name = child_results->NextAs<Identifier*>();
auto type = child_results->NextAs<TypeExpression*>();
return ParseResult{NameAndTypeExpression{std::move(name), type}};
return ParseResult{NameAndTypeExpression{name, type}};
}
base::Optional<ParseResult> MakeClassField(ParseResultIterator* child_results) {
auto weak = child_results->NextAs<bool>();
auto name = child_results->NextAs<std::string>();
auto name = child_results->NextAs<Identifier*>();
auto index = child_results->NextAs<base::Optional<std::string>>();
auto type = child_results->NextAs<TypeExpression*>();
return ParseResult{
ClassFieldExpression{{std::move(name), type}, index, weak}};
return ParseResult{ClassFieldExpression{{name, type}, index, weak}};
}
base::Optional<ParseResult> MakeStructField(
ParseResultIterator* child_results) {
auto name = child_results->NextAs<std::string>();
auto name = child_results->NextAs<Identifier*>();
auto type = child_results->NextAs<TypeExpression*>();
return ParseResult{StructFieldExpression{{std::move(name), type}}};
return ParseResult{StructFieldExpression{{name, type}}};
}
base::Optional<ParseResult> ExtractAssignmentOperator(
......@@ -1218,7 +1223,7 @@ struct TorqueGrammar : Grammar {
// Result: std::string
Symbol identifier = {Rule({Pattern(MatchIdentifier)}, YieldMatchedInput)};
// Result: Identifier
// Result: Identifier*
Symbol name = {Rule({&identifier}, MakeIdentifier)};
// Result: std::string
......@@ -1304,19 +1309,18 @@ struct TorqueGrammar : Grammar {
NonemptyList<Statement*>(&atomarStatement, Token(","))}))};
// Result: NameAndTypeExpression
Symbol nameAndType = {
Rule({&identifier, Token(":"), &type}, MakeNameAndType)};
Symbol nameAndType = {Rule({&name, Token(":"), &type}, MakeNameAndType)};
Symbol* optionalArraySpecifier = {
Optional<std::string>(Sequence({Token("["), &identifier, Token("]")}))};
Symbol classField = {
Rule({CheckIf(Token("weak")), &identifier, optionalArraySpecifier,
Token(":"), &type, Token(";")},
Rule({CheckIf(Token("weak")), &name, optionalArraySpecifier, Token(":"),
&type, Token(";")},
MakeClassField)};
Symbol structField = {
Rule({&identifier, Token(":"), &type, Token(";")}, MakeStructField)};
Rule({&name, Token(":"), &type, Token(";")}, MakeStructField)};
// Result: ParameterList
Symbol parameterListNoVararg = {
......@@ -1363,10 +1367,9 @@ struct TorqueGrammar : Grammar {
// Result: LocationExpression*
Symbol identifierExpression = {
Rule(
{List<std::string>(Sequence({&identifier, Token("::")})), &identifier,
TryOrDefault<TypeList>(&genericSpecializationTypeList)},
MakeIdentifierExpression),
Rule({List<std::string>(Sequence({&identifier, Token("::")})), &name,
TryOrDefault<TypeList>(&genericSpecializationTypeList)},
MakeIdentifierExpression),
};
// Result: LocationExpression*
......
......@@ -51,6 +51,7 @@ static const char* const CONST_INT32_TYPE_STRING = "constexpr int32";
static const char* const CONST_FLOAT64_TYPE_STRING = "constexpr float64";
class AggregateType;
struct Identifier;
class Macro;
class Method;
class StructType;
......@@ -587,6 +588,8 @@ std::ostream& operator<<(std::ostream& os, const ParameterTypes& parameters);
enum class ParameterMode { kProcessImplicit, kIgnoreImplicit };
typedef std::vector<Identifier*> NameVector;
struct Signature {
Signature(NameVector n, base::Optional<std::string> arguments_variable,
ParameterTypes p, size_t i, const Type* r, LabelDeclarationVector l)
......
......@@ -18,8 +18,6 @@ namespace v8 {
namespace internal {
namespace torque {
typedef std::vector<std::string> NameVector;
std::string StringLiteralUnquote(const std::string& s);
std::string StringLiteralQuote(const std::string& s);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment