| 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 #include "tools/gn/functions.h" | 5 #include "tools/gn/functions.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 | 8 |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 " Returns true if the given argument is defined. This is most useful in\n" | 334 " Returns true if the given argument is defined. This is most useful in\n" |
| 335 " templates to assert that the caller set things up properly.\n" | 335 " templates to assert that the caller set things up properly.\n" |
| 336 "\n" | 336 "\n" |
| 337 " You can pass an identifier:\n" | 337 " You can pass an identifier:\n" |
| 338 " defined(foo)\n" | 338 " defined(foo)\n" |
| 339 " which will return true or false depending on whether foo is defined in\n" | 339 " which will return true or false depending on whether foo is defined in\n" |
| 340 " the current scope.\n" | 340 " the current scope.\n" |
| 341 "\n" | 341 "\n" |
| 342 " You can also check a named scope:\n" | 342 " You can also check a named scope:\n" |
| 343 " defined(foo.bar)\n" | 343 " defined(foo.bar)\n" |
| 344 " which returns true if both foo is defined and bar is defined on the\n" | 344 " which will return true or false depending on whether bar is defined in\n" |
| 345 " named scope foo. It will throw an error if foo is defined but is not\n" | 345 " the named scope foo. It will throw an error if foo is not defined or\n" |
| 346 " a scope.\n" | 346 " is not a scope.\n" |
| 347 "\n" | 347 "\n" |
| 348 "Example:\n" | 348 "Example:\n" |
| 349 "\n" | 349 "\n" |
| 350 " template(\"mytemplate\") {\n" | 350 " template(\"mytemplate\") {\n" |
| 351 " # To help users call this template properly...\n" | 351 " # To help users call this template properly...\n" |
| 352 " assert(defined(invoker.sources), \"Sources must be defined\")\n" | 352 " assert(defined(invoker.sources), \"Sources must be defined\")\n" |
| 353 "\n" | 353 "\n" |
| 354 " # If we want to accept an optional \"values\" argument, we don't\n" | 354 " # If we want to accept an optional \"values\" argument, we don't\n" |
| 355 " # want to dereference something that may not be defined.\n" | 355 " # want to dereference something that may not be defined.\n" |
| 356 " if (defined(invoker.values)) {\n" | 356 " if (defined(invoker.values)) {\n" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 378 return Value(function, true); | 378 return Value(function, true); |
| 379 return Value(function, false); | 379 return Value(function, false); |
| 380 } | 380 } |
| 381 | 381 |
| 382 const AccessorNode* accessor = args_vector[0]->AsAccessor(); | 382 const AccessorNode* accessor = args_vector[0]->AsAccessor(); |
| 383 if (accessor) { | 383 if (accessor) { |
| 384 // Passed an accessor "defined(foo.bar)". | 384 // Passed an accessor "defined(foo.bar)". |
| 385 if (accessor->member()) { | 385 if (accessor->member()) { |
| 386 // The base of the accessor must be a scope if it's defined. | 386 // The base of the accessor must be a scope if it's defined. |
| 387 const Value* base = scope->GetValue(accessor->base().value()); | 387 const Value* base = scope->GetValue(accessor->base().value()); |
| 388 if (!base) | 388 if (!base) { |
| 389 return Value(function, false); | 389 *err = Err(accessor, "Undefined identifier"); |
| 390 return Value(); |
| 391 } |
| 390 if (!base->VerifyTypeIs(Value::SCOPE, err)) | 392 if (!base->VerifyTypeIs(Value::SCOPE, err)) |
| 391 return Value(); | 393 return Value(); |
| 392 | 394 |
| 393 // Check the member inside the scope to see if its defined. | 395 // Check the member inside the scope to see if its defined. |
| 394 if (base->scope_value()->GetValue(accessor->member()->value().value())) | 396 if (base->scope_value()->GetValue(accessor->member()->value().value())) |
| 395 return Value(function, true); | 397 return Value(function, true); |
| 396 return Value(function, false); | 398 return Value(function, false); |
| 397 } | 399 } |
| 398 } | 400 } |
| 399 | 401 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 815 } |
| 814 | 816 |
| 815 // Otherwise it's a no-block function. | 817 // Otherwise it's a no-block function. |
| 816 if (!VerifyNoBlockForFunctionCall(function, block, err)) | 818 if (!VerifyNoBlockForFunctionCall(function, block, err)) |
| 817 return Value(); | 819 return Value(); |
| 818 return found_function->second.no_block_runner(scope, function, | 820 return found_function->second.no_block_runner(scope, function, |
| 819 args.list_value(), err); | 821 args.list_value(), err); |
| 820 } | 822 } |
| 821 | 823 |
| 822 } // namespace functions | 824 } // namespace functions |
| OLD | NEW |