| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_FUNCTIONS_H_ | 5 #ifndef TOOLS_GN_FUNCTIONS_H_ |
| 6 #define TOOLS_GN_FUNCTIONS_H_ | 6 #define TOOLS_GN_FUNCTIONS_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 Value RunFunction(Scope* scope, | 408 Value RunFunction(Scope* scope, |
| 409 const FunctionCallNode* function, | 409 const FunctionCallNode* function, |
| 410 const ListNode* args_list, | 410 const ListNode* args_list, |
| 411 BlockNode* block, // Optional. | 411 BlockNode* block, // Optional. |
| 412 Err* err); | 412 Err* err); |
| 413 | 413 |
| 414 } // namespace functions | 414 } // namespace functions |
| 415 | 415 |
| 416 // Helper functions ----------------------------------------------------------- | 416 // Helper functions ----------------------------------------------------------- |
| 417 | 417 |
| 418 // Validates that the scope that a value is defined in is not the scope | |
| 419 // of the current declare_args() call, if that's what we're in. It is | |
| 420 // illegal to read a value from inside the same declare_args() call, since | |
| 421 // the overrides will not have been applied yet (see `gn help declare_args` | |
| 422 // for more). | |
| 423 bool EnsureNotReadingFromSameDeclareArgs(const ParseNode* node, | |
| 424 const Scope* cur_scope, | |
| 425 const Scope* val_scope, | |
| 426 Err* err); | |
| 427 | |
| 428 // Verifies that the current scope is not processing an import. If it is, it | 418 // Verifies that the current scope is not processing an import. If it is, it |
| 429 // will set the error, blame the given parse node for it, and return false. | 419 // will set the error, blame the given parse node for it, and return false. |
| 430 bool EnsureNotProcessingImport(const ParseNode* node, | 420 bool EnsureNotProcessingImport(const ParseNode* node, |
| 431 const Scope* scope, | 421 const Scope* scope, |
| 432 Err* err); | 422 Err* err); |
| 433 | 423 |
| 434 // Like EnsureNotProcessingImport but checks for running the build config. | 424 // Like EnsureNotProcessingImport but checks for running the build config. |
| 435 bool EnsureNotProcessingBuildConfig(const ParseNode* node, | 425 bool EnsureNotProcessingBuildConfig(const ParseNode* node, |
| 436 const Scope* scope, | 426 const Scope* scope, |
| 437 Err* err); | 427 Err* err); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 466 | 456 |
| 467 // Returns the name of the toolchain for the given scope. | 457 // Returns the name of the toolchain for the given scope. |
| 468 const Label& ToolchainLabelForScope(const Scope* scope); | 458 const Label& ToolchainLabelForScope(const Scope* scope); |
| 469 | 459 |
| 470 // Generates a label for the given scope, using the current directory and | 460 // Generates a label for the given scope, using the current directory and |
| 471 // toolchain, and the given name. | 461 // toolchain, and the given name. |
| 472 Label MakeLabelForScope(const Scope* scope, | 462 Label MakeLabelForScope(const Scope* scope, |
| 473 const FunctionCallNode* function, | 463 const FunctionCallNode* function, |
| 474 const std::string& name); | 464 const std::string& name); |
| 475 | 465 |
| 476 // Some types of blocks can't be nested inside other ones. For such cases, | 466 // Some tyesp of blocks can't be nested inside other ones. For such cases, |
| 477 // instantiate this object upon entering the block and Enter() will fail if | 467 // instantiate this object upon entering the block and Enter() will fail if |
| 478 // there is already another non-nestable block on the stack. | 468 // there is already another non-nestable block on the stack. |
| 479 class NonNestableBlock { | 469 class NonNestableBlock { |
| 480 public: | 470 public: |
| 481 // type_description is a string that will be used in error messages | 471 // type_description is a string that will be used in error messages |
| 482 // describing the type of the block, for example, "template" or "config". | 472 // describing the type of the block, for example, "template" or "config". |
| 483 NonNestableBlock(Scope* scope, | 473 NonNestableBlock(Scope* scope, |
| 484 const FunctionCallNode* function, | 474 const FunctionCallNode* function, |
| 485 const char* type_description); | 475 const char* type_description); |
| 486 ~NonNestableBlock(); | 476 ~NonNestableBlock(); |
| 487 | 477 |
| 488 bool Enter(Err* err); | 478 bool Enter(Err* err); |
| 489 | 479 |
| 490 private: | 480 private: |
| 491 // Used as a void* key for the Scope to track our property. The actual value | 481 // Used as a void* key for the Scope to track our property. The actual value |
| 492 // is never used. | 482 // is never used. |
| 493 static const int kKey; | 483 static const int kKey; |
| 494 | 484 |
| 495 Scope* scope_; | 485 Scope* scope_; |
| 496 const FunctionCallNode* function_; | 486 const FunctionCallNode* function_; |
| 497 const char* type_description_; | 487 const char* type_description_; |
| 498 | 488 |
| 499 // Set to true when the key is added to the scope so we don't try to | 489 // Set to true when the key is added to the scope so we don't try to |
| 500 // delete nonexistant keys which will cause assertions. | 490 // delete nonexistant keys which will cause assertions. |
| 501 bool key_added_; | 491 bool key_added_; |
| 502 }; | 492 }; |
| 503 | 493 |
| 504 #endif // TOOLS_GN_FUNCTIONS_H_ | 494 #endif // TOOLS_GN_FUNCTIONS_H_ |
| OLD | NEW |