Exemple #1
0
    def __getattr__(self, aname):
        em = object.__getattribute__(self, "em")

        # This pops 'this expr' off the stack, so we can
        # replace it with an extended expression
        pop_expr()

        ret = None
        if isinstance(em, ExprArraySubscriptModel):
            # TODO: Need to get the core type
            fm = None
            if isinstance(em.lhs, ExprIndexedFieldRefModel):
                fm = em.lhs.get_target()
            elif isinstance(em.lhs, ExprFieldRefModel):
                fm = em.lhs.fm
            else:
                raise Exception("Unsupported path-chaining expression " +
                                str(em.lhs))

            if aname in fm.type_t.field_id_m.keys():
                idx = fm.type_t.field_id_m[aname]
                ret = expr(ExprIndexedFieldRefModel(em, [idx]))
            elif aname in fm.type_t.constraint_dynamic_m.keys():
                idx = fm.type_t.constraint_dynamic_m[aname]
                ret = dynamic_constraint_proxy(ExprIndexedDynRefModel(em, idx))
            else:
                raise Exception("Type %s does not contain a field \"%s\"" %
                                (fm.type_t.name, aname))
        else:
            raise Exception("Expression getattribute access on non-subscript")

        return ret
Exemple #2
0
    def get_indexed_fieldref_expr(self):
        if self.parent is None:
            raise Exception("Field has no parent")
        else:
            idx_l = []
            p = self.parent
            s = self
            while p is not None:
                idx_l.insert(0, s.idx)
                s = p
                p = p.parent

            return ExprIndexedFieldRefModel(s, idx_l)
Exemple #3
0
    def to_expr(self):
        if self._int_field_info.id != -1:
            # Need something like an indirect reference
            # - root reference
            # - leaf reference
            id_l = []
            fi = self._int_field_info
            
            while fi.parent is not None:
                id_l.insert(0, fi.id)
                fi = fi.parent

            return expr(ExprIndexedFieldRefModel(fi.root_e, id_l))
        else:
            return expr(ExprFieldRefModel(self._int_field_info.model))
Exemple #4
0
    def to_expr(self):
        if self._int_field_info.id != -1:
            # A non-negative id means that this field
            # should be referenced indirectly. Follow the
            # parent/child relationships up to construct an
            # index list back to this field
            id_l = []
            fi = self._int_field_info

            while fi.parent is not None:
                id_l.insert(0, fi.id)
                fi = fi.parent

            return expr(ExprIndexedFieldRefModel(fi.root_e, id_l))
        else:
            return expr(ExprFieldRefModel(self._int_field_info.model))
Exemple #5
0
    def visit_expr_indexed_fieldref(self, e: ExprIndexedFieldRefModel):
        if ForeachRefExpander.EN_DEBUG > 0:
            print("--> ForeachRefExpander::visit_indexed_fieldref")

        # See if the base involves an index
        e.root.accept(self)

        if self._field is not None:
            # Resolve relative to the target
            self._field = e.get_target(self._field)

        # Propagate the _field up, but not the _expr
        self._expr = None

        if ForeachRefExpander.EN_DEBUG > 0:
            print("<-- ForeachRefExpander::visit_indexed_fieldref %s" %
                  str(self._field))
Exemple #6
0
    def __getattr__(self, aname):
        em = object.__getattribute__(self, "em")
        pop_expr()

        ret = None
        if isinstance(em, ExprArraySubscriptModel):
            # TODO: Need to get the core type
            lhs = em.lhs.fm

            if aname in lhs.type_t.field_id_m.keys():
                idx = lhs.type_t.field_id_m[aname]
                ret = expr(ExprIndexedFieldRefModel(em, [idx]))
            else:
                raise Exception("Type " + lhs.type_f.name +
                                " does not contain " + aname)
        else:
            raise Exception("Expression getattribute access on non-subscript")

        return ret
Exemple #7
0
 def visit_expr_indexed_fieldref(self, e: ExprIndexedFieldRefModel):
     self.fm = e.get_target()