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

Side by Side Diff: grit/node/base.py

Issue 122253002: Simplify how variable_map is initialized. Suggestion by thakis@chromium.org. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 '''Base types for nodes in a GRIT resource tree. 6 '''Base types for nodes in a GRIT resource tree.
7 ''' 7 '''
8 8
9 import collections 9 import collections
10 import os 10 import os
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 def EvaluateExpression(cls, expr, defs, target_platform, extra_variables=None) : 462 def EvaluateExpression(cls, expr, defs, target_platform, extra_variables=None) :
463 '''Worker for EvaluateCondition (below) and conditions in XTB files.''' 463 '''Worker for EvaluateCondition (below) and conditions in XTB files.'''
464 cache_dict = cls.eval_expr_cache[ 464 cache_dict = cls.eval_expr_cache[
465 (tuple(defs.iteritems()), target_platform, extra_variables)] 465 (tuple(defs.iteritems()), target_platform, extra_variables)]
466 if expr in cache_dict: 466 if expr in cache_dict:
467 return cache_dict[expr] 467 return cache_dict[expr]
468 def pp_ifdef(symbol): 468 def pp_ifdef(symbol):
469 return symbol in defs 469 return symbol in defs
470 def pp_if(symbol): 470 def pp_if(symbol):
471 return defs.get(symbol, False) 471 return defs.get(symbol, False)
472 platform_assertion = Node.GetPlatformAssertion(target_platform)
473 variable_map = { 472 variable_map = {
474 'defs' : defs, 473 'defs' : defs,
475 'os': target_platform, 474 'os': target_platform,
476 'is_linux': platform_assertion == 'is_linux', 475
477 'is_macosx': platform_assertion == 'is_macosx', 476 # One of these is_xyz assertions gets set to True in the line
478 'is_win': platform_assertion == 'is_win', 477 # following this initializer block.
479 'is_android': platform_assertion == 'is_android', 478 'is_linux': False,
480 'is_ios': platform_assertion == 'is_ios', 479 'is_macosx': False,
481 # is_posix is not mutually exclusive of the others 480 'is_win': False,
481 'is_android': False,
482 'is_ios': False,
483
484 # is_posix is not mutually exclusive of the others and gets
485 # set here, not below.
482 'is_posix': (target_platform in ('darwin', 'linux2', 'linux3', 'sunos5') 486 'is_posix': (target_platform in ('darwin', 'linux2', 'linux3', 'sunos5')
483 or 'bsd' in sys.platform), 487 or 'bsd' in sys.platform),
488
484 'pp_ifdef' : pp_ifdef, 489 'pp_ifdef' : pp_ifdef,
485 'pp_if' : pp_if, 490 'pp_if' : pp_if,
486 } 491 }
492 variable_map[Node.GetPlatformAssertion(target_platform)] = True
493
487 if extra_variables: 494 if extra_variables:
488 variable_map.update(extra_variables) 495 variable_map.update(extra_variables)
489 eval_result = cache_dict[expr] = eval(expr, {}, variable_map) 496 eval_result = cache_dict[expr] = eval(expr, {}, variable_map)
490 return eval_result 497 return eval_result
491 498
492 def EvaluateCondition(self, expr): 499 def EvaluateCondition(self, expr):
493 '''Returns true if and only if the Python expression 'expr' evaluates 500 '''Returns true if and only if the Python expression 'expr' evaluates
494 to true. 501 to true.
495 502
496 The expression is given a few local variables: 503 The expression is given a few local variables:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 def ExpandVariables(self): 583 def ExpandVariables(self):
577 '''Whether we need to expand variables on a given node.''' 584 '''Whether we need to expand variables on a given node.'''
578 return False 585 return False
579 586
580 587
581 class ContentNode(Node): 588 class ContentNode(Node):
582 '''Convenience baseclass for nodes that can have content.''' 589 '''Convenience baseclass for nodes that can have content.'''
583 def _ContentType(self): 590 def _ContentType(self):
584 return self._CONTENT_TYPE_MIXED 591 return self._CONTENT_TYPE_MIXED
585 592
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698