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

Side by Side Diff: src/preparser.h

Issue 196953004: Parser / PreParser unification: Add docs. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Code review (rossberg) 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 20 matching lines...) Expand all
31 #include "func-name-inferrer.h" 31 #include "func-name-inferrer.h"
32 #include "hashmap.h" 32 #include "hashmap.h"
33 #include "scopes.h" 33 #include "scopes.h"
34 #include "token.h" 34 #include "token.h"
35 #include "scanner.h" 35 #include "scanner.h"
36 #include "v8.h" 36 #include "v8.h"
37 37
38 namespace v8 { 38 namespace v8 {
39 namespace internal { 39 namespace internal {
40 40
41 // Common base class shared between parser and pre-parser. 41 // Common base class shared between parser and pre-parser. Traits encapsulate
42 // the differences between Parser and PreParser:
43
44 // - Return types: For example, Parser functions return Expression* and
45 // PreParser functions return PreParserExpression.
46
47 // - Creating parse tree nodes: Parser generates an AST during the recursive
48 // descent. PreParser doesn't create a tree. Instead, it passes around minimal
49 // data objects (PreParserExpression, PreParserIdentifier etc.) which contain
50 // just enough data for the upper layer functions. PreParserFactory is
51 // responsible for creating these dummy objects. It provides a similar kind of
52 // interface as AstNodeFactory, so ParserBase doesn't need to care which one is
53 // used.
54
55 // - Miscellanous other tasks interleaved with the recursive descent. For
56 // example, Parser keeps track of which function literals should be marked as
57 // pretenured, and PreParser doesn't care.
58
59 // 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.
60 // struct Traits {
61 // struct Type {
62 // // Used by FunctionState and BlockState.
63 // typedef Scope;
64 // typedef GeneratorVariable;
65 // typedef Zone;
66 // // Return types for traversing functions.
67 // typedef Identifier;
68 // typedef Expression;
69 // typedef FunctionLiteral;
70 // typedef ObjectLiteralProperty;
71 // typedef Literal;
72 // typedef ExpressionList;
73 // typedef PropertyList;
74 // // For constructing objects returned by the traversing functions.
75 // typedef Factory;
76 // };
77 // };
rossberg 2014/03/12 17:29:11 ...and "// ..." here.
marja 2014/03/12 19:07:45 Done.
78
42 template <typename Traits> 79 template <typename Traits>
43 class ParserBase : public Traits { 80 class ParserBase : public Traits {
44 public: 81 public:
45 ParserBase(Scanner* scanner, uintptr_t stack_limit, 82 ParserBase(Scanner* scanner, uintptr_t stack_limit,
46 v8::Extension* extension, 83 v8::Extension* extension,
47 typename Traits::Type::Zone* zone, 84 typename Traits::Type::Zone* zone,
48 typename Traits::Type::Parser this_object) 85 typename Traits::Type::Parser this_object)
49 : Traits(this_object), 86 : Traits(this_object),
50 parenthesized_function_(false), 87 parenthesized_function_(false),
51 scope_(NULL), 88 scope_(NULL),
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return PreParserExpression::Default(); 682 return PreParserExpression::Default();
646 } 683 }
647 }; 684 };
648 685
649 686
650 class PreParser; 687 class PreParser;
651 688
652 class PreParserTraits { 689 class PreParserTraits {
653 public: 690 public:
654 struct Type { 691 struct Type {
692 // TODO(marja): To be removed. The Traits object should contain all the data
693 // it needs.
655 typedef PreParser* Parser; 694 typedef PreParser* Parser;
656 695
657 // Types used by FunctionState and BlockState. 696 // Used by FunctionState and BlockState.
658 typedef PreParserScope Scope; 697 typedef PreParserScope Scope;
659 typedef PreParserFactory Factory;
660 // PreParser doesn't need to store generator variables. 698 // PreParser doesn't need to store generator variables.
661 typedef void GeneratorVariable; 699 typedef void GeneratorVariable;
662 // No interaction with Zones. 700 // No interaction with Zones.
663 typedef void Zone; 701 typedef void Zone;
664 702
665 // Return types for traversing functions. 703 // Return types for traversing functions.
666 typedef PreParserIdentifier Identifier; 704 typedef PreParserIdentifier Identifier;
667 typedef PreParserExpression Expression; 705 typedef PreParserExpression Expression;
668 typedef PreParserExpression FunctionLiteral; 706 typedef PreParserExpression FunctionLiteral;
669 typedef PreParserExpression ObjectLiteralProperty; 707 typedef PreParserExpression ObjectLiteralProperty;
670 typedef PreParserExpression Literal; 708 typedef PreParserExpression Literal;
671 typedef PreParserExpressionList ExpressionList; 709 typedef PreParserExpressionList ExpressionList;
672 typedef PreParserExpressionList PropertyList; 710 typedef PreParserExpressionList PropertyList;
711
712 // For constructing objects returned by the traversing functions.
713 typedef PreParserFactory Factory;
673 }; 714 };
674 715
675 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 716 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
676 717
677 // Custom operations executed when FunctionStates are created and 718 // Custom operations executed when FunctionStates are created and
678 // destructed. (The PreParser doesn't need to do anything.) 719 // destructed. (The PreParser doesn't need to do anything.)
679 template<typename FunctionState> 720 template<typename FunctionState>
680 static void SetUpFunctionState(FunctionState* function_state, void*) {} 721 static void SetUpFunctionState(FunctionState* function_state, void*) {}
681 template<typename FunctionState> 722 template<typename FunctionState>
682 static void TearDownFunctionState(FunctionState* function_state) {} 723 static void TearDownFunctionState(FunctionState* function_state) {}
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 "accessor_get_set"); 1577 "accessor_get_set");
1537 } 1578 }
1538 *ok = false; 1579 *ok = false;
1539 } 1580 }
1540 } 1581 }
1541 1582
1542 1583
1543 } } // v8::internal 1584 } } // v8::internal
1544 1585
1545 #endif // V8_PREPARSER_H 1586 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698