Fix #10043 unexpected designator (#2966)

This commit is contained in:
kskjerve 2020-12-21 13:25:41 +01:00 committed by GitHub
parent 86f1ee5267
commit c22290f5a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 15 deletions

View File

@ -335,7 +335,7 @@ class InitializerParser:
if new != self.root: if new != self.root:
# Mark all elements up to self.root root as designated # Mark all elements up to self.root root as designated
parent = new parent = new
while parent != self.root: while parent and parent != self.root:
parent.isDesignated = True parent.isDesignated = True
parent = parent.parent parent = parent.parent
self.rootStack.append((self.root, new)) self.rootStack.append((self.root, new))
@ -361,14 +361,15 @@ class InitializerParser:
else: else:
self.token = self.token.astParent self.token = self.token.astParent
if self.token.str == '{': if self.token.str == '{':
self.ed = self.root.getLastValueElement() if self.root:
self.ed.markAsCurrent() self.ed = self.root.getLastValueElement()
self.ed.markAsCurrent()
# Cleanup if root is dummy node representing excess levels in initializer # Cleanup if root is dummy node representing excess levels in initializer
if self.root and self.root.name == '<-': if self.root.name == '<-':
self.root.children[0].parent = self.root.parent self.root.children[0].parent = self.root.parent
self.root = self.root.parent self.root = self.root.parent
if self.token.astParent == None: if self.token.astParent == None:
self.token = None self.token = None
@ -459,6 +460,9 @@ def createRecordChildrenDefs(ed):
ed.addChild(child) ed.addChild(child)
def getElementByDesignator(ed, token): def getElementByDesignator(ed, token):
if not token.str in [ '.', '[' ]:
return None
while token.str in [ '.', '[' ]: while token.str in [ '.', '[' ]:
token = token.astOperand1 token = token.astOperand1
@ -466,27 +470,27 @@ def getElementByDesignator(ed, token):
token = token.astParent token = token.astParent
if token.str == '[': if token.str == '[':
if not ed.isArray:
ed.markStuctureViolation(token)
chIndex = -1 chIndex = -1
if token.astOperand2 is not None: if token.astOperand2 is not None:
chIndex = token.astOperand2.getKnownIntValue() chIndex = token.astOperand2.getKnownIntValue()
elif token.astOperand1 is not None: elif token.astOperand1 is not None:
chIndex = token.astOperand1.getKnownIntValue() chIndex = token.astOperand1.getKnownIntValue()
if not ed.isArray: ed = ed.getChildByIndex(chIndex) if chIndex is not None else None
ed.markStuctureViolation(token)
ed = ed.getChildByIndex(chIndex)
elif token.str == '.': elif token.str == '.':
if not ed.isRecord:
ed.markStuctureViolation(token)
name = "" name = ""
if token.astOperand2 is not None: if token.astOperand2 is not None:
name = token.astOperand2.str name = token.astOperand2.str
elif token.astOperand1 is not None: elif token.astOperand1 is not None:
name = token.astOperand1.str name = token.astOperand1.str
if not ed.isRecord:
ed.markStuctureViolation(token)
ed = ed.getChildByName(name) ed = ed.getChildByName(name)
return ed return ed