def _resolve_cls_refs(self, grammar_parser, model_parser):

        resolved_classes = {}

        def _resolve_cls(cls):

            if cls in resolved_classes:
                return resolved_classes[cls]

            metamodel = model_parser.metamodel

            to_resolve = cls
            if isinstance(cls, ClassCrossRef):
                if cls.cls_name not in metamodel:
                    line, col = grammar_parser.pos_to_linecol(cls.position)
                    raise TextXSemanticError(
                        'Unknown class/rule "{}" at {}.'
                        .format(cls.cls_name, (line, col)), line, col)
                cls = metamodel[cls.cls_name]
            resolved_classes[to_resolve] = cls

            if cls._tx_type == RULE_ABSTRACT:
                # Resolve inherited classes
                for idx, inh in enumerate(cls._tx_inh_by):
                    inh = _resolve_cls(inh)
                    cls._tx_inh_by[idx] = inh

            else:

                # If this is not abstract class than it must be common or match.
                # Resolve referred classes.
                # If there is no attributes collected than it ``
                for attr in cls._tx_attrs.values():
                    attr.cls = _resolve_cls(attr.cls)

                    # If target cls is of a base type or match rule
                    # then attr can not be a reference.
                    if attr.cls.__name__ in BASE_TYPE_NAMES \
                            or attr.cls._tx_type == RULE_MATCH:
                        attr.ref = False
                        attr.cont = True
                    else:
                        attr.ref = True

                    if grammar_parser.debug:
                        grammar_parser.dprint(
                            "Resolved attribute {}:{}[cls={}, cont={}, "
                            "ref={}, mult={}, pos={}]"
                            .format(cls.__name__, attr.name,
                                    attr.cls.__name__,
                                    attr.cont, attr.ref, attr.mult,
                                    attr.position))

            return cls


        if grammar_parser.debug:
            grammar_parser.dprint("RESOLVING METACLASS REFS")

        for cls in model_parser.metamodel:
            _resolve_cls(cls)
dataset/ETHPy150Open igordejanovic/textX/textx/textx.py/TextXModelSA._resolve_cls_refs/original