CMake: pro2cmake: Fix handling of chained scopes with else branches
Fix handling of things like: foo:bar:buz: { do something } else: wat { do something else } The else relates to foo AND bar AND buz, not just to buz in this case. Change-Id: I40d1fa295b4d6dd95ae5e1ce2d58372edc807b86 Reviewed-by: Albert Astals Cid <albert.astals.cid@kdab.com> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
73f5036be5
commit
64e3c8bb19
@ -288,6 +288,31 @@ class Scope(object):
|
||||
def currentdir(self) -> str:
|
||||
return self._currentdir
|
||||
|
||||
def can_merge_condition(self):
|
||||
if self._condition == 'else':
|
||||
return False
|
||||
if self._operations:
|
||||
return False
|
||||
|
||||
child_count = len(self._children)
|
||||
if child_count == 0 or child_count > 2:
|
||||
return False
|
||||
assert child_count != 1 or self._children[0]._condition != 'else'
|
||||
return child_count == 1 or self._children[1]._condition == 'else'
|
||||
|
||||
def settle_condition(self):
|
||||
new_children: typing.List[scope] = []
|
||||
for c in self._children:
|
||||
c.settle_condition()
|
||||
|
||||
if c.can_merge_condition():
|
||||
child = c._children[0]
|
||||
child._condition = '({}) AND ({})'.format(c._condition, child._condition)
|
||||
new_children += c._children
|
||||
else:
|
||||
new_children.append(c)
|
||||
self._children = new_children
|
||||
|
||||
@staticmethod
|
||||
def FromDict(parent_scope: typing.Optional['Scope'],
|
||||
file: str, statements, cond: str = '', base_dir: str = '') -> Scope:
|
||||
@ -333,7 +358,7 @@ class Scope(object):
|
||||
else_statements = statement.get('else_statements')
|
||||
if else_statements:
|
||||
Scope.FromDict(scope, file, else_statements,
|
||||
'NOT ' + condition, scope.basedir)
|
||||
'else', scope.basedir)
|
||||
continue
|
||||
|
||||
loaded = statement.get('loaded')
|
||||
@ -355,6 +380,8 @@ class Scope(object):
|
||||
scope.currentdir)))
|
||||
continue
|
||||
|
||||
scope.settle_condition()
|
||||
|
||||
if scope.scope_debug:
|
||||
print('..... [SCOPE_DEBUG]: Created scope {}:'.format(scope))
|
||||
scope.dump(indent=1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user