Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _refine_type(self, accessor, rostype, **kwargs):
stack = [accessor]
expr = accessor.message
while expr.is_accessor:
stack.append(expr)
expr = expr.message
assert expr.is_value and (expr.is_this_msg or expr.is_variable)
if expr.is_this_msg:
t = rostype
else:
if expr.name not in kwargs:
raise HplSanityError(
"undefined message alias: '{}'".format(expr.name))
t = kwargs[expr.name]
assert t.is_message
expr.ros_type = t
while stack:
expr = stack.pop()
if expr.is_field:
if not t.is_message or expr.field not in t.fields:
raise HplTypeError.ros_field(t, expr.field, expr)
t = t.fields[expr.field]
else:
assert expr.is_indexed
if not t.is_array:
raise HplTypeError.ros_array(t, expr)
i = expr.index
if (i.is_value and i.is_literal
def _check_expression_vars(self, t):
uid = id(self)
used = 0
for obj in self.condition.iterate():
assert obj.is_expression
if obj.is_value and obj.is_variable:
v = obj.name
if self.variable == v:
if obj.is_defined:
assert obj.defined_at != uid
raise HplSanityError(self._MULTI_DEF.format(v, self))
obj.defined_at = uid
self._type_check(obj, t)
used += 1
if not used:
raise HplSanityError(self._UNUSED.format(self.variable, self))
def _check_refs_defined(self, refs, available):
for ref in refs:
if not ref in available:
raise HplSanityError(
"reference to undefined event: " + repr(ref))
def _check_duplicates(self, aliases, available):
for alias in aliases:
if alias in available:
raise HplSanityError("duplicate alias: " + repr(alias))
def _some_field_refs(self, table):
# There is, at least, one reference to a field (own).
# [NYI] Stricter: one reference per atomic condition.
for refs in table.itervalues():
for ref in refs:
if not ref.is_accessor:
break
if ref.is_indexed:
break
if not ref.message.is_value:
break
assert ref.message.is_reference
if not ref.message.is_this_msg:
break
return # OK
raise HplSanityError(self._NO_REFS)
def _check_domain_vars(self):
dom = self.domain
for obj in dom.iterate():
assert obj.is_expression
if obj.is_value and obj.is_variable:
assert not obj.is_defined
v = obj.name
if self.variable == v:
raise HplSanityError(self._SET_REF.format(v, self))
if dom.is_value:
if dom.is_set or dom.is_range:
return dom.subtypes
return T_PRIM