# Path: kll/common/id.py
# class CapId(Id):
#     '''
#     Capability identifier
#     '''
# 
#     def __init__(self, name, type, arg_list=[]):
#         '''
#         @param name:     Name of capability
#         @param type:     Type of capability definition, string
#         @param arg_list: List of CapArgIds, empty list if there are none
#         '''
#         Id.__init__(self)
#         self.name = name
#         self.type = type
#         self.arg_list = arg_list
# 
#     def __repr__(self):
#         # Generate prettified argument list
#         arg_string = ""
#         for arg in self.arg_list:
#             arg_string += "{0},".format(arg)
#         if len(arg_string) > 0:
#             arg_string = arg_string[:-1]
# 
#         return "{0}({1})".format(self.name, arg_string)
# 
#     def json(self):
#         '''
#         JSON representation of CapId
#         '''
#         return {
#             'type' : self.type,
#             'name' : self.name,
#             'args' : [arg.json() for arg in self.arg_list]
#         }
# 
#     def total_arg_bytes(self, capabilities_dict=None):
#         '''
#         Calculate the total number of bytes needed for the args
# 
#         @param capabilities_dict: Dictionary of capabilities used, just in case no widths have been assigned
# 
#         return: Number of bytes
#         '''
#         # Zero if no args
#         total_bytes = 0
#         for index, arg in enumerate(self.arg_list):
#             # Lookup actual width if necessary (wasn't set explicitly)
#             if capabilities_dict is not None and (arg.type == 'CapArgValue' or arg.width is None):
#                 # Check if there are enough arguments
#                 expected = len(capabilities_dict[self.name].association.arg_list)
#                 got = len(self.arg_list)
#                 if got != expected:
#                     print("{0} incorrect number of arguments for {1}. Expected {2} Got {3}".format(
#                         ERROR,
#                         self,
#                         expected,
#                         got,
#                     ))
#                     print("\t{0}".format(capabilities_dict[self.name].kllify()))
#                     raise AssertionError("Invalid arguments")
# 
#                 total_bytes += capabilities_dict[self.name].association.arg_list[index].width
# 
#             # Otherwise use the set width
#             else:
#                 total_bytes += arg.width
# 
#         return total_bytes


import copy
from kll.common.id import CapId
        return self.__repr__()

    def unique_keys(self):
        '''
        Generates a list of unique identifiers for the expression that is mergeable
        with other functional equivalent expressions.
        '''
        return [(self.name, self)]


class NameAssociationExpression(Expression):
    '''
    Container class for name association KLL expressions
    '''
    type = None
    name = None
    association = None

    ## Setters ##
    def capability(self, name, association, parameters):
        '''
        Assign a capability C function name association

        @param name: Name of capability
        @param association: Name of capability in target backend output

        @return: True if parsing was successful
        '''
        self.type = 'Capability'
        self.name = name

# Path: kll/common/id.py
# class CapId(Id):
#     '''
#     Capability identifier
#     '''
# 
#     def __init__(self, name, type, arg_list=[]):
#         '''
#         @param name:     Name of capability
#         @param type:     Type of capability definition, string
#         @param arg_list: List of CapArgIds, empty list if there are none
#         '''
#         Id.__init__(self)
#         self.name = name
#         self.type = type
#         self.arg_list = arg_list
# 
#     def __repr__(self):
#         # Generate prettified argument list
#         arg_string = ""
#         for arg in self.arg_list:
#             arg_string += "{0},".format(arg)
#         if len(arg_string) > 0:
#             arg_string = arg_string[:-1]
# 
#         return "{0}({1})".format(self.name, arg_string)
# 
#     def json(self):
#         '''
#         JSON representation of CapId
#         '''
#         return {
#             'type' : self.type,
#             'name' : self.name,
#             'args' : [arg.json() for arg in self.arg_list]
#         }
# 
#     def total_arg_bytes(self, capabilities_dict=None):
#         '''
#         Calculate the total number of bytes needed for the args
# 
#         @param capabilities_dict: Dictionary of capabilities used, just in case no widths have been assigned
# 
#         return: Number of bytes
#         '''
#         # Zero if no args
#         total_bytes = 0
#         for index, arg in enumerate(self.arg_list):
#             # Lookup actual width if necessary (wasn't set explicitly)
#             if capabilities_dict is not None and (arg.type == 'CapArgValue' or arg.width is None):
#                 # Check if there are enough arguments
#                 expected = len(capabilities_dict[self.name].association.arg_list)
#                 got = len(self.arg_list)
#                 if got != expected:
#                     print("{0} incorrect number of arguments for {1}. Expected {2} Got {3}".format(
#                         ERROR,
#                         self,
#                         expected,
#                         got,
#                     ))
#                     print("\t{0}".format(capabilities_dict[self.name].kllify()))
#                     raise AssertionError("Invalid arguments")
# 
#                 total_bytes += capabilities_dict[self.name].association.arg_list[index].width
# 
#             # Otherwise use the set width
#             else:
#                 total_bytes += arg.width
# 
#         return total_bytes


# Path: kll/common/expression.py
import copy
from kll.common.id import CapId

        return self.__repr__()

    def unique_keys(self):
        '''
        Generates a list of unique identifiers for the expression that is mergeable
        with other functional equivalent expressions.
        '''
        return [(self.name, self)]


class NameAssociationExpression(Expression):
    '''
    Container class for name association KLL expressions
    '''
    type = None
    name = None
    association = None

    ## Setters ##
    def capability(self, name, association, parameters):
        '''
        Assign a capability C function name association

        @param name: Name of capability
        @param association: Name of capability in target backend output

        @return: True if parsing was successful
        '''
        self.type = 'Capability'
        self.name = name

        self.association = CapId(association, 'Definition', parameters)