Chromium Code Reviews| Index: src/preparser.h |
| diff --git a/src/preparser.h b/src/preparser.h |
| index 55685a124a249f6cbf8546823ec3070e3818591b..ec0fd5acb9cf64cea7d9aeacebcd7a9cd4e6894c 100644 |
| --- a/src/preparser.h |
| +++ b/src/preparser.h |
| @@ -38,7 +38,44 @@ |
| namespace v8 { |
| namespace internal { |
| -// Common base class shared between parser and pre-parser. |
| +// Common base class shared between parser and pre-parser. Traits encapsulate |
| +// the differences between Parser and PreParser: |
| + |
| +// - Return types: For example, Parser functions return Expression* and |
| +// PreParser functions return PreParserExpression. |
| + |
| +// - Creating parse tree nodes: Parser generates an AST during the recursive |
| +// descent. PreParser doesn't create a tree. Instead, it passes around minimal |
| +// data objects (PreParserExpression, PreParserIdentifier etc.) which contain |
| +// just enough data for the upper layer functions. PreParserFactory is |
| +// responsible for creating these dummy objects. It provides a similar kind of |
| +// interface as AstNodeFactory, so ParserBase doesn't need to care which one is |
| +// used. |
| + |
| +// - Miscellanous other tasks interleaved with the recursive descent. For |
| +// example, Parser keeps track of which function literals should be marked as |
| +// pretenured, and PreParser doesn't care. |
| + |
| +// The traits are expected to contain the following typedefs: |
|
rossberg
2014/03/12 17:29:11
Nit: For clarity, perhaps say "In particular, ..."
marja
2014/03/12 19:07:45
Done.
|
| +// struct Traits { |
| +// struct Type { |
| +// // Used by FunctionState and BlockState. |
| +// typedef Scope; |
| +// typedef GeneratorVariable; |
| +// typedef Zone; |
| +// // Return types for traversing functions. |
| +// typedef Identifier; |
| +// typedef Expression; |
| +// typedef FunctionLiteral; |
| +// typedef ObjectLiteralProperty; |
| +// typedef Literal; |
| +// typedef ExpressionList; |
| +// typedef PropertyList; |
| +// // For constructing objects returned by the traversing functions. |
| +// typedef Factory; |
| +// }; |
| +// }; |
|
rossberg
2014/03/12 17:29:11
...and "// ..." here.
marja
2014/03/12 19:07:45
Done.
|
| + |
| template <typename Traits> |
| class ParserBase : public Traits { |
| public: |
| @@ -652,11 +689,12 @@ class PreParser; |
| class PreParserTraits { |
| public: |
| struct Type { |
| + // TODO(marja): To be removed. The Traits object should contain all the data |
| + // it needs. |
| typedef PreParser* Parser; |
| - // Types used by FunctionState and BlockState. |
| + // Used by FunctionState and BlockState. |
| typedef PreParserScope Scope; |
| - typedef PreParserFactory Factory; |
| // PreParser doesn't need to store generator variables. |
| typedef void GeneratorVariable; |
| // No interaction with Zones. |
| @@ -670,6 +708,9 @@ class PreParserTraits { |
| typedef PreParserExpression Literal; |
| typedef PreParserExpressionList ExpressionList; |
| typedef PreParserExpressionList PropertyList; |
| + |
| + // For constructing objects returned by the traversing functions. |
| + typedef PreParserFactory Factory; |
| }; |
| explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} |