Beispiel #1
0
def typecheck(self, context):
    settings.requireExtended();

    (formatString,) = self.children
    formatString.typecheck(context)

    return ast.StringType
Beispiel #2
0
def typecheck(self, context):
    settings.requireExtended();

    args = self.children
    for arg in args:
        arg.typecheck(context)

    def types(s):
        ls = s.split("%")
        if len(ls) == 1:
            return
        for sub in ls[1:]:
            if len(sub) == 0:
                raise TypecheckException()
            c = sub[0]
            if c == 'd':
                yield (ast.IntType, )
            elif c == 'b':
                yield (ast.BoolType, )
            elif c == 's':
                yield (ast.StringType, ast.BaseObjectType)
            else:
                raise TypecheckException("Format string: unknown format type")
    argTypes = list(types(self.string))

    if len(argTypes) != len(args):
        raise TypecheckException()

    for arg, t in zip(args, argTypes):
        if (arg.nodeType not in t) and not (ast.BaseObjectType in t and isinstance(arg.nodeType, ast.BaseObjectType)):
            raise TypecheckException("Format string: format type does not match argument")

    self.string = self.string.replace('%b', '%s')

    return ast.FormatString
Beispiel #3
0
def typecheck(self, context):
    settings.requireExtended();

    a, b = self.children
    if a.typecheck(context) != ast.IntType or b.typecheck(context) != ast.IntType:
        raise TypecheckException("Arguments to Math.pow must be integers, are {0}, {1}".format(a, b))
    return a.nodeType
Beispiel #4
0
def typecheck(self, context):
    settings.requireExtended();

    (call,) = self.children

    call.typecheck(context)

    return ast.MethodCall
Beispiel #5
0
def typecheck(self, context):
    settings.requireExtended();

    (expr,) = self.children
    
    if not isCompatible(context.program, expr.typecheck(context), context.method.retType.typename):
        raise TypecheckException("Invalid yield type")

    return ast.Yield
Beispiel #6
0
def typecheck(self, context):
    settings.requireExtended();
    
    cond, ifstmt = self.children
    
    if cond.typecheck(context) != ast.BoolType:
        raise TypecheckException("Error with If: condition must be boolean")

    if ifstmt.typecheck(context) == ast.Decl:
        raise TypecheckException("Error with If: cannot have single declaration in if")

    return ast.If
Beispiel #7
0
def typecheck(self, context):
    settings.requireExtended();
    if not context.method.inloop:
        raise TypecheckException("Break outside of loop")