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

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: moar 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:
60 // struct Traits {
61 // // In particular...
62 // struct Type {
63 // // Used by FunctionState and BlockState.
64 // typedef Scope;
65 // typedef GeneratorVariable;
66 // typedef Zone;
67 // // Return types for traversing functions.
68 // typedef Identifier;
69 // typedef Expression;
70 // typedef FunctionLiteral;
71 // typedef ObjectLiteralProperty;
72 // typedef Literal;
73 // typedef ExpressionList;
74 // typedef PropertyList;
75 // // For constructing objects returned by the traversing functions.
76 // typedef Factory;
77 // };
78 // // ...
79 // };
80
42 template <typename Traits> 81 template <typename Traits>
43 class ParserBase : public Traits { 82 class ParserBase : public Traits {
44 public: 83 public:
45 ParserBase(Scanner* scanner, uintptr_t stack_limit, 84 ParserBase(Scanner* scanner, uintptr_t stack_limit,
46 v8::Extension* extension, 85 v8::Extension* extension,
47 typename Traits::Type::Zone* zone, 86 typename Traits::Type::Zone* zone,
48 typename Traits::Type::Parser this_object) 87 typename Traits::Type::Parser this_object)
49 : Traits(this_object), 88 : Traits(this_object),
50 parenthesized_function_(false), 89 parenthesized_function_(false),
51 scope_(NULL), 90 scope_(NULL),
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 return PreParserExpression::Default(); 684 return PreParserExpression::Default();
646 } 685 }
647 }; 686 };
648 687
649 688
650 class PreParser; 689 class PreParser;
651 690
652 class PreParserTraits { 691 class PreParserTraits {
653 public: 692 public:
654 struct Type { 693 struct Type {
694 // TODO(marja): To be removed. The Traits object should contain all the data
695 // it needs.
655 typedef PreParser* Parser; 696 typedef PreParser* Parser;
656 697
657 // Types used by FunctionState and BlockState. 698 // Used by FunctionState and BlockState.
658 typedef PreParserScope Scope; 699 typedef PreParserScope Scope;
659 typedef PreParserFactory Factory;
660 // PreParser doesn't need to store generator variables. 700 // PreParser doesn't need to store generator variables.
661 typedef void GeneratorVariable; 701 typedef void GeneratorVariable;
662 // No interaction with Zones. 702 // No interaction with Zones.
663 typedef void Zone; 703 typedef void Zone;
664 704
665 // Return types for traversing functions. 705 // Return types for traversing functions.
666 typedef PreParserIdentifier Identifier; 706 typedef PreParserIdentifier Identifier;
667 typedef PreParserExpression Expression; 707 typedef PreParserExpression Expression;
668 typedef PreParserExpression FunctionLiteral; 708 typedef PreParserExpression FunctionLiteral;
669 typedef PreParserExpression ObjectLiteralProperty; 709 typedef PreParserExpression ObjectLiteralProperty;
670 typedef PreParserExpression Literal; 710 typedef PreParserExpression Literal;
671 typedef PreParserExpressionList ExpressionList; 711 typedef PreParserExpressionList ExpressionList;
672 typedef PreParserExpressionList PropertyList; 712 typedef PreParserExpressionList PropertyList;
713
714 // For constructing objects returned by the traversing functions.
715 typedef PreParserFactory Factory;
673 }; 716 };
674 717
675 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {} 718 explicit PreParserTraits(PreParser* pre_parser) : pre_parser_(pre_parser) {}
676 719
677 // Custom operations executed when FunctionStates are created and 720 // Custom operations executed when FunctionStates are created and
678 // destructed. (The PreParser doesn't need to do anything.) 721 // destructed. (The PreParser doesn't need to do anything.)
679 template<typename FunctionState> 722 template<typename FunctionState>
680 static void SetUpFunctionState(FunctionState* function_state, void*) {} 723 static void SetUpFunctionState(FunctionState* function_state, void*) {}
681 template<typename FunctionState> 724 template<typename FunctionState>
682 static void TearDownFunctionState(FunctionState* function_state) {} 725 static void TearDownFunctionState(FunctionState* function_state) {}
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1536 "accessor_get_set"); 1579 "accessor_get_set");
1537 } 1580 }
1538 *ok = false; 1581 *ok = false;
1539 } 1582 }
1540 } 1583 }
1541 1584
1542 1585
1543 } } // v8::internal 1586 } } // v8::internal
1544 1587
1545 #endif // V8_PREPARSER_H 1588 #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