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