Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Unified Diff: src/parser.h

Issue 196133017: Experimental parser: merge r19949 (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/optimizing-compiler-thread.cc ('k') | src/parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index 4a2cb0290b4b20d97d12ea6204028784a6afe137..9fd636c222b81961c12343a4535d46189a63f252 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -39,7 +39,6 @@ namespace v8 {
namespace internal {
class CompilationInfo;
-class FuncNameInferrer;
class ParserLog;
class PositionStack;
class Target;
@@ -54,7 +53,7 @@ class FunctionEntry BASE_EMBEDDED {
kEndPositionIndex,
kLiteralCountIndex,
kPropertyCountIndex,
- kLanguageModeIndex,
+ kStrictModeIndex,
kSize
};
@@ -67,11 +66,10 @@ class FunctionEntry BASE_EMBEDDED {
int end_pos() { return backing_[kEndPositionIndex]; }
int literal_count() { return backing_[kLiteralCountIndex]; }
int property_count() { return backing_[kPropertyCountIndex]; }
- LanguageMode language_mode() {
- ASSERT(backing_[kLanguageModeIndex] == CLASSIC_MODE ||
- backing_[kLanguageModeIndex] == STRICT_MODE ||
- backing_[kLanguageModeIndex] == EXTENDED_MODE);
- return static_cast<LanguageMode>(backing_[kLanguageModeIndex]);
+ StrictMode strict_mode() {
+ ASSERT(backing_[kStrictModeIndex] == SLOPPY ||
+ backing_[kStrictModeIndex] == STRICT);
+ return static_cast<StrictMode>(backing_[kStrictModeIndex]);
}
bool is_valid() { return !backing_.is_empty(); }
@@ -410,18 +408,27 @@ class SingletonLogger;
class ParserTraits {
public:
struct Type {
+ // TODO(marja): To be removed. The Traits object should contain all the data
+ // it needs.
typedef v8::internal::Parser* Parser;
- // Types used by FunctionState and BlockState.
+ // Used by FunctionState and BlockState.
typedef v8::internal::Scope Scope;
- typedef AstNodeFactory<AstConstructionVisitor> Factory;
typedef Variable GeneratorVariable;
typedef v8::internal::Zone Zone;
// Return types for traversing functions.
typedef Handle<String> Identifier;
typedef v8::internal::Expression* Expression;
+ typedef Yield* YieldExpression;
+ typedef v8::internal::FunctionLiteral* FunctionLiteral;
+ typedef v8::internal::Literal* Literal;
+ typedef ObjectLiteral::Property* ObjectLiteralProperty;
typedef ZoneList<v8::internal::Expression*>* ExpressionList;
+ typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
+
+ // For constructing objects returned by the traversing functions.
+ typedef AstNodeFactory<AstConstructionVisitor> Factory;
};
explicit ParserTraits(Parser* parser) : parser_(parser) {}
@@ -446,6 +453,51 @@ class ParserTraits {
// Helper functions for recursive descent.
bool IsEvalOrArguments(Handle<String> identifier) const;
+ // Returns true if the expression is of type "this.foo".
+ static bool IsThisProperty(Expression* expression);
+
+ static bool IsBoilerplateProperty(ObjectLiteral::Property* property) {
+ return ObjectLiteral::IsBoilerplateProperty(property);
+ }
+
+ static bool IsArrayIndex(Handle<String> string, uint32_t* index) {
+ return !string.is_null() && string->AsArrayIndex(index);
+ }
+
+ // Functions for encapsulating the differences between parsing and preparsing;
+ // operations interleaved with the recursive descent.
+ static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) {
+ fni->PushLiteralName(id);
+ }
+
+ static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
+ Scope* scope, Expression* value, bool* has_function) {
+ if (scope->DeclarationScope()->is_global_scope() &&
+ value->AsFunctionLiteral() != NULL) {
+ *has_function = true;
+ value->AsFunctionLiteral()->set_pretenure();
+ }
+ }
+
+ // If we assign a function literal to a property we pretenure the
+ // literal so it can be added as a constant function property.
+ static void CheckAssigningFunctionLiteralToProperty(Expression* left,
+ Expression* right);
+
+ // Signal a reference error if the expression is an invalid left-hand side
+ // expression. We could report this as a syntax error but for compatibility
+ // with JSC we choose to report the error at runtime.
+ Expression* ValidateAssignmentLeftHandSide(Expression* expression) const;
+
+ // Determine if the expression is a variable proxy and mark it as being used
+ // in an assignment or with a increment/decrement operator. This is currently
+ // used on for the statically checking assignments to harmony const bindings.
+ static Expression* MarkExpressionAsLValue(Expression* expression);
+
+ // Checks LHS expression for assignment and prefix/postfix increment/decrement
+ // in strict mode.
+ void CheckStrictModeLValue(Expression*expression, bool* ok);
+
// Reporting errors.
void ReportMessageAt(Scanner::Location source_location,
const char* message,
@@ -462,6 +514,12 @@ class ParserTraits {
static Expression* EmptyExpression() {
return NULL;
}
+ static Literal* EmptyLiteral() {
+ return NULL;
+ }
+ static ZoneList<Expression*>* NullExpressionList() {
+ return NULL;
+ }
// Odd-ball literal creators.
Literal* GetLiteralTheHole(int position,
@@ -473,7 +531,7 @@ class ParserTraits {
PretenureFlag tenured);
Expression* ThisExpression(Scope* scope,
AstNodeFactory<AstConstructionVisitor>* factory);
- Expression* ExpressionFromLiteral(
+ Literal* ExpressionFromLiteral(
Token::Value token, int pos, Scanner* scanner,
AstNodeFactory<AstConstructionVisitor>* factory);
Expression* ExpressionFromIdentifier(
@@ -485,11 +543,21 @@ class ParserTraits {
ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
}
+ ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
+ return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
+ }
// Temporary glue; these functions will move to ParserBase.
- Expression* ParseObjectLiteral(bool* ok);
- Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
Expression* ParseV8Intrinsic(bool* ok);
+ FunctionLiteral* ParseFunctionLiteral(
+ Handle<String> name,
+ Scanner::Location function_name_location,
+ bool name_is_strict_reserved,
+ bool is_generator,
+ int function_token_position,
+ FunctionLiteral::FunctionType type,
+ bool* ok);
+ Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
private:
Parser* parser_;
@@ -578,10 +646,6 @@ class Parser : public ParserBase<ParserTraits> {
bool inside_with() const { return scope_->inside_with(); }
Mode mode() const { return mode_; }
ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
- bool is_extended_mode() {
- ASSERT(scope_ != NULL);
- return scope_->is_extended_mode();
- }
Scope* DeclarationScope(VariableMode mode) {
return IsLexicalVariableMode(mode)
? scope_ : scope_->DeclarationScope();
@@ -636,8 +700,6 @@ class Parser : public ParserBase<ParserTraits> {
// Support for hamony block scoped bindings.
Block* ParseScopedBlock(ZoneStringList* labels, bool* ok);
- Expression* ParseAssignmentExpression(bool accept_IN, bool* ok);
- Expression* ParseYieldExpression(bool* ok);
Expression* ParseConditionalExpression(bool accept_IN, bool* ok);
Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
Expression* ParseUnaryExpression(bool* ok);
@@ -655,7 +717,6 @@ class Parser : public ParserBase<ParserTraits> {
Expression* subject,
Statement* body);
- ZoneList<Expression*>* ParseArguments(bool* ok);
FunctionLiteral* ParseFunctionLiteral(
Handle<String> name,
Scanner::Location function_name_location,
@@ -670,28 +731,9 @@ class Parser : public ParserBase<ParserTraits> {
bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
- Handle<String> LiteralString(PretenureFlag tenured) {
- if (scanner()->is_literal_ascii()) {
- return isolate_->factory()->NewStringFromAscii(
- scanner()->literal_ascii_string(), tenured);
- } else {
- return isolate_->factory()->NewStringFromTwoByte(
- scanner()->literal_utf16_string(), tenured);
- }
- }
-
// Get odd-ball literals.
Literal* GetLiteralUndefined(int position);
- // Determine if the expression is a variable proxy and mark it as being used
- // in an assignment or with a increment/decrement operator. This is currently
- // used on for the statically checking assignments to harmony const bindings.
- void MarkAsLValue(Expression* expression);
-
- // Strict mode validation of LValue expressions
- void CheckStrictModeLValue(Expression* expression,
- bool* ok);
-
// For harmony block scoping mode: Check if the scope has conflicting var/let
// declarations from different scopes. It covers for example
//
@@ -754,7 +796,6 @@ class Parser : public ParserBase<ParserTraits> {
Scope* original_scope_; // for ES5 function declarations in sloppy eval
Target* target_stack_; // for break, continue statements
ScriptDataImpl* pre_parse_data_;
- FuncNameInferrer* fni_;
Mode mode_;
« no previous file with comments | « src/optimizing-compiler-thread.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698