Ejemplo n.º 1
0
def domainInterface2dict(semObj):
    out = a3t.gen2dict(semObj)

    da = a3t.inTwo(semObj, "domainAdapter2domainInterface")
    if da == None:
        reportError("Domain interface must take a domain adapter on input.", semObj)
        ## Have to short-circuit to prevent weird errors from happening.
        return out
    else:
        attributes = a3t.getAttributes(da)
        out["parameters"] = attributes

    iCall = a3t.outOne(semObj, "domainInterface2Interface")
    i = a3t.outTwo(semObj, "domainInterface2Interface")
    if i == None:
        reportError("Domain interface must call a local interface.", semObj)
    else:
        name = a3t.evalAtom3Type(i.name)
        calls = a3t.gen2dict(iCall)
        iParameters = a3t.evalAtom3Type(i.parameters)
        calls["name"] = name
        out["calls"] = calls

        ## Constraints on interface call.
        testCall(calls["arguments"], out["parameters"], iParameters, iCall)

    deleteEmptyKeys(out)

    testValidName(out.get("name"), semObj)

    return out
Ejemplo n.º 2
0
def domainOutput2dict(domainOutput):
    out = a3t.gen2dict(domainOutput)

    da = a3t.inTwo(domainOutput, "domainAdapter2domainOutput")
    if da == None:
        reportError("Domain output must take a domain adapter on input.", domainOutput)
    else:
        returns = a3t.gen2dict(da)
        testValidArgs(returns.values(), [], da)
        out["returns"] = returns

    deleteEmptyKeys(out)
    testValidName(out.get("name"), domainOutput)
    return out
Ejemplo n.º 3
0
Archivo: rosc.py Proyecto: OEP/rdis
def getMappings(adapterType):
  """
  Generates statements which perform the argument transformation.
  """
  pushBuf()
  mappings = a3t.gen2dict(adapterType)

  for (key, value) in mappings.items():
    write("env['{}'] = rdis.safeEval('{}', env)".format(key, value))

  return flush()
Ejemplo n.º 4
0
Archivo: rosc.py Proyecto: OEP/rdis
def getInitializations(adapterType, msgName="rdisMsg"):
  """
  For each attribute in adapterType, generate a statement which initializes
  that attribute in an environment. Return as a textblob.
  """
  pushBuf()
  mappings = a3t.gen2dict(adapterType)

  for (key,value) in mappings.items():
    write("env['{}'] = {}['{}']".format(key, msgName, key))
  return flush()
Ejemplo n.º 5
0
def primitive2dict(primitive):
    out = a3t.gen2dict(primitive)
    cnx = getPrimitiveConnection(primitive)
    deleteEmptyKeys(out)

    if cnx != None:
        out["connection"] = a3t.evalAtom3Type(cnx.name)

    testPrimitive(out, primitive)

    return out
Ejemplo n.º 6
0
def getPrimitiveCalls(interface, parameters):
    semCalls = a3t.filterOutboundEdges(interface, "interface2primitive")
    output = list()

    for semCall in semCalls:
        out = a3t.gen2dict(semCall)
        primitive = a3t.outOne(semCall)
        print semCall
        out["name"] = a3t.evalAtom3Type(primitive.name)

        testPrimitiveCall(out, semCall)
        output.append(out)

    return output
Ejemplo n.º 7
0
def addThreading(obj, connectionSem):
    threadingSem = a3t.outTwo(connectionSem, "connection2threading")

    if threadingSem == None:
        reportError("Connections must have a threading object.", connectionSem)
    else:
        threadObj = a3t.gen2dict(threadingSem)
        deleteEmptyKeys(threadObj)

        if isinstance(threadingSem, SingleThreading):
            testSingleThreading(threadObj, threadingSem)
            obj["singleThreading"] = threadObj
        else:
            reportError("Unbound threading type: {}".format(repr(threadingSem.__class__)), threading)
Ejemplo n.º 8
0
def connection2dict(semObj):
    out = a3t.gen2dict(semObj)

    k = a3t.outOne(semObj, "connectionKeepalive")
    s = a3t.outOne(semObj, "connectionStartup")
    t = a3t.outOne(semObj, "connectionTerminate")

    for thing in (("keepalive", k), ("startup", s), ("terminate", t)):
        if thing[1] != None:
            out[thing[0]] = a3t.gen2dict(thing[1])
            out[thing[0]]["name"] = a3t.evalAtom3Type(a3t.outOne(thing[1]).name)

            ## Get arguments for remote interface.
            myLocals = []
            myArgs = out[thing[0]]["arguments"]
            theirParams = a3t.evalAtom3Type(a3t.outOne(thing[1]).parameters)

            testCall(myArgs, myLocals, theirParams, thing[1])

            if thing[0] == "keepalive":
                testKeepalive(out["keepalive"], k)
                if out["keepalive"]["interval"] <= 0:
                    reportError("Keepalive interval should be >0.", k)

    addThreading(out, semObj)

    deleteEmptyKeys(out)

    if isinstance(semObj, SerialConnection):
        testSerial(out, semObj)
    else:
        reportError("Unbound connection type: {}".format(repr(semObj.__class__)), semObj)

    testValidName(out.get("name"), semObj)

    return out
Ejemplo n.º 9
0
def interface2dict(interface):
    """
  Converts interface semantic object into a Python dict.
  """
    out = a3t.gen2dict(interface)
    out["primitiveCalls"] = getPrimitiveCalls(interface, out["parameters"])

    do = a3t.outTwo(interface, "interface2domainOutput")

    if do != None:
        outputName = a3t.evalAtom3Type(do.name)
        out["triggers"] = outputName

    deleteEmptyKeys(out)

    testValidName(out.get("name"), interface)

    return out
Ejemplo n.º 10
0
def getReturns(interface):
    domainAdapter = a3t.outTwo(interface, "interface2domainAdapter")
    if domainAdapter == None:
        return None
    returns = a3t.gen2dict(domainAdapter)
    return returns
Ejemplo n.º 11
0
def stateVar2dict(semObj):
    out = a3t.gen2dict(semObj)
    testType(out["value"], out["type"], semObj)
    return out