Commit 7783d6fa authored by adamk's avatar adamk Committed by Commit bot

[style] Rename some enum values with 'k' prefix

See https://google.github.io/styleguide/cppguide.html#Enumerator_Names

Also rename "FunctionBody" to "FunctionBodyType" and move it inside
Parser, which is the only place it's referenced.

R=caitp@igalia.com, littledan@chromium.org

Review-Url: https://codereview.chromium.org/2245133003
Cr-Commit-Position: refs/heads/master@{#38671}
parent 43b76f1a
...@@ -16,7 +16,7 @@ class AstString; ...@@ -16,7 +16,7 @@ class AstString;
class AstValueFactory; class AstValueFactory;
class FunctionLiteral; class FunctionLiteral;
enum class InferName { Yes, No }; enum class InferName { kYes, kNo };
// FuncNameInferrer is a stateful class that is used to perform name // FuncNameInferrer is a stateful class that is used to perform name
// inference for anonymous functions during static analysis of source code. // inference for anonymous functions during static analysis of source code.
......
...@@ -30,8 +30,6 @@ enum AllowLabelledFunctionStatement { ...@@ -30,8 +30,6 @@ enum AllowLabelledFunctionStatement {
kDisallowLabelledFunctionStatement, kDisallowLabelledFunctionStatement,
}; };
enum class FunctionBody { Normal, SingleExpression };
enum class ParseFunctionFlags { enum class ParseFunctionFlags {
kIsNormal = 0, kIsNormal = 0,
kIsGenerator = 1, kIsGenerator = 1,
...@@ -59,21 +57,22 @@ static inline bool operator&(ParseFunctionFlags bitfield, ...@@ -59,21 +57,22 @@ static inline bool operator&(ParseFunctionFlags bitfield,
} }
enum class MethodKind { enum class MethodKind {
Normal = 0, kNormal = 0,
Static = 1 << 0, kStatic = 1 << 0,
Generator = 1 << 1, kGenerator = 1 << 1,
StaticGenerator = Static | Generator, kStaticGenerator = kStatic | kGenerator,
Async = 1 << 2, kAsync = 1 << 2,
StaticAsync = Static | Async, kStaticAsync = kStatic | kAsync,
/* Any non-ordinary method kinds */ /* Any non-ordinary method kinds */
SpecialMask = Generator | Async kSpecialMask = kGenerator | kAsync
}; };
inline bool IsValidMethodKind(MethodKind kind) { inline bool IsValidMethodKind(MethodKind kind) {
return kind == MethodKind::Normal || kind == MethodKind::Static || return kind == MethodKind::kNormal || kind == MethodKind::kStatic ||
kind == MethodKind::Generator || kind == MethodKind::StaticGenerator || kind == MethodKind::kGenerator ||
kind == MethodKind::Async || kind == MethodKind::StaticAsync; kind == MethodKind::kStaticGenerator || kind == MethodKind::kAsync ||
kind == MethodKind::kStaticAsync;
} }
static inline MethodKind operator|(MethodKind lhs, MethodKind rhs) { static inline MethodKind operator|(MethodKind lhs, MethodKind rhs) {
...@@ -93,22 +92,22 @@ static inline bool operator&(MethodKind bitfield, MethodKind mask) { ...@@ -93,22 +92,22 @@ static inline bool operator&(MethodKind bitfield, MethodKind mask) {
} }
inline bool IsNormalMethod(MethodKind kind) { inline bool IsNormalMethod(MethodKind kind) {
return kind == MethodKind::Normal; return kind == MethodKind::kNormal;
} }
inline bool IsSpecialMethod(MethodKind kind) { inline bool IsSpecialMethod(MethodKind kind) {
return kind & MethodKind::SpecialMask; return kind & MethodKind::kSpecialMask;
} }
inline bool IsStaticMethod(MethodKind kind) { inline bool IsStaticMethod(MethodKind kind) {
return kind & MethodKind::Static; return kind & MethodKind::kStatic;
} }
inline bool IsGeneratorMethod(MethodKind kind) { inline bool IsGeneratorMethod(MethodKind kind) {
return kind & MethodKind::Generator; return kind & MethodKind::kGenerator;
} }
inline bool IsAsyncMethod(MethodKind kind) { return kind & MethodKind::Async; } inline bool IsAsyncMethod(MethodKind kind) { return kind & MethodKind::kAsync; }
struct FormalParametersBase { struct FormalParametersBase {
explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {} explicit FormalParametersBase(DeclarationScope* scope) : scope(scope) {}
...@@ -1942,7 +1941,7 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -1942,7 +1941,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
Token::Value name_token = peek(); Token::Value name_token = peek();
if (is_generator) { if (is_generator) {
method_kind |= MethodKind::Generator; method_kind |= MethodKind::kGenerator;
} else if (allow_harmony_async_await() && name_token == Token::ASYNC && } else if (allow_harmony_async_await() && name_token == Token::ASYNC &&
!scanner()->HasAnyLineTerminatorAfterNext() && !scanner()->HasAnyLineTerminatorAfterNext() &&
PeekAhead() != Token::LPAREN && PeekAhead()) { PeekAhead() != Token::LPAREN && PeekAhead()) {
...@@ -1966,7 +1965,7 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -1966,7 +1965,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
// PropertyDefinition // PropertyDefinition
// PropertyName ':' AssignmentExpression // PropertyName ':' AssignmentExpression
if (!*is_computed_name) { if (!*is_computed_name) {
checker->CheckProperty(name_token, kValueProperty, MethodKind::Normal, checker->CheckProperty(name_token, kValueProperty, MethodKind::kNormal,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
} }
Consume(Token::COLON); Consume(Token::COLON);
...@@ -2052,7 +2051,7 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -2052,7 +2051,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
name_expression = ParsePropertyName( name_expression = ParsePropertyName(
name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier, name, &dont_care, &dont_care, &dont_care, is_computed_name, classifier,
CHECK_OK_CUSTOM(EmptyObjectLiteralProperty)); CHECK_OK_CUSTOM(EmptyObjectLiteralProperty));
method_kind |= MethodKind::Async; method_kind |= MethodKind::kAsync;
} }
if (is_generator || peek() == Token::LPAREN) { if (is_generator || peek() == Token::LPAREN) {
...@@ -2091,7 +2090,7 @@ ParserBase<Traits>::ParsePropertyDefinition( ...@@ -2091,7 +2090,7 @@ ParserBase<Traits>::ParsePropertyDefinition(
// 'static' MethodDefinition // 'static' MethodDefinition
*name = this->EmptyIdentifier(); *name = this->EmptyIdentifier();
ObjectLiteralPropertyT property = ParsePropertyDefinition( ObjectLiteralPropertyT property = ParsePropertyDefinition(
checker, true, has_extends, MethodKind::Static, is_computed_name, checker, true, has_extends, MethodKind::kStatic, is_computed_name,
nullptr, classifier, name, ok); nullptr, classifier, name, ok);
Traits::RewriteNonPattern(classifier, ok); Traits::RewriteNonPattern(classifier, ok);
return property; return property;
...@@ -2164,7 +2163,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral( ...@@ -2164,7 +2163,7 @@ typename ParserBase<Traits>::ExpressionT ParserBase<Traits>::ParseObjectLiteral(
bool is_computed_name = false; bool is_computed_name = false;
IdentifierT name = this->EmptyIdentifier(); IdentifierT name = this->EmptyIdentifier();
ObjectLiteralPropertyT property = this->ParsePropertyDefinition( ObjectLiteralPropertyT property = this->ParsePropertyDefinition(
&checker, in_class, has_extends, MethodKind::Normal, &is_computed_name, &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
NULL, classifier, &name, CHECK_OK); NULL, classifier, &name, CHECK_OK);
if (is_computed_name) { if (is_computed_name) {
...@@ -2330,7 +2329,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN, ...@@ -2330,7 +2329,7 @@ ParserBase<Traits>::ParseAssignmentExpression(bool accept_IN,
IdentifierT name = IdentifierT name =
ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK); ParseAndClassifyIdentifier(&arrow_formals_classifier, CHECK_OK);
expression = this->ExpressionFromIdentifier( expression = this->ExpressionFromIdentifier(
name, position(), scanner()->location().end_pos, InferName::No); name, position(), scanner()->location().end_pos, InferName::kNo);
if (fni_) { if (fni_) {
// Remove `async` keyword from inferred name stack. // Remove `async` keyword from inferred name stack.
fni_->RemoveAsyncKeywordFromEnd(); fni_->RemoveAsyncKeywordFromEnd();
......
...@@ -768,7 +768,7 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name, ...@@ -768,7 +768,7 @@ Expression* ParserTraits::ExpressionFromIdentifier(const AstRawString* name,
int start_position, int start_position,
int end_position, int end_position,
InferName infer) { InferName infer) {
if (infer == InferName::Yes && parser_->fni_ != NULL) { if (infer == InferName::kYes && parser_->fni_ != NULL) {
parser_->fni_->PushVariableName(name); parser_->fni_->PushVariableName(name);
} }
return parser_->NewUnresolved(name, start_position, end_position); return parser_->NewUnresolved(name, start_position, end_position);
...@@ -4124,14 +4124,15 @@ void ParserTraits::ParseAsyncArrowSingleExpressionBody( ...@@ -4124,14 +4124,15 @@ void ParserTraits::ParseAsyncArrowSingleExpressionBody(
Type::ExpressionClassifier* classifier, int pos, bool* ok) { Type::ExpressionClassifier* classifier, int pos, bool* ok) {
parser_->DesugarAsyncFunctionBody( parser_->DesugarAsyncFunctionBody(
parser_->ast_value_factory()->empty_string(), parser_->scope(), body, parser_->ast_value_factory()->empty_string(), parser_->scope(), body,
classifier, kAsyncArrowFunction, FunctionBody::SingleExpression, classifier, kAsyncArrowFunction,
accept_IN, pos, ok); Parser::FunctionBodyType::kSingleExpression, accept_IN, pos, ok);
} }
void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
Scope* scope, ZoneList<Statement*>* body, Scope* scope, ZoneList<Statement*>* body,
ExpressionClassifier* classifier, ExpressionClassifier* classifier,
FunctionKind kind, FunctionBody body_type, FunctionKind kind,
FunctionBodyType body_type,
bool accept_IN, int pos, bool* ok) { bool accept_IN, int pos, bool* ok) {
// function async_function() { // function async_function() {
// try { // try {
...@@ -4158,7 +4159,7 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name, ...@@ -4158,7 +4159,7 @@ void Parser::DesugarAsyncFunctionBody(const AstRawString* function_name,
ZoneList<Statement*>* inner_body = try_block->statements(); ZoneList<Statement*>* inner_body = try_block->statements();
Expression* return_value = nullptr; Expression* return_value = nullptr;
if (body_type == FunctionBody::Normal) { if (body_type == FunctionBodyType::kNormal) {
ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID);
return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
} else { } else {
...@@ -4881,7 +4882,8 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody( ...@@ -4881,7 +4882,8 @@ ZoneList<Statement*>* Parser::ParseEagerFunctionBody(
} else if (IsAsyncFunction(kind)) { } else if (IsAsyncFunction(kind)) {
const bool accept_IN = true; const bool accept_IN = true;
DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind, DesugarAsyncFunctionBody(function_name, inner_scope, body, nullptr, kind,
FunctionBody::Normal, accept_IN, pos, CHECK_OK); FunctionBodyType::kNormal, accept_IN, pos,
CHECK_OK);
} else { } else {
ParseStatementList(body, Token::RBRACE, CHECK_OK); ParseStatementList(body, Token::RBRACE, CHECK_OK);
} }
...@@ -5052,7 +5054,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier, ...@@ -5052,7 +5054,7 @@ Expression* Parser::ParseClassLiteral(ExpressionClassifier* classifier,
ExpressionClassifier property_classifier(this); ExpressionClassifier property_classifier(this);
const AstRawString* property_name = nullptr; const AstRawString* property_name = nullptr;
ObjectLiteral::Property* property = ParsePropertyDefinition( ObjectLiteral::Property* property = ParsePropertyDefinition(
&checker, in_class, has_extends, MethodKind::Normal, &is_computed_name, &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
&has_seen_constructor, &property_classifier, &property_name, CHECK_OK); &has_seen_constructor, &property_classifier, &property_name, CHECK_OK);
RewriteNonPattern(&property_classifier, CHECK_OK); RewriteNonPattern(&property_classifier, CHECK_OK);
if (classifier != nullptr) { if (classifier != nullptr) {
......
...@@ -558,7 +558,7 @@ class ParserTraits { ...@@ -558,7 +558,7 @@ class ParserTraits {
AstNodeFactory* factory); AstNodeFactory* factory);
Expression* ExpressionFromIdentifier(const AstRawString* name, Expression* ExpressionFromIdentifier(const AstRawString* name,
int start_position, int end_position, int start_position, int end_position,
InferName = InferName::Yes); InferName = InferName::kYes);
Expression* ExpressionFromString(int pos, Scanner* scanner, Expression* ExpressionFromString(int pos, Scanner* scanner,
AstNodeFactory* factory); AstNodeFactory* factory);
Expression* GetIterator(Expression* iterable, AstNodeFactory* factory, Expression* GetIterator(Expression* iterable, AstNodeFactory* factory,
...@@ -769,6 +769,8 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -769,6 +769,8 @@ class Parser : public ParserBase<ParserTraits> {
kAbruptCompletion kAbruptCompletion
}; };
enum class FunctionBodyType { kNormal, kSingleExpression };
DeclarationScope* GetDeclarationScope() const { DeclarationScope* GetDeclarationScope() const {
return scope()->GetDeclarationScope(); return scope()->GetDeclarationScope();
} }
...@@ -1041,7 +1043,7 @@ class Parser : public ParserBase<ParserTraits> { ...@@ -1041,7 +1043,7 @@ class Parser : public ParserBase<ParserTraits> {
void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope, void DesugarAsyncFunctionBody(const AstRawString* function_name, Scope* scope,
ZoneList<Statement*>* body, ZoneList<Statement*>* body,
Type::ExpressionClassifier* classifier, Type::ExpressionClassifier* classifier,
FunctionKind kind, FunctionBody type, FunctionKind kind, FunctionBodyType type,
bool accept_IN, int pos, bool* ok); bool accept_IN, int pos, bool* ok);
void RewriteDoExpression(Expression* expr, bool* ok); void RewriteDoExpression(Expression* expr, bool* ok);
......
...@@ -1251,9 +1251,9 @@ PreParserExpression PreParser::ParseClassLiteral( ...@@ -1251,9 +1251,9 @@ PreParserExpression PreParser::ParseClassLiteral(
// property names here. // property names here.
Identifier name; Identifier name;
ExpressionClassifier property_classifier(this); ExpressionClassifier property_classifier(this);
ParsePropertyDefinition(&checker, in_class, has_extends, MethodKind::Normal, ParsePropertyDefinition(
&is_computed_name, &has_seen_constructor, &checker, in_class, has_extends, MethodKind::kNormal, &is_computed_name,
&property_classifier, &name, CHECK_OK); &has_seen_constructor, &property_classifier, &name, CHECK_OK);
ValidateExpression(&property_classifier, CHECK_OK); ValidateExpression(&property_classifier, CHECK_OK);
if (classifier != nullptr) { if (classifier != nullptr) {
classifier->Accumulate(&property_classifier, classifier->Accumulate(&property_classifier,
......
...@@ -833,7 +833,7 @@ class PreParserTraits { ...@@ -833,7 +833,7 @@ class PreParserTraits {
static PreParserExpression ExpressionFromIdentifier( static PreParserExpression ExpressionFromIdentifier(
PreParserIdentifier name, int start_position, int end_position, PreParserIdentifier name, int start_position, int end_position,
InferName = InferName::Yes) { InferName = InferName::kYes) {
return PreParserExpression::FromIdentifier(name); return PreParserExpression::FromIdentifier(name);
} }
......
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