예제 #1
0
def typeDecl2Chapel(decl, varname=None, isArray=False, isPtr=False):
    if not isinstance(decl, c_ast.TypeDecl):
        decl.show()
        raise c_parser.ParseError("Unable to parse type declaration at %s" %
                                  decl.coord)
    tmp = decl.type
    if varname is None:
        varname = decl.declname
    if not isinstance(tmp, c_ast.IdentifierType):
        decl.show()
        raise c_parser.ParseError("Unable to parse type declaration at %s" %
                                  decl.coord)
    name = tmp.names[0]
    if name.startswith("MPI_"):
        chapeltype = name
    else:
        if name not in c2chapel.keys():
            raise c_parser.ParseError("Unknown type % at %s" %
                                      (name, decl.coord))
        chapeltype = c2chapel[name]
    if isArray:
        chapeltype = "[]" + chapeltype
    if chapeltype is not None:
        varname += ": " + chapeltype
    if isPtr:
        varname = "ref " + varname
    return varname
예제 #2
0
def typeDecl2Chapel(decl, varname=None, isArray=False, isPtr=False):
    if not isinstance(decl, c_ast.TypeDecl):
        decl.show()
        raise c_parser.ParseError("Unable to parse type declaration at %s" %
                                  decl.coord)
    tmp = decl.type
    if varname is None:
        varname = decl.declname
        ##if len(decl.quals) > 0 :
        ##    quals1 = ' '.join([quals[q1] for q1 in decl.quals])
        ##    varname = quals1+' '+varname

    # Cases
    if isinstance(tmp, c_ast.IdentifierType):
        name = tmp.names[0]
        if name not in c2chapel.keys():
            raise c_parser.ParseError("Unknown type % at %s" %
                                      (name, decl.coord))
        chapeltype = c2chapel[name]
    elif isinstance(tmp, c_ast.Enum):
        chapeltype = None
    else:
        decl.show()
        print type(tmp)
        raise c_parser.ParseError("Unable to parse type declaration at %s" %
                                  decl.coord)
    if isArray:
        chapeltype = "[]" + chapeltype
    if chapeltype is not None:
        varname += ": " + chapeltype
    if isPtr:
        varname = "ref " + varname
    return varname
예제 #3
0
def toChapelType(ty):
    if isPointerTo(ty, "char"):
        return "c_string"
    elif isPointerTo(ty, "void"):
        return "c_void_ptr"
    elif type(ty) == c_ast.ArrayDecl:
        return "c_ptr(" + toChapelType(ty.type) + ")"
    elif type(ty) == c_ast.PtrDecl:
        if type(ty.type) == c_ast.FuncDecl:
            return "c_fn_ptr"
        else:
            return "c_ptr(" + toChapelType(ty.type) + ")"
    elif type(ty) == c_ast.TypeDecl:
        inner = ty.type
        name = ""
        try:
            name = getDeclName(ty)
        except Exception as e:
            raise Exception("toChapelType: " + str(e))

        if name in c2chapel:
            return c2chapel[name]

        return name
    elif type(ty) == c_ast.FuncDecl:
        return "c_fn_ptr"
    else:
        ty.show()
        raise c_parser.ParseError("Unable to translate to Chapel type")
예제 #4
0
def getFunctionName(ty):
    if type(ty) == c_ast.PtrDecl:
        return getFunctionName(ty.type)
    elif type(ty) == c_ast.FuncDecl:
        return getFunctionName(ty.type)
    else:
        if type(ty) != c_ast.TypeDecl:
            ty.show()
            raise c_parser.ParseError("Expecting TypeDecl...")
        return ty.declname
예제 #5
0
def computeArgName(decl):
    if type(decl) == c_ast.Typename:
        return ""
    elif type(decl) == c_ast.Decl:
        if decl.name in chapelKeywords:
            return decl.name + "_arg"
        else:
            return decl.name
    else:
        decl.show()
        raise c_parser.ParseError("Unhandled Node type")