blob: b4d7df9737b7e44a826d9cfce0bb7ec3c8329f81 [file] [log] [blame]
# Copyright 2013, Big Switch Networks, Inc.
#
# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
# the following special exception:
#
# LOXI Exception
#
# As a special exception to the terms of the EPL, you may distribute libraries
# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
# that copyright and licensing notices generated by LoxiGen are not altered or removed
# from the LoxiGen Libraries and the notice provided below is (i) included in
# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
# documentation for the LoxiGen Libraries, if distributed in binary form.
#
# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
#
# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
# a copy of the EPL at:
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# EPL for the specific language governing permissions and limitations
# under the EPL.
from generic_utils import *
import c_gen.loxi_utils_legacy as loxi_utils
import loxi_globals
inheritance_roots = [
'of_instruction',
'of_instruction_id',
'of_action',
'of_action_id',
'of_oxm',
'of_queue_prop',
'of_hello_elem',
'of_table_feature_prop',
'of_meter_band',
'of_bsn_vport',
'of_bsn_tlv',
]
def class_is_virtual(cls):
"""
Returns True if cls is a virtual class
"""
if cls.endswith("header"):
return True
if loxi_utils.class_is_list(cls):
return True
return loxi_globals.unified.class_by_name(cls).virtual
def class_is_inheritance_root(cls):
return cls in inheritance_roots
# map from parent class name to set of subclass names
inheritance_map = dict()
def generate_maps():
def inheritance_root(ofclass):
if not ofclass.superclass:
if ofclass.name in inheritance_roots:
return ofclass
else:
return None
else:
return inheritance_root(ofclass.superclass)
for version, protocol in loxi_globals.ir.items():
wire_version = version.wire_version
for ofclass in protocol.classes:
root = inheritance_root(ofclass)
if not root or root == ofclass:
continue
if root.name not in inheritance_map:
inheritance_map[root.name] = set()
inheritance_map[root.name].add(ofclass.name)
def sub_class_map(base_type, version):
"""
Returns an iterable object giving the instance nameys and subclass types
for the base_type, version values
"""
rv = []
if base_type not in inheritance_map:
return rv
for subcls in inheritance_map[base_type]:
if not loxi_utils.class_in_version(subcls, version):
continue
instance = loxi_utils.class_to_instance(subcls, base_type)
rv.append((instance, subcls))
return rv