aboutsummaryrefslogtreecommitdiff
path: root/scripts/pdl/ast.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pdl/ast.py')
-rw-r--r--scripts/pdl/ast.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/scripts/pdl/ast.py b/scripts/pdl/ast.py
index b07f6ad..5ade0fa 100644
--- a/scripts/pdl/ast.py
+++ b/scripts/pdl/ast.py
@@ -66,7 +66,10 @@ class Constraint(Node):
@dataclass
class Field(Node):
parent: Node = field(init=False)
-
+ cond: Optional[Constraint] = field(init=False, default=None)
+ # Backlink to the (optional) optional field referencing
+ # this field as condition.
+ cond_for: Optional['Field'] = field(init=False, default=None)
@node('checksum_field')
class ChecksumField(Field):
@@ -274,8 +277,14 @@ def convert_(obj: object) -> object:
loc = SourceRange(loc['file'], SourceLocation(**loc['start']), SourceLocation(**loc['end']))
constructor = constructors_.get(kind)
members = {'loc': loc, 'kind': kind}
+ cond = None
for name, value in obj.items():
- if name != 'kind' and name != 'loc':
+ if name == 'cond':
+ cond = convert_(value)
+ elif name != 'kind' and name != 'loc':
members[name] = convert_(value)
- return constructor(**members)
+ val = constructor(**members)
+ if cond:
+ val.cond = cond
+ return val
raise Exception('Unhandled json object type')