| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef TOOLS_GN_PARSE_TREE_H_ | 5 #ifndef TOOLS_GN_PARSE_TREE_H_ |
| 6 #define TOOLS_GN_PARSE_TREE_H_ | 6 #define TOOLS_GN_PARSE_TREE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 13 #include "tools/gn/err.h" | 12 #include "tools/gn/err.h" |
| 14 #include "tools/gn/token.h" | 13 #include "tools/gn/token.h" |
| 15 #include "tools/gn/value.h" | 14 #include "tools/gn/value.h" |
| 16 | 15 |
| 17 class AccessorNode; | 16 class AccessorNode; |
| 18 class BinaryOpNode; | 17 class BinaryOpNode; |
| 19 class BlockCommentNode; | 18 class BlockCommentNode; |
| 20 class BlockNode; | 19 class BlockNode; |
| 21 class ConditionNode; | 20 class ConditionNode; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // | 129 // |
| 131 // Additionally, the left-hand-side of the accessor must currently be an | 130 // Additionally, the left-hand-side of the accessor must currently be an |
| 132 // identifier. So you can't do things like: | 131 // identifier. So you can't do things like: |
| 133 // function_call()[1] | 132 // function_call()[1] |
| 134 // a = b.c.d | 133 // a = b.c.d |
| 135 // These are easier to implement if we needed them but given the very limited | 134 // These are easier to implement if we needed them but given the very limited |
| 136 // use cases for this, it hasn't seemed worth the bother. | 135 // use cases for this, it hasn't seemed worth the bother. |
| 137 class AccessorNode : public ParseNode { | 136 class AccessorNode : public ParseNode { |
| 138 public: | 137 public: |
| 139 AccessorNode(); | 138 AccessorNode(); |
| 140 virtual ~AccessorNode(); | 139 ~AccessorNode() override; |
| 141 | 140 |
| 142 virtual const AccessorNode* AsAccessor() const override; | 141 const AccessorNode* AsAccessor() const override; |
| 143 virtual Value Execute(Scope* scope, Err* err) const override; | 142 Value Execute(Scope* scope, Err* err) const override; |
| 144 virtual LocationRange GetRange() const override; | 143 LocationRange GetRange() const override; |
| 145 virtual Err MakeErrorDescribing( | 144 Err MakeErrorDescribing( |
| 146 const std::string& msg, | 145 const std::string& msg, |
| 147 const std::string& help = std::string()) const override; | 146 const std::string& help = std::string()) const override; |
| 148 virtual void Print(std::ostream& out, int indent) const override; | 147 void Print(std::ostream& out, int indent) const override; |
| 149 | 148 |
| 150 // Base is the thing on the left of the [] or dot, currently always required | 149 // Base is the thing on the left of the [] or dot, currently always required |
| 151 // to be an identifier token. | 150 // to be an identifier token. |
| 152 const Token& base() const { return base_; } | 151 const Token& base() const { return base_; } |
| 153 void set_base(const Token& b) { base_ = b; } | 152 void set_base(const Token& b) { base_ = b; } |
| 154 | 153 |
| 155 // Index is the expression inside the []. Will be null if member is set. | 154 // Index is the expression inside the []. Will be null if member is set. |
| 156 const ParseNode* index() const { return index_.get(); } | 155 const ParseNode* index() const { return index_.get(); } |
| 157 void set_index(scoped_ptr<ParseNode> i) { index_ = i.Pass(); } | 156 void set_index(scoped_ptr<ParseNode> i) { index_ = i.Pass(); } |
| 158 | 157 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 173 scoped_ptr<IdentifierNode> member_; | 172 scoped_ptr<IdentifierNode> member_; |
| 174 | 173 |
| 175 DISALLOW_COPY_AND_ASSIGN(AccessorNode); | 174 DISALLOW_COPY_AND_ASSIGN(AccessorNode); |
| 176 }; | 175 }; |
| 177 | 176 |
| 178 // BinaryOpNode ---------------------------------------------------------------- | 177 // BinaryOpNode ---------------------------------------------------------------- |
| 179 | 178 |
| 180 class BinaryOpNode : public ParseNode { | 179 class BinaryOpNode : public ParseNode { |
| 181 public: | 180 public: |
| 182 BinaryOpNode(); | 181 BinaryOpNode(); |
| 183 virtual ~BinaryOpNode(); | 182 ~BinaryOpNode() override; |
| 184 | 183 |
| 185 virtual const BinaryOpNode* AsBinaryOp() const override; | 184 const BinaryOpNode* AsBinaryOp() const override; |
| 186 virtual Value Execute(Scope* scope, Err* err) const override; | 185 Value Execute(Scope* scope, Err* err) const override; |
| 187 virtual LocationRange GetRange() const override; | 186 LocationRange GetRange() const override; |
| 188 virtual Err MakeErrorDescribing( | 187 Err MakeErrorDescribing( |
| 189 const std::string& msg, | 188 const std::string& msg, |
| 190 const std::string& help = std::string()) const override; | 189 const std::string& help = std::string()) const override; |
| 191 virtual void Print(std::ostream& out, int indent) const override; | 190 void Print(std::ostream& out, int indent) const override; |
| 192 | 191 |
| 193 const Token& op() const { return op_; } | 192 const Token& op() const { return op_; } |
| 194 void set_op(const Token& t) { op_ = t; } | 193 void set_op(const Token& t) { op_ = t; } |
| 195 | 194 |
| 196 const ParseNode* left() const { return left_.get(); } | 195 const ParseNode* left() const { return left_.get(); } |
| 197 void set_left(scoped_ptr<ParseNode> left) { | 196 void set_left(scoped_ptr<ParseNode> left) { |
| 198 left_ = left.Pass(); | 197 left_ = left.Pass(); |
| 199 } | 198 } |
| 200 | 199 |
| 201 const ParseNode* right() const { return right_.get(); } | 200 const ParseNode* right() const { return right_.get(); } |
| 202 void set_right(scoped_ptr<ParseNode> right) { | 201 void set_right(scoped_ptr<ParseNode> right) { |
| 203 right_ = right.Pass(); | 202 right_ = right.Pass(); |
| 204 } | 203 } |
| 205 | 204 |
| 206 private: | 205 private: |
| 207 scoped_ptr<ParseNode> left_; | 206 scoped_ptr<ParseNode> left_; |
| 208 Token op_; | 207 Token op_; |
| 209 scoped_ptr<ParseNode> right_; | 208 scoped_ptr<ParseNode> right_; |
| 210 | 209 |
| 211 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); | 210 DISALLOW_COPY_AND_ASSIGN(BinaryOpNode); |
| 212 }; | 211 }; |
| 213 | 212 |
| 214 // BlockNode ------------------------------------------------------------------- | 213 // BlockNode ------------------------------------------------------------------- |
| 215 | 214 |
| 216 class BlockNode : public ParseNode { | 215 class BlockNode : public ParseNode { |
| 217 public: | 216 public: |
| 218 // Set has_scope if this block introduces a nested scope. | 217 // Set has_scope if this block introduces a nested scope. |
| 219 explicit BlockNode(bool has_scope); | 218 explicit BlockNode(bool has_scope); |
| 220 virtual ~BlockNode(); | 219 ~BlockNode() override; |
| 221 | 220 |
| 222 virtual const BlockNode* AsBlock() const override; | 221 const BlockNode* AsBlock() const override; |
| 223 virtual Value Execute(Scope* scope, Err* err) const override; | 222 Value Execute(Scope* scope, Err* err) const override; |
| 224 virtual LocationRange GetRange() const override; | 223 LocationRange GetRange() const override; |
| 225 virtual Err MakeErrorDescribing( | 224 Err MakeErrorDescribing( |
| 226 const std::string& msg, | 225 const std::string& msg, |
| 227 const std::string& help = std::string()) const override; | 226 const std::string& help = std::string()) const override; |
| 228 virtual void Print(std::ostream& out, int indent) const override; | 227 void Print(std::ostream& out, int indent) const override; |
| 229 | 228 |
| 230 void set_begin_token(const Token& t) { begin_token_ = t; } | 229 void set_begin_token(const Token& t) { begin_token_ = t; } |
| 231 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } | 230 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } |
| 232 const EndNode* End() const { return end_.get(); } | 231 const EndNode* End() const { return end_.get(); } |
| 233 | 232 |
| 234 const std::vector<ParseNode*>& statements() const { return statements_; } | 233 const std::vector<ParseNode*>& statements() const { return statements_; } |
| 235 void append_statement(scoped_ptr<ParseNode> s) { | 234 void append_statement(scoped_ptr<ParseNode> s) { |
| 236 statements_.push_back(s.release()); | 235 statements_.push_back(s.release()); |
| 237 } | 236 } |
| 238 | 237 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 251 std::vector<ParseNode*> statements_; | 250 std::vector<ParseNode*> statements_; |
| 252 | 251 |
| 253 DISALLOW_COPY_AND_ASSIGN(BlockNode); | 252 DISALLOW_COPY_AND_ASSIGN(BlockNode); |
| 254 }; | 253 }; |
| 255 | 254 |
| 256 // ConditionNode --------------------------------------------------------------- | 255 // ConditionNode --------------------------------------------------------------- |
| 257 | 256 |
| 258 class ConditionNode : public ParseNode { | 257 class ConditionNode : public ParseNode { |
| 259 public: | 258 public: |
| 260 ConditionNode(); | 259 ConditionNode(); |
| 261 virtual ~ConditionNode(); | 260 ~ConditionNode() override; |
| 262 | 261 |
| 263 virtual const ConditionNode* AsConditionNode() const override; | 262 const ConditionNode* AsConditionNode() const override; |
| 264 virtual Value Execute(Scope* scope, Err* err) const override; | 263 Value Execute(Scope* scope, Err* err) const override; |
| 265 virtual LocationRange GetRange() const override; | 264 LocationRange GetRange() const override; |
| 266 virtual Err MakeErrorDescribing( | 265 Err MakeErrorDescribing( |
| 267 const std::string& msg, | 266 const std::string& msg, |
| 268 const std::string& help = std::string()) const override; | 267 const std::string& help = std::string()) const override; |
| 269 virtual void Print(std::ostream& out, int indent) const override; | 268 void Print(std::ostream& out, int indent) const override; |
| 270 | 269 |
| 271 void set_if_token(const Token& token) { if_token_ = token; } | 270 void set_if_token(const Token& token) { if_token_ = token; } |
| 272 | 271 |
| 273 const ParseNode* condition() const { return condition_.get(); } | 272 const ParseNode* condition() const { return condition_.get(); } |
| 274 void set_condition(scoped_ptr<ParseNode> c) { | 273 void set_condition(scoped_ptr<ParseNode> c) { |
| 275 condition_ = c.Pass(); | 274 condition_ = c.Pass(); |
| 276 } | 275 } |
| 277 | 276 |
| 278 const BlockNode* if_true() const { return if_true_.get(); } | 277 const BlockNode* if_true() const { return if_true_.get(); } |
| 279 void set_if_true(scoped_ptr<BlockNode> t) { | 278 void set_if_true(scoped_ptr<BlockNode> t) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 296 scoped_ptr<ParseNode> if_false_; // May be null. | 295 scoped_ptr<ParseNode> if_false_; // May be null. |
| 297 | 296 |
| 298 DISALLOW_COPY_AND_ASSIGN(ConditionNode); | 297 DISALLOW_COPY_AND_ASSIGN(ConditionNode); |
| 299 }; | 298 }; |
| 300 | 299 |
| 301 // FunctionCallNode ------------------------------------------------------------ | 300 // FunctionCallNode ------------------------------------------------------------ |
| 302 | 301 |
| 303 class FunctionCallNode : public ParseNode { | 302 class FunctionCallNode : public ParseNode { |
| 304 public: | 303 public: |
| 305 FunctionCallNode(); | 304 FunctionCallNode(); |
| 306 virtual ~FunctionCallNode(); | 305 ~FunctionCallNode() override; |
| 307 | 306 |
| 308 virtual const FunctionCallNode* AsFunctionCall() const override; | 307 const FunctionCallNode* AsFunctionCall() const override; |
| 309 virtual Value Execute(Scope* scope, Err* err) const override; | 308 Value Execute(Scope* scope, Err* err) const override; |
| 310 virtual LocationRange GetRange() const override; | 309 LocationRange GetRange() const override; |
| 311 virtual Err MakeErrorDescribing( | 310 Err MakeErrorDescribing( |
| 312 const std::string& msg, | 311 const std::string& msg, |
| 313 const std::string& help = std::string()) const override; | 312 const std::string& help = std::string()) const override; |
| 314 virtual void Print(std::ostream& out, int indent) const override; | 313 void Print(std::ostream& out, int indent) const override; |
| 315 | 314 |
| 316 const Token& function() const { return function_; } | 315 const Token& function() const { return function_; } |
| 317 void set_function(Token t) { function_ = t; } | 316 void set_function(Token t) { function_ = t; } |
| 318 | 317 |
| 319 const ListNode* args() const { return args_.get(); } | 318 const ListNode* args() const { return args_.get(); } |
| 320 void set_args(scoped_ptr<ListNode> a) { args_ = a.Pass(); } | 319 void set_args(scoped_ptr<ListNode> a) { args_ = a.Pass(); } |
| 321 | 320 |
| 322 const BlockNode* block() const { return block_.get(); } | 321 const BlockNode* block() const { return block_.get(); } |
| 323 void set_block(scoped_ptr<BlockNode> b) { block_ = b.Pass(); } | 322 void set_block(scoped_ptr<BlockNode> b) { block_ = b.Pass(); } |
| 324 | 323 |
| 325 private: | 324 private: |
| 326 Token function_; | 325 Token function_; |
| 327 scoped_ptr<ListNode> args_; | 326 scoped_ptr<ListNode> args_; |
| 328 scoped_ptr<BlockNode> block_; // May be null. | 327 scoped_ptr<BlockNode> block_; // May be null. |
| 329 | 328 |
| 330 DISALLOW_COPY_AND_ASSIGN(FunctionCallNode); | 329 DISALLOW_COPY_AND_ASSIGN(FunctionCallNode); |
| 331 }; | 330 }; |
| 332 | 331 |
| 333 // IdentifierNode -------------------------------------------------------------- | 332 // IdentifierNode -------------------------------------------------------------- |
| 334 | 333 |
| 335 class IdentifierNode : public ParseNode { | 334 class IdentifierNode : public ParseNode { |
| 336 public: | 335 public: |
| 337 IdentifierNode(); | 336 IdentifierNode(); |
| 338 IdentifierNode(const Token& token); | 337 IdentifierNode(const Token& token); |
| 339 virtual ~IdentifierNode(); | 338 ~IdentifierNode() override; |
| 340 | 339 |
| 341 virtual const IdentifierNode* AsIdentifier() const override; | 340 const IdentifierNode* AsIdentifier() const override; |
| 342 virtual Value Execute(Scope* scope, Err* err) const override; | 341 Value Execute(Scope* scope, Err* err) const override; |
| 343 virtual LocationRange GetRange() const override; | 342 LocationRange GetRange() const override; |
| 344 virtual Err MakeErrorDescribing( | 343 Err MakeErrorDescribing( |
| 345 const std::string& msg, | 344 const std::string& msg, |
| 346 const std::string& help = std::string()) const override; | 345 const std::string& help = std::string()) const override; |
| 347 virtual void Print(std::ostream& out, int indent) const override; | 346 void Print(std::ostream& out, int indent) const override; |
| 348 | 347 |
| 349 const Token& value() const { return value_; } | 348 const Token& value() const { return value_; } |
| 350 void set_value(const Token& t) { value_ = t; } | 349 void set_value(const Token& t) { value_ = t; } |
| 351 | 350 |
| 352 private: | 351 private: |
| 353 Token value_; | 352 Token value_; |
| 354 | 353 |
| 355 DISALLOW_COPY_AND_ASSIGN(IdentifierNode); | 354 DISALLOW_COPY_AND_ASSIGN(IdentifierNode); |
| 356 }; | 355 }; |
| 357 | 356 |
| 358 // ListNode -------------------------------------------------------------------- | 357 // ListNode -------------------------------------------------------------------- |
| 359 | 358 |
| 360 class ListNode : public ParseNode { | 359 class ListNode : public ParseNode { |
| 361 public: | 360 public: |
| 362 ListNode(); | 361 ListNode(); |
| 363 virtual ~ListNode(); | 362 ~ListNode() override; |
| 364 | 363 |
| 365 virtual const ListNode* AsList() const override; | 364 const ListNode* AsList() const override; |
| 366 virtual Value Execute(Scope* scope, Err* err) const override; | 365 Value Execute(Scope* scope, Err* err) const override; |
| 367 virtual LocationRange GetRange() const override; | 366 LocationRange GetRange() const override; |
| 368 virtual Err MakeErrorDescribing( | 367 Err MakeErrorDescribing( |
| 369 const std::string& msg, | 368 const std::string& msg, |
| 370 const std::string& help = std::string()) const override; | 369 const std::string& help = std::string()) const override; |
| 371 virtual void Print(std::ostream& out, int indent) const override; | 370 void Print(std::ostream& out, int indent) const override; |
| 372 | 371 |
| 373 void set_begin_token(const Token& t) { begin_token_ = t; } | 372 void set_begin_token(const Token& t) { begin_token_ = t; } |
| 374 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } | 373 void set_end(scoped_ptr<EndNode> e) { end_ = e.Pass(); } |
| 375 const EndNode* End() const { return end_.get(); } | 374 const EndNode* End() const { return end_.get(); } |
| 376 | 375 |
| 377 void append_item(scoped_ptr<ParseNode> s) { | 376 void append_item(scoped_ptr<ParseNode> s) { |
| 378 contents_.push_back(s.release()); | 377 contents_.push_back(s.release()); |
| 379 } | 378 } |
| 380 const std::vector<const ParseNode*>& contents() const { return contents_; } | 379 const std::vector<const ParseNode*>& contents() const { return contents_; } |
| 381 | 380 |
| 382 private: | 381 private: |
| 383 // Tokens corresponding to the [ and ]. The end token is stored in inside an | 382 // Tokens corresponding to the [ and ]. The end token is stored in inside an |
| 384 // custom parse node so that it can have comments hung off of it. | 383 // custom parse node so that it can have comments hung off of it. |
| 385 Token begin_token_; | 384 Token begin_token_; |
| 386 scoped_ptr<EndNode> end_; | 385 scoped_ptr<EndNode> end_; |
| 387 | 386 |
| 388 // Owning pointers, use unique_ptr when we can use C++11. | 387 // Owning pointers, use unique_ptr when we can use C++11. |
| 389 std::vector<const ParseNode*> contents_; | 388 std::vector<const ParseNode*> contents_; |
| 390 | 389 |
| 391 DISALLOW_COPY_AND_ASSIGN(ListNode); | 390 DISALLOW_COPY_AND_ASSIGN(ListNode); |
| 392 }; | 391 }; |
| 393 | 392 |
| 394 // LiteralNode ----------------------------------------------------------------- | 393 // LiteralNode ----------------------------------------------------------------- |
| 395 | 394 |
| 396 class LiteralNode : public ParseNode { | 395 class LiteralNode : public ParseNode { |
| 397 public: | 396 public: |
| 398 LiteralNode(); | 397 LiteralNode(); |
| 399 LiteralNode(const Token& token); | 398 LiteralNode(const Token& token); |
| 400 virtual ~LiteralNode(); | 399 ~LiteralNode() override; |
| 401 | 400 |
| 402 virtual const LiteralNode* AsLiteral() const override; | 401 const LiteralNode* AsLiteral() const override; |
| 403 virtual Value Execute(Scope* scope, Err* err) const override; | 402 Value Execute(Scope* scope, Err* err) const override; |
| 404 virtual LocationRange GetRange() const override; | 403 LocationRange GetRange() const override; |
| 405 virtual Err MakeErrorDescribing( | 404 Err MakeErrorDescribing( |
| 406 const std::string& msg, | 405 const std::string& msg, |
| 407 const std::string& help = std::string()) const override; | 406 const std::string& help = std::string()) const override; |
| 408 virtual void Print(std::ostream& out, int indent) const override; | 407 void Print(std::ostream& out, int indent) const override; |
| 409 | 408 |
| 410 const Token& value() const { return value_; } | 409 const Token& value() const { return value_; } |
| 411 void set_value(const Token& t) { value_ = t; } | 410 void set_value(const Token& t) { value_ = t; } |
| 412 | 411 |
| 413 private: | 412 private: |
| 414 Token value_; | 413 Token value_; |
| 415 | 414 |
| 416 DISALLOW_COPY_AND_ASSIGN(LiteralNode); | 415 DISALLOW_COPY_AND_ASSIGN(LiteralNode); |
| 417 }; | 416 }; |
| 418 | 417 |
| 419 // UnaryOpNode ----------------------------------------------------------------- | 418 // UnaryOpNode ----------------------------------------------------------------- |
| 420 | 419 |
| 421 class UnaryOpNode : public ParseNode { | 420 class UnaryOpNode : public ParseNode { |
| 422 public: | 421 public: |
| 423 UnaryOpNode(); | 422 UnaryOpNode(); |
| 424 virtual ~UnaryOpNode(); | 423 ~UnaryOpNode() override; |
| 425 | 424 |
| 426 virtual const UnaryOpNode* AsUnaryOp() const override; | 425 const UnaryOpNode* AsUnaryOp() const override; |
| 427 virtual Value Execute(Scope* scope, Err* err) const override; | 426 Value Execute(Scope* scope, Err* err) const override; |
| 428 virtual LocationRange GetRange() const override; | 427 LocationRange GetRange() const override; |
| 429 virtual Err MakeErrorDescribing( | 428 Err MakeErrorDescribing( |
| 430 const std::string& msg, | 429 const std::string& msg, |
| 431 const std::string& help = std::string()) const override; | 430 const std::string& help = std::string()) const override; |
| 432 virtual void Print(std::ostream& out, int indent) const override; | 431 void Print(std::ostream& out, int indent) const override; |
| 433 | 432 |
| 434 const Token& op() const { return op_; } | 433 const Token& op() const { return op_; } |
| 435 void set_op(const Token& t) { op_ = t; } | 434 void set_op(const Token& t) { op_ = t; } |
| 436 | 435 |
| 437 const ParseNode* operand() const { return operand_.get(); } | 436 const ParseNode* operand() const { return operand_.get(); } |
| 438 void set_operand(scoped_ptr<ParseNode> operand) { | 437 void set_operand(scoped_ptr<ParseNode> operand) { |
| 439 operand_ = operand.Pass(); | 438 operand_ = operand.Pass(); |
| 440 } | 439 } |
| 441 | 440 |
| 442 private: | 441 private: |
| 443 Token op_; | 442 Token op_; |
| 444 scoped_ptr<ParseNode> operand_; | 443 scoped_ptr<ParseNode> operand_; |
| 445 | 444 |
| 446 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); | 445 DISALLOW_COPY_AND_ASSIGN(UnaryOpNode); |
| 447 }; | 446 }; |
| 448 | 447 |
| 449 // BlockCommentNode ------------------------------------------------------------ | 448 // BlockCommentNode ------------------------------------------------------------ |
| 450 | 449 |
| 451 // This node type is only used for standalone comments (that is, those not | 450 // This node type is only used for standalone comments (that is, those not |
| 452 // specifically attached to another syntax element. The most common of these | 451 // specifically attached to another syntax element. The most common of these |
| 453 // is a standard header block. This node contains only the last line of such | 452 // is a standard header block. This node contains only the last line of such |
| 454 // a comment block as the anchor, and other lines of the block comment are | 453 // a comment block as the anchor, and other lines of the block comment are |
| 455 // hung off of it as Before comments, similar to other syntax elements. | 454 // hung off of it as Before comments, similar to other syntax elements. |
| 456 class BlockCommentNode : public ParseNode { | 455 class BlockCommentNode : public ParseNode { |
| 457 public: | 456 public: |
| 458 BlockCommentNode(); | 457 BlockCommentNode(); |
| 459 virtual ~BlockCommentNode(); | 458 ~BlockCommentNode() override; |
| 460 | 459 |
| 461 virtual const BlockCommentNode* AsBlockComment() const override; | 460 const BlockCommentNode* AsBlockComment() const override; |
| 462 virtual Value Execute(Scope* scope, Err* err) const override; | 461 Value Execute(Scope* scope, Err* err) const override; |
| 463 virtual LocationRange GetRange() const override; | 462 LocationRange GetRange() const override; |
| 464 virtual Err MakeErrorDescribing( | 463 Err MakeErrorDescribing( |
| 465 const std::string& msg, | 464 const std::string& msg, |
| 466 const std::string& help = std::string()) const override; | 465 const std::string& help = std::string()) const override; |
| 467 virtual void Print(std::ostream& out, int indent) const override; | 466 void Print(std::ostream& out, int indent) const override; |
| 468 | 467 |
| 469 const Token& comment() const { return comment_; } | 468 const Token& comment() const { return comment_; } |
| 470 void set_comment(const Token& t) { comment_ = t; } | 469 void set_comment(const Token& t) { comment_ = t; } |
| 471 | 470 |
| 472 private: | 471 private: |
| 473 Token comment_; | 472 Token comment_; |
| 474 | 473 |
| 475 DISALLOW_COPY_AND_ASSIGN(BlockCommentNode); | 474 DISALLOW_COPY_AND_ASSIGN(BlockCommentNode); |
| 476 }; | 475 }; |
| 477 | 476 |
| 478 // EndNode --------------------------------------------------------------------- | 477 // EndNode --------------------------------------------------------------------- |
| 479 | 478 |
| 480 // This node type is used as the end_ object for lists and blocks (rather than | 479 // This node type is used as the end_ object for lists and blocks (rather than |
| 481 // just the end ']', '}', or ')' token). This is so that during formatting | 480 // just the end ']', '}', or ')' token). This is so that during formatting |
| 482 // traversal there is a node that appears at the end of the block to which | 481 // traversal there is a node that appears at the end of the block to which |
| 483 // comments can be attached. | 482 // comments can be attached. |
| 484 class EndNode : public ParseNode { | 483 class EndNode : public ParseNode { |
| 485 public: | 484 public: |
| 486 EndNode(const Token& token); | 485 EndNode(const Token& token); |
| 487 virtual ~EndNode(); | 486 ~EndNode() override; |
| 488 | 487 |
| 489 virtual const EndNode* AsEnd() const override; | 488 const EndNode* AsEnd() const override; |
| 490 virtual Value Execute(Scope* scope, Err* err) const override; | 489 Value Execute(Scope* scope, Err* err) const override; |
| 491 virtual LocationRange GetRange() const override; | 490 LocationRange GetRange() const override; |
| 492 virtual Err MakeErrorDescribing( | 491 Err MakeErrorDescribing( |
| 493 const std::string& msg, | 492 const std::string& msg, |
| 494 const std::string& help = std::string()) const override; | 493 const std::string& help = std::string()) const override; |
| 495 virtual void Print(std::ostream& out, int indent) const override; | 494 void Print(std::ostream& out, int indent) const override; |
| 496 | 495 |
| 497 const Token& value() const { return value_; } | 496 const Token& value() const { return value_; } |
| 498 void set_value(const Token& t) { value_ = t; } | 497 void set_value(const Token& t) { value_ = t; } |
| 499 | 498 |
| 500 private: | 499 private: |
| 501 Token value_; | 500 Token value_; |
| 502 | 501 |
| 503 DISALLOW_COPY_AND_ASSIGN(EndNode); | 502 DISALLOW_COPY_AND_ASSIGN(EndNode); |
| 504 }; | 503 }; |
| 505 | 504 |
| 506 #endif // TOOLS_GN_PARSE_TREE_H_ | 505 #endif // TOOLS_GN_PARSE_TREE_H_ |
| OLD | NEW |