Beispiel #1
0
def check(files):
    try:
        trees = build_envs(files)
        #All statements must be reachable. Details of the exact definition of
        #reachability are specified in Section 14.20 of the Java Language
        #Specification.
        for tree in trees:
            for block in (tree.findall(".//method/block") +
                          tree.findall(".//constructor_body")):
                check_reachability(block)
            for method in tree.findall(".//method"):
                if method.find(".//tok_void") is None:
                    returns = always_returns(method.find("block"))
                    error_if(not returns,
                          "Doesn't always return from nonvoid method")

        #Every local variable must have an initializer, and the variable must
        #not occur in its own initializer.
        for tree in trees:
            for lvar in tree.findall(".//local_variable_declaration"):
                name = lvar.find(".//variable/tok_identifier").text
                error_if(lvar.find(".//expression") is None,
                      "Every local variable must have an initializer")
                for ident in lvar.findall(".//expression//name"):
                    error_if(name == name_to_str(ident),
                          "Self cannot appear in local variable initializer.")
        return 0
    except JoosSyntaxException, e:
        if not Testing.testing:
            print e.msg
        return 42
Beispiel #2
0
def check_files(files):
    trees = build_envs(files)
    for tree in [x for x in trees if not hasattr(x, "typechecked")]:
        CurrentFile.name = tree.filename
        populate_environment(tree)
    for tree in [x for x in trees if not hasattr(x, "typechecked")]:
        CurrentFile.name = tree.filename
        typecheck(tree)
        typecheck_other_conditions(tree)
        check_field_initializers(tree)
        tree.typechecked = True
    return trees