Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / gn / parse_tree.h
index 73ac0e5..60d1570 100644 (file)
@@ -8,7 +8,6 @@
 #include <vector>
 
 #include "base/basictypes.h"
-#include "base/compiler_specific.h"
 #include "base/memory/scoped_ptr.h"
 #include "tools/gn/err.h"
 #include "tools/gn/token.h"
 
 class AccessorNode;
 class BinaryOpNode;
+class BlockCommentNode;
 class BlockNode;
 class ConditionNode;
+class EndNode;
 class FunctionCallNode;
 class IdentifierNode;
 class ListNode;
 class LiteralNode;
 class Scope;
 class UnaryOpNode;
-class BlockCommentNode;
 
 class Comments {
  public:
@@ -74,14 +74,15 @@ class ParseNode {
 
   virtual const AccessorNode* AsAccessor() const;
   virtual const BinaryOpNode* AsBinaryOp() const;
+  virtual const BlockCommentNode* AsBlockComment() const;
   virtual const BlockNode* AsBlock() const;
   virtual const ConditionNode* AsConditionNode() const;
+  virtual const EndNode* AsEnd() const;
   virtual const FunctionCallNode* AsFunctionCall() const;
   virtual const IdentifierNode* AsIdentifier() const;
   virtual const ListNode* AsList() const;
   virtual const LiteralNode* AsLiteral() const;
   virtual const UnaryOpNode* AsUnaryOp() const;
-  virtual const BlockCommentNode* AsBlockComment() const;
 
   virtual Value Execute(Scope* scope, Err* err) const = 0;
 
@@ -135,15 +136,15 @@ class ParseNode {
 class AccessorNode : public ParseNode {
  public:
   AccessorNode();
-  virtual ~AccessorNode();
+  ~AccessorNode() override;
 
-  virtual const AccessorNode* AsAccessor() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const AccessorNode* AsAccessor() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   // Base is the thing on the left of the [] or dot, currently always required
   // to be an identifier token.
@@ -178,15 +179,15 @@ class AccessorNode : public ParseNode {
 class BinaryOpNode : public ParseNode {
  public:
   BinaryOpNode();
-  virtual ~BinaryOpNode();
+  ~BinaryOpNode() override;
 
-  virtual const BinaryOpNode* AsBinaryOp() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const BinaryOpNode* AsBinaryOp() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& op() const { return op_; }
   void set_op(const Token& t) { op_ = t; }
@@ -215,18 +216,19 @@ class BlockNode : public ParseNode {
  public:
   // Set has_scope if this block introduces a nested scope.
   explicit BlockNode(bool has_scope);
-  virtual ~BlockNode();
+  ~BlockNode() override;
 
-  virtual const BlockNode* AsBlock() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const BlockNode* AsBlock() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   void set_begin_token(const Token& t) { begin_token_ = t; }
-  void set_end_token(const Token& t) { end_token_ = t; }
+  void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); }
+  const EndNode* End() const { return end_.get(); }
 
   const std::vector<ParseNode*>& statements() const { return statements_; }
   void append_statement(scoped_ptr<ParseNode> s) {
@@ -239,9 +241,10 @@ class BlockNode : public ParseNode {
  private:
   bool has_scope_;
 
-  // Tokens corresponding to { and }, if any (may be NULL).
+  // Tokens corresponding to { and }, if any (may be NULL). The end is stored
+  // in a custom parse node so that it can have comments hung off of it.
   Token begin_token_;
-  Token end_token_;
+  scoped_ptr<EndNode> end_;
 
   // Owning pointers, use unique_ptr when we can use C++11.
   std::vector<ParseNode*> statements_;
@@ -254,15 +257,15 @@ class BlockNode : public ParseNode {
 class ConditionNode : public ParseNode {
  public:
   ConditionNode();
-  virtual ~ConditionNode();
+  ~ConditionNode() override;
 
-  virtual const ConditionNode* AsConditionNode() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const ConditionNode* AsConditionNode() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   void set_if_token(const Token& token) { if_token_ = token; }
 
@@ -299,15 +302,15 @@ class ConditionNode : public ParseNode {
 class FunctionCallNode : public ParseNode {
  public:
   FunctionCallNode();
-  virtual ~FunctionCallNode();
+  ~FunctionCallNode() override;
 
-  virtual const FunctionCallNode* AsFunctionCall() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const FunctionCallNode* AsFunctionCall() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& function() const { return function_; }
   void set_function(Token t) { function_ = t; }
@@ -332,15 +335,15 @@ class IdentifierNode : public ParseNode {
  public:
   IdentifierNode();
   IdentifierNode(const Token& token);
-  virtual ~IdentifierNode();
+  ~IdentifierNode() override;
 
-  virtual const IdentifierNode* AsIdentifier() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const IdentifierNode* AsIdentifier() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& value() const { return value_; }
   void set_value(const Token& t) { value_ = t; }
@@ -356,18 +359,19 @@ class IdentifierNode : public ParseNode {
 class ListNode : public ParseNode {
  public:
   ListNode();
-  virtual ~ListNode();
+  ~ListNode() override;
 
-  virtual const ListNode* AsList() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const ListNode* AsList() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   void set_begin_token(const Token& t) { begin_token_ = t; }
-  void set_end_token(const Token& t) { end_token_ = t; }
+  void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); }
+  const EndNode* End() const { return end_.get(); }
 
   void append_item(scoped_ptr<ParseNode> s) {
     contents_.push_back(s.release());
@@ -375,9 +379,10 @@ class ListNode : public ParseNode {
   const std::vector<const ParseNode*>& contents() const { return contents_; }
 
  private:
-  // Tokens corresponding to the [ and ].
+  // Tokens corresponding to the [ and ]. The end token is stored in inside an
+  // custom parse node so that it can have comments hung off of it.
   Token begin_token_;
-  Token end_token_;
+  scoped_ptr<EndNode> end_;
 
   // Owning pointers, use unique_ptr when we can use C++11.
   std::vector<const ParseNode*> contents_;
@@ -391,15 +396,15 @@ class LiteralNode : public ParseNode {
  public:
   LiteralNode();
   LiteralNode(const Token& token);
-  virtual ~LiteralNode();
+  ~LiteralNode() override;
 
-  virtual const LiteralNode* AsLiteral() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const LiteralNode* AsLiteral() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& value() const { return value_; }
   void set_value(const Token& t) { value_ = t; }
@@ -415,15 +420,15 @@ class LiteralNode : public ParseNode {
 class UnaryOpNode : public ParseNode {
  public:
   UnaryOpNode();
-  virtual ~UnaryOpNode();
+  ~UnaryOpNode() override;
 
-  virtual const UnaryOpNode* AsUnaryOp() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const UnaryOpNode* AsUnaryOp() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& op() const { return op_; }
   void set_op(const Token& t) { op_ = t; }
@@ -450,15 +455,15 @@ class UnaryOpNode : public ParseNode {
 class BlockCommentNode : public ParseNode {
  public:
   BlockCommentNode();
-  virtual ~BlockCommentNode();
+  ~BlockCommentNode() override;
 
-  virtual const BlockCommentNode* AsBlockComment() const OVERRIDE;
-  virtual Value Execute(Scope* scope, Err* err) const OVERRIDE;
-  virtual LocationRange GetRange() const OVERRIDE;
-  virtual Err MakeErrorDescribing(
+  const BlockCommentNode* AsBlockComment() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
       const std::string& msg,
-      const std::string& help = std::string()) const OVERRIDE;
-  virtual void Print(std::ostream& out, int indent) const OVERRIDE;
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
 
   const Token& comment() const { return comment_; }
   void set_comment(const Token& t) { comment_ = t; }
@@ -469,4 +474,32 @@ class BlockCommentNode : public ParseNode {
   DISALLOW_COPY_AND_ASSIGN(BlockCommentNode);
 };
 
+// EndNode ---------------------------------------------------------------------
+
+// This node type is used as the end_ object for lists and blocks (rather than
+// just the end ']', '}', or ')' token). This is so that during formatting
+// traversal there is a node that appears at the end of the block to which
+// comments can be attached.
+class EndNode : public ParseNode {
+ public:
+  EndNode(const Token& token);
+  ~EndNode() override;
+
+  const EndNode* AsEnd() const override;
+  Value Execute(Scope* scope, Err* err) const override;
+  LocationRange GetRange() const override;
+  Err MakeErrorDescribing(
+      const std::string& msg,
+      const std::string& help = std::string()) const override;
+  void Print(std::ostream& out, int indent) const override;
+
+  const Token& value() const { return value_; }
+  void set_value(const Token& t) { value_ = t; }
+
+ private:
+  Token value_;
+
+  DISALLOW_COPY_AND_ASSIGN(EndNode);
+};
+
 #endif  // TOOLS_GN_PARSE_TREE_H_