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

Side by Side Diff: tools/gn/functions.cc

Issue 223783005: Add support for reading .gypi files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
OLDNEW
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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 // Passed an identifier "defined(foo)". 347 // Passed an identifier "defined(foo)".
348 if (scope->GetValue(identifier->value().value())) 348 if (scope->GetValue(identifier->value().value()))
349 return Value(function, true); 349 return Value(function, true);
350 return Value(function, false); 350 return Value(function, false);
351 } 351 }
352 352
353 const AccessorNode* accessor = args_vector[0]->AsAccessor(); 353 const AccessorNode* accessor = args_vector[0]->AsAccessor();
354 if (accessor) { 354 if (accessor) {
355 // Passed an accessor "defined(foo.bar)". 355 // Passed an accessor "defined(foo.bar)".
356 if (accessor->member()) { 356 if (accessor->member()) {
357 // The base of the accessor must be a scope if it's defined. 357 // The base of the accessor must be a scope/dict if it's defined.
358 const Value* base = scope->GetValue(accessor->base().value()); 358 const Value* base = scope->GetValue(accessor->base().value());
359 if (!base) 359 if (!base)
360 return Value(function, false); 360 return Value(function, false);
361 if (!base->VerifyTypeIs(Value::SCOPE, err)) 361 if (base->type() == Value::SCOPE) {
362 // Check the member inside the scope to see if its defined.
363 if (base->scope_value()->GetValue(accessor->member()->value().value()))
364 return Value(function, true);
365 } else if (base->type() == Value::DICT) {
366 // Check the dictionary to see if the member is present.
367 if (base->dict_value().find(
368 accessor->member()->value().value().as_string()) !=
369 base->dict_value().end())
370 return Value(function, true);
371 } else {
372 *err = Err(function,
373 std::string("Type \"") + Value::DescribeType(base->type()) +
374 "\" is not usable with the '.' operator.");
362 return Value(); 375 return Value();
363 376 }
364 // Check the member inside the scope to see if its defined.
365 if (base->scope_value()->GetValue(accessor->member()->value().value()))
366 return Value(function, true);
367 return Value(function, false); 377 return Value(function, false);
368 } 378 }
369 } 379 }
370 380
371 // Argument is invalid. 381 // Argument is invalid.
372 *err = Err(function, "Bad thing passed to defined().", 382 *err = Err(function, "Bad thing passed to defined().",
373 "It should be of the form defined(foo) or defined(foo.bar)."); 383 "It should be of the form defined(foo) or defined(foo.bar).");
374 return Value(); 384 return Value();
375 } 385 }
376 386
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 return found_function->second.executed_block_runner( 727 return found_function->second.executed_block_runner(
718 function, args.list_value(), &block_scope, err); 728 function, args.list_value(), &block_scope, err);
719 } 729 }
720 730
721 // Otherwise it's a no-block function. 731 // Otherwise it's a no-block function.
722 return found_function->second.no_block_runner(scope, function, 732 return found_function->second.no_block_runner(scope, function,
723 args.list_value(), err); 733 args.list_value(), err);
724 } 734 }
725 735
726 } // namespace functions 736 } // namespace functions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698