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

Side by Side Diff: src/ast.h

Issue 9615009: Basic interface inference for modules. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Eps. Created 8 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/SConscript ('k') | src/ast.cc » ('j') | 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 23 matching lines...) Expand all
34 #include "factory.h" 34 #include "factory.h"
35 #include "isolate.h" 35 #include "isolate.h"
36 #include "jsregexp.h" 36 #include "jsregexp.h"
37 #include "list-inl.h" 37 #include "list-inl.h"
38 #include "runtime.h" 38 #include "runtime.h"
39 #include "small-pointer-list.h" 39 #include "small-pointer-list.h"
40 #include "smart-array-pointer.h" 40 #include "smart-array-pointer.h"
41 #include "token.h" 41 #include "token.h"
42 #include "utils.h" 42 #include "utils.h"
43 #include "variables.h" 43 #include "variables.h"
44 #include "interface.h"
44 #include "zone-inl.h" 45 #include "zone-inl.h"
45 46
46 namespace v8 { 47 namespace v8 {
47 namespace internal { 48 namespace internal {
48 49
49 // The abstract syntax tree is an intermediate, light-weight 50 // The abstract syntax tree is an intermediate, light-weight
50 // representation of the parsed JavaScript code suitable for 51 // representation of the parsed JavaScript code suitable for
51 // compilation to native code. 52 // compilation to native code.
52 53
53 // Nodes are allocated in a separate zone, which allows faster 54 // Nodes are allocated in a separate zone, which allows faster
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 template<class> friend class AstNodeFactory; 583 template<class> friend class AstNodeFactory;
583 584
584 ExportDeclaration(VariableProxy* proxy, 585 ExportDeclaration(VariableProxy* proxy,
585 Scope* scope) 586 Scope* scope)
586 : Declaration(proxy, LET, scope) { 587 : Declaration(proxy, LET, scope) {
587 } 588 }
588 }; 589 };
589 590
590 591
591 class Module: public AstNode { 592 class Module: public AstNode {
592 // TODO(rossberg): stuff to come... 593 public:
594 Interface* interface() const { return interface_; }
595
593 protected: 596 protected:
594 Module() {} 597 Module() : interface_(Interface::NewModule()) {}
598 explicit Module(Interface* interface) : interface_(interface) {}
599
600 private:
601 Interface* interface_;
595 }; 602 };
596 603
597 604
598 class ModuleLiteral: public Module { 605 class ModuleLiteral: public Module {
599 public: 606 public:
600 DECLARE_NODE_TYPE(ModuleLiteral) 607 DECLARE_NODE_TYPE(ModuleLiteral)
601 608
602 Block* body() const { return body_; } 609 Block* body() const { return body_; }
603 610
604 protected: 611 protected:
605 template<class> friend class AstNodeFactory; 612 template<class> friend class AstNodeFactory;
606 613
607 explicit ModuleLiteral(Block* body) 614 ModuleLiteral(Block* body, Interface* interface)
608 : body_(body) { 615 : Module(interface),
616 body_(body) {
609 } 617 }
610 618
611 private: 619 private:
612 Block* body_; 620 Block* body_;
613 }; 621 };
614 622
615 623
616 class ModuleVariable: public Module { 624 class ModuleVariable: public Module {
617 public: 625 public:
618 DECLARE_NODE_TYPE(ModuleVariable) 626 DECLARE_NODE_TYPE(ModuleVariable)
619 627
620 VariableProxy* proxy() const { return proxy_; } 628 VariableProxy* proxy() const { return proxy_; }
621 629
622 protected: 630 protected:
623 template<class> friend class AstNodeFactory; 631 template<class> friend class AstNodeFactory;
624 632
625 explicit ModuleVariable(VariableProxy* proxy) 633 inline explicit ModuleVariable(VariableProxy* proxy);
626 : proxy_(proxy) {
627 }
628 634
629 private: 635 private:
630 VariableProxy* proxy_; 636 VariableProxy* proxy_;
631 }; 637 };
632 638
633 639
634 class ModulePath: public Module { 640 class ModulePath: public Module {
635 public: 641 public:
636 DECLARE_NODE_TYPE(ModulePath) 642 DECLARE_NODE_TYPE(ModulePath)
637 643
(...skipping 806 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 bool IsArguments() { return var_ != NULL && var_->is_arguments(); } 1450 bool IsArguments() { return var_ != NULL && var_->is_arguments(); }
1445 1451
1446 bool IsLValue() { 1452 bool IsLValue() {
1447 return is_lvalue_; 1453 return is_lvalue_;
1448 } 1454 }
1449 1455
1450 Handle<String> name() const { return name_; } 1456 Handle<String> name() const { return name_; }
1451 Variable* var() const { return var_; } 1457 Variable* var() const { return var_; }
1452 bool is_this() const { return is_this_; } 1458 bool is_this() const { return is_this_; }
1453 int position() const { return position_; } 1459 int position() const { return position_; }
1460 Interface* interface() const { return interface_; }
1461
1454 1462
1455 void MarkAsTrivial() { is_trivial_ = true; } 1463 void MarkAsTrivial() { is_trivial_ = true; }
1456 void MarkAsLValue() { is_lvalue_ = true; } 1464 void MarkAsLValue() { is_lvalue_ = true; }
1457 1465
1458 // Bind this proxy to the variable var. 1466 // Bind this proxy to the variable var.
1459 void BindTo(Variable* var); 1467 void BindTo(Variable* var);
1460 1468
1461 protected: 1469 protected:
1462 template<class> friend class AstNodeFactory; 1470 template<class> friend class AstNodeFactory;
1463 1471
1464 VariableProxy(Isolate* isolate, Variable* var); 1472 VariableProxy(Isolate* isolate, Variable* var);
1465 1473
1466 VariableProxy(Isolate* isolate, 1474 VariableProxy(Isolate* isolate,
1467 Handle<String> name, 1475 Handle<String> name,
1468 bool is_this, 1476 bool is_this,
1469 int position); 1477 int position,
1478 Interface* interface);
1470 1479
1471 Handle<String> name_; 1480 Handle<String> name_;
1472 Variable* var_; // resolved variable, or NULL 1481 Variable* var_; // resolved variable, or NULL
1473 bool is_this_; 1482 bool is_this_;
1474 bool is_trivial_; 1483 bool is_trivial_;
1475 // True if this variable proxy is being used in an assignment 1484 // True if this variable proxy is being used in an assignment
1476 // or with a increment/decrement operator. 1485 // or with a increment/decrement operator.
1477 bool is_lvalue_; 1486 bool is_lvalue_;
1478 int position_; 1487 int position_;
1488 Interface* interface_;
1479 }; 1489 };
1480 1490
1481 1491
1482 class Property: public Expression { 1492 class Property: public Expression {
1483 public: 1493 public:
1484 DECLARE_NODE_TYPE(Property) 1494 DECLARE_NODE_TYPE(Property)
1485 1495
1486 virtual bool IsValidLeftHandSide() { return true; } 1496 virtual bool IsValidLeftHandSide() { return true; }
1487 1497
1488 Expression* obj() const { return obj_; } 1498 Expression* obj() const { return obj_; }
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 virtual int min_match() { return 0; } 2509 virtual int min_match() { return 0; }
2500 virtual int max_match() { return 0; } 2510 virtual int max_match() { return 0; }
2501 static RegExpEmpty* GetInstance() { 2511 static RegExpEmpty* GetInstance() {
2502 static RegExpEmpty* instance = ::new RegExpEmpty(); 2512 static RegExpEmpty* instance = ::new RegExpEmpty();
2503 return instance; 2513 return instance;
2504 } 2514 }
2505 }; 2515 };
2506 2516
2507 2517
2508 // ---------------------------------------------------------------------------- 2518 // ----------------------------------------------------------------------------
2519 // Out-of-line inline constructors (to side-step cyclic dependencies).
2520
2521 inline ModuleVariable::ModuleVariable(VariableProxy* proxy)
2522 : Module(proxy->interface()),
2523 proxy_(proxy) {
2524 }
2525
2526
2527 // ----------------------------------------------------------------------------
2509 // Basic visitor 2528 // Basic visitor
2510 // - leaf node visitors are abstract. 2529 // - leaf node visitors are abstract.
2511 2530
2512 class AstVisitor BASE_EMBEDDED { 2531 class AstVisitor BASE_EMBEDDED {
2513 public: 2532 public:
2514 AstVisitor() : isolate_(Isolate::Current()), stack_overflow_(false) { } 2533 AstVisitor() : isolate_(Isolate::Current()), stack_overflow_(false) { }
2515 virtual ~AstVisitor() { } 2534 virtual ~AstVisitor() { }
2516 2535
2517 // Stack overflow check and dynamic dispatch. 2536 // Stack overflow check and dynamic dispatch.
2518 void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); } 2537 void Visit(AstNode* node) { if (!CheckStackOverflow()) node->Accept(this); }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
2632 VISIT_AND_RETURN(ImportDeclaration, decl) 2651 VISIT_AND_RETURN(ImportDeclaration, decl)
2633 } 2652 }
2634 2653
2635 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, 2654 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
2636 Scope* scope) { 2655 Scope* scope) {
2637 ExportDeclaration* decl = 2656 ExportDeclaration* decl =
2638 new(zone_) ExportDeclaration(proxy, scope); 2657 new(zone_) ExportDeclaration(proxy, scope);
2639 VISIT_AND_RETURN(ExportDeclaration, decl) 2658 VISIT_AND_RETURN(ExportDeclaration, decl)
2640 } 2659 }
2641 2660
2642 ModuleLiteral* NewModuleLiteral(Block* body) { 2661 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface) {
2643 ModuleLiteral* module = new(zone_) ModuleLiteral(body); 2662 ModuleLiteral* module = new(zone_) ModuleLiteral(body, interface);
2644 VISIT_AND_RETURN(ModuleLiteral, module) 2663 VISIT_AND_RETURN(ModuleLiteral, module)
2645 } 2664 }
2646 2665
2647 ModuleVariable* NewModuleVariable(VariableProxy* proxy) { 2666 ModuleVariable* NewModuleVariable(VariableProxy* proxy) {
2648 ModuleVariable* module = new(zone_) ModuleVariable(proxy); 2667 ModuleVariable* module = new(zone_) ModuleVariable(proxy);
2649 VISIT_AND_RETURN(ModuleVariable, module) 2668 VISIT_AND_RETURN(ModuleVariable, module)
2650 } 2669 }
2651 2670
2652 ModulePath* NewModulePath(Module* origin, Handle<String> name) { 2671 ModulePath* NewModulePath(Module* origin, Handle<String> name) {
2653 ModulePath* module = new(zone_) ModulePath(origin, name); 2672 ModulePath* module = new(zone_) ModulePath(origin, name);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 VISIT_AND_RETURN(ArrayLiteral, lit) 2808 VISIT_AND_RETURN(ArrayLiteral, lit)
2790 } 2809 }
2791 2810
2792 VariableProxy* NewVariableProxy(Variable* var) { 2811 VariableProxy* NewVariableProxy(Variable* var) {
2793 VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var); 2812 VariableProxy* proxy = new(zone_) VariableProxy(isolate_, var);
2794 VISIT_AND_RETURN(VariableProxy, proxy) 2813 VISIT_AND_RETURN(VariableProxy, proxy)
2795 } 2814 }
2796 2815
2797 VariableProxy* NewVariableProxy(Handle<String> name, 2816 VariableProxy* NewVariableProxy(Handle<String> name,
2798 bool is_this, 2817 bool is_this,
2799 int position = RelocInfo::kNoPosition) { 2818 int position = RelocInfo::kNoPosition,
2819 Interface* interface =
2820 Interface::NewValue()) {
2800 VariableProxy* proxy = 2821 VariableProxy* proxy =
2801 new(zone_) VariableProxy(isolate_, name, is_this, position); 2822 new(zone_) VariableProxy(isolate_, name, is_this, position, interface);
2802 VISIT_AND_RETURN(VariableProxy, proxy) 2823 VISIT_AND_RETURN(VariableProxy, proxy)
2803 } 2824 }
2804 2825
2805 Property* NewProperty(Expression* obj, Expression* key, int pos) { 2826 Property* NewProperty(Expression* obj, Expression* key, int pos) {
2806 Property* prop = new(zone_) Property(isolate_, obj, key, pos); 2827 Property* prop = new(zone_) Property(isolate_, obj, key, pos);
2807 VISIT_AND_RETURN(Property, prop) 2828 VISIT_AND_RETURN(Property, prop)
2808 } 2829 }
2809 2830
2810 Call* NewCall(Expression* expression, 2831 Call* NewCall(Expression* expression,
2811 ZoneList<Expression*>* arguments, 2832 ZoneList<Expression*>* arguments,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 private: 2953 private:
2933 Isolate* isolate_; 2954 Isolate* isolate_;
2934 Zone* zone_; 2955 Zone* zone_;
2935 Visitor visitor_; 2956 Visitor visitor_;
2936 }; 2957 };
2937 2958
2938 2959
2939 } } // namespace v8::internal 2960 } } // namespace v8::internal
2940 2961
2941 #endif // V8_AST_H_ 2962 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/SConscript ('k') | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698