From b151ce473d5264ca69e8677a38053ca6c2daf9b2 Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 10:33:00 -0500 Subject: [PATCH 01/12] Python 2/3 port of jsketch, using modernize -x map -x filter --no-six --- java_sk/__init__.py | 1 + java_sk/decode/__init__.py | 9 +++-- java_sk/decode/collection.py | 1 + java_sk/decode/finder.py | 1 + java_sk/decode/replacer.py | 1 + java_sk/decode/semantic_checker.py | 1 + java_sk/encoder.py | 3 +- java_sk/glob2/compat.py | 1 + java_sk/glob2/fnmatch.py | 1 + java_sk/logger.py | 3 +- java_sk/main.py | 7 ++-- java_sk/psketch.py | 4 +- java_sk/rewrite/__init__.py | 9 +++-- java_sk/rewrite/desugar.py | 1 + java_sk/rewrite/generator.py | 1 + java_sk/rewrite/hole.py | 1 + java_sk/rewrite/semantic_checker.py | 1 + java_sk/sketch.py | 5 ++- java_sk/translator.py | 9 +++-- java_sk/util.py | 3 +- java_sk/visit.py | 3 +- jskparser/ast/body/annotationdeclaration.py | 1 + .../ast/body/annotationmemberdeclaration.py | 1 + jskparser/ast/body/axiomdeclaration.py | 1 + jskparser/ast/body/axiomparameter.py | 1 + jskparser/ast/body/bodydeclaration.py | 1 + .../ast/body/classorinterfacedeclaration.py | 6 ++- jskparser/ast/body/constructordeclaration.py | 1 + jskparser/ast/body/fielddeclaration.py | 1 + jskparser/ast/body/initializerdeclaration.py | 3 +- jskparser/ast/body/methoddeclaration.py | 1 + jskparser/ast/body/parameter.py | 1 + jskparser/ast/body/typedeclaration.py | 3 +- jskparser/ast/body/variabledeclarator.py | 1 + jskparser/ast/body/xform.py | 3 +- jskparser/ast/comments/comment.py | 1 + jskparser/ast/compilationunit.py | 3 +- jskparser/ast/dataflow/dataflow.py | 22 +++++----- jskparser/ast/expr/arrayaccessexpr.py | 1 + jskparser/ast/expr/arraycreationexpr.py | 4 +- jskparser/ast/expr/arrayinitializerexpr.py | 1 + jskparser/ast/expr/assignexpr.py | 1 + jskparser/ast/expr/binaryexpr.py | 1 + jskparser/ast/expr/castexpr.py | 1 + jskparser/ast/expr/conditionalexpr.py | 1 + jskparser/ast/expr/enclosedexpr.py | 1 + jskparser/ast/expr/expression.py | 1 + jskparser/ast/expr/fieldaccessexpr.py | 1 + jskparser/ast/expr/generatorexpr.py | 1 + jskparser/ast/expr/instanceofexpr.py | 1 + jskparser/ast/expr/methodcallexpr.py | 1 + jskparser/ast/expr/nameexpr.py | 1 + jskparser/ast/expr/objectcreationexpr.py | 1 + jskparser/ast/expr/qualifiednameexpr.py | 1 + .../ast/expr/singlememberannotationexpr.py | 1 + jskparser/ast/expr/unaryexpr.py | 1 + jskparser/ast/expr/variabledeclarationexpr.py | 1 + jskparser/ast/importdeclaration.py | 3 +- jskparser/ast/node.py | 1 + jskparser/ast/stmt/assertstmt.py | 1 + jskparser/ast/stmt/assumestmt.py | 1 + jskparser/ast/stmt/blockstmt.py | 1 + jskparser/ast/stmt/catchclause.py | 1 + .../stmt/explicitconstructorinvocationstmt.py | 1 + jskparser/ast/stmt/expressionstmt.py | 1 + jskparser/ast/stmt/foreachstmt.py | 1 + jskparser/ast/stmt/forstmt.py | 1 + jskparser/ast/stmt/ifstmt.py | 1 + jskparser/ast/stmt/minrepeatstmt.py | 1 + jskparser/ast/stmt/returnstmt.py | 1 + jskparser/ast/stmt/switchentrystmt.py | 1 + jskparser/ast/stmt/switchstmt.py | 1 + jskparser/ast/stmt/throwstmt.py | 1 + jskparser/ast/stmt/trystmt.py | 1 + jskparser/ast/stmt/whilestmt.py | 1 + jskparser/ast/type/referencetype.py | 4 +- jskparser/ast/type/type.py | 1 + jskparser/ast/typearguments.py | 1 + jskparser/ast/typeparameter.py | 3 +- jskparser/ast/utils/utils.py | 6 ++- jskparser/ast/visit/generic.py | 3 +- jskparser/ast/visit/sourcevisitor.py | 8 ++-- jskparser/ast/visit/symtabgen.py | 3 +- jskparser/ast/visit/visit.py | 3 +- jskparser/jskparser/glob2/compat.py | 1 + jskparser/jskparser/glob2/fnmatch.py | 1 + jskparser/jskparser/jskparser.py | 8 ++-- jskparser/jskparser/logger.py | 3 +- jskparser/jskparser/util.py | 1 + lib/const.py | 5 ++- lib/glob2/compat.py | 1 + lib/glob2/fnmatch.py | 1 + lib/rlock.py | 1 + lib/visit.py | 3 +- test/__init__.py | 1 + test/axioms/ArrayList/run.py | 34 ++++++++-------- test/axioms/HashMap/run.py | 34 ++++++++-------- test/axioms/Stack/run.py | 28 +++++++------ test/axioms/String/format.py | 8 ++-- test/axioms/String/run.py | 40 ++++++++++--------- test/axioms/run.py | 26 ++++++------ test/test_axiom_gen.py | 1 + test/test_axioms.py | 1 + test/test_benchmark_axioms.py | 2 + test/test_big_benchmark_axioms.py | 2 + test/test_erroneous.py | 1 + test/test_java.py | 4 +- test/test_java_precisely.py | 1 + test/test_lib.py | 1 + test/test_mini.py | 1 + test/test_new_ast.py | 1 + 111 files changed, 267 insertions(+), 135 deletions(-) diff --git a/java_sk/__init__.py b/java_sk/__init__.py index 5f8525d..2a3f885 100644 --- a/java_sk/__init__.py +++ b/java_sk/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import sys import os diff --git a/java_sk/decode/__init__.py b/java_sk/decode/__init__.py index 6bbe75e..52583de 100644 --- a/java_sk/decode/__init__.py +++ b/java_sk/decode/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import logging @@ -7,11 +8,11 @@ from .. import util from ..meta.program import Program -from finder import HFinder, EGFinder -from replacer import HReplacer, EGReplacer, MGReplacer +from .finder import HFinder, EGFinder +from .replacer import HReplacer, EGReplacer, MGReplacer -from collection import Collection -from semantic_checker import SemanticChecker +from .collection import Collection +from .semantic_checker import SemanticChecker # white-list checking diff --git a/java_sk/decode/collection.py b/java_sk/decode/collection.py index 7c17f64..b2d5ffd 100644 --- a/java_sk/decode/collection.py +++ b/java_sk/decode/collection.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from lib.typecheck import * import lib.visit as v import lib.const as C diff --git a/java_sk/decode/finder.py b/java_sk/decode/finder.py index aa41c3d..f976310 100644 --- a/java_sk/decode/finder.py +++ b/java_sk/decode/finder.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import lib.visit as v diff --git a/java_sk/decode/replacer.py b/java_sk/decode/replacer.py index a00de62..53e04b0 100644 --- a/java_sk/decode/replacer.py +++ b/java_sk/decode/replacer.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import operator as op import re import logging diff --git a/java_sk/decode/semantic_checker.py b/java_sk/decode/semantic_checker.py index d134160..074b8ba 100644 --- a/java_sk/decode/semantic_checker.py +++ b/java_sk/decode/semantic_checker.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import lib.const as C diff --git a/java_sk/encoder.py b/java_sk/encoder.py index 5b74826..0ac1070 100644 --- a/java_sk/encoder.py +++ b/java_sk/encoder.py @@ -1,12 +1,13 @@ from __future__ import print_function +from __future__ import absolute_import import cStringIO import math import os import copy as cp import logging -import util +from . import util from functools import partial diff --git a/java_sk/glob2/compat.py b/java_sk/glob2/compat.py index 00a4d6f..b8edda0 100644 --- a/java_sk/glob2/compat.py +++ b/java_sk/glob2/compat.py @@ -1,6 +1,7 @@ # Back-port functools.lru_cache to Python 2 (and <= 3.2) # {{{ http://code.activestate.com/recipes/578078/ (r6) +from __future__ import absolute_import from collections import namedtuple from functools import update_wrapper from threading import RLock diff --git a/java_sk/glob2/fnmatch.py b/java_sk/glob2/fnmatch.py index 47db550..b87878b 100644 --- a/java_sk/glob2/fnmatch.py +++ b/java_sk/glob2/fnmatch.py @@ -9,6 +9,7 @@ The function translate(PATTERN) returns a regular expression corresponding to PATTERN. (It does not compile it.) """ +from __future__ import absolute_import import os import posixpath import re diff --git a/java_sk/logger.py b/java_sk/logger.py index 862cab1..d8b893d 100644 --- a/java_sk/logger.py +++ b/java_sk/logger.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import re import sys @@ -6,7 +7,7 @@ from lib.enum import enum from lib.rlock import FLockFileHandler -import util +from . import util C.log_caller = enum(JAVASK="jsk", PSKETCH="psketch") diff --git a/java_sk/main.py b/java_sk/main.py index 70b0d55..8210529 100755 --- a/java_sk/main.py +++ b/java_sk/main.py @@ -1,12 +1,13 @@ #! /usr/bin/env python +from __future__ import absolute_import import os import sys import logging import logging.config -import sketch -import util -from encoder import Encoder +from . import sketch +from . import util +from .encoder import Encoder from jskparser.jskparser import parse diff --git a/java_sk/psketch.py b/java_sk/psketch.py index ab5e9ae..1c6e657 100755 --- a/java_sk/psketch.py +++ b/java_sk/psketch.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import absolute_import import multiprocessing import os import logging @@ -44,7 +45,8 @@ def p_run(cmd, argv): n_cpu = multiprocessing.cpu_count() pool = multiprocessing.Pool(max(1, int(n_cpu * 0.75))) - def found( (fname, r) ): + def found(cegis_result): + (fname, r) = cegis_result if r: # found, copy that output file shutil.copyfile(fname, output_path) pool.close() diff --git a/java_sk/rewrite/__init__.py b/java_sk/rewrite/__init__.py index b1b68aa..f6c6636 100644 --- a/java_sk/rewrite/__init__.py +++ b/java_sk/rewrite/__init__.py @@ -1,13 +1,14 @@ +from __future__ import absolute_import import logging from lib.typecheck import * from ..meta.program import Program -from desugar import Desugar -from generator import CGenerator, MGenerator -from hole import EHole -from semantic_checker import SemanticChecker +from .desugar import Desugar +from .generator import CGenerator, MGenerator +from .hole import EHole +from .semantic_checker import SemanticChecker @takes(Program) @returns(nothing) diff --git a/java_sk/rewrite/desugar.py b/java_sk/rewrite/desugar.py index 5f03753..9638e18 100644 --- a/java_sk/rewrite/desugar.py +++ b/java_sk/rewrite/desugar.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import lib.const as C diff --git a/java_sk/rewrite/generator.py b/java_sk/rewrite/generator.py index f75c111..ccdd996 100644 --- a/java_sk/rewrite/generator.py +++ b/java_sk/rewrite/generator.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import copy import logging diff --git a/java_sk/rewrite/hole.py b/java_sk/rewrite/hole.py index 7ced5f7..2c939cf 100644 --- a/java_sk/rewrite/hole.py +++ b/java_sk/rewrite/hole.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import lib.const as C diff --git a/java_sk/rewrite/semantic_checker.py b/java_sk/rewrite/semantic_checker.py index 753ea22..ef4ff0c 100644 --- a/java_sk/rewrite/semantic_checker.py +++ b/java_sk/rewrite/semantic_checker.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import logging import lib.const as C diff --git a/java_sk/sketch.py b/java_sk/sketch.py index 2d88245..13495f7 100755 --- a/java_sk/sketch.py +++ b/java_sk/sketch.py @@ -1,5 +1,7 @@ #! /usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function import multiprocessing import os import logging @@ -48,7 +50,8 @@ def p_run(sk_dir, output_path): n_cpu = multiprocessing.cpu_count() pool = multiprocessing.Pool(max(1, int(n_cpu * 0.75))) - def found( (fname, r) ): + def found(sketch_result): + (fname, r) = sketch_result if r: # found, copy that output file shutil.copyfile(fname, output_path) pool.close() diff --git a/java_sk/translator.py b/java_sk/translator.py index 32961ea..285ef33 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -1,6 +1,8 @@ #!/usr/bin/env python +from __future__ import absolute_import from __future__ import print_function +from functools import reduce import sys import cStringIO import logging @@ -12,7 +14,7 @@ from . import convert from . import builtins -import visit as v +from . import visit as v from ast import Operators as op from ast import AssignOperators as assignop @@ -1057,7 +1059,7 @@ def visit(self, n, **kwargs): # break else: if len(typs) == len(c.param_typs()) and \ - all(map(lambda (a,b): (str(a) == str(b)), zip(typs, c.param_typs()))): + all([(str(a) == str(b)) for (a, b) in zip(typs, c.param_typs())]): nm = str(c) break self.printt(nm) @@ -1518,7 +1520,8 @@ def trans_fld(self, fld): ty = 'Array_{}'.format(ty) return (ty, nm, init) - def trans_params(self, (ty, nm)): + def trans_params(self, ty_nm): + (ty, nm) = ty_nm return ' '.join([self.trans_ty(ty), nm]) def trans_call(self, callexpr, **kwargs): diff --git a/java_sk/util.py b/java_sk/util.py index 82f6728..14c54cb 100644 --- a/java_sk/util.py +++ b/java_sk/util.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os from itertools import ifilter, ifilterfalse @@ -5,7 +6,7 @@ from ast.utils import utils from ast.body.classorinterfacedeclaration import ClassOrInterfaceDeclaration -import glob2 +from . import glob2 """ regarding paths and files diff --git a/java_sk/visit.py b/java_sk/visit.py index d2ca96f..890df4f 100644 --- a/java_sk/visit.py +++ b/java_sk/visit.py @@ -4,6 +4,7 @@ # visit.py # Updated 2013-06-20 to fix bug on line 41 +from __future__ import absolute_import import inspect __all__ = ['on', 'when'] @@ -18,7 +19,7 @@ def f(fn): def when(param_type): def f(fn): frame = inspect.currentframe().f_back - dispatcher = frame.f_locals[fn.func_name] + dispatcher = frame.f_locals[fn.__name__] if not isinstance(dispatcher, Dispatcher): dispatcher = dispatcher.dispatcher dispatcher.add_target(param_type, fn) diff --git a/jskparser/ast/body/annotationdeclaration.py b/jskparser/ast/body/annotationdeclaration.py index 0521a9e..c3bb1fa 100644 --- a/jskparser/ast/body/annotationdeclaration.py +++ b/jskparser/ast/body/annotationdeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .typedeclaration import TypeDeclaration diff --git a/jskparser/ast/body/annotationmemberdeclaration.py b/jskparser/ast/body/annotationmemberdeclaration.py index abb8f42..04980b7 100644 --- a/jskparser/ast/body/annotationmemberdeclaration.py +++ b/jskparser/ast/body/annotationmemberdeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .typedeclaration import TypeDeclaration diff --git a/jskparser/ast/body/axiomdeclaration.py b/jskparser/ast/body/axiomdeclaration.py index 61ca44d..8a3e208 100644 --- a/jskparser/ast/body/axiomdeclaration.py +++ b/jskparser/ast/body/axiomdeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..body.bodydeclaration import BodyDeclaration diff --git a/jskparser/ast/body/axiomparameter.py b/jskparser/ast/body/axiomparameter.py index 1f65de3..ee919a3 100644 --- a/jskparser/ast/body/axiomparameter.py +++ b/jskparser/ast/body/axiomparameter.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..node import Node diff --git a/jskparser/ast/body/bodydeclaration.py b/jskparser/ast/body/bodydeclaration.py index 1670090..fe5bde4 100644 --- a/jskparser/ast/body/bodydeclaration.py +++ b/jskparser/ast/body/bodydeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..node import Node diff --git a/jskparser/ast/body/classorinterfacedeclaration.py b/jskparser/ast/body/classorinterfacedeclaration.py index 692d7b5..f701928 100644 --- a/jskparser/ast/body/classorinterfacedeclaration.py +++ b/jskparser/ast/body/classorinterfacedeclaration.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function from . import _import from .typedeclaration import TypeDeclaration @@ -68,7 +70,7 @@ def get_sups(n): # logging.warning('class {} extends unknown type {}'.format(n.name, e.name)) else: sups.append(sc) else: - print 'ERROR: class {} not in symbol table of {}'.format(e.name, n.name) # library? + print('ERROR: class {} not in symbol table of {}'.format(e.name, n.name)) # library? return for i in n.implementsList: ic = n.symtab.get(i.name) @@ -78,7 +80,7 @@ def get_sups(n): # logging.warning('class {} implements type (no class def) {}'.format(str(self), i.name)) else: sups.append(ic) else: - print 'ERROR: class {} not in symbol table of {}'.format(e.name, n.name) # library? + print('ERROR: class {} not in symbol table of {}'.format(e.name, n.name)) # library? continue lst.extend(sups) map(get_sups, sups) diff --git a/jskparser/ast/body/constructordeclaration.py b/jskparser/ast/body/constructordeclaration.py index 0001b25..89a10a8 100644 --- a/jskparser/ast/body/constructordeclaration.py +++ b/jskparser/ast/body/constructordeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .bodydeclaration import BodyDeclaration from ..type.classorinterfacetype import ClassOrInterfaceType diff --git a/jskparser/ast/body/fielddeclaration.py b/jskparser/ast/body/fielddeclaration.py index 1b07572..155a040 100644 --- a/jskparser/ast/body/fielddeclaration.py +++ b/jskparser/ast/body/fielddeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .bodydeclaration import BodyDeclaration diff --git a/jskparser/ast/body/initializerdeclaration.py b/jskparser/ast/body/initializerdeclaration.py index d1cfe41..6018062 100644 --- a/jskparser/ast/body/initializerdeclaration.py +++ b/jskparser/ast/body/initializerdeclaration.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -from bodydeclaration import BodyDeclaration +from __future__ import absolute_import +from .bodydeclaration import BodyDeclaration IMPORTS = vars() diff --git a/jskparser/ast/body/methoddeclaration.py b/jskparser/ast/body/methoddeclaration.py index d240263..6edf2a0 100644 --- a/jskparser/ast/body/methoddeclaration.py +++ b/jskparser/ast/body/methoddeclaration.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .bodydeclaration import BodyDeclaration diff --git a/jskparser/ast/body/parameter.py b/jskparser/ast/body/parameter.py index 4f64462..93ac867 100644 --- a/jskparser/ast/body/parameter.py +++ b/jskparser/ast/body/parameter.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from ..node import Node from . import _import diff --git a/jskparser/ast/body/typedeclaration.py b/jskparser/ast/body/typedeclaration.py index 0fb26eb..e1c5813 100644 --- a/jskparser/ast/body/typedeclaration.py +++ b/jskparser/ast/body/typedeclaration.py @@ -1,9 +1,10 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .. import Modifiers -from bodydeclaration import BodyDeclaration +from .bodydeclaration import BodyDeclaration class TypeDeclaration(BodyDeclaration): def __init__(self, kwargs={}): diff --git a/jskparser/ast/body/variabledeclarator.py b/jskparser/ast/body/variabledeclarator.py index 9e88a1b..ce07451 100644 --- a/jskparser/ast/body/variabledeclarator.py +++ b/jskparser/ast/body/variabledeclarator.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..node import Node diff --git a/jskparser/ast/body/xform.py b/jskparser/ast/body/xform.py index 39bcc0d..7841aad 100644 --- a/jskparser/ast/body/xform.py +++ b/jskparser/ast/body/xform.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .. import Modifiers @@ -17,7 +18,7 @@ from ..utils import utils -from axiomparameter import AxiomParameter +from .axiomparameter import AxiomParameter # This is just going to be a child of MethodDeclaration and allow for special handling of # the switch statements diff --git a/jskparser/ast/comments/comment.py b/jskparser/ast/comments/comment.py index c961807..145bdd6 100644 --- a/jskparser/ast/comments/comment.py +++ b/jskparser/ast/comments/comment.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from ..node import Node from . import _import diff --git a/jskparser/ast/compilationunit.py b/jskparser/ast/compilationunit.py index e9cf509..1e5f980 100644 --- a/jskparser/ast/compilationunit.py +++ b/jskparser/ast/compilationunit.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -from node import Node +from __future__ import absolute_import +from .node import Node from . import _import class CompilationUnit(Node): diff --git a/jskparser/ast/dataflow/dataflow.py b/jskparser/ast/dataflow/dataflow.py index 8b521a6..fb2c043 100644 --- a/jskparser/ast/dataflow/dataflow.py +++ b/jskparser/ast/dataflow/dataflow.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function from ..utils import utils from ..body.methoddeclaration import MethodDeclaration @@ -61,14 +63,14 @@ def analyze(self, program, gsymtab, kwargs): return None, None if verbose: def f1(node): - print 'node:', type(node), 'name:', node.name, \ + print('node:', type(node), 'name:', node.name, \ '\n\tin:', node.in_set, \ '\n\tout:', node.out_set, \ '\n\tinputs:', node.inputs, \ - '\n\toutputs:', node.outputs - print + '\n\toutputs:', node.outputs) + print() self._walk(f1, self._program) - if inputs: print ins, outs + if inputs: print(ins, outs) return ins, outs def _doreach(self, program=None): @@ -138,9 +140,9 @@ def _compute_in_out(self, n): t = n.gen().union((self._minus(n.in_set, n.kill()))) if self._debug: - print 'n:', n, 'in:', n.in_set, 'gen:', n.gen(), 'kill:', n.kill(), \ + print('n:', n, 'in:', n.in_set, 'gen:', n.gen(), 'kill:', n.kill(), \ 'in-kill', self._minus(n.in_set, n.kill()), 't:', t, \ - 'out_set:', n.out_set + 'out_set:', n.out_set) if type(n.parentNode) == ForStmt: inits = set(utils.flatten([e.out_set for e in n.parentNode.init])) \ @@ -180,9 +182,9 @@ def _inputs(self, n, c_defs): reach_x = filter(lambda x: x[0] == ch.lbl[0], ch.in_set) ins = self._rm_dups(filter(lambda x: x in c_defs, reach_x)) if self._debug: - print 'ch:', ch, 'ch.in_set:', ch.in_set, \ + print('ch:', ch, 'ch.in_set:', ch.in_set, \ 'reach_x:', reach_x, \ - 'c_defs:', c_defs, 'ins:', ins + 'c_defs:', c_defs, 'ins:', ins) if ins: ch.inputs = list(ins) # all this crap is to remove duplicate var defs from in/out sets if ch.inputs: @@ -198,7 +200,7 @@ def _gen_inputs(self, method): ctx.childrenNodes = body[:self._estart] e = BlockStmt() e.childrenNodes = body[self._estart:self._estop + 1] - if self._debug: print '*******inputs*******' + if self._debug: print('*******inputs*******') # need to add this to the initial context if it is at the start of method params = map(lambda x: x.lbl, method.parameters) @@ -211,7 +213,7 @@ def _gen_inputs(self, method): # inputs to context, which are outputs from e ctx.childrenNodes = body[self._estop + 1:] if ctx.childrenNodes: - if self._debug: print '*******outputs******' + if self._debug: print('*******outputs******') c_defs = e.childrenNodes[-1].out_set.difference(e.childrenNodes[0].in_set) self._inputs(ctx, c_defs) diff --git a/jskparser/ast/expr/arrayaccessexpr.py b/jskparser/ast/expr/arrayaccessexpr.py index 5752529..c182e8e 100644 --- a/jskparser/ast/expr/arrayaccessexpr.py +++ b/jskparser/ast/expr/arrayaccessexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/arraycreationexpr.py b/jskparser/ast/expr/arraycreationexpr.py index e3cfa7b..330efe3 100644 --- a/jskparser/ast/expr/arraycreationexpr.py +++ b/jskparser/ast/expr/arraycreationexpr.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function from .expression import Expression from . import _import @@ -30,7 +32,7 @@ def __init__(self, kwargs={}): aa = kwargs.get(u'arraysAnnotations', {}) ad = [None] if not aa else aa.get(u'@e') if ad[0]: - print 'ReferenceType annotations not implemented' + print('ReferenceType annotations not implemented') for a in aa: self._arraysAnnotations.append(locs[u'AnnotationExpr'](a) if a else None) diff --git a/jskparser/ast/expr/arrayinitializerexpr.py b/jskparser/ast/expr/arrayinitializerexpr.py index ea56449..f722b49 100644 --- a/jskparser/ast/expr/arrayinitializerexpr.py +++ b/jskparser/ast/expr/arrayinitializerexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/assignexpr.py b/jskparser/ast/expr/assignexpr.py index 34eb6c0..b06bbaf 100644 --- a/jskparser/ast/expr/assignexpr.py +++ b/jskparser/ast/expr/assignexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/binaryexpr.py b/jskparser/ast/expr/binaryexpr.py index dcd8bcf..e217aa0 100644 --- a/jskparser/ast/expr/binaryexpr.py +++ b/jskparser/ast/expr/binaryexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .expression import Expression diff --git a/jskparser/ast/expr/castexpr.py b/jskparser/ast/expr/castexpr.py index fc9be49..751f26c 100644 --- a/jskparser/ast/expr/castexpr.py +++ b/jskparser/ast/expr/castexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/conditionalexpr.py b/jskparser/ast/expr/conditionalexpr.py index 3e9df55..f4d4a08 100644 --- a/jskparser/ast/expr/conditionalexpr.py +++ b/jskparser/ast/expr/conditionalexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/enclosedexpr.py b/jskparser/ast/expr/enclosedexpr.py index e3bcab4..df7f823 100644 --- a/jskparser/ast/expr/enclosedexpr.py +++ b/jskparser/ast/expr/enclosedexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/expression.py b/jskparser/ast/expr/expression.py index 5bd0611..5e8a0cc 100644 --- a/jskparser/ast/expr/expression.py +++ b/jskparser/ast/expr/expression.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..node import Node diff --git a/jskparser/ast/expr/fieldaccessexpr.py b/jskparser/ast/expr/fieldaccessexpr.py index 50636e7..b086f36 100644 --- a/jskparser/ast/expr/fieldaccessexpr.py +++ b/jskparser/ast/expr/fieldaccessexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/generatorexpr.py b/jskparser/ast/expr/generatorexpr.py index 089cb30..a669850 100644 --- a/jskparser/ast/expr/generatorexpr.py +++ b/jskparser/ast/expr/generatorexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .expression import Expression diff --git a/jskparser/ast/expr/instanceofexpr.py b/jskparser/ast/expr/instanceofexpr.py index 6db680c..cfd428b 100644 --- a/jskparser/ast/expr/instanceofexpr.py +++ b/jskparser/ast/expr/instanceofexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/methodcallexpr.py b/jskparser/ast/expr/methodcallexpr.py index 22bf50f..c9cef06 100644 --- a/jskparser/ast/expr/methodcallexpr.py +++ b/jskparser/ast/expr/methodcallexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import import itertools from . import _import diff --git a/jskparser/ast/expr/nameexpr.py b/jskparser/ast/expr/nameexpr.py index e69ba97..54ad2f2 100644 --- a/jskparser/ast/expr/nameexpr.py +++ b/jskparser/ast/expr/nameexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .expression import Expression diff --git a/jskparser/ast/expr/objectcreationexpr.py b/jskparser/ast/expr/objectcreationexpr.py index b0f1d5c..d597068 100644 --- a/jskparser/ast/expr/objectcreationexpr.py +++ b/jskparser/ast/expr/objectcreationexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from ..type.classorinterfacetype import ClassOrInterfaceType from ..body.classorinterfacedeclaration import ClassOrInterfaceDeclaration diff --git a/jskparser/ast/expr/qualifiednameexpr.py b/jskparser/ast/expr/qualifiednameexpr.py index 3535827..1056f9e 100644 --- a/jskparser/ast/expr/qualifiednameexpr.py +++ b/jskparser/ast/expr/qualifiednameexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .nameexpr import NameExpr diff --git a/jskparser/ast/expr/singlememberannotationexpr.py b/jskparser/ast/expr/singlememberannotationexpr.py index 9ff8194..47b85c6 100644 --- a/jskparser/ast/expr/singlememberannotationexpr.py +++ b/jskparser/ast/expr/singlememberannotationexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .annotationexpr import AnnotationExpr diff --git a/jskparser/ast/expr/unaryexpr.py b/jskparser/ast/expr/unaryexpr.py index 0b29a91..5db9c60 100644 --- a/jskparser/ast/expr/unaryexpr.py +++ b/jskparser/ast/expr/unaryexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .expression import Expression from . import _import diff --git a/jskparser/ast/expr/variabledeclarationexpr.py b/jskparser/ast/expr/variabledeclarationexpr.py index 5434edb..748410b 100644 --- a/jskparser/ast/expr/variabledeclarationexpr.py +++ b/jskparser/ast/expr/variabledeclarationexpr.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from ..body.variabledeclarator import VariableDeclarator from .expression import Expression from . import _import diff --git a/jskparser/ast/importdeclaration.py b/jskparser/ast/importdeclaration.py index bd26c2a..5a8630b 100644 --- a/jskparser/ast/importdeclaration.py +++ b/jskparser/ast/importdeclaration.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -from node import Node +from __future__ import absolute_import +from .node import Node from . import _import diff --git a/jskparser/ast/node.py b/jskparser/ast/node.py index 29e9c59..fffa79f 100644 --- a/jskparser/ast/node.py +++ b/jskparser/ast/node.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import absolute_import import json from . import _import diff --git a/jskparser/ast/stmt/assertstmt.py b/jskparser/ast/stmt/assertstmt.py index 65056b3..c984518 100644 --- a/jskparser/ast/stmt/assertstmt.py +++ b/jskparser/ast/stmt/assertstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/assumestmt.py b/jskparser/ast/stmt/assumestmt.py index ba230b4..0cc01fb 100644 --- a/jskparser/ast/stmt/assumestmt.py +++ b/jskparser/ast/stmt/assumestmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/blockstmt.py b/jskparser/ast/stmt/blockstmt.py index e161113..7a83ee6 100644 --- a/jskparser/ast/stmt/blockstmt.py +++ b/jskparser/ast/stmt/blockstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .statement import Statement diff --git a/jskparser/ast/stmt/catchclause.py b/jskparser/ast/stmt/catchclause.py index 4d1ee66..fec9fcb 100644 --- a/jskparser/ast/stmt/catchclause.py +++ b/jskparser/ast/stmt/catchclause.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/explicitconstructorinvocationstmt.py b/jskparser/ast/stmt/explicitconstructorinvocationstmt.py index 7be37e0..353b1b4 100644 --- a/jskparser/ast/stmt/explicitconstructorinvocationstmt.py +++ b/jskparser/ast/stmt/explicitconstructorinvocationstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from .statement import Statement diff --git a/jskparser/ast/stmt/expressionstmt.py b/jskparser/ast/stmt/expressionstmt.py index 7c9a4da..c241e82 100644 --- a/jskparser/ast/stmt/expressionstmt.py +++ b/jskparser/ast/stmt/expressionstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/foreachstmt.py b/jskparser/ast/stmt/foreachstmt.py index 204e1aa..afd9f0b 100644 --- a/jskparser/ast/stmt/foreachstmt.py +++ b/jskparser/ast/stmt/foreachstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/forstmt.py b/jskparser/ast/stmt/forstmt.py index 9cba31a..27217cc 100644 --- a/jskparser/ast/stmt/forstmt.py +++ b/jskparser/ast/stmt/forstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/ifstmt.py b/jskparser/ast/stmt/ifstmt.py index a7cb29c..1b11228 100644 --- a/jskparser/ast/stmt/ifstmt.py +++ b/jskparser/ast/stmt/ifstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/minrepeatstmt.py b/jskparser/ast/stmt/minrepeatstmt.py index 584213c..6ee0bbb 100644 --- a/jskparser/ast/stmt/minrepeatstmt.py +++ b/jskparser/ast/stmt/minrepeatstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/returnstmt.py b/jskparser/ast/stmt/returnstmt.py index 0943ec5..5bcf131 100644 --- a/jskparser/ast/stmt/returnstmt.py +++ b/jskparser/ast/stmt/returnstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from ..expr.nameexpr import NameExpr from ..expr.literalexpr import LiteralExpr diff --git a/jskparser/ast/stmt/switchentrystmt.py b/jskparser/ast/stmt/switchentrystmt.py index 148ed40..b86734f 100644 --- a/jskparser/ast/stmt/switchentrystmt.py +++ b/jskparser/ast/stmt/switchentrystmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/switchstmt.py b/jskparser/ast/stmt/switchstmt.py index 75a9766..c05748d 100644 --- a/jskparser/ast/stmt/switchstmt.py +++ b/jskparser/ast/stmt/switchstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from .switchentrystmt import SwitchEntryStmt diff --git a/jskparser/ast/stmt/throwstmt.py b/jskparser/ast/stmt/throwstmt.py index de29455..89159e4 100644 --- a/jskparser/ast/stmt/throwstmt.py +++ b/jskparser/ast/stmt/throwstmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/trystmt.py b/jskparser/ast/stmt/trystmt.py index a8324e3..9eb3977 100644 --- a/jskparser/ast/stmt/trystmt.py +++ b/jskparser/ast/stmt/trystmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/stmt/whilestmt.py b/jskparser/ast/stmt/whilestmt.py index bdd64cd..72bc82e 100644 --- a/jskparser/ast/stmt/whilestmt.py +++ b/jskparser/ast/stmt/whilestmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from .statement import Statement from . import _import diff --git a/jskparser/ast/type/referencetype.py b/jskparser/ast/type/referencetype.py index 5713ac3..26d2158 100644 --- a/jskparser/ast/type/referencetype.py +++ b/jskparser/ast/type/referencetype.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function from .type import Type from . import _import @@ -30,7 +32,7 @@ def __init__(self, kwargs={}): if ad: if ad[0]: - print 'ReferenceType annotations not implemented' + print('ReferenceType annotations not implemented') for a in aa: self._arraysAnnotations.append(locs[u'AnnotationExpr'](a) if a else None) diff --git a/jskparser/ast/type/type.py b/jskparser/ast/type/type.py index 08e49f1..fb0e22b 100644 --- a/jskparser/ast/type/type.py +++ b/jskparser/ast/type/type.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import from ..node import Node diff --git a/jskparser/ast/typearguments.py b/jskparser/ast/typearguments.py index dd008bf..095d52c 100644 --- a/jskparser/ast/typearguments.py +++ b/jskparser/ast/typearguments.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import absolute_import from . import _import class TypeArguments(object): diff --git a/jskparser/ast/typeparameter.py b/jskparser/ast/typeparameter.py index 01c371b..389d70b 100644 --- a/jskparser/ast/typeparameter.py +++ b/jskparser/ast/typeparameter.py @@ -3,7 +3,8 @@ # The TypeParameter is constructed following the syntax:
# TypeParameter ::= ( "extends" }{@link ClassOrInterfaceType}{@code ( "&" }{@link ClassOrInterfaceType}{@code )* )? -from node import Node +from __future__ import absolute_import +from .node import Node from .type.classorinterfacetype import ClassOrInterfaceType diff --git a/jskparser/ast/utils/utils.py b/jskparser/ast/utils/utils.py index dd7e117..679a02a 100644 --- a/jskparser/ast/utils/utils.py +++ b/jskparser/ast/utils/utils.py @@ -1,6 +1,8 @@ # This is a bit silly having utils/utils.py but it's the only way I could # make this an importable package. +from __future__ import absolute_import +from __future__ import print_function import os import logging import subprocess @@ -229,7 +231,7 @@ def find_obj(obj): else: o = find_obj(n) if not o: - print 'node_to_obj() -- Cant find {}.{}:{}'.format(str(n.name), n.get_coid(),n.beginLine) + print('node_to_obj() -- Cant find {}.{}:{}'.format(str(n.name), n.get_coid(),n.beginLine)) # n might be a static reference to an imported class for k, v in n.symtab.get(u'_cu_').symtab.items(): nm = k.split('.')[-1] @@ -289,7 +291,7 @@ def find_fld(n, obj_struct): if isinstance(scope, Parameter): scope = scope.idd if not scope: - print 'Cant find {}.{}:{}'.format(n.scope.name, n.name, n.beginLine) + print('Cant find {}.{}:{}'.format(n.scope.name, n.name, n.beginLine)) return None # n's scope might be a class (if static field) diff --git a/jskparser/ast/visit/generic.py b/jskparser/ast/visit/generic.py index a109007..683f4d6 100644 --- a/jskparser/ast/visit/generic.py +++ b/jskparser/ast/visit/generic.py @@ -1,6 +1,7 @@ #!/usr/bin/env python -import visit as v +from __future__ import absolute_import +from . import visit as v from ..node import Node diff --git a/jskparser/ast/visit/sourcevisitor.py b/jskparser/ast/visit/sourcevisitor.py index e8f9c8a..9020b13 100644 --- a/jskparser/ast/visit/sourcevisitor.py +++ b/jskparser/ast/visit/sourcevisitor.py @@ -1,7 +1,9 @@ #!/usr/bin/env python +from __future__ import absolute_import +from __future__ import print_function import cStringIO -import visit as v +from . import visit as v from .. import Operators as op from .. import AssignOperators as assignop @@ -99,7 +101,7 @@ def visit(self, node): @v.when(Node) def visit(self, n): - print "Unimplemented node:", n + print("Unimplemented node:", n) @v.when(CompilationUnit) def visit(self, n): @@ -619,7 +621,7 @@ def visit(self, n): self.printLn(' {') self.indent() for m in n.anonymousClassBody: - print 'm:', m, m.name, type(m) + print('m:', m, m.name, type(m)) self.printMembers(n.anonymousClassBody) self.unindent() self.printt('}') diff --git a/jskparser/ast/visit/symtabgen.py b/jskparser/ast/visit/symtabgen.py index ca7356d..2f7a847 100644 --- a/jskparser/ast/visit/symtabgen.py +++ b/jskparser/ast/visit/symtabgen.py @@ -1,4 +1,5 @@ -import visit as v +from __future__ import absolute_import +from . import visit as v from .. import JAVA_LANG from .. import PRIMITIVES diff --git a/jskparser/ast/visit/visit.py b/jskparser/ast/visit/visit.py index d2ca96f..890df4f 100644 --- a/jskparser/ast/visit/visit.py +++ b/jskparser/ast/visit/visit.py @@ -4,6 +4,7 @@ # visit.py # Updated 2013-06-20 to fix bug on line 41 +from __future__ import absolute_import import inspect __all__ = ['on', 'when'] @@ -18,7 +19,7 @@ def f(fn): def when(param_type): def f(fn): frame = inspect.currentframe().f_back - dispatcher = frame.f_locals[fn.func_name] + dispatcher = frame.f_locals[fn.__name__] if not isinstance(dispatcher, Dispatcher): dispatcher = dispatcher.dispatcher dispatcher.add_target(param_type, fn) diff --git a/jskparser/jskparser/glob2/compat.py b/jskparser/jskparser/glob2/compat.py index 00a4d6f..b8edda0 100644 --- a/jskparser/jskparser/glob2/compat.py +++ b/jskparser/jskparser/glob2/compat.py @@ -1,6 +1,7 @@ # Back-port functools.lru_cache to Python 2 (and <= 3.2) # {{{ http://code.activestate.com/recipes/578078/ (r6) +from __future__ import absolute_import from collections import namedtuple from functools import update_wrapper from threading import RLock diff --git a/jskparser/jskparser/glob2/fnmatch.py b/jskparser/jskparser/glob2/fnmatch.py index 47db550..b87878b 100644 --- a/jskparser/jskparser/glob2/fnmatch.py +++ b/jskparser/jskparser/glob2/fnmatch.py @@ -9,6 +9,7 @@ The function translate(PATTERN) returns a regular expression corresponding to PATTERN. (It does not compile it.) """ +from __future__ import absolute_import import os import posixpath import re diff --git a/jskparser/jskparser/jskparser.py b/jskparser/jskparser/jskparser.py index b92c98e..4c1c0b7 100644 --- a/jskparser/jskparser/jskparser.py +++ b/jskparser/jskparser/jskparser.py @@ -1,6 +1,8 @@ #! /usr/bin/env python -import util +from __future__ import absolute_import +from __future__ import print_function +from . import util import json import logging import logging.config @@ -103,10 +105,10 @@ def create_logger(log_lvl): if OPT.symtab: def f(n): if type(n) not in SymtabGen.NONSYM: - print type(n).__name__, n.name, map(lambda nn: (nn[0], nn[1]), n.symtab.items()) + print(type(n).__name__, n.name, map(lambda nn: (nn[0], nn[1]), n.symtab.items())) g = GenericVisitor(f) g.visit(program) else: p = SourcePrinter() - print p.visit(program) + print(p.visit(program)) exit(0) diff --git a/jskparser/jskparser/logger.py b/jskparser/jskparser/logger.py index 862cab1..d8b893d 100644 --- a/jskparser/jskparser/logger.py +++ b/jskparser/jskparser/logger.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import re import sys @@ -6,7 +7,7 @@ from lib.enum import enum from lib.rlock import FLockFileHandler -import util +from . import util C.log_caller = enum(JAVASK="jsk", PSKETCH="psketch") diff --git a/jskparser/jskparser/util.py b/jskparser/jskparser/util.py index 955f542..d8bd725 100644 --- a/jskparser/jskparser/util.py +++ b/jskparser/jskparser/util.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os from subprocess import call diff --git a/lib/const.py b/lib/const.py index 46d9822..a188669 100644 --- a/lib/const.py +++ b/lib/const.py @@ -1,10 +1,11 @@ # http://code.activestate.com/recipes/65207 +from __future__ import absolute_import class _const: class ConstError(TypeError): pass def __setattr__(self, name, v): - if self.__dict__.has_key(name): - raise self.ConstError, "Can't rebind const(%s)" % name + if name in self.__dict__: + raise self.ConstError("Can't rebind const(%s)" % name) self.__dict__[name] = v import sys diff --git a/lib/glob2/compat.py b/lib/glob2/compat.py index 00a4d6f..b8edda0 100644 --- a/lib/glob2/compat.py +++ b/lib/glob2/compat.py @@ -1,6 +1,7 @@ # Back-port functools.lru_cache to Python 2 (and <= 3.2) # {{{ http://code.activestate.com/recipes/578078/ (r6) +from __future__ import absolute_import from collections import namedtuple from functools import update_wrapper from threading import RLock diff --git a/lib/glob2/fnmatch.py b/lib/glob2/fnmatch.py index 47db550..b87878b 100644 --- a/lib/glob2/fnmatch.py +++ b/lib/glob2/fnmatch.py @@ -9,6 +9,7 @@ The function translate(PATTERN) returns a regular expression corresponding to PATTERN. (It does not compile it.) """ +from __future__ import absolute_import import os import posixpath import re diff --git a/lib/rlock.py b/lib/rlock.py index d76cebc..99e3f68 100644 --- a/lib/rlock.py +++ b/lib/rlock.py @@ -21,6 +21,7 @@ Tested under Debian GNU/Linux, with Python 2.4, 2.5, 2.6 and 3.1. """ +from __future__ import absolute_import import logging import os import sys diff --git a/lib/visit.py b/lib/visit.py index d2ca96f..890df4f 100644 --- a/lib/visit.py +++ b/lib/visit.py @@ -4,6 +4,7 @@ # visit.py # Updated 2013-06-20 to fix bug on line 41 +from __future__ import absolute_import import inspect __all__ = ['on', 'when'] @@ -18,7 +19,7 @@ def f(fn): def when(param_type): def f(fn): frame = inspect.currentframe().f_back - dispatcher = frame.f_locals[fn.func_name] + dispatcher = frame.f_locals[fn.__name__] if not isinstance(dispatcher, Dispatcher): dispatcher = dispatcher.dispatcher dispatcher.add_target(param_type, fn) diff --git a/test/__init__.py b/test/__init__.py index bbfb500..3614088 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import subprocess import unittest diff --git a/test/axioms/ArrayList/run.py b/test/axioms/ArrayList/run.py index 187a2e2..67ef28a 100644 --- a/test/axioms/ArrayList/run.py +++ b/test/axioms/ArrayList/run.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import subprocess import re import time @@ -13,7 +15,7 @@ def main(num_trials, test, first_test, last_test): log = open(log_file, 'w') if last_test == 0: last_test = int(re.findall(r't[0-9]+', text)[-1][1:]) for i in xrange(first_test + 1 if first_test == -1 else first_test, last_test+1): - print 'Running test {}'.format(i) + print('Running test {}'.format(i)) times = [] for j in xrange(num_trials): cmd = ['sketch', '--fe-def', 'TID={}'.format(i), '--fe-inc', input_dir, '{}/main.sk'.format(input_dir)] @@ -25,11 +27,11 @@ def main(num_trials, test, first_test, last_test): times.append(float(t[start:t.find('\n', start)])) time.sleep(1) except: - print 'ERROR: {}'.format(' '.join(cmd)) + print('ERROR: {}'.format(' '.join(cmd))) with open(error_file, 'a') as f: f.write('{}\n'.format(' '.join(cmd))) times.extend([0.0]*num_trials) break - if first_test != -1: print 'Test: {}, times: {}'.format(i, times) + if first_test != -1: print('Test: {}, times: {}'.format(i, times)) with open(result_file, 'a') as f: [f.write('{:.2f}\t'.format(n)) for n in times] f.write('\n') @@ -63,29 +65,29 @@ def sort_results(test): jskparser.add_option('-l', action='store', type='int', dest='last_test', default=0, help='Last test to run.') (options, args) = jskparser.parse_args() - print 'Number of trials: {}'.format(options.trials) + print('Number of trials: {}'.format(options.trials)) if options.impl: - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print + print() if options.adt_n: - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test) - print + print() if options.adt_d: - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test) - print + print() if options.obj: - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) - print + print() if (not options.impl) and (not options.adt_n) and (not options.adt_d) and (not options.obj): - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test) - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test) - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) diff --git a/test/axioms/HashMap/run.py b/test/axioms/HashMap/run.py index 187a2e2..67ef28a 100644 --- a/test/axioms/HashMap/run.py +++ b/test/axioms/HashMap/run.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import subprocess import re import time @@ -13,7 +15,7 @@ def main(num_trials, test, first_test, last_test): log = open(log_file, 'w') if last_test == 0: last_test = int(re.findall(r't[0-9]+', text)[-1][1:]) for i in xrange(first_test + 1 if first_test == -1 else first_test, last_test+1): - print 'Running test {}'.format(i) + print('Running test {}'.format(i)) times = [] for j in xrange(num_trials): cmd = ['sketch', '--fe-def', 'TID={}'.format(i), '--fe-inc', input_dir, '{}/main.sk'.format(input_dir)] @@ -25,11 +27,11 @@ def main(num_trials, test, first_test, last_test): times.append(float(t[start:t.find('\n', start)])) time.sleep(1) except: - print 'ERROR: {}'.format(' '.join(cmd)) + print('ERROR: {}'.format(' '.join(cmd))) with open(error_file, 'a') as f: f.write('{}\n'.format(' '.join(cmd))) times.extend([0.0]*num_trials) break - if first_test != -1: print 'Test: {}, times: {}'.format(i, times) + if first_test != -1: print('Test: {}, times: {}'.format(i, times)) with open(result_file, 'a') as f: [f.write('{:.2f}\t'.format(n)) for n in times] f.write('\n') @@ -63,29 +65,29 @@ def sort_results(test): jskparser.add_option('-l', action='store', type='int', dest='last_test', default=0, help='Last test to run.') (options, args) = jskparser.parse_args() - print 'Number of trials: {}'.format(options.trials) + print('Number of trials: {}'.format(options.trials)) if options.impl: - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print + print() if options.adt_n: - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test) - print + print() if options.adt_d: - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test) - print + print() if options.obj: - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) - print + print() if (not options.impl) and (not options.adt_n) and (not options.adt_d) and (not options.obj): - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test) - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test) - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) diff --git a/test/axioms/Stack/run.py b/test/axioms/Stack/run.py index 3aa064a..5def10c 100644 --- a/test/axioms/Stack/run.py +++ b/test/axioms/Stack/run.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import subprocess import re @@ -12,7 +14,7 @@ def main(num_trials, test, first_test, last_test): log = open(log_file, 'w') if last_test == 0: last_test = int(re.findall(r't[0-9]+', text)[-1][1:]) for i in xrange(first_test + 1 if first_test == -1 else first_test, last_test+1): - print 'Running test {}'.format(i) + print('Running test {}'.format(i)) times = [] for j in range(num_trials): cmd = ['sketch', '--fe-def', 'TID={}'.format(i), '--fe-inc', input_dir, '{}/main.sk'.format(input_dir)] @@ -23,11 +25,11 @@ def main(num_trials, test, first_test, last_test): start = t.rfind('Total time = ') + len('Total time = ') times.append(float(t[start:t.find('\n', start)])) except: - print 'ERROR: {}'.format(' '.join(cmd)) + print('ERROR: {}'.format(' '.join(cmd))) with open(error_file, 'a') as f: f.write('{}\n'.format(' '.join(cmd))) times.extend([0.0]*num_trials) break - if first_test != -1: print 'Test: {}, times: {}'.format(i, times) + if first_test != -1: print('Test: {}, times: {}'.format(i, times)) with open(result_file, 'a') as f: [f.write('{:.2f}\t'.format(n)) for n in times] f.write('\n') @@ -59,23 +61,23 @@ def sort_results(test): jskparser.add_option('-l', action='store', type='int', dest='last_test', default=0, help='Last test to run.') (options, args) = jskparser.parse_args() - print 'Number of trials: {}'.format(options.trials) + print('Number of trials: {}'.format(options.trials)) if options.impl: - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print + print() if options.adt: - print 'Testing adt' + print('Testing adt') main(options.trials, 'adt', options.first_test, options.last_test) - print + print() if options.obj: - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) - print + print() if (not options.impl) and (not options.adt) and (not options.obj): - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test) - print 'Testing adt' + print('Testing adt') main(options.trials, 'adt', options.first_test, options.last_test) - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test) diff --git a/test/axioms/String/format.py b/test/axioms/String/format.py index 4b57ca4..31a46c0 100644 --- a/test/axioms/String/format.py +++ b/test/axioms/String/format.py @@ -1,15 +1,17 @@ +from __future__ import absolute_import +from __future__ import print_function import sys import re FILE_NAME=sys.argv[1] -print FILE_NAME +print(FILE_NAME) FILE_RENAME=FILE_NAME[:FILE_NAME.rfind('.')]+'.csv' -print FILE_RENAME +print(FILE_RENAME) with open(FILE_NAME, 'r') as f: text = f.read() text = re.sub(r'\n', '', text) text = re.sub(r'Number of trials: 15Testing .+?Running test 8Test: 8, times: \[', '', text) text = re.sub('\]', '\n', text) text = re.sub(', ', '\t', text) -print text +print(text) with open(FILE_RENAME, 'w') as f: f.write(text) diff --git a/test/axioms/String/run.py b/test/axioms/String/run.py index c1930a5..e7393dc 100644 --- a/test/axioms/String/run.py +++ b/test/axioms/String/run.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import subprocess import re import time @@ -13,7 +15,7 @@ def main(num_trials, test, first_test, last_test, I): log = open(log_file, 'w') if last_test == -1: last_test = int(re.findall(r't[0-9]+', text)[-1][1:]) for i in xrange(first_test + 1 if first_test == -1 else first_test, last_test+1): - print 'Running test {}'.format(i) + print('Running test {}'.format(i)) times = [] for j in range(num_trials): cmd = ['sketch', '--fe-def', 'TID={}'.format(i), '--fe-def', 'I={}'.format(I), '--fe-inc', input_dir, '{}/main.sk'.format(input_dir)] @@ -25,11 +27,11 @@ def main(num_trials, test, first_test, last_test, I): times.append(float(t[start:t.find('\n', start)])) time.sleep(1) except: - print 'ERROR: {}'.format(' '.join(cmd)) + print('ERROR: {}'.format(' '.join(cmd))) with open(error_file, 'a') as f: f.write('{}\n'.format(' '.join(cmd))) times.extend([0.0]*num_trials) break - if first_test != -1: print 'Test: {}, times: {}'.format(i, times) + if first_test != -1: print('Test: {}, times: {}'.format(i, times)) with open(result_file, 'a') as f: [f.write('{:.2f}\t'.format(n)) for n in times] f.write('\n') @@ -67,36 +69,36 @@ def sort_results(test): jskparser.add_option('-I', action='store', type='int', dest='I', default=0, help='Loop amount for various tests.') (options, args) = jskparser.parse_args() - print 'Number of trials: {}'.format(options.trials) + print('Number of trials: {}'.format(options.trials)) if options.impl: - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test, options.I) - print + print() if options.adt_n: - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test, options.I) - print + print() if options.adt_d: - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test, options.I) - print + print() if options.adt_a: - print 'Testing arithmetize adt' + print('Testing arithmetize adt') main(options.trials, 'adt_a', options.first_test, options.last_test, options.I) - print + print() if options.obj: - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test, options.I) - print + print() if (not options.impl) and (not options.adt_n) and (not options.adt_d) and \ (not options.adt_a) and (not options.obj): - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl', options.first_test, options.last_test, options.I) - print 'Testing non-deterministic adt' + print('Testing non-deterministic adt') main(options.trials, 'adt_n', options.first_test, options.last_test, options.I) - print 'Testing deterministic adt' + print('Testing deterministic adt') main(options.trials, 'adt_d', options.first_test, options.last_test, options.I) - print 'Testing arithmetize adt' + print('Testing arithmetize adt') main(options.trials, 'adt_a', options.first_test, options.last_test, options.I) - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object', options.first_test, options.last_test, options.I) diff --git a/test/axioms/run.py b/test/axioms/run.py index b7934f4..209b5c2 100644 --- a/test/axioms/run.py +++ b/test/axioms/run.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import subprocess import re import math @@ -14,7 +16,7 @@ def main(num_trials, test): log = open(log_file, 'w') num_tests=int(re.findall(r't[0-9]+', text)[-1][1:]) + 1 for i in range(num_tests): - print 'Running test {}'.format(i) + print('Running test {}'.format(i)) times = [] for j in range(num_trials): cmd = ['sketch', '--fe-def', 'TID={}'.format(i), '--fe-inc', input_dir, '{}/main.sk'.format(input_dir)] @@ -26,7 +28,7 @@ def main(num_trials, test): times.append(float(t[start:t.find('\n', start)])) time.sleep(1) except: - print 'ERROR: {}'.format(' '.join(cmd)) + print('ERROR: {}'.format(' '.join(cmd))) with open(error_file, 'a') as f: f.write('{}\n'.format(' '.join(cmd))) times.extend([0.0]*num_trials) break @@ -83,23 +85,23 @@ def median(nums): jskparser.add_option('-n', action='store', type='int', dest='trials', default=1, help='Number of trials to run.') (options, args) = jskparser.parse_args() - print 'Number of trials: {}'.format(options.trials) + print('Number of trials: {}'.format(options.trials)) if options.impl: - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl') - print + print() if options.adt: - print 'Testing adt' + print('Testing adt') main(options.trials, 'adt') - print + print() if options.obj: - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object') - print + print() if (not options.impl) and (not options.adt) and (not options.obj): - print 'Testing implementation' + print('Testing implementation') main(options.trials, 'impl') - print 'Testing adt' + print('Testing adt') main(options.trials, 'adt') - print 'Testing Object' + print('Testing Object') main(options.trials, 'Object') diff --git a/test/test_axiom_gen.py b/test/test_axiom_gen.py index 10a3bd0..c431b10 100644 --- a/test/test_axiom_gen.py +++ b/test/test_axiom_gen.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_axioms.py b/test/test_axioms.py index 0db4cee..f8345e7 100644 --- a/test/test_axioms.py +++ b/test/test_axioms.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_benchmark_axioms.py b/test/test_benchmark_axioms.py index fbcff67..fe6d90a 100644 --- a/test/test_benchmark_axioms.py +++ b/test/test_benchmark_axioms.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from functools import reduce import os import unittest import csv diff --git a/test/test_big_benchmark_axioms.py b/test/test_big_benchmark_axioms.py index 0707dd5..02b84ff 100644 --- a/test/test_big_benchmark_axioms.py +++ b/test/test_big_benchmark_axioms.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from functools import reduce import os import unittest import csv diff --git a/test/test_erroneous.py b/test/test_erroneous.py index c60515c..66bde20 100644 --- a/test/test_erroneous.py +++ b/test/test_erroneous.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_java.py b/test/test_java.py index f2ff08a..f986472 100644 --- a/test/test_java.py +++ b/test/test_java.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import +from __future__ import print_function import os import unittest @@ -18,7 +20,7 @@ def __test(self, fs, using_model=False): _fs = map(append_b, fs) if using_model: _fs.extend(java_sk.util.get_files_from_path(model_dir, "java")) - print fs + print(fs) ret = java_sk.main.main(_fs, '30') self.assertEqual(ret, 0) diff --git a/test/test_java_precisely.py b/test/test_java_precisely.py index 9956e2f..e0108bc 100644 --- a/test/test_java_precisely.py +++ b/test/test_java_precisely.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_lib.py b/test/test_lib.py index ab699ad..84a1367 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_mini.py b/test/test_mini.py index e743edd..e8b153a 100644 --- a/test/test_mini.py +++ b/test/test_mini.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest diff --git a/test/test_new_ast.py b/test/test_new_ast.py index 98d4b87..fa9f5c6 100644 --- a/test/test_new_ast.py +++ b/test/test_new_ast.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import os import unittest From 3c424311b59770f9d252a395855fc076188b6ef0 Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 14:40:57 -0500 Subject: [PATCH 02/12] Handle OSError raised when missing '/usr/libexec/java_home' --- jskparser/ast/utils/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jskparser/ast/utils/utils.py b/jskparser/ast/utils/utils.py index 679a02a..3191f47 100644 --- a/jskparser/ast/utils/utils.py +++ b/jskparser/ast/utils/utils.py @@ -360,8 +360,8 @@ def unpack_class_file(nm): cmd = ['/usr/libexec/java_home'] try: JAVA_HOME = subprocess.check_output(cmd).strip(' \n') - except subprocess.CalledProcessError as e: - logging.error('Unable to extract "{}" from RT_JAR "{}": {}'.format(nm, RT_JAR, e.output)) + except (OSError, subprocess.CalledProcessError) as e: + logging.error('Unable to set JAVA_HOME: {} {}'.format(e, getattr(e, 'output', ''))) raise Exception('Unable to set JAVA_HOME') RT_JAR = os.path.join(JAVA_HOME, 'jre','lib', 'rt.jar') From 9c4c11e1f41f37abc700f1a93d271c06652266ac Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 15:38:54 -0500 Subject: [PATCH 03/12] Hacks around python 2/3 unicode difference. This code seems to rely pretty heavily on nuances of string encodings, and without being sure of exactly how, it seems safer just to work around it. --- java_sk/decode/__init__.py | 2 ++ java_sk/decode/collection.py | 2 ++ java_sk/decode/replacer.py | 2 ++ java_sk/glob2/impl.py | 2 ++ java_sk/rewrite/generator.py | 2 ++ java_sk/translator.py | 2 ++ jskparser/ast/dataflow/dataflow.py | 2 ++ jskparser/ast/expr/methodcallexpr.py | 2 ++ jskparser/ast/importdeclaration.py | 2 ++ jskparser/ast/node.py | 2 ++ jskparser/ast/utils/utils.py | 2 ++ jskparser/jskparser/glob2/impl.py | 2 ++ lib/glob2/impl.py | 2 ++ 13 files changed, 26 insertions(+) diff --git a/java_sk/decode/__init__.py b/java_sk/decode/__init__.py index 52583de..c441b0a 100644 --- a/java_sk/decode/__init__.py +++ b/java_sk/decode/__init__.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import os import logging diff --git a/java_sk/decode/collection.py b/java_sk/decode/collection.py index b2d5ffd..980af17 100644 --- a/java_sk/decode/collection.py +++ b/java_sk/decode/collection.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ from lib.typecheck import * import lib.visit as v import lib.const as C diff --git a/java_sk/decode/replacer.py b/java_sk/decode/replacer.py index 53e04b0..558326a 100644 --- a/java_sk/decode/replacer.py +++ b/java_sk/decode/replacer.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import operator as op import re import logging diff --git a/java_sk/glob2/impl.py b/java_sk/glob2/impl.py index 0186451..91a16a8 100644 --- a/java_sk/glob2/impl.py +++ b/java_sk/glob2/impl.py @@ -1,6 +1,8 @@ """Filename globbing utility.""" from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import sys import os diff --git a/java_sk/rewrite/generator.py b/java_sk/rewrite/generator.py index ccdd996..e1d8562 100644 --- a/java_sk/rewrite/generator.py +++ b/java_sk/rewrite/generator.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import copy import logging diff --git a/java_sk/translator.py b/java_sk/translator.py index 285ef33..f1fabbd 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -1,6 +1,8 @@ #!/usr/bin/env python from __future__ import absolute_import from __future__ import print_function +try: unicode +except: unicode = u"".__class__ from functools import reduce import sys diff --git a/jskparser/ast/dataflow/dataflow.py b/jskparser/ast/dataflow/dataflow.py index fb2c043..2e966b3 100644 --- a/jskparser/ast/dataflow/dataflow.py +++ b/jskparser/ast/dataflow/dataflow.py @@ -2,6 +2,8 @@ from __future__ import absolute_import from __future__ import print_function +try: unicode +except: unicode = u"".__class__ from ..utils import utils from ..body.methoddeclaration import MethodDeclaration diff --git a/jskparser/ast/expr/methodcallexpr.py b/jskparser/ast/expr/methodcallexpr.py index c9cef06..a7cac42 100644 --- a/jskparser/ast/expr/methodcallexpr.py +++ b/jskparser/ast/expr/methodcallexpr.py @@ -1,6 +1,8 @@ #!/usr/bin/env python from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import itertools from . import _import diff --git a/jskparser/ast/importdeclaration.py b/jskparser/ast/importdeclaration.py index 5a8630b..a3ecbf0 100644 --- a/jskparser/ast/importdeclaration.py +++ b/jskparser/ast/importdeclaration.py @@ -1,6 +1,8 @@ #!/usr/bin/env python from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ from .node import Node from . import _import diff --git a/jskparser/ast/node.py b/jskparser/ast/node.py index fffa79f..ac9ce56 100644 --- a/jskparser/ast/node.py +++ b/jskparser/ast/node.py @@ -1,5 +1,7 @@ #!/usr/bin/env python from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import json from . import _import diff --git a/jskparser/ast/utils/utils.py b/jskparser/ast/utils/utils.py index 3191f47..eb0320e 100644 --- a/jskparser/ast/utils/utils.py +++ b/jskparser/ast/utils/utils.py @@ -3,6 +3,8 @@ from __future__ import absolute_import from __future__ import print_function +try: unicode +except: unicode = u"".__class__ import os import logging import subprocess diff --git a/jskparser/jskparser/glob2/impl.py b/jskparser/jskparser/glob2/impl.py index 0186451..91a16a8 100644 --- a/jskparser/jskparser/glob2/impl.py +++ b/jskparser/jskparser/glob2/impl.py @@ -1,6 +1,8 @@ """Filename globbing utility.""" from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import sys import os diff --git a/lib/glob2/impl.py b/lib/glob2/impl.py index 0186451..91a16a8 100644 --- a/lib/glob2/impl.py +++ b/lib/glob2/impl.py @@ -1,6 +1,8 @@ """Filename globbing utility.""" from __future__ import absolute_import +try: unicode +except: unicode = u"".__class__ import sys import os From 52f5e9ba095ebe93cc981f4f2e261f288925518f Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 15:41:30 -0500 Subject: [PATCH 04/12] Hacks around python 2/3 missing imports. --- java_sk/encoder.py | 5 ++++- java_sk/translator.py | 5 ++++- java_sk/util.py | 6 +++++- jskparser/ast/visit/sourcevisitor.py | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/java_sk/encoder.py b/java_sk/encoder.py index 0ac1070..e5de653 100644 --- a/java_sk/encoder.py +++ b/java_sk/encoder.py @@ -1,7 +1,10 @@ from __future__ import print_function from __future__ import absolute_import -import cStringIO +try: + import cStringIO +except: # so sue me. + import io as cStringIO import math import os import copy as cp diff --git a/java_sk/translator.py b/java_sk/translator.py index f1fabbd..811b3d2 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -6,7 +6,10 @@ from functools import reduce import sys -import cStringIO +try: + import cStringIO +except: # so sue me. + import io as cStringIO import logging import copy import os diff --git a/java_sk/util.py b/java_sk/util.py index 14c54cb..f4a05cd 100644 --- a/java_sk/util.py +++ b/java_sk/util.py @@ -1,7 +1,11 @@ from __future__ import absolute_import import os -from itertools import ifilter, ifilterfalse +try: + from itertools import ifilter, ifilterfalse +except: + ifilter = filter + from itertools import filterfalse as ifilterfalse from ast.utils import utils from ast.body.classorinterfacedeclaration import ClassOrInterfaceDeclaration diff --git a/jskparser/ast/visit/sourcevisitor.py b/jskparser/ast/visit/sourcevisitor.py index 9020b13..58881d9 100644 --- a/jskparser/ast/visit/sourcevisitor.py +++ b/jskparser/ast/visit/sourcevisitor.py @@ -2,7 +2,10 @@ from __future__ import absolute_import from __future__ import print_function -import cStringIO +try: + import cStringIO +except: # so sue me. + import io as cStringIO from . import visit as v from .. import Operators as op From e9d3e1850f94da83e0f1d0765372c3662bd3afed Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 16:41:11 -0500 Subject: [PATCH 05/12] Port map/filter for python 2/3, using modernize -f map -f filter Turns out this was necessary after all, because python 3 map and filter return iterators, not lists. --- java_sk/decode/__init__.py | 3 +- java_sk/decode/collection.py | 2 +- java_sk/decode/replacer.py | 8 +- java_sk/encoder.py | 85 ++++++++++--------- java_sk/glob2/impl.py | 6 +- java_sk/rewrite/desugar.py | 2 +- java_sk/translator.py | 74 ++++++++-------- java_sk/util.py | 7 +- jskparser/ast/body/axiomdeclaration.py | 20 ++--- jskparser/ast/body/axiomparameter.py | 3 +- jskparser/ast/body/bodydeclaration.py | 3 +- .../ast/body/classorinterfacedeclaration.py | 14 +-- jskparser/ast/body/constructordeclaration.py | 15 ++-- jskparser/ast/body/methoddeclaration.py | 35 ++++---- jskparser/ast/body/parameter.py | 3 +- jskparser/ast/body/typedeclaration.py | 3 +- jskparser/ast/body/xform.py | 21 +++-- jskparser/ast/compilationunit.py | 8 +- jskparser/ast/dataflow/dataflow.py | 26 +++--- jskparser/ast/expr/arraycreationexpr.py | 4 +- jskparser/ast/expr/arrayinitializerexpr.py | 4 +- jskparser/ast/expr/generatorexpr.py | 4 +- jskparser/ast/expr/methodcallexpr.py | 34 ++++---- jskparser/ast/expr/objectcreationexpr.py | 12 +-- jskparser/ast/expr/variabledeclarationexpr.py | 6 +- jskparser/ast/node.py | 4 +- .../stmt/explicitconstructorinvocationstmt.py | 4 +- jskparser/ast/stmt/forstmt.py | 8 +- jskparser/ast/stmt/switchentrystmt.py | 4 +- jskparser/ast/stmt/switchstmt.py | 2 +- jskparser/ast/stmt/trystmt.py | 8 +- jskparser/ast/type/referencetype.py | 4 +- jskparser/ast/type/type.py | 4 +- jskparser/ast/typearguments.py | 4 +- jskparser/ast/typeparameter.py | 8 +- jskparser/ast/utils/utils.py | 18 ++-- jskparser/ast/visit/sourcevisitor.py | 2 +- jskparser/ast/visit/symtabgen.py | 60 ++++++++----- jskparser/ast/visit/visit.py | 2 +- jskparser/jskparser/glob2/impl.py | 6 +- jskparser/jskparser/jskparser.py | 2 +- lib/glob2/impl.py | 6 +- test/axioms/run.py | 15 ++-- test/test_axiom_gen.py | 4 +- test/test_axioms.py | 80 ++++++++--------- test/test_benchmark_axioms.py | 42 ++++----- test/test_big_benchmark_axioms.py | 42 ++++----- test/test_erroneous.py | 2 +- test/test_java.py | 2 +- test/test_java_precisely.py | 2 +- test/test_lib.py | 2 +- test/test_mini.py | 2 +- test/test_new_ast.py | 2 +- 53 files changed, 383 insertions(+), 360 deletions(-) diff --git a/java_sk/decode/__init__.py b/java_sk/decode/__init__.py index c441b0a..6d823b5 100644 --- a/java_sk/decode/__init__.py +++ b/java_sk/decode/__init__.py @@ -82,7 +82,8 @@ def to_java(java_dir, pgr, output_path): # replace collections of interface types with actual classes, if any _visitors.append(Collection()) _visitors.append(SemanticChecker()) - map(lambda vis: pgr.accept(vis), _visitors) + for vis in _visitors: + pgr.accept(vis) ## trimming of the program trim(pgr) diff --git a/java_sk/decode/collection.py b/java_sk/decode/collection.py index 980af17..9b91d90 100644 --- a/java_sk/decode/collection.py +++ b/java_sk/decode/collection.py @@ -34,7 +34,7 @@ class Collection(object): def repl_itf(tname, init=True): if not util.is_collection(tname): return tname _ids = util.of_collection(tname) - ids = map(util.autoboxing, _ids) + ids = [util.autoboxing(i) for i in _ids] collection = ids[0] if init: collection = Collection.__impl[collection] generics = ids[1:] # don't be recursive, like map(repl_itf, ids[1:]) diff --git a/java_sk/decode/replacer.py b/java_sk/decode/replacer.py index 558326a..93dcae3 100644 --- a/java_sk/decode/replacer.py +++ b/java_sk/decode/replacer.py @@ -1,7 +1,6 @@ from __future__ import absolute_import try: unicode except: unicode = u"".__class__ -import operator as op import re import logging @@ -32,7 +31,7 @@ def __init__(self, output_path, holes): ## hole assignments for roles ## glblInit_fid__cid_????,StmtAssign,accessor_???? = n - names = map(op.attrgetter("name"), self._holes) + names = [hole.name for hole in self._holes] regex_role = r"({})__(\S+)_\S+ = (\d+)$".format('|'.join(names)) # interpret the synthesis result @@ -211,12 +210,11 @@ def visit(self, node): rty = node.typ if node.typ != C.J.v else C.J.OBJ node.body = to_statements(node, u"{} _out;".format(rty)) - op_strip = op.methodcaller("strip") _assigns = self._assigns[mname] for _assign in _assigns: - lhs, rhs = map(op_strip, _assign.split('=')) + lhs, rhs = [a.strip() for a in _assign.split('=')] if len(lhs.split(' ')) > 1: # i.e., var decl - ty, v = map(op_strip, lhs.split(' ')) + ty, v = [l.strip() for l in lhs.split(' ')] ty = ty.split('@')[0] # TODO: cleaner way to retrieve/sanitize type node.body += to_statements(node, u"{} {} = {};".format(ty, v, rhs)) else: # stmt assign diff --git a/java_sk/encoder.py b/java_sk/encoder.py index e5de653..082b650 100644 --- a/java_sk/encoder.py +++ b/java_sk/encoder.py @@ -81,9 +81,9 @@ def __init__(self, program, out_dir, fs): self.main_cls() clss = utils.extract_nodes([ClassOrInterfaceDeclaration], self.prg) - # is_ax_cls = any(map(lambda c: c._axiom, clss)) - is_ax_cls = True if len(filter(lambda c: c.box, clss)) > 0 else False - ax_clss = filter(lambda c: c.axiom, clss) + # is_ax_cls = [c._axiom for c in clss] + is_ax_cls = True if len([c for c in clss if c.box]) > 0 else False + ax_clss = [c for c in clss if c.axiom] self.is_ax_cls = is_ax_cls self.ax_clss = ax_clss @@ -102,17 +102,17 @@ def find_main(self): mtds = [] for c in self.clss: m = utils.extract_nodes([MethodDeclaration], c) - mtds.extend(filter(lambda m: m.name == u'main', m)) + mtds.extend([m for m in m if m.name == u'main']) # do we care if main is static? # mtds.extend(filter(lambda m: td.isStatic(m) and m.name == u'main', m)) lenn = len(mtds) if lenn > 1: - raise Exception("multiple main()s", map(lambda m: str(utils.get_coid(m)), mtds)) + raise Exception("multiple main()s", [str(utils.get_coid(m)) for m in mtds]) return mtds[0] if lenn == 1 else None def find_harness(self): # TODO: these can also be specified with annotations -- we don't support those yet - mtds = filter(td.isHarness, self.mtds) + mtds = [m for m in self.mtds if td.isHarness(m)] return mtds[0] if mtds else None def main_cls(self): @@ -134,7 +134,7 @@ def to_sk(self): else: os.makedirs(self.sk_dir) clss = utils.extract_nodes([ClassOrInterfaceDeclaration], self.prg) - is_ax_cls = any(map(lambda c: c._axiom, clss)) + is_ax_cls = any([c._axiom for c in clss]) # consist builds up some class hierarchies which happens in main.py # prg.consist() @@ -183,9 +183,9 @@ def print_obj_struct(self, is_ax_cls): if self.tltr.obj_struct: # pretty print - i_flds = filter(lambda m: type(m) == FieldDeclaration, self.tltr.obj_struct.members) - flds = map(self.tltr.trans_fld, i_flds) - lens = map(lambda f: len(f[0]), flds) + i_flds = [m for m in self.tltr.obj_struct.members if type(m) == FieldDeclaration] + flds = [self.tltr.trans_fld(m) for m in i_flds] + lens = [len(f[0]) for f in flds] m = max(lens) + 1 buf.write("struct " + str(self.tltr.obj_struct) + " {\n") if is_ax_cls: @@ -204,7 +204,7 @@ def print_obj_struct(self, is_ax_cls): if isinstance(i_f.typee, ReferenceType): if isinstance(i_f.typee.typee, ClassOrInterfaceType): clss = utils.extract_nodes([ClassOrInterfaceDeclaration], self.prg) - clss = map(lambda a: a.name, filter(lambda c: c._axiom, clss)) + clss = [a.name for a in [c for c in clss if c._axiom]] if i_f.typee.typee.name in clss: typ = u'Object' @@ -265,7 +265,7 @@ def gen_meta_sk(self, is_ax_cls): buf.write("// distinct class IDs\n") items = sorted(self.CLASS_NUMS.items()) - lens = map(lambda i: len(i[0]), items) + lens = [len(i[0]) for i in items] m = max(lens) for k,v in items: if k not in utils.narrow: @@ -288,7 +288,8 @@ def gen_object_sk(self, is_ax_cls): buf.write("package Object;\n\n") self.bases = util.rm_subs(self.clss) - filter(None, map(partial(self.to_struct, is_ax_cls), self.bases)) + for b in self.bases: + self.to_struct(is_ax_cls, b) buf.write('Object Object_Object(Object self){\n return self;\n}\n\n') with open(os.path.join(self.sk_dir, "Object.sk"), 'w') as f: f.write(util.get_and_close(buf)) @@ -301,7 +302,7 @@ def gen_cls_sk(self, cls, is_ax_cls): mtds = utils.extract_nodes([MethodDeclaration], cls, recurse=False) cons = utils.extract_nodes([ConstructorDeclaration], cls, recurse=False) flds = utils.extract_nodes([FieldDeclaration], cls, recurse=False) - s_flds = filter(td.isStatic, flds) + s_flds = [f for f in flds if td.isStatic(f)] # filter out non-static fields with initial values ns_flds = filter(lambda f: not td.isStatic(f) and f.variable.init, flds) @@ -349,7 +350,7 @@ def gen_cls_sk(self, cls, is_ax_cls): if etypes: buf.write('Object self{};\n\n'.format(len(etypes)-1)) # not a base class, not the harness class, and doesn't override the base constructor # if cls not in self.bases and str(cls) != str(self.mcls) and \ - if not filter(lambda c: len(c.parameters) == 0, cons): + if not [c for c in cons if len(c.parameters) == 0]: # these represent this$N (inner classes) if etypes: i = len(etypes)-1 @@ -414,7 +415,7 @@ def gen_adt_constructor(mtd): typ = self.tltr.trans_ty(t) if isinstance(t, ReferenceType) and t.arrayCount > 0: typ = "Array_"+typ - if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in map(lambda c: c.name, self.ax_clss) and not self.is_ax_cls: + if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls: typ = u'Object' # if p.typee.name in p.symtab: @@ -443,14 +444,14 @@ def gen_obj_constructor(mtd): ptyps = [] ptyps_name = [] for t in mtd_param_typs: - if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in map(lambda c: c.name, self.ax_clss) and not self.is_ax_cls: + if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls: typ = u'Object' else: typ = self.tltr.trans_ty(t) ptyps.append(typ) if typ == u'Object' or str(t) == u'byte': typ = str(t) ptyps_name.append(typ) - pnms = map(str, mtd.param_names()) + pnms = [str(p) for p in mtd.param_names()] # (ptyps, pnms) = (map(lambda t: self.tltr.trans_ty(t), mtd.param_typs()), map(str, mtd.param_names())) # ptyps_name = cp.deepcopy(ptyps) if is_ax_cls: @@ -467,9 +468,9 @@ def gen_obj_constructor(mtd): if isinstance(mtd_param_typs[i], ReferenceType): if mtd_param_typs[i].arrayCount > 0: ptyps[i] = "Array_"+ptyps[i] - params = ', '.join(map(lambda p: ' '.join(p), zip(ptyps, pnms))) + params = ', '.join([' '.join(p) for p in zip(ptyps, pnms)]) c = 'Object ' - if (not is_ax_cls and mtd_name2.split('_')[0] in map(lambda x: x.name, ax_mtds)) and not mtd.boxedRet: + if (not is_ax_cls and mtd_name2.split('_')[0] in [x.name for x in ax_mtds]) and not mtd.boxedRet: # c = str(mtd.typee) + u' ' c = self.tltr.trans_ty(mtd.typee) + u' ' if isinstance(mtd.typee, ReferenceType) and mtd.typee.arrayCount > 0 and (not is_ax_cls and not mtd.boxedRet and not mtd.is_bang): @@ -496,7 +497,7 @@ def gen_obj_constructor(mtd): c += '{}) {{\n '.format(params) else: c += ') {\n ' - if mtd_name2.split('_')[0] not in map(lambda x: x.name, ax_mtds): + if mtd_name2.split('_')[0] not in [x.name for x in ax_mtds]: # THERE MUST BE A BETTER WAY TO DETECT BANG TYPE METHODS if mtd_name2.split('_')[0].endswith('b'): c += 'self._{0}=new {1}('.format(cls.name.lower(), mtd_name2.capitalize()) @@ -543,8 +544,8 @@ def gen_obj_constructor(mtd): # Creates list of adt "functions" (i.e. constructors from top of java file) # including bang functions mtds = utils.extract_nodes([MethodDeclaration], cls, recurse=False) - adt_mtds = filter(lambda m: m.adt, mtds) - non_adt_mtds = filter(lambda m: not m.adt, mtds) + adt_mtds = [m for m in mtds if m.adt] + non_adt_mtds = [m for m in mtds if not m.adt] # Write all non axiom / adt functions to file (like static functions) for m in non_adt_mtds: @@ -581,12 +582,12 @@ def gen_obj_constructor(mtd): adt_mtds = [m] + adt_mtds # I like to format - max_len = max(map(lambda m: len(m.name), adt_mtds)) + max_len = max([len(m.name) for m in adt_mtds]) # Create ADT constructors for all methods and wraps them in ADT struct # Also create a dictionary for object constructors for symbol table reference - cons = map(gen_obj_constructor, adt_mtds) - adt_cons = map(gen_adt_constructor, adt_mtds) + cons = [gen_obj_constructor(m) for m in adt_mtds] + adt_cons = [gen_adt_constructor(m) for m in adt_mtds] adt = 'adt {} {{\n{}}}\n\n{}'.format(cname, ''.join(adt_cons), ''.join(cons)) buf.write(adt) @@ -612,7 +613,7 @@ def cpy_sym(n, *args): _self = Parameter({u'id':{u'name':u'selff'}, u'type':{u'@t': u'ReferenceType', u'type': {u'@t':u'ClassOrInterfaceType', u'name':cname},},},) x.childrenNodes.append(_self) - x.parameters = [_self] + map(cp.copy, a.parameters) + x.parameters = [_self] + [cp.copy(p) for p in a.parameters] x.adtName = str(a) x.add_parent_post(cls, True) @@ -622,7 +623,8 @@ def cpy_sym(n, *args): # Applies cpy_sym to all children of this class and all children of those # Updates symbol table of each of these children to include parent's # symbol table - map(partial(utils.walk, cpy_sym), cls.childrenNodes) + for c in cls.childrenNodes: + utils.walk(cpy_sym, c) # # create xform dispatch method # # i.e. calls the right xform depending on type of ADT @@ -725,14 +727,14 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames): else: xname = ((name+u'_')*(depth))+name+u'.'+xname - poss_names = filter(lambda n: len(n.split('_')) == depth+1, xnames) + poss_names = [n for n in xnames if len(n.split('_')) == depth+1] if len(poss_names) > 0: new_xname = poss_names[0].split('.')[0] xname = new_xname+u'.'+xname.split('.')[-1] xf_sym.symtab[old_name] = xname xnames.append(xname) else: - xf2 = filter(lambda m: param.method.name == m.name.split('_')[0], adt_mtds)[0] + xf2 = [m for m in adt_mtds if param.method.name == m.name.split('_')[0]][0] if depth == 0: set_param_names(param.method, xf2, adt_mtds, depth+1, xf_sym, xparam.name, xnames) else: @@ -810,19 +812,21 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames): # this will give it access to the argument names of a # then updates xf children with xf.symtab = dict(a.symtab.items() + xf.symtab.items()) - map(partial(utils.walk, cpy_sym), xf.childrenNodes) + for c in xf.childrenNodes: + utils.walk(cpy_sym, c) # NOT SURE WHY THIS IS NEEDED # without this it isn't able to resolve the string type of the # function. not sure why... a.symtab = dict(xf.symtab.items() + a.symtab.items()) - map(partial(utils.walk, cpy_sym), a.childrenNodes) + for c in a.childrenNodes: + utils.walk(cpy_sym, c) # returns empty switch statement to be filled by axioms declarations # of the axiom "a" body = xf.get_xform() - if any(map(lambda p: p.method, a.parameters)): + if any([p.method for p in a.parameters]): # iterate through body of axiom declarations of a, translate # them to appropriate IRs (i.e. JSON dicts) a.body.stmts = self.tltr.trans_xform(a.name, body, a.body.stmts) @@ -838,7 +842,7 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames): # cases = map(lambda d: d.name_no_nested().capitalize(), decs) - decs2 = filter(lambda m: m.name.split('_')[0] == a.parameters[i].name and a.parameters[i].name == cls.name, adt_mtds) + decs2 = [m for m in adt_mtds if m.name.split('_')[0] == a.parameters[i].name and a.parameters[i].name == cls.name] # Add the empty constructor to the declarations if needed if not a.parameters[0].method: @@ -868,7 +872,7 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames): casess.append(cases) # add cases to body - if any(map(lambda p: p.method, a.parameters)): + if any([p.method for p in a.parameters]): body.add_body_nested(casess, a.body.stmts, adt_mtds, xf.parameters, cls, a, self.is_ax_cls) else: body.create_normal_body(a.body) @@ -908,17 +912,20 @@ def per_cls(cls): cname = str(cls) if cname != str(cls_v): self.tltr.ty[str(cls)] = str(cls_v) if not cls.axiom else str(cls) - flds = filter(lambda m: type(m) == FieldDeclaration, cls.members) + flds = [m for m in cls.members if type(m) == FieldDeclaration] def cp_fld(fld): fld_v = cp.copy(fld) fld_v.parentNode = cls cls_v.members.append(fld_v) cls_v.childrenNodes.append(fld_v) - map(cp_fld, filter(lambda f: not td.isStatic(f), flds)) - map(per_cls, utils.all_subClasses(cls)) + for f in flds: + if not td.isStatic(f): + cp_fld(f) + for c in utils.all_subClasses(cls): + per_cls(c) # add ADT fields - axiom_clss = filter(lambda c: c.axiom, utils.all_subClasses(cls)) + axiom_clss = [c for c in utils.all_subClasses(cls) if c.axiom] for a in axiom_clss: fd = FieldDeclaration( {u'variables':{u'@e': [{u'@t': u'VariableDeclarator', diff --git a/java_sk/glob2/impl.py b/java_sk/glob2/impl.py index 91a16a8..2374384 100644 --- a/java_sk/glob2/impl.py +++ b/java_sk/glob2/impl.py @@ -69,7 +69,7 @@ def iglob(self, pathname, with_matches=False): result = self._iglob(pathname) if with_matches: return result - return map(lambda s: s[0], result) + return [s[0] for s in result] def _iglob(self, pathname, rootcall=True): """Internal implementation that backs :meth:`iglob`. @@ -152,7 +152,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): names = [''] if globstar_with_root else [] for top, entries in self.walk(dirname): _mkabs = lambda s: os.path.join(top[len(dirname)+1:], s) - names.extend(map(_mkabs, entries)) + names.extend([_mkabs(e) for e in entries]) # Reset pattern so that fnmatch(), which does not understand # ** specifically, will only return a single group match. pattern = '*' @@ -165,7 +165,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): # Remove hidden files by default, but take care to ensure # that the empty string we may have added earlier remains. # Do not filter out the '' that we might have added earlier - names = filter(lambda x: not x or not _ishidden(x), names) + names = [x for x in names if not x or not _ishidden(x)] return fnmatch.filter(names, pattern) diff --git a/java_sk/rewrite/desugar.py b/java_sk/rewrite/desugar.py index 9638e18..bcbeb9e 100644 --- a/java_sk/rewrite/desugar.py +++ b/java_sk/rewrite/desugar.py @@ -39,7 +39,7 @@ def visit(self, node): @v.when(Statement) def visit(self, node): if node.kind == C.S.MINREPEAT: - b = '\n'.join(map(str, node.b)) + b = '\n'.join([str(b) for b in node.b]) body = u"" for i in xrange(9): # TODO: parameterize body += u""" diff --git a/java_sk/translator.py b/java_sk/translator.py index 811b3d2..a7430a8 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -175,7 +175,7 @@ def visit(self, n, **kwargs): # self.printSepList(n.parameters) for i in range(0, len(n.parameters)): param = n.parameters[i] - if isinstance(param.typee, ReferenceType) and isinstance(param.typee.typee, ClassOrInterfaceType) and str(param.typee.typee) in map(lambda c: c.name, self._ax_clss) and not self._is_ax_cls: + if isinstance(param.typee, ReferenceType) and isinstance(param.typee.typee, ClassOrInterfaceType) and str(param.typee.typee) in [c.name for c in self._ax_clss] and not self._is_ax_cls: self.printt('Object') else: param.typee.accept(self, **kwargs) @@ -208,9 +208,9 @@ def visit(self, n, **kwargs): s.append(u'fs_s@Object(HashMap_NoHash_HashMap_NoHash(new Object(__cid=HashMap_NoHash())));') n.body.stmts = s + n.body.stmts - boxedRet = u'boxedRet' in map(lambda a: str(a), n.annotations) or n.boxedRet + boxedRet = u'boxedRet' in [str(a) for a in n.annotations] or n.boxedRet - if (isinstance(n.typee, ReferenceType) and isinstance(n.typee.typee, ClassOrInterfaceType) and str(n.typee.typee) in map(lambda c: c.name, self._ax_clss) and not self._is_ax_cls) or boxedRet: + if (isinstance(n.typee, ReferenceType) and isinstance(n.typee.typee, ClassOrInterfaceType) and str(n.typee.typee) in [c.name for c in self._ax_clss] and not self._is_ax_cls) or boxedRet: self.printt('Object') else: n.typee.accept(self, **kwargs) @@ -235,13 +235,13 @@ def visit(self, n, **kwargs): # print("HERE: "+str(n)) # for i in range(0, len(params)): # p = params[i] - # if isinstance(p.typee, ReferenceType) and isinstance(p.typee.typee, ClassOrInterfaceType) and str(p.typee.typee) in map(lambda c: c.name, self._ax_clss) and not self._is_ax_cls: + # if isinstance(p.typee, ReferenceType) and isinstance(p.typee.typee, ClassOrInterfaceType) and str(p.typee.typee) in [c.name for c in self._ax_clss] and not self._is_ax_cls: # params[i] = Parameter({u'id':{u'name':p.name}, # u'type':{u'@t': u'ReferenceType', u'type': {u'@t':u'ClassOrInterfaceType', u'name':u'Object'},},},) for i in range(0, len(params)): param = params[i] - if ((isinstance(param.typee, ReferenceType) and isinstance(param.typee.typee, ClassOrInterfaceType) and str(param.typee.typee) in map(lambda c: c.name, self._ax_clss) and not self._is_ax_cls and not str(n).startswith('xform_')) or (i+1) in n.boxedArgs) or (i == 0 and n.boxedRet): + if ((isinstance(param.typee, ReferenceType) and isinstance(param.typee.typee, ClassOrInterfaceType) and str(param.typee.typee) in [c.name for c in self._ax_clss] and not self._is_ax_cls and not str(n).startswith('xform_')) or (i+1) in n.boxedArgs) or (i == 0 and n.boxedRet): self.printt('Object') else: param.typee.accept(self, **kwargs) @@ -312,7 +312,7 @@ def visit(self, n, **kwargs): name = names[0] for nam in names[1:]: name += u'_'+nam - adt_mtd = filter(lambda m: str(m) == name or (str(m) == name.replace('_Object', '', 1)),e.adt_mtds)[0] + adt_mtd = [m for m in e.adt_mtds if str(m) == name or (str(m) == name.replace('_Object', '', 1))][0] ret_val = str(n)[6:].lower().capitalize()+u'(' if not len(adt_mtd.parameters) == 0 and adt_mtd.parameters[0].name == u'self': ret_val += u'self=selff._'+str(parent).lower() @@ -629,7 +629,7 @@ def visit(self, n, **kwargs): @v.when(ExplicitConstructorInvocationStmt) def visit(self, n, **kwargs): if n.isThis: - self.printt('_'.join([str(n.get_coid()), str(n.get_coid())] + map(str, n.arg_typs()))) + self.printt('_'.join([str(n.get_coid()), str(n.get_coid())] + [str(t) for t in n.arg_typs()])) else: if n.expr: n.expr.accept(self, **kwargs) @@ -639,7 +639,7 @@ def visit(self, n, **kwargs): if not sups: exit('Calling super with with no super class: {}'.format(str(cls))) def ty(a): return a.typee.name if type(a) != NameExpr else n.symtab[a.name].typee.name - self.printt('_'.join([str(sups[0]), str(sups[0])] + map(ty, n.args))) + self.printt('_'.join([str(sups[0]), str(sups[0])] + [ty(a) for a in n.args])) self.printt('@{}'.format(str(sups[0]))) self.printt(u'(self') if n.args: self.printt(', ') @@ -712,13 +712,13 @@ def visit(self, n, **kwargs): if typ and isinstance(typ, ClassOrInterfaceType) or isinstance(typ, ReferenceType): cls = typ.symtab.get(typ.name) - if (cls and isinstance(cls, ClassOrInterfaceDeclaration) and cls.axiom) or (n.annotations != [] and ((u'isBoxed' in map(lambda a: str(a), n.annotations) or u'box' in map(lambda a: str(a), n.annotations)))): + if (cls and isinstance(cls, ClassOrInterfaceDeclaration) and cls.axiom) or (n.annotations != [] and ((u'isBoxed' in [str(a) for a in n.annotations] or u'box' in [str(a) for a in n.annotations]))): self.printt('Object') else: n.typee.accept(self, **kwargs) # self.printt(' ') - kwargs[u'box'] = u'box' in map(lambda a: str(a), n.annotations) - kwargs[u'unbox'] = (u'unbox' in map(lambda a: str(a), n.annotations), n.typee) + kwargs[u'box'] = u'box' in [str(a) for a in n.annotations] + kwargs[u'unbox'] = (u'unbox' in [str(a) for a in n.annotations], n.typee) self.printSepList(n.varss, **kwargs) kwargs[u'box'] = False kwargs[u'unbox'] = False @@ -1038,10 +1038,10 @@ def visit(self, n, **kwargs): self.printt('.') if n.args: typs = [] - tparam_nms = map(lambda t: t.name, cls.typeParameters) + tparam_nms = [t.name for t in cls.typeParameters] cons = utils.extract_nodes([ConstructorDeclaration], cls) if cls.axiom: - cons += filter(lambda m: m.constructor, utils.extract_nodes([MethodDeclaration], cls)) + cons += [m for m in utils.extract_nodes([MethodDeclaration], cls) if m.constructor] for a in n.args: if type(a) == FieldAccessExpr: tname = utils.find_fld(a, self.obj_struct).typee @@ -1081,12 +1081,13 @@ def visit(self, n, **kwargs): anon_cls.childrenNodes.extend(anon_cls.members) anon_cls.symtab = {} anon_cls.symtab.update({anon_cls.name:anon_cls}) - map(lambda m: anon_cls.symtab.update({str(m):m}), n.anonymousClassBody) + for m in n.anonymousClassBody: + anon_cls.symtab.update({str(m):m}) target.symtab.update({nm:anon_cls}) tltr = copy.copy(self) tltr.indentation = '' - anon = map(tltr.trans, anon_cls.members) + anon = [tltr.trans(m) for m in anon_cls.members] anon.append('int {}() {{ return {}; }}\n'.format(anon_cls.name, self.anon_ids)) self.anon_ids -= 1 @@ -1590,9 +1591,9 @@ def write_call(): if not cls: pmdec = utils.get_parent(callexpr, MethodDeclaration) pcls = callexpr.get_coid() - tparams = map(lambda p: p, pcls.typeParameters) + \ - map(lambda p: p, pmdec.typeParameters) if pmdec else [] - tparam = filter(lambda p: p.name == scope.typee.name, tparams) + tparams = [p for p in pcls.typeParameters] + \ + [p for p in pmdec.typeParameters] if pmdec else [] + tparam = [p for p in tparams if p.name == scope.typee.name] if tparam: tparam = tparam[0] cls = scope.symtab.get(tparam.typeBound[0].name) @@ -1613,7 +1614,7 @@ def uninterpreted(): # write uninterpreted function signature # add fun declaration as uninterpreted with open(os.path.join(self.sk_dir, 'meta.sk'), 'a') as f: - trans_ftypes = set([tuple(map(self.trans_ty, map(convert, c))) for c in ftypes]) + trans_ftypes = set([tuple([self.trans_ty(convert(t)) for t in c]) for c in ftypes]) for fun in [list(d) for d in trans_ftypes]: if len(fun) > 1: sig = '{}.{}.{}'.format(fun[0], fun[1], callexpr.name) @@ -1687,18 +1688,18 @@ def uninterpreted(): # Compile-Time Step 2: Determine Method Signature # 15.12.2.1. Identify Potentially Applicable Methods pots = self.identify_potentials(callexpr, cls) - logging.debug('potentitals: {}'.format(map(lambda m: str(m), pots))) + logging.debug('potentitals: {}'.format([str(m) for m in pots])) if not pots: uninterpreted() return # 15.12.2.2. Phase 1: Identify Matching Arity Methods Applicable by Strict Invocation strict_mtds = self.identify_strict(callexpr, pots) - logging.debug('strict_applicable: {}'.format(map(lambda m: str(m), strict_mtds))) + logging.debug('strict_applicable: {}'.format([str(m) for m in strict_mtds])) # 15.12.2.3. Phase 2: Identify Matching Arity Methods Applicable by Loose Invocation loose_mtds = self.identify_loose(callexpr, pots) - logging.debug('loose_applicable: {}'.format(map(lambda m: str(m), loose_mtds))) + logging.debug('loose_applicable: {}'.format([str(m) for m in loose_mtds])) # 15.12.2.4. Phase 3: Identify Methods Applicable by Variable Arity Invocation # TODO: this @@ -1755,8 +1756,8 @@ def uninterpreted(): return clss = [cls] + utils.all_subClasses(cls) if invocation_mode != 'uninterpreted' else \ utils.all_subClasses(cls) - clss = filter(lambda c: not c.interface, clss) - logging.debug('subclasses: {}'.format(map(lambda c: str(c), clss))) + clss = [c for c in clss if not c.interface] + logging.debug('subclasses: {}'.format([str(c) for c in clss])) scp = tltr.trans(callexpr.scope) args = [NameExpr({u'name':scp})] + callexpr.args @@ -1811,20 +1812,20 @@ def identify_potentials(self, callexpr, cls): call_arg_typs = callexpr.arg_typs() for key,val in cls.symtab.items(): if type(val) != MethodDeclaration: continue - tparam_names = map(lambda t: t.name, val.typeParameters) - tparam_names.extend(map(lambda t: t.name, val.get_coid().typeParameters)) + tparam_names = [t.name for t in val.typeParameters] + tparam_names.extend([t.name for t in val.get_coid().typeParameters]) if self._is_ax_cls or callexpr.name.startswith('xform'): name = callexpr.name if val.adtType and callexpr.name != val.name and len(call_arg_typs) > 1: name += '_'+'_'.join(map(str, call_arg_typs[1:])) if name == val.name and len(callexpr.args) == len(val.parameters): - if all(map(lambda t: t[1].name in tparam_names or utils.is_subtype(t[0], t[1]), - zip(call_arg_typs, val.param_typs()))): + if all([t[1].name in tparam_names or utils.is_subtype(t[0], t[1]) for t in + zip(call_arg_typs, val.param_typs())]): mtds.append(val) else: if callexpr.name == val.name and len(callexpr.args) == len(val.parameters): - if all(map(lambda t: t[1].name in tparam_names or utils.is_subtype(t[0], t[1]), - zip(call_arg_typs, val.param_typs()))): + if all([t[1].name in tparam_names or utils.is_subtype(t[0], t[1]) for t in + zip(call_arg_typs, val.param_typs())]): mtds.append(val) return mtds @@ -1839,7 +1840,7 @@ def identify_strict(self, callexpr, mtds, **kwargs): def match_strict(self, arg_typs, param_typs, **kwargs): for atyp,ptyp in zip(arg_typs, param_typs): - if ptyp.name in map(lambda p: p.name, param_typs): continue + if ptyp.name in [p.name for p in param_typs]: continue if not (self.identity_conversion(atyp,ptyp) or \ self.primitive_widening(atyp,ptyp) or \ self.reference_widening(atyp,ptyp)): @@ -1858,8 +1859,8 @@ def identify_loose(self, callexpr, mtds, **kwargs): def match_loose(self, arg_typs, param_typs, typeParameters): # TODO: Spec says if the result is a raw type, do an unchecked conversion. Does this already happen? for atyp,ptyp in zip(arg_typs, param_typs): - if ptyp.name in map(lambda p: p.name, param_typs): continue - if ptyp.name in map(lambda p: p.name, typeParameters) and not isinstance(atyp, PrimitiveType): continue + if ptyp.name in [p.name for p in param_typs]: continue + if ptyp.name in [p.name for p in typeParameters] and not isinstance(atyp, PrimitiveType): continue # going to ignore, identity and widenings b/c they should be caught with strict if not (self.boxing_conversion(atyp, ptyp) or \ (self.unboxing_conversion(atyp, ptyp) and \ @@ -1871,8 +1872,8 @@ def most(candidate, others): ctypes = candidate.param_typs() for i in range(len(others)): # if the parameters of the candidate aren't less specific than all the parameters of other - if not all(map(lambda t: utils.is_subtype(t[0], t[1]), \ - zip(ctypes, others[i].param_typs()))): + if not all([utils.is_subtype(t[0], t[1]) for t in + zip(ctypes, others[i].param_typs())]): return False return True for mi in xrange(len(mtds)): @@ -2139,7 +2140,8 @@ def change_call(s, *args): # apply change_call to every statement, and every statement's children # note that stmt is changed first, followed by it's children - map(lambda s: utils.walk(change_call, s), stmts) + for s in stmts: + utils.walk(change_call, s) # alter stmts to wrap and unwrap primitives appropriately new_stmts = [] diff --git a/java_sk/util.py b/java_sk/util.py index f4a05cd..941319d 100644 --- a/java_sk/util.py +++ b/java_sk/util.py @@ -41,17 +41,18 @@ def clean_dir(path): def add_object(ast): clss = utils.extract_nodes([ClassOrInterfaceDeclaration], ast) - clss = filter(lambda c: c.name != u'Object', clss) + clss = [c for c in clss if c.name != u'Object'] obj = ast.symtab.get(u'Object') def obj_subs(n): if not n.extendsList: n.extendsList = [obj] obj.subClasses.append(n) - map(obj_subs, clss) + for c in clss: + obj_subs(c) ast.types.append(obj) def rm_subs(clss): - return filter(lambda c: not c.extendsList and not c.implementsList, clss) + return [c for c in clss if not c.extendsList and not c.implementsList] def sanitize_mname(mname): return mname.replace("[]",'s') diff --git a/jskparser/ast/body/axiomdeclaration.py b/jskparser/ast/body/axiomdeclaration.py index 8a3e208..387b465 100644 --- a/jskparser/ast/body/axiomdeclaration.py +++ b/jskparser/ast/body/axiomdeclaration.py @@ -19,13 +19,11 @@ def __init__(self, kwargs={}): # List parameters params = kwargs.get(u'parameters', []) - self._parameters = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - params.get(u'@e', [])) if params else [] + self._parameters = [locs[x[u'@t']](x) if u'@t' in x else [] for x in params.get(u'@e', [])] if params else [] # List typeParameters = kwargs.get(u'typeParameters', []) - self._typeParameters = map(lambda x: TypeParameter(x) if u'@t' in x else [], - typeParameters.get(u'@e', [])) if typeParameters else [] + self._typeParameters = [TypeParameter(x) if u'@t' in x else [] for x in typeParameters.get(u'@e', [])] if typeParameters else [] # BlockStmt body; body = kwargs.get(u'body') @@ -36,8 +34,8 @@ def __init__(self, kwargs={}): self.add_as_parent(self.parameters+[self.typee]+[self.body]) # if self._body and self._body.childrenNodes: - # chs = filter(lambda c: not isinstance(c, Comment), self._body.childrenNodes) - # if chs: chs[0].in_set = set(map(lambda x: x.lbl, self._parameters)) + # chs = [c for c in self._body.childrenNodes if not isinstance(c, Comment)] + # if chs: chs[0].in_set = set([x.lbl for x in self._parameters]) @property def typeParameters(self): return self._typeParameters @@ -76,13 +74,13 @@ def name(self, v): self._name = v def adtName(self): typs = self.iddTypes() - return '_'.join([self.name] + map(str, typs)) + return '_'.join([self.name] + [str(t) for t in typs]) def iddTypes(self): - return map(lambda i: i.idd.typee, filter(lambda p: p.idd, self.parameters)) + return [i.idd.typee for i in [p for p in self.parameters if p.idd]] - def param_typs(self): return map(lambda p: p.typee, self.parameters) - def param_names(self): return map(lambda p: p.name, self.parameters) + def param_typs(self): return [p.typee for p in self.parameters] + def param_names(self): return [p.name for p in self.parameters] def sig(self): return 'a{}'.format(str(self)) @@ -107,7 +105,7 @@ def ptypes(): else: params.append(str(p.method.typee)) return params - pots = filter(lambda m: m.name == self.name and len(m.parameters) == len(self.parameters)-1, adt_mtds) + pots = [m for m in adt_mtds if m.name == self.name and len(m.parameters) == len(self.parameters)-1] name1 = u'_'.join([self.name] + ptypes()) name2 = pots[0].name_no_nested(False) if len(pots) > 0 else '' diff --git a/jskparser/ast/body/axiomparameter.py b/jskparser/ast/body/axiomparameter.py index ee919a3..f374912 100644 --- a/jskparser/ast/body/axiomparameter.py +++ b/jskparser/ast/body/axiomparameter.py @@ -27,8 +27,7 @@ def __init__(self, kwargs={}): # List annotations; annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [locs[x[u'@t']](x) if u'@t' in x else [] for x in annotations.get(u'@e', [])] if annotations else [] self.add_as_parent([self.typee]+[self.annotations]) if self._id: self.add_as_parent([self._id]) diff --git a/jskparser/ast/body/bodydeclaration.py b/jskparser/ast/body/bodydeclaration.py index fe5bde4..14883a5 100644 --- a/jskparser/ast/body/bodydeclaration.py +++ b/jskparser/ast/body/bodydeclaration.py @@ -13,8 +13,7 @@ def __init__(self, kwargs={}): # List annotations; annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [locs[x[u'@t']](x) if u'@t' in x else [] for x in annotations.get(u'@e', [])] if annotations else [] @property def annotations(self): return self._annotations diff --git a/jskparser/ast/body/classorinterfacedeclaration.py b/jskparser/ast/body/classorinterfacedeclaration.py index f701928..5811244 100644 --- a/jskparser/ast/body/classorinterfacedeclaration.py +++ b/jskparser/ast/body/classorinterfacedeclaration.py @@ -20,8 +20,7 @@ def __init__(self, kwargs={}): # List typeParameters = kwargs.get(u'typeParameters', []) - self._typeParameters = map(lambda x: TypeParameter(x) if u'@t' in x else [], - typeParameters.get(u'@e', [])) if typeParameters else [] + self._typeParameters = [TypeParameter(x) if u'@t' in x else [] for x in typeParameters.get(u'@e', [])] if typeParameters else [] # Can contain more than one item if this is an interface # List @@ -40,9 +39,9 @@ def __init__(self, kwargs={}): self._axiom = False self._box = False if self.annotations: - # self._axiom = any(map(lambda a: str(a) == 'axiomClass', self.annotations)) - self._axiom = any(map(lambda a: str(a) == 'rewriteClass', self.annotations)) - self._box = any(map(lambda a: str(a) == 'autoBox', self.annotations)) + # self._axiom = any([str(a) == 'axiomClass' for a in self.annotations]) + self._axiom = any([str(a) == 'rewriteClass' for a in self.annotations]) + self._box = any([str(a) == 'autoBox' for a in self.annotations]) self.add_as_parent(self.typeParameters+self.extendsList+self.implementsList+self.subClasses) @@ -83,7 +82,8 @@ def get_sups(n): print('ERROR: class {} not in symbol table of {}'.format(e.name, n.name)) # library? continue lst.extend(sups) - map(get_sups, sups) + for sup in sups: + get_sups(sup) get_sups(self) return lst @@ -114,7 +114,7 @@ def subClasses(self, v): self._subClasses = v @property def fullname(self): - return '_'.join(map(lambda c: c.name, self.enclosing_types()) + [self.name]) + return '_'.join([c.name for c in self.enclosing_types()] + [self.name]) @fullname.setter def fullname(self, v): self._fullname = v diff --git a/jskparser/ast/body/constructordeclaration.py b/jskparser/ast/body/constructordeclaration.py index 89a10a8..662fb39 100644 --- a/jskparser/ast/body/constructordeclaration.py +++ b/jskparser/ast/body/constructordeclaration.py @@ -21,21 +21,18 @@ def __init__(self, kwargs={}): # List params = kwargs.get(u'parameters', {}) - self._parameters = map(lambda x: locs[x[u'@t']](x), - params.get(u'@e', [])) if params else [] + self._parameters = [locs[x[u'@t']](x) for x in params.get(u'@e', [])] if params else [] # List typeParameters = kwargs.get(u'typeParameters', {}) - self._typeParameters = map(lambda x: TypeParameter(x) if u'@t' in x else [], - typeParameters.get(u'@e', [])) if typeParameters else [] + self._typeParameters = [TypeParameter(x) if u'@t' in x else [] for x in typeParameters.get(u'@e', [])] if typeParameters else [] # Type (just the class name wrapped in a Type) self._type = ClassOrInterfaceType(kwargs.get(u'name',{})) # List throws_; throws = kwargs.get(u'throws_', {}) - self._throws = map(lambda x: locs[u'NameExpr'](x) if u'@t' in x else [], - throws.get(u'@e', [])) if throws else [] + self._throws = [locs[u'NameExpr'](x) if u'@t' in x else [] for x in throws.get(u'@e', [])] if throws else [] # BlockStmt block; body = kwargs.get(u'block') @@ -81,8 +78,8 @@ def typeParameters(self): return self._typeParameters @typeParameters.setter def typeParameters(self, v): self._typeParameters = v - def param_typs(self): return map(lambda p: p.typee, self.parameters) - def param_names(self): return map(lambda p: p.name, self.parameters) + def param_typs(self): return [p.typee for p in self.parameters] + def param_names(self): return [p.name for p in self.parameters] def sig(self): return 'm{}'.format(str(self)) @@ -91,5 +88,5 @@ def __str__(self): cls = self.get_coid() nm = '{0}_{0}'.format(str(cls)) if cls.isinner(): nm += '_{}'.format(str(cls.get_coid())) - params = map(self.sanitize_ty, map(lambda p: p.typee.name, self.parameters)) + params = [self.sanitize_ty(p.typee.name) for p in self.parameters] return u'_'.join([nm] + params) diff --git a/jskparser/ast/body/methoddeclaration.py b/jskparser/ast/body/methoddeclaration.py index 6edf2a0..4dec410 100644 --- a/jskparser/ast/body/methoddeclaration.py +++ b/jskparser/ast/body/methoddeclaration.py @@ -25,29 +25,26 @@ def __init__(self, kwargs={}): # List parameters params = kwargs.get(u'parameters', []) self._params = params - self._parameters = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - params.get(u'@e', [])) if params else [] + self._parameters = [locs[x[u'@t']](x) if u'@t' in x else [] for x in params.get(u'@e', [])] if params else [] # List typeParameters = kwargs.get(u'typeParameters', []) - self._typeParameters = map(lambda x: TypeParameter(x) if u'@t' in x else [], - typeParameters.get(u'@e', [])) if typeParameters else [] + self._typeParameters = [TypeParameter(x) if u'@t' in x else [] for x in typeParameters.get(u'@e', [])] if typeParameters else [] # int arrayCount; self._arrayCount = kwargs.get(u'arrayCount', 0) # List throws_; throws = kwargs.get(u'throws_', []) - self._throws = map(lambda x: locs[u'ReferenceType'](x) if u'@t' in x else [], - throws.get(u'@e', [])) if throws else [] + self._throws = [locs[u'ReferenceType'](x) if u'@t' in x else [] for x in throws.get(u'@e', [])] if throws else [] # BlockStmt body; body = kwargs.get(u'body') self._body = locs[u'BlockStmt'](body) if body else None if self._body and self._body.childrenNodes: - chs = filter(lambda c: not isinstance(c, Comment), self._body.childrenNodes) - if chs: chs[0].in_set = set(map(lambda x: x.lbl, self._parameters)) + chs = [c for c in self._body.childrenNodes if not isinstance(c, Comment)] + if chs: chs[0].in_set = set([x.lbl for x in self._parameters]) self._adt = False self._pure = False @@ -57,13 +54,13 @@ def __init__(self, kwargs={}): self._boxedArgs = [] self._is_bang = False if self.annotations: - # self._adt = any(map(lambda a: str(a) == 'adt', self.annotations)) - self._adt = any(map(lambda a: str(a) == 'alg', self.annotations)) - self._pure = any(map(lambda a: str(a) == 'pure', self.annotations)) - self._default = any(map(lambda a: str(a) == 'default', self.annotations)) - self._constructor = any(map(lambda a: str(a) == 'constructor', self.annotations)) - self._boxedRet = any(map(lambda a: str(a) == 'boxedRet', self.annotations)) - self._boxedArgs = map(lambda m: int(m.memberValue.value), filter(lambda a: str(a) == 'boxedArgs', self.annotations)) + # self._adt = any([str(a) == 'adt' for a in self.annotations]) + self._adt = any([str(a) == 'alg' for a in self.annotations]) + self._pure = any([str(a) == 'pure' for a in self.annotations]) + self._default = any([str(a) == 'default' for a in self.annotations]) + self._constructor = any([str(a) == 'constructor' for a in self.annotations]) + self._boxedRet = any([str(a) == 'boxedRet' for a in self.annotations]) + self._boxedArgs = [int(m.memberValue.value) for m in [a for a in self.annotations if str(a) == 'boxedArgs']] self._bang = kwargs.get(u'bang', False) self._adtType = kwargs.get(u'adtType', False) @@ -169,8 +166,8 @@ def adtName(self): return self._adtName @adtName.setter def adtName(self, v): self._adtName = v - def param_typs(self): return map(lambda p: p.typee, self.parameters) - def param_names(self): return map(lambda p: p.name, self.parameters) + def param_typs(self): return [p.typee for p in self.parameters] + def param_names(self): return [p.name for p in self.parameters] def get_xform(self): from .xform import Xform @@ -209,7 +206,7 @@ def ptypes(): typ = '' if p.idd: typ = str(p.typee.name) else: typ = str(p.method.typee) - # if typ.capitalize() in map(str, self.parentNode.typeParameters): + # if typ.capitalize() in list(map(str, self.parentNode.typeParameters)): # print("\t\tHERE43: "+str(typ.capitalize())) # typ = u'Object' params.append(typ) @@ -222,7 +219,7 @@ def __str__(self): name = '_'.join(name.split('_')[:2]) # return self.name_no_nested(False) - params = map(self.sanitize_ty, map(lambda p: p.typee.name, self.parameters)) + params = [self.sanitize_ty(p.typee.name) for p in self.parameters] if self.adt: params = ["Object"]+params diff --git a/jskparser/ast/body/parameter.py b/jskparser/ast/body/parameter.py index 93ac867..c654444 100644 --- a/jskparser/ast/body/parameter.py +++ b/jskparser/ast/body/parameter.py @@ -28,8 +28,7 @@ def __init__(self, kwargs={}): # List annotations; annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [locs[x[u'@t']](x) if u'@t' in x else [] for x in annotations.get(u'@e', [])] if annotations else [] self.add_as_parent([self.idd]) diff --git a/jskparser/ast/body/typedeclaration.py b/jskparser/ast/body/typedeclaration.py index e1c5813..0221b61 100644 --- a/jskparser/ast/body/typedeclaration.py +++ b/jskparser/ast/body/typedeclaration.py @@ -16,8 +16,7 @@ def __init__(self, kwargs={}): # List self._members = [] - self._members.extend(map(lambda x: locs[x[u'@t']](x), - kwargs.get(u'members', {}).get(u'@e', []))) + self._members.extend([locs[x[u'@t']](x) for x in kwargs.get(u'members', {}).get(u'@e', [])]) self.add_as_parent(self.members) diff --git a/jskparser/ast/body/xform.py b/jskparser/ast/body/xform.py index 7841aad..208ae97 100644 --- a/jskparser/ast/body/xform.py +++ b/jskparser/ast/body/xform.py @@ -141,7 +141,7 @@ def gen_switch(self, adt_mtds, depth, arg, cls, mtd, args, is_ax_cls, mtd_name, # print("HERE: "+str(mtd_name).lower()) # for a in adt_mtds: # print("\t: "+str(a.name).lower()) - current_mtds = filter(lambda m: m.adt and str(m.name).lower() == str(mtd_name).lower(), mtds) + current_mtds = [m for m in mtds if m.adt and str(m.name).lower() == str(mtd_name).lower()] # name = u'selff' name = str(arg.name) @@ -192,8 +192,8 @@ def gen_switch(self, adt_mtds, depth, arg, cls, mtd, args, is_ax_cls, mtd_name, u'right': {u'@t':u'NullLiteralExpr',}, u'op': {u'name': u'equals',},} - adt_mtd = filter(lambda m: str(m.name).lower() == str(self.name.split('_')[1]).lower() or str(m.name).lower() + u'b' == str(self.name.split('_')[1]).lower(), mtds)[0] - # adt_mtd = filter(lambda m: m.adt and m.name == a.name, mtds)[0] + adt_mtd = [m for m in mtds if str(m.name).lower() == str(self.name.split('_')[1]).lower() or str(m.name).lower() + u'b' == str(self.name.split('_')[1]).lower()][0] + # adt_mtd = [m for m in mtds if m.adt and m.name == a.name][0] ret_val = u'new '+str(mtd.name).lower().capitalize()+u'(self=selff._'+str(cls).lower() for ap,mp in zip(adt_mtd.parameters, args[1:]): @@ -280,7 +280,8 @@ def build_switch(self, cases, body, adt_mtds, depth, arg_num, args, switch, cls, b.stmts = body s.stmts = [b] b.add_parent_post(s, True) - map(lambda s: s.add_parent_post(b), body) + for s in body: + s.add_parent_post(b) else: b = BlockStmt() switch2 = s.stmts[0].stmts[0] if len(s.stmts) > 0 else None @@ -289,7 +290,8 @@ def build_switch(self, cases, body, adt_mtds, depth, arg_num, args, switch, cls, b.stmts = body s.stmts = [b] b.add_parent_post(s, True) - map(lambda s: s.add_parent_post(b), body) + for s in body: + s.add_parent_post(b) return new_block @@ -309,7 +311,8 @@ def add_body(self, cases, body, adt_mtds): b.stmts = body s.stmts = [b] b.add_parent_post(s, True) - map(lambda s: s.add_parent_post(b), body) + for s in body: + s.add_parent_post(b) def create_normal_body(self, body): self.normal_body = True @@ -338,7 +341,8 @@ def add_body_nested(self, casess, body, adt_mtds, args, cls, a, is_ax_cls): b.stmts = body s.stmts = [b] b.add_parent_post(s, True) - map(lambda s: s.add_parent_post(b), body) + for s in body: + s.add_parent_post(b) else: b = BlockStmt() switch = s.stmts[0].stmts[0] if len(s.stmts) > 0 else None @@ -347,7 +351,8 @@ def add_body_nested(self, casess, body, adt_mtds, args, cls, a, is_ax_cls): b.stmts = body s.stmts = [b] b.add_parent_post(s, True) - map(lambda s: s.add_parent_post(b), body) + for s in body: + s.add_parent_post(b) # def areNamesEqual(self, diff --git a/jskparser/ast/compilationunit.py b/jskparser/ast/compilationunit.py index 1e5f980..3a2b18e 100644 --- a/jskparser/ast/compilationunit.py +++ b/jskparser/ast/compilationunit.py @@ -16,14 +16,14 @@ def __init__(self, kwargs={}): # List imports = kwargs.get('imports') - self._imports = map(lambda x: locs[u'ImportDeclaration'](x), - imports.get('@e', [])) if imports else [] + self._imports = [locs[u'ImportDeclaration'](x) for x in + imports.get('@e', [])] if imports else [] # for i in self._imports: print i.name # List types = kwargs.get('types') - self._types = map(lambda x: locs[x['@t']](x), - types.get('@e', [])) if types else [] + self._types = [locs[x['@t']](x) for x in + types.get('@e', [])] if types else [] self._gsymtab = self.GSYMTAB @property diff --git a/jskparser/ast/dataflow/dataflow.py b/jskparser/ast/dataflow/dataflow.py index 2e966b3..9b8b999 100644 --- a/jskparser/ast/dataflow/dataflow.py +++ b/jskparser/ast/dataflow/dataflow.py @@ -165,7 +165,7 @@ def _compute_in_out(self, n): names = utils.extract_nodes([NameExpr], n) names = [nm.name for nm in names] # TODO: can return more than one name, don't know if that makes sense - n.out_set = set(filter(lambda x: x[0] in names, n.in_set)) + n.out_set = set([x for x in n.in_set if x[0] in names]) # out_set has changed. out_set of these are handled above elif t != n.out_set and type(n) not in NO_OUT: @@ -181,8 +181,8 @@ def _compute_in_out(self, n): def _inputs(self, n, c_defs): for ch in n.childrenNodes: self._inputs(ch, c_defs) - reach_x = filter(lambda x: x[0] == ch.lbl[0], ch.in_set) - ins = self._rm_dups(filter(lambda x: x in c_defs, reach_x)) + reach_x = [x for x in ch.in_set if x[0] == ch.lbl[0]] + ins = self._rm_dups([x for x in reach_x if x in c_defs]) if self._debug: print('ch:', ch, 'ch.in_set:', ch.in_set, \ 'reach_x:', reach_x, \ @@ -205,7 +205,7 @@ def _gen_inputs(self, method): if self._debug: print('*******inputs*******') # need to add this to the initial context if it is at the start of method - params = map(lambda x: x.lbl, method.parameters) + params = [x.lbl for x in method.parameters] # c_defs are all the defs leaving the context. defs in e will have to # be part of this set to be valid inputs c_defs = ctx.childrenNodes[-1].out_set.union(set(params)) if ctx.childrenNodes else set(params) @@ -222,9 +222,10 @@ def _gen_inputs(self, method): e.childrenNodes[-1].outputs = [] ins = set([]) - map(lambda x: ins.update(x.inputs), ctx.childrenNodes) + for x in ctx.childrenNodes: + ins.update(x.inputs) if ins: - e.childrenNodes[-1].outputs = [map(lambda t: t.name, map(self.get_typ, list(self._rm_dups(ins))))[0]] + e.childrenNodes[-1].outputs = [[self.get_typ(i).name for i in list(self._rm_dups(ins))][0]] else: if utils.extract_nodes([ReturnStmt], e): e.childrenNodes[-1].outputs = [unicode(method.typee)] @@ -232,11 +233,12 @@ def _gen_inputs(self, method): # we need all the inputs for all the childrenNodes of e # TODO: can we assume we can just smash all the inputs together? ins = set([]) - map(lambda x: ins.update(x.inputs), e.childrenNodes) + for x in e.childrenNodes: + ins.update(x.inputs) def to_nm(n): - n.inputs = map(lambda t: t.name, map(self.get_typ, n.inputs)) + n.inputs = [self.get_typ(i).name for i in n.inputs] self._walk(to_nm, e) - e.childrenNodes[0].inputs = map(lambda t: t.name, map(self.get_typ, ins)) + e.childrenNodes[0].inputs = [self.get_typ(i).name for i in ins] return e.childrenNodes[0].inputs, e.childrenNodes[-1].outputs def get_typ(self, lbl): @@ -261,12 +263,12 @@ def _minus(self, inn, kill): elif not kill: return set(inn) s = cp.copy(inn) for k in kill: - s = filter(lambda x: x[0] != k[0], s) + s = [x for x in s if x[0] != k[0]] return s def _intersection(self, s0, s1): - names = map(lambda x: x[0], list(s0)) - return set(filter(lambda x: x[0] in names, list(s1))) + names = [x[0] for x in list(s0)] + return set([x for x in list(s1) if x[0] in names]) def _wappend(self, n, *args): self._worklist.append(n) diff --git a/jskparser/ast/expr/arraycreationexpr.py b/jskparser/ast/expr/arraycreationexpr.py index 330efe3..e5e7151 100644 --- a/jskparser/ast/expr/arraycreationexpr.py +++ b/jskparser/ast/expr/arraycreationexpr.py @@ -24,8 +24,8 @@ def __init__(self, kwargs={}): # List dimensions; dim = kwargs.get(u'dimensions', {}) - self._dimensions = map(lambda e: locs[e[u'@t']](e) if u'@t' in e else [], - dim.get(u'@e', [])) if dim else [] + self._dimensions = [locs[e[u'@t']](e) if u'@t' in e else [] for e in + dim.get(u'@e', [])] if dim else [] # List> arraysAnnotations; self._arraysAnnotations = [] diff --git a/jskparser/ast/expr/arrayinitializerexpr.py b/jskparser/ast/expr/arrayinitializerexpr.py index f722b49..52ac1bb 100644 --- a/jskparser/ast/expr/arrayinitializerexpr.py +++ b/jskparser/ast/expr/arrayinitializerexpr.py @@ -12,8 +12,8 @@ def __init__(self, kwargs={}): # List values; v = kwargs.get(u'values', {}) - self._values = map(lambda e: locs[e[u'@t']](e) if u'@t' in e else [], - v.get(u'@e', [])) if v else [] + self._values = [locs[e[u'@t']](e) if u'@t' in e else [] for e in + v.get(u'@e', [])] if v else [] self.add_as_parent(self.values) diff --git a/jskparser/ast/expr/generatorexpr.py b/jskparser/ast/expr/generatorexpr.py index a669850..5f56a6f 100644 --- a/jskparser/ast/expr/generatorexpr.py +++ b/jskparser/ast/expr/generatorexpr.py @@ -18,8 +18,8 @@ def __init__(self, kwargs={}): # List Expression exprs = kwargs.get(u'exprs', {}) - self._exprs = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - exprs.get(u'@e', [])) if exprs else [] + self._exprs = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + exprs.get(u'@e', [])] if exprs else [] self.add_as_parent(self.exprs) diff --git a/jskparser/ast/expr/methodcallexpr.py b/jskparser/ast/expr/methodcallexpr.py index a7cac42..fcaac19 100644 --- a/jskparser/ast/expr/methodcallexpr.py +++ b/jskparser/ast/expr/methodcallexpr.py @@ -33,8 +33,8 @@ def __init__(self, kwargs={}): # List args; args = kwargs.get(u'args', {}) - self._args = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - args.get(u'@e', [])) if args else [] + self._args = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + args.get(u'@e', [])] if args else [] self.add_as_parent([self.scope]+self.args) @@ -124,12 +124,12 @@ def typee(self): nm = self.sig().split('_') args = nm[1:] nm = nm[0] - tps = map(str, cls.typeParameters) + tps = [str(p) for p in cls.typeParameters] if len(args) == 1: - nms = map(lambda n: '_'.join([nm, n]), tps) + nms = ['_'.join([nm, n]) for n in tps] else: - nms = map(lambda n: '_'.join([nm]+list(n)), list(itertools.chain(itertools.product(tps,args), itertools.product(args,tps)))) - nms.extend(map(lambda n: '_'.join([nm]+list(n)), list(itertools.chain(itertools.product(tps, tps))))) + nms = ['_'.join([nm]+list(n)) for n in list(itertools.chain(itertools.product(tps,args), itertools.product(args,tps)))] + nms.extend(['_'.join([nm]+list(n)) for n in list(itertools.chain(itertools.product(tps, tps)))]) for n in nms: if cls.symtab.get(n): return cls.symtab.get(n).typee @@ -160,12 +160,12 @@ def identify_potentials(self, callexpr, cls): call_arg_typs = callexpr.arg_typs() for key,val in cls.symtab.items(): if type(val) != MethodDeclaration: continue - tparam_names = map(lambda t: t.name, val.typeParameters) - tparam_names.extend(map(lambda t: t.name, val.get_coid().typeParameters)) + tparam_names = [t.name for t in val.typeParameters] + tparam_names.extend([t.name for t in val.get_coid().typeParameters]) if callexpr.name == val.name and len(callexpr.args) == len(val.parameters): - if all(map(lambda t: t[1].name in tparam_names or utils.is_subtype(t[0], t[1]), - zip(call_arg_typs, val.param_typs()))): + if all([t[1].name in tparam_names or utils.is_subtype(t[0], t[1]) for t in + zip(call_arg_typs, val.param_typs())]): mtds.append(val) return mtds @@ -180,7 +180,7 @@ def identify_strict(self, callexpr, mtds, **kwargs): def match_strict(self, arg_typs, param_typs, **kwargs): for atyp,ptyp in zip(arg_typs, param_typs): - if ptyp.name in map(lambda p: p.name, param_typs): continue + if ptyp.name in [p.name for p in param_typs]: continue if not (self.identity_conversion(atyp,ptyp) or \ self.primitive_widening(atyp,ptyp) or \ self.reference_widening(atyp,ptyp)): @@ -199,8 +199,8 @@ def identify_loose(self, callexpr, mtds, **kwargs): def match_loose(self, arg_typs, param_typs, typeParameters): # TODO: Spec says if the result is a raw type, do an unchecked conversion. Does this already happen? for atyp,ptyp in zip(arg_typs, param_typs): - if ptyp.name in map(lambda p: p.name, param_typs): continue - if ptyp.name in map(lambda p: p.name, typeParameters) and not isinstance(atyp, PrimitiveType): continue + if ptyp.name in [p.name for p in param_typs]: continue + if ptyp.name in [p.name for p in typeParameters] and not isinstance(atyp, PrimitiveType): continue # going to ignore, identity and widenings b/c they should be caught with strict if not (self.boxing_conversion(atyp, ptyp) or \ (self.unboxing_conversion(atyp, ptyp) and \ @@ -212,8 +212,8 @@ def most(candidate, others): ctypes = candidate.param_typs() for i in range(len(others)): # if the parameters of the candidate aren't less specific than all the parameters of other - if not all(map(lambda t: utils.is_subtype(t[0], t[1]), \ - zip(ctypes, others[i].param_typs()))): + if not all([utils.is_subtype(t[0], t[1]) for t in + zip(ctypes, others[i].param_typs())]): return False return True for mi in xrange(len(mtds)): @@ -247,7 +247,7 @@ def typee(self, v): self._typee = v def sig(self): return 'm{}'.format(str(self)) - # atyps = ','.join(map(str, self.arg_typs())) if self.args else '' + # atyps = ','.join([str(t) for t in self.arg_typs()]) if self.args else '' # return '{} {}({});'.format(str(self.typee), str(self), atyps) def arg_typs(self): @@ -294,6 +294,6 @@ def __str__(self): name = self.name+'b' if self._add_bang else self.name if a: return '_'.join([self.sanitize_ty(name)] + \ - map(lambda a: self.sanitize_ty(a.name), a)) + [self.sanitize_ty(a.name) for a in a]) else: return self.name diff --git a/jskparser/ast/expr/objectcreationexpr.py b/jskparser/ast/expr/objectcreationexpr.py index d597068..0af7c40 100644 --- a/jskparser/ast/expr/objectcreationexpr.py +++ b/jskparser/ast/expr/objectcreationexpr.py @@ -25,20 +25,20 @@ def __init__(self, kwargs={}): # List typeArgs; typeArgs = kwargs.get(u'typeArgs', {}) - self._typeArgs = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - typeArgs.get(u'@e', [])) if typeArgs else [] + self._typeArgs = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + typeArgs.get(u'@e', [])] if typeArgs else [] # List args; args = kwargs.get(u'args', {}) self._tmpargs = args - self._args = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - args.get(u'@e', [])) if args else [] + self._args = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + args.get(u'@e', [])] if args else [] # This can be null, to indicate there is no body # List anonymousClassBody; anon = kwargs.get(u'anonymousClassBody', {}) - self._anonymousClassBody = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - anon.get(u'@e', [])) if anon else [] + self._anonymousClassBody = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + anon.get(u'@e', [])] if anon else [] box = kwargs.get(u'box', {}) self._box = box if box else False diff --git a/jskparser/ast/expr/variabledeclarationexpr.py b/jskparser/ast/expr/variabledeclarationexpr.py index 748410b..18b4868 100644 --- a/jskparser/ast/expr/variabledeclarationexpr.py +++ b/jskparser/ast/expr/variabledeclarationexpr.py @@ -19,14 +19,14 @@ def __init__(self, kwargs={}): # List vars var = kwargs.get(u'vars', {}).get(u'@e') - self._varss = map(lambda v: VariableDeclarator(v), var) + self._varss = [VariableDeclarator(v) for v in var] self._arrayCount = kwargs.get(u'arrayCount', 0) # List annotations annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + annotations.get(u'@e', [])] if annotations else [] self.add_as_parent([self.typee]+self.varss) diff --git a/jskparser/ast/node.py b/jskparser/ast/node.py index ac9ce56..b45a35d 100644 --- a/jskparser/ast/node.py +++ b/jskparser/ast/node.py @@ -54,8 +54,8 @@ def __init__(self, kwargs={}): # List orphanComments orphanComments = kwargs.get(u'orphanComments', []) - self._orphanComments = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - orphanComments.get(u'@e', [])) if orphanComments else [] + self._orphanComments = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + orphanComments.get(u'@e', [])] if orphanComments else [] # JavadocComment javadocComment; jdc = kwargs.get(u'javadoccomment', {}) self._javadocComment = locs[u'JavadocComment'](jdc) if jdc else {} diff --git a/jskparser/ast/stmt/explicitconstructorinvocationstmt.py b/jskparser/ast/stmt/explicitconstructorinvocationstmt.py index 353b1b4..9885c84 100644 --- a/jskparser/ast/stmt/explicitconstructorinvocationstmt.py +++ b/jskparser/ast/stmt/explicitconstructorinvocationstmt.py @@ -26,8 +26,8 @@ def __init__(self, kwargs={}): # List args; args = kwargs.get(u'args', {}) - self._args = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - args.get(u'@e', [])) if args else [] + self._args = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + args.get(u'@e', [])] if args else [] self.add_as_parent([self.expr]+self.args) diff --git a/jskparser/ast/stmt/forstmt.py b/jskparser/ast/stmt/forstmt.py index 27217cc..6efdef6 100644 --- a/jskparser/ast/stmt/forstmt.py +++ b/jskparser/ast/stmt/forstmt.py @@ -11,8 +11,8 @@ def __init__(self, kwargs={}): # List init; init = kwargs.get(u'init', {}) - self._init = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - init.get(u'@e', [])) if init else [] + self._init = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + init.get(u'@e', [])] if init else [] # Expression compare; compare = kwargs.get(u'compare', {}) @@ -20,8 +20,8 @@ def __init__(self, kwargs={}): # List update; update = kwargs.get(u'update', {}) - self._update = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - update.get(u'@e', [])) if update else [] + self._update = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + update.get(u'@e', [])] if update else [] # Statement body; body = kwargs.get(u'body', {}) diff --git a/jskparser/ast/stmt/switchentrystmt.py b/jskparser/ast/stmt/switchentrystmt.py index b86734f..ea6852b 100644 --- a/jskparser/ast/stmt/switchentrystmt.py +++ b/jskparser/ast/stmt/switchentrystmt.py @@ -16,8 +16,8 @@ def __init__(self, kwargs={}): # List stmts; s = kwargs.get(u'stmts', {}) - self._stmts = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - s.get(u'@e', [])) if s else [] + self._stmts = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + s.get(u'@e', [])] if s else [] self.add_as_parent([self.label]+self.stmts) diff --git a/jskparser/ast/stmt/switchstmt.py b/jskparser/ast/stmt/switchstmt.py index c05748d..f1ce6f6 100644 --- a/jskparser/ast/stmt/switchstmt.py +++ b/jskparser/ast/stmt/switchstmt.py @@ -17,7 +17,7 @@ def __init__(self, kwargs={}): # List entries; en = kwargs.get(u'entries', {}).get(u'@e') - self._entries = map(lambda e: SwitchEntryStmt(e), en) if en else [] + self._entries = [SwitchEntryStmt(e) for e in en] if en else [] self.add_as_parent([self.selector]+self.entries) diff --git a/jskparser/ast/stmt/trystmt.py b/jskparser/ast/stmt/trystmt.py index 9eb3977..c8dda36 100644 --- a/jskparser/ast/stmt/trystmt.py +++ b/jskparser/ast/stmt/trystmt.py @@ -11,8 +11,8 @@ def __init__(self, kwargs={}): # List resources; resources = kwargs.get(u'resources', {}) - self._resources = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - resources.get(u'@e', [])) if resources else [] + self._resources = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + resources.get(u'@e', [])] if resources else [] # BlockStmt tryBlock; tryBlock = kwargs.get(u'tryBlock', {}) @@ -20,8 +20,8 @@ def __init__(self, kwargs={}): # List catchs; catchs = kwargs.get(u'catchs', []) - self._catchs = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - catchs.get(u'@e', [])) if catchs else [] + self._catchs = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + catchs.get(u'@e', [])] if catchs else [] # BlockStmt finallyBlock; finallyBlock = kwargs.get(u'finallyBlock', {}) diff --git a/jskparser/ast/type/referencetype.py b/jskparser/ast/type/referencetype.py index 26d2158..88df9e2 100644 --- a/jskparser/ast/type/referencetype.py +++ b/jskparser/ast/type/referencetype.py @@ -21,8 +21,8 @@ def __init__(self, kwargs={}): if type(v) == list: self._values = v else: - self._values = map(lambda e: locs[e[u'@t']](e) if u'@t' in e else [], - v.get(u'@e', [])) if v else [] + self._values = [locs[e[u'@t']](e) if u'@t' in e else [] for e in + v.get(u'@e', [])] if v else [] # List> arraysAnnotations; self._arraysAnnotations = [] diff --git a/jskparser/ast/type/type.py b/jskparser/ast/type/type.py index fb0e22b..a373fcc 100644 --- a/jskparser/ast/type/type.py +++ b/jskparser/ast/type/type.py @@ -13,8 +13,8 @@ def __init__(self, kwargs={}): # List annotations; annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + annotations.get(u'@e', [])] if annotations else [] @property def annotations(self): return self._annotations diff --git a/jskparser/ast/typearguments.py b/jskparser/ast/typearguments.py index 095d52c..9eb0d80 100644 --- a/jskparser/ast/typearguments.py +++ b/jskparser/ast/typearguments.py @@ -9,8 +9,8 @@ def __init__(self, kwargs={}): # List typeArguments; typeArguments = kwargs.get(u'typeArguments', []) - self._typeArguments = map(lambda x: locs[x[u'@t']](x) if u'@t' in x else [], - typeArguments.get(u'@e', [])) if typeArguments else [] + self._typeArguments = [locs[x[u'@t']](x) if u'@t' in x else [] for x in + typeArguments.get(u'@e', [])] if typeArguments else [] # boolean usesDiamondOperator; self._usesDiamondOperator = kwargs.get(u'usesDiamondOperator', False) diff --git a/jskparser/ast/typeparameter.py b/jskparser/ast/typeparameter.py index 389d70b..c3c1d32 100644 --- a/jskparser/ast/typeparameter.py +++ b/jskparser/ast/typeparameter.py @@ -16,13 +16,13 @@ def __init__(self, kwargs={}): # List annotations; annotations = kwargs.get(u'annotations', []) - self._annotations = map(lambda x: AnnotationExpr(x) if u'@t' in x else [], - annotations.get(u'@e', [])) if annotations else [] + self._annotations = [AnnotationExpr(x) if u'@t' in x else [] for x in + annotations.get(u'@e', [])] if annotations else [] # List typeBound; typeBound = kwargs.get(u'typeBound', []) - self._typeBound = map(lambda x: ClassOrInterfaceType(x) if u'@t' in x else [], - typeBound.get(u'@e', [])) if typeBound else [] + self._typeBound = [ClassOrInterfaceType(x) if u'@t' in x else [] for x in + typeBound.get(u'@e', [])] if typeBound else [] self.add_as_parent(typeBound) diff --git a/jskparser/ast/utils/utils.py b/jskparser/ast/utils/utils.py index eb0320e..1c74ae3 100644 --- a/jskparser/ast/utils/utils.py +++ b/jskparser/ast/utils/utils.py @@ -115,9 +115,9 @@ def extract_nodes(typ, ast, istance=False, recurse=True): lst = [] def f1(n, *args): if istance: - if any(map(partial(isinstance, n),typ)): lst.append(n) + if any([isinstance(n, t) for t in typ]): lst.append(n) elif type(n) in typ: lst.append(n) - walk(f1, ast) if recurse else map(f1, [ast] + ast.childrenNodes) + walk(f1, ast) if recurse else [f1(c) for c in [ast] + ast.childrenNodes] return lst # check whether node is in AST @@ -182,7 +182,7 @@ def is_subtype(t1, t2): raise Exception('Cant dereference {} or {}'.format(t1.name, t2.name)) if cls1 in cls2.subClasses or cls1 == cls2: return True elif cls2.subClasses: - return any(map(partial(is_subtype, cls1), cls2.subClasses)) + return any([is_subtype(cls1, c) for c in cls2.subClasses]) else: return False def all_subClasses(n): @@ -350,7 +350,7 @@ def anon_nm(a): else: return anon_nm(a.parentNode) def rm_comments(node): - node.childrenNodes = filter(lambda n: not isinstance(n, Comment), node.childrenNodes) + node.childrenNodes = [n for n in node.childrenNodes if not isinstance(n, Comment)] def unpack_class_file(nm): global JAVA_HOME, RT_JAR @@ -391,7 +391,7 @@ def get_descriptors(nm): # this is a cool bit of sorcery to pair names with their descriptors cls = zip(*[iter(cls)]*2) - flds = filter(lambda d: '(' not in d[0] and 'static {};' not in d[0], cls) + flds = [d for d in cls if '(' not in d[0] and 'static {};' not in d[0]] # print 'flds:', flds cls_nm_full = nm.replace('/', '.') # [nm.rfind('/')+1:] @@ -420,7 +420,7 @@ def get_fld_descriptors(path): # print 'fld_descriptors', flds descriptors = [] for d in flds: - nm = filter(lambda n: n not in ACCESS_MODS, d[0].split(' '))[1].strip(';') + nm = [n for n in d[0].split(' ') if n not in ACCESS_MODS][1].strip(';') typ = d[1].split(' ')[1].strip('[L;') if typ[0] == '[': typ = typ[1:] if '/' in typ: typ = typ[typ.rfind('/')+1:] @@ -460,9 +460,9 @@ def filter_by_params(c): ptypes.append(list(typs + [c[-1]])) return True return False - filter(filter_by_params, candidates) - # print 'filtered:', filter(filter_by_params, candidates) - # print 'ptypes:', ptypes + filtered = [filter_by_params(c) for c in candidates] + # print('filtered:', filtered) + # print('ptypes:', ptypes) return ptypes def mtd_type_from_callexpr(callexpr): diff --git a/jskparser/ast/visit/sourcevisitor.py b/jskparser/ast/visit/sourcevisitor.py index 58881d9..cd1de57 100644 --- a/jskparser/ast/visit/sourcevisitor.py +++ b/jskparser/ast/visit/sourcevisitor.py @@ -149,7 +149,7 @@ def visit(self, n): # don't print extends Object if n.extendsList and \ - (u'Object' not in map(lambda e: e.name, n.extendsList) and len(n.extendsList) == 1): + (u'Object' not in [e.name for e in n.extendsList] and len(n.extendsList) == 1): self.printt(' extends ') self.printSepList(n.extendsList) diff --git a/jskparser/ast/visit/symtabgen.py b/jskparser/ast/visit/symtabgen.py index 2f7a847..568c1bd 100644 --- a/jskparser/ast/visit/symtabgen.py +++ b/jskparser/ast/visit/symtabgen.py @@ -58,7 +58,8 @@ def new_symtab(self, n, cp=False): def visit(self, node): if type(node) in self.NONSYM: return self.new_symtab(node) - map(lambda n: n.accept(self), node.childrenNodes) + for n in node.childrenNodes: + n.accept(self) # print "Unimplemented node:", node @v.when(CompilationUnit) @@ -79,7 +80,7 @@ def visit(self, node): } node.imports.append(ImportDeclaration({u'@t':u'ImportDeclaration',u'name':qn, u'implicit': True})) for i in node.imports: node.symtab.update({str(i):i}) - d = dict([v for v in map(lambda t: (t.name,t), node.types)]) + d = dict([v for v in [(t.name,t) for t in node.types]]) for ty in node.types: ty.symtab.update({u'_cu_':node}) if self.lib: @@ -100,11 +101,13 @@ def visit(self, node): [node.symtab.update({n.name:n}) for n in node.extendsList if n.name not in node.symtab] [node.symtab.update({n.name:n}) for n in node.implementsList if n.name not in node.symtab] [node.symtab.update({n.name:n}) for n in node.typeParameters if n.name not in node.symtab] - node.members = filter(lambda n: not isinstance(n, EmptyMemberDeclaration), node.members) - map(lambda n: node.symtab.update({n.name:n} if isinstance(n, FieldDeclaration) or \ + node.members = [n for n in node.members if not isinstance(n, EmptyMemberDeclaration)] + for n in node.members: + node.symtab.update({n.name:n} if isinstance(n, FieldDeclaration) or \ isinstance(n, ClassOrInterfaceDeclaration) else \ - {n.sig():n}), node.members) - map(lambda n: n.accept(self), node.members) + {n.sig():n}) + for n in node.members: + n.accept(self) @v.when(MethodDeclaration) def visit(self, node): @@ -117,11 +120,16 @@ def visit(self, node): if str(node.typee) not in PRIMITIVES and str(node.typee) not in node.symtab: node.symtab.update({str(node.typee):node.typee}) # somethign is weird here. shouldnt have to visit idd and parameters - map(lambda p: p.idd.accept(self), node.parameters) - map(lambda p: p.accept(self), node.parameters) - map(lambda t: node.symtab.update({t.name:t}), node.typeParameters) - map(lambda p: p.idd.symtab.update(node.symtab), node.parameters) - # map(lambda c: c.accept(self), node.childrenNodes) + for p in node.parameters: + p.idd.accept(self) + for p in node.parameters: + p.accept(self) + for t in node.typeParameters: + node.symtab.update({t.name:t}) + for p in node.parameters: + p.idd.symtab.update(node.symtab) + # for c in node.childrenNodes: + # c.accept(self) if node.body: node.body.accept(self) if type(node.parentNode) == ObjectCreationExpr: @@ -144,7 +152,8 @@ def visit(self, node): # for p in node.parameters: # if p.idd: p.idd.accept(self) # if p.method: p.method.accept(self) - map(lambda p: p.accept(self), node.parameters) + for p in node.parameters: + p.accept(self) for p in node.parameters: if p.idd: p.idd.symtab.update(node.symtab) @@ -180,9 +189,12 @@ def visit(self, node): self.new_symtab(node, cp=True) node.parentNode.symtab.update({str(node):node}) node.symtab.update({str(node):node}) - map(lambda p: p.idd.accept(self), node.parameters) - map(lambda p: p.accept(self), node.parameters) - map(lambda p: p.idd.symtab.update(node.symtab), node.parameters) + for p in node.parameters: + p.idd.accept(self) + for p in node.parameters: + p.accept(self) + for p in node.parameters: + p.idd.symtab.update(node.symtab) if node.body: node.body.accept(self) @v.when(FieldDeclaration) @@ -237,29 +249,35 @@ def visit(self, node): @v.when(ExpressionStmt) def visit(self, node): self.new_symtab(node) - map(lambda n: n.accept(self), node.childrenNodes) + for n in node.childrenNodes: + n.accept(self) # expr/ @v.when(FieldAccessExpr) def visit(self, node): self.new_symtab(node, cp=True) - map(lambda n: n.accept(self), node.childrenNodes) + for n in node.childrenNodes: + n.accept(self) @v.when(MethodCallExpr) def visit(self, node): self.new_symtab(node, cp=True) - map(lambda n: n.accept(self), node.childrenNodes) + for n in node.childrenNodes: + n.accept(self) @v.when(VariableDeclarationExpr) def visit(self, node): self.new_symtab(node) - map(lambda v: v.accept(self), node.childrenNodes) - # map(lambda v: v.accept(self), node.varss) + for v in node.childrenNodes: + v.accept(self) + # for v in node.varss: + # v.accept(self) @v.when(BinaryExpr) def visit(self, node): self.new_symtab(node) - map(lambda n: n.accept(self), node.childrenNodes) + for n in node.childrenNodes: + n.accept(self) @v.when(NameExpr) def visit(self, node): diff --git a/jskparser/ast/visit/visit.py b/jskparser/ast/visit/visit.py index 890df4f..bad1199 100644 --- a/jskparser/ast/visit/visit.py +++ b/jskparser/ast/visit/visit.py @@ -46,7 +46,7 @@ def __call__(self, *args, **kw): else: issub = issubclass t = self.targets - ks = t.iterkeys() + ks = iter(t.keys()) return [t[k](*args, **kw) for k in ks if issub(typ, k)] def add_target(self, typ, target): diff --git a/jskparser/jskparser/glob2/impl.py b/jskparser/jskparser/glob2/impl.py index 91a16a8..2374384 100644 --- a/jskparser/jskparser/glob2/impl.py +++ b/jskparser/jskparser/glob2/impl.py @@ -69,7 +69,7 @@ def iglob(self, pathname, with_matches=False): result = self._iglob(pathname) if with_matches: return result - return map(lambda s: s[0], result) + return [s[0] for s in result] def _iglob(self, pathname, rootcall=True): """Internal implementation that backs :meth:`iglob`. @@ -152,7 +152,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): names = [''] if globstar_with_root else [] for top, entries in self.walk(dirname): _mkabs = lambda s: os.path.join(top[len(dirname)+1:], s) - names.extend(map(_mkabs, entries)) + names.extend([_mkabs(e) for e in entries]) # Reset pattern so that fnmatch(), which does not understand # ** specifically, will only return a single group match. pattern = '*' @@ -165,7 +165,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): # Remove hidden files by default, but take care to ensure # that the empty string we may have added earlier remains. # Do not filter out the '' that we might have added earlier - names = filter(lambda x: not x or not _ishidden(x), names) + names = [x for x in names if not x or not _ishidden(x)] return fnmatch.filter(names, pattern) diff --git a/jskparser/jskparser/jskparser.py b/jskparser/jskparser/jskparser.py index 4c1c0b7..2bdd560 100644 --- a/jskparser/jskparser/jskparser.py +++ b/jskparser/jskparser/jskparser.py @@ -105,7 +105,7 @@ def create_logger(log_lvl): if OPT.symtab: def f(n): if type(n) not in SymtabGen.NONSYM: - print(type(n).__name__, n.name, map(lambda nn: (nn[0], nn[1]), n.symtab.items())) + print(type(n).__name__, n.name, [(nn[0], nn[1]) for nn in n.symtab.items()]) g = GenericVisitor(f) g.visit(program) else: diff --git a/lib/glob2/impl.py b/lib/glob2/impl.py index 91a16a8..2374384 100644 --- a/lib/glob2/impl.py +++ b/lib/glob2/impl.py @@ -69,7 +69,7 @@ def iglob(self, pathname, with_matches=False): result = self._iglob(pathname) if with_matches: return result - return map(lambda s: s[0], result) + return [s[0] for s in result] def _iglob(self, pathname, rootcall=True): """Internal implementation that backs :meth:`iglob`. @@ -152,7 +152,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): names = [''] if globstar_with_root else [] for top, entries in self.walk(dirname): _mkabs = lambda s: os.path.join(top[len(dirname)+1:], s) - names.extend(map(_mkabs, entries)) + names.extend([_mkabs(e) for e in entries]) # Reset pattern so that fnmatch(), which does not understand # ** specifically, will only return a single group match. pattern = '*' @@ -165,7 +165,7 @@ def resolve_pattern(self, dirname, pattern, globstar_with_root): # Remove hidden files by default, but take care to ensure # that the empty string we may have added earlier remains. # Do not filter out the '' that we might have added earlier - names = filter(lambda x: not x or not _ishidden(x), names) + names = [x for x in names if not x or not _ishidden(x)] return fnmatch.filter(names, pattern) diff --git a/test/axioms/run.py b/test/axioms/run.py index 209b5c2..73c68a3 100644 --- a/test/axioms/run.py +++ b/test/axioms/run.py @@ -45,11 +45,11 @@ def median(nums): else: return nums[int(math.floor(mid))] with open('results/impl.csv','r') as impl_fd: - impl_txt = map(lambda v: v.strip('\n\t'), impl_fd.readlines()) + impl_txt = [v.strip('\n\t') for v in impl_fd.readlines()] with open('results/adt.csv','r') as adt_fd: - adt_txt = map(lambda v: v.strip('\n\t'), adt_fd.readlines()) + adt_txt = [v.strip('\n\t') for v in adt_fd.readlines()] with open('results/Object.csv','r') as obj_fd: - Object_txt = map(lambda v: v.strip('\n\t'), obj_fd.readlines()) + Object_txt = [v.strip('\n\t') for v in obj_fd.readlines()] impl_fd = open('results/impl_s.csv','w') adt_fd = open('results/adt_s.csv','w') @@ -60,9 +60,9 @@ def median(nums): strs_a = a.split('\t') if a.split('\t') != [''] else [0] strs_o = o.split('\t') if o.split('\t') != [''] else [0] - mi = median(map(float, strs_i)) - ma = median(map(float, strs_a)) - mo = median(map(float, strs_o)) + mi = median([float(s) for s in strs_i]) + ma = median([float(s) for s in strs_a]) + mo = median([float(s) for s in strs_o]) vals.append((mi, ma, mo)) # rewrite these in sorted order b/c Numbers on OS X is a POS @@ -71,7 +71,8 @@ def median(nums): obj_fd.write('{}\n'.format('\t'.join(map(str,(sorted(map(float, strs_o))))))) with open('results/all.csv', 'w') as f: - map(lambda v: f.write('{}\t{}\t{}\n'.format(v[0], v[1], v[2])), vals) + for v in vals: + f.write('{}\t{}\t{}\n'.format(v[0], v[1], v[2])) if __name__ == '__main__': from optparse import OptionParser diff --git a/test/test_axiom_gen.py b/test/test_axiom_gen.py index c431b10..eb0225d 100644 --- a/test/test_axiom_gen.py +++ b/test/test_axiom_gen.py @@ -11,7 +11,7 @@ class TestJava(TestCommon): def __test(self, fs, inline, unroll, adp_conc=False, arr=32): - _fs = map(lambda f: os.path.join(tests, f), fs) + _fs = [os.path.join(tests, f) for f in fs] if adp_conc: ret = java_sk.main.translate(prg=_fs, log_lvl='30', lib=False, opts=["--bnd-inline-amnt", str(inline), "--bnd-unroll-amnt", str(unroll), "--bnd-arr-size", str(arr), "--slv-timeout", "10", "--slv-randassign", "--slv-simple-inputs"]) else: @@ -161,7 +161,7 @@ def __test(self, fs, inline, unroll, adp_conc=False, arr=32): def test_EasyCSVRewrite(self): files = ["CsvDocument.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "EasyCSV/" + s, files) + files = ["EasyCSV/" + s for s in files] inline = 3 unroll = 5 # self.__test(files, inline, unroll, True) diff --git a/test/test_axioms.py b/test/test_axioms.py index f8345e7..63bad2e 100644 --- a/test/test_axioms.py +++ b/test/test_axioms.py @@ -11,7 +11,7 @@ class TestJava(TestCommon): def __test(self, fs, inline, unroll, adp_conc=False, arr=32): - _fs = map(lambda f: os.path.join(tests, f), fs) + _fs = [os.path.join(tests, f) for f in fs] if adp_conc: ret = java_sk.main.translate(prg=_fs, log_lvl='30', lib=False, opts=["--bnd-inline-amnt", str(inline), "--bnd-unroll-amnt", str(unroll), "--bnd-arr-size", str(arr), "--slv-timeout", "10", "--slv-randassign", "--slv-simple-inputs"]) else: @@ -24,7 +24,7 @@ def __test(self, fs, inline, unroll, adp_conc=False, arr=32): def test_SuffixArrayRewrite(self): files = ["SuffixArray_loops2.java", "SuffixArrayTest.java", "rewrite/"] - files = map(lambda s: "SuffixArray_bigger/" + s, files) + files = ["SuffixArray_bigger/" + s for s in files] inline = 3 unroll = 8 self.__test(files, inline, unroll) @@ -32,7 +32,7 @@ def test_SuffixArrayRewrite(self): # def test_KafkaRewrite(self): # # files = ["JCECipher_syn_rewrite.java", "OpenSSLCipher_syn_rewrite.java", "CipherFactory.java", "ICipher_rewrite.java", "Tester_rewrite.java", "rewrite/", "shared/"] # files = ["JCECipher_syn.java", "OpenSSLCipher_syn.java", "CipherFactory.java", "ICipher_model.java", "Tester_model.java", "model/", "shared/"] - # files = map(lambda s: "Kafka_biggest/" + s, files) + # files = ["Kafka_biggest/" + s for s in files] # inline = 2 # unroll = 35 # # inline = 1 @@ -41,15 +41,15 @@ def test_SuffixArrayRewrite(self): # def test_SimpleArrayListZ3(self): # files = ["SimpleExample.java", "ArrayList.java", "Object.java"] - # files = map(lambda s: "SimpleArrayListExampleZ3/" + s, files) + # files = ["SimpleArrayListExampleZ3/" + s for s in files] # inline = 2 # unroll = 8 # self.__test(files, inline, unroll) - + # def test_RomList_bigger(self): # files = ["RomlistParser_syn_model.java", "RomlistGame.java", "Tester.java", "model/", "shared/"] # # files = ["RomlistParser_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "RomList_bigger/" + s, files) + # files = ["RomList_bigger/" + s for s in files] # inline = 2 # unroll = 26 # # unroll = 19 @@ -58,7 +58,7 @@ def test_SuffixArrayRewrite(self): # def test_ComparatorRewrite(self): # files = ["CommunicationWithFiles_syn_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "Comparator_bigger/" + s, files) + # files = ["Comparator_bigger/" + s for s in files] # inline = 2 # unroll = 10 # self.__test(files, inline, unroll, True) @@ -66,14 +66,14 @@ def test_SuffixArrayRewrite(self): # def test_PasswordManager_bigger(self): # files = ["Cryptographer_syn_model.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "model/", "shared/"] # # files = ["Cryptographer_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] - # files = map(lambda s: "PasswordManager_bigger/" + s, files) + # files = ["PasswordManager_bigger/" + s for s in files] # inline = 2 # unroll = 16 # self.__test(files, inline, unroll) - + # def test_EasyCSVRewrite_bigger(self): # files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "EasyCSV_bigger/" + s, files) + # files = ["EasyCSV_bigger/" + s for s in files] # inline = 3 # unroll = 5 # # self.__test(files, inline, unroll, True) @@ -81,77 +81,77 @@ def test_SuffixArrayRewrite(self): # def test_CipherFactoryModel_bigger(self): # files = ["CryptoManager_syn_model.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_model.java", "ICipherFactory.java", "ICryptoManager.java", "model/", "shared/"] - # files = map(lambda s: "CipherFactory_bigger/" + s, files) + # files = ["CipherFactory_bigger/" + s for s in files] # inline = 2 # unroll = 9 # self.__test(files, inline, unroll) # def test_SuffixArrayModel_bigger(self): # files = ["SuffixArray_loops.java", "SuffixArrayTest.java", "model/"] - # files = map(lambda s: "SuffixArray_bigger/" + s, files) + # files = ["SuffixArray_bigger/" + s for s in files] # inline = 3 # unroll = 8 # self.__test(files, inline, unroll) # def test_SuffixArrayModel(self): # files = ["SuffixArray_loops.java", "SuffixArrayTest.java", "model/"] - # files = map(lambda s: "SuffixArray/" + s, files) + # files = ["SuffixArray/" + s for s in files] # inline = 2 # unroll = 8 # self.__test(files, inline, unroll) # def test_HashMap1Model(self): # files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "model/", "shared/"] - # files = map(lambda s: "HashMap1/" + s, files) + # files = ["HashMap1/" + s for s in files] # inline = 2 # unroll = 13 # self.__test(files, inline, unroll) - + # def test_HashMap2Model(self): # files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "model/", "shared/"] - # files = map(lambda s: "HashMap2/" + s, files) + # files = ["HashMap2/" + s for s in files] # inline = 1 # unroll = 11 # self.__test(files, inline, unroll) - + # def test_PasswordManagerModel(self): # files = ["Cryptographer_syn_model.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "model/", "shared/"] - # files = map(lambda s: "PasswordManager/" + s, files) + # files = ["PasswordManager/" + s for s in files] # inline = 2 # unroll = 16 # self.__test(files, inline, unroll) - + # def test_CipherFactoryModel(self): # files = ["CryptoManager_syn_model.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_model.java", "ICipherFactory.java", "ICryptoManager.java", "model/", "shared/"] - # files = map(lambda s: "CipherFactory/" + s, files) + # files = ["CipherFactory/" + s for s in files] # inline = 2 # unroll = 9 # self.__test(files, inline, unroll) - + # def test_KafkaModel(self): # files = ["JCECipher_syn.java", "OpenSSLCipher_syn.java", "CipherFactory.java", "ICipher_model.java", "Tester.java", "model/", "shared/"] - # files = map(lambda s: "Kafka/" + s, files) + # files = ["Kafka/" + s for s in files] # inline = 2 # unroll = 35 # self.__test(files, inline, unroll) # def test_EasyCSVModel(self): # files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "model/", "shared/"] - # files = map(lambda s: "EasyCSV/" + s, files) + # files = ["EasyCSV/" + s for s in files] # inline = 3 # unroll = 5 # self.__test(files, inline, unroll) # def test_RomListModel(self): # files = ["RomlistParser_syn_model.java", "RomlistGame.java", "Tester.java", "model/", "shared/"] - # files = map(lambda s: "RomList/" + s, files) + # files = ["RomList/" + s for s in files] # inline = 2 # unroll = 26 # self.__test(files, inline, unroll, True) # def test_ComparatorModel(self): # files = ["CommunicationWithFiles_syn_model.java", "Comparator_model.java", "Tester.java", "model/", "shared/"] - # files = map(lambda s: "Comparator/" + s, files) + # files = ["Comparator/" + s for s in files] # inline = 2 # unroll = 10 # self.__test(files, inline, unroll, True, 50) @@ -159,24 +159,24 @@ def test_SuffixArrayRewrite(self): ################################################################# ## REWRITE TESTS ################################################################# - + # def test_SuffixArrayRewrite(self): # files = ["SuffixArray_loops.java", "SuffixArrayTest.java", "rewrite/"] - # files = map(lambda s: "SuffixArray/" + s, files) + # files = ["SuffixArray/" + s for s in files] # inline = 3 # unroll = 8 # self.__test(files, inline, unroll) # def test_HashMap1Rewrite(self): # files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "rewrite/", "shared/"] - # files = map(lambda s: "HashMap1/" + s, files) + # files = ["HashMap1/" + s for s in files] # inline = 3 # unroll = 3 # self.__test(files, inline, unroll) # def test_HashMap2Rewrite(self): # files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "rewrite/", "shared/"] - # files = map(lambda s: "HashMap2/" + s, files) + # files = ["HashMap2/" + s for s in files] # inline = 1 # unroll = 2 # self.__test(files, inline, unroll) @@ -184,22 +184,22 @@ def test_SuffixArrayRewrite(self): # def test_PasswordManagerRewrite(self): # files = ["Cryptographer_syn_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] # # files = ["Cryptographer_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] - # files = map(lambda s: "PasswordManager/" + s, files) + # files = ["PasswordManager/" + s for s in files] # inline = 2 # unroll = 16 # self.__test(files, inline, unroll) - + # def test_PasswordManagerRewrite_nobox(self): # files = ["Cryptographer_syn_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] # # files = ["Cryptographer_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] - # files = map(lambda s: "PasswordManager_nobox/" + s, files) + # files = ["PasswordManager_nobox/" + s for s in files] # inline = 2 # unroll = 16 # self.__test(files, inline, unroll) - + # def test_CipherFactoryRewrite(self): # files = ["CryptoManager_syn_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] - # files = map(lambda s: "CipherFactory/" + s, files) + # files = ["CipherFactory/" + s for s in files] # inline = 2 # unroll = 9 # self.__test(files, inline, unroll) @@ -207,7 +207,7 @@ def test_SuffixArrayRewrite(self): # def test_CipherFactoryRewrite_nobox(self): # files = ["CryptoManager_syn_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] # # files = ["CryptoManager_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] - # files = map(lambda s: "CipherFactory_nobox/" + s, files) + # files = ["CipherFactory_nobox/" + s for s in files] # inline = 2 # unroll = 9 # self.__test(files, inline, unroll) @@ -215,14 +215,14 @@ def test_SuffixArrayRewrite(self): # def test_KafkaRewrite(self): # files = ["JCECipher_syn_rewrite.java", "OpenSSLCipher_syn_rewrite.java", "CipherFactory.java", "ICipher_rewrite.java", "Tester.java", "rewrite/", "shared/"] # # files = ["OpenSSLCipher_syn_rewrite", "JCECipher_syn_rewrite.java", "ICipher.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "Kafka/" + s, files) + # files = ["Kafka/" + s for s in files] # inline = 2 # unroll = 35 # self.__test(files, inline, unroll) # def test_KafkaRewrite_nobox(self): # files = ["JCECipher_syn_rewrite.java", "OpenSSLCipher_syn_rewrite.java", "CipherFactory.java", "ICipher_rewrite.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "Kafka_nobox/" + s, files) + # files = ["Kafka_nobox/" + s for s in files] # inline = 2 # unroll = 35 # # inline = 1 @@ -231,7 +231,7 @@ def test_SuffixArrayRewrite(self): # def test_EasyCSVRewrite(self): # files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "EasyCSV/" + s, files) + # files = ["EasyCSV/" + s for s in files] # inline = 3 # unroll = 5 # # self.__test(files, inline, unroll, True) @@ -240,7 +240,7 @@ def test_SuffixArrayRewrite(self): # def test_RomListRewrite(self): # files = ["RomlistParser_syn_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] # # files = ["RomlistParser_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "RomList/" + s, files) + # files = ["RomList/" + s for s in files] # inline = 2 # unroll = 26 # # unroll = 19 @@ -249,7 +249,7 @@ def test_SuffixArrayRewrite(self): # def test_ComparatorRewrite(self): # files = ["CommunicationWithFiles_syn_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared/"] - # files = map(lambda s: "Comparator/" + s, files) + # files = ["Comparator/" + s for s in files] # inline = 2 # unroll = 10 # self.__test(files, inline, unroll, True) diff --git a/test/test_benchmark_axioms.py b/test/test_benchmark_axioms.py index fe6d90a..1a77146 100644 --- a/test/test_benchmark_axioms.py +++ b/test/test_benchmark_axioms.py @@ -16,7 +16,7 @@ class TestJava(TestCommon): def __test(self, fs, inline, unroll, adp_conc=False, arr=32): - _fs = map(lambda f: os.path.join(tests, f), fs) + _fs = [os.path.join(tests, f) for f in fs] if adp_conc: ret = java_sk.main.translate(prg=_fs, log_lvl='30', lib=False, opts=["--bnd-inline-amnt", str(inline), "--bnd-unroll-amnt", str(unroll), "--bnd-arr-size", str(arr), "--slv-timeout", "10", "--slv-randassign", "--slv-simple-inputs"]) else: @@ -73,7 +73,7 @@ def test_runModels(self): (self.run_CipherFactoryModel, 'CipherFactoryTests'), (self.run_KafkaModel, 'Kafka_Tester') ] - results = map(lambda x: [x], reduce(lambda x,y: x + y, self.run_tests(modelTests, []))) + results = [[x] for x in reduce(lambda x,y: x + y, self.run_tests(modelTests, []))] writer.writerows(results) modelResults.close() @@ -92,62 +92,62 @@ def test_runRewrites(self): (self.run_CipherFactoryRewrite, 'CipherFactoryTests'), (self.run_KafkaRewrite, 'Kafka_Tester') ] - results = map(lambda x: [x], reduce(lambda x,y: x + y, self.run_tests(rewriteTests, []))) + results = [[x] for x in reduce(lambda x,y: x + y, self.run_tests(rewriteTests, []))] writer.writerows(results) modelResults.close() def run_SuffixArrayModel(self): files = ["SuffixArray_loops.java", "SuffixArrayTest.java", "model/"] - files = map(lambda s: "SuffixArray/" + s, files) + files = ["SuffixArray/" + s for s in files] inline = 2 unroll = 8 return self.__test(files, inline, unroll) def run_SuffixArrayRewrite(self): files = ["SuffixArray_loops.java", "SuffixArrayTest.java", "rewrite/"] - files = map(lambda s: "SuffixArray/" + s, files) + files = ["SuffixArray/" + s for s in files] inline = 2 unroll = 8 return self.__test(files, inline, unroll) def run_HashMap1Model(self): files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "model/", "shared/"] - files = map(lambda s: "HashMap1/" + s, files) + files = ["HashMap1/" + s for s in files] inline = 3 unroll = 13 return self.__test(files, inline, unroll) def run_HashMap1Rewrite(self): files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "rewrite/", "shared/"] - files = map(lambda s: "HashMap1/" + s, files) + files = ["HashMap1/" + s for s in files] inline = 3 unroll = 13 return self.__test(files, inline, unroll) def run_HashMap2Model(self): files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "model/", "shared/"] - files = map(lambda s: "HashMap2/" + s, files) + files = ["HashMap2/" + s for s in files] inline = 1 unroll = 11 return self.__test(files, inline, unroll) def run_HashMap2Rewrite(self): files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "rewrite/", "shared/"] - files = map(lambda s: "HashMap2/" + s, files) + files = ["HashMap2/" + s for s in files] inline = 1 unroll = 11 #2 return self.__test(files, inline, unroll) def run_EasyCSVModel(self): files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "EasyCSV/" + s, files) + files = ["EasyCSV/" + s for s in files] inline = 3 unroll = 5 return self.__test(files, inline, unroll) def run_EasyCSVRewrite(self): files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "EasyCSV/" + s, files) + files = ["EasyCSV/" + s for s in files] inline = 3 unroll = 5 # return self.__test(files, inline, unroll, True) @@ -155,7 +155,7 @@ def run_EasyCSVRewrite(self): def run_RomListModel(self): files = ["RomlistParser_syn_model.java", "RomlistGame.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "RomList/" + s, files) + files = ["RomList/" + s for s in files] inline = 2 unroll = 26 return self.__test(files, inline, unroll, True) @@ -163,7 +163,7 @@ def run_RomListModel(self): def run_RomListRewrite(self): files = ["RomlistParser_syn_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] # files = ["RomlistParser_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "RomList/" + s, files) + files = ["RomList/" + s for s in files] inline = 2 unroll = 26 # unroll = 19 @@ -172,7 +172,7 @@ def run_RomListRewrite(self): def run_ComparatorModel(self): files = ["CommunicationWithFiles_syn_model.java", "Comparator_model.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "Comparator/" + s, files) + files = ["Comparator/" + s for s in files] inline = 2 unroll = 10 return self.__test(files, inline, unroll, True, 50) @@ -181,7 +181,7 @@ def run_ComparatorModel(self): def run_ComparatorRewrite(self): files = ["CommunicationWithFiles_syn_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared/"] # files = ["CommunicationWithFiles_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "Comparator/" + s, files) + files = ["Comparator/" + s for s in files] inline = 2 #2 unroll = 10 #10 return self.__test(files, inline, unroll, True) @@ -189,7 +189,7 @@ def run_ComparatorRewrite(self): def run_PasswordManagerModel(self): files = ["Cryptographer_syn_model.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "model/", "shared/"] - files = map(lambda s: "PasswordManager/" + s, files) + files = ["PasswordManager/" + s for s in files] inline = 2 unroll = 16 return self.__test(files, inline, unroll) @@ -197,14 +197,14 @@ def run_PasswordManagerModel(self): def run_PasswordManagerRewrite(self): files = ["Cryptographer_syn_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] # files = ["Cryptographer_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] - files = map(lambda s: "PasswordManager_nobox/" + s, files) + files = ["PasswordManager_nobox/" + s for s in files] inline = 2 unroll = 16 return self.__test(files, inline, unroll) def run_CipherFactoryModel(self): files = ["CryptoManager_syn_model.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_model.java", "ICipherFactory.java", "ICryptoManager.java", "model/", "shared/"] - files = map(lambda s: "CipherFactory/" + s, files) + files = ["CipherFactory/" + s for s in files] inline = 2 unroll = 9 return self.__test(files, inline, unroll) @@ -212,21 +212,21 @@ def run_CipherFactoryModel(self): def run_CipherFactoryRewrite(self): files = ["CryptoManager_syn_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] # files = ["CryptoManager_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] - files = map(lambda s: "CipherFactory_nobox/" + s, files) + files = ["CipherFactory_nobox/" + s for s in files] inline = 2 unroll = 9 return self.__test(files, inline, unroll) def run_KafkaModel(self): files = ["JCECipher_syn.java", "OpenSSLCipher_syn.java", "CipherFactory.java", "ICipher_model.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "Kafka/" + s, files) + files = ["Kafka/" + s for s in files] inline = 2 unroll = 35 return self.__test(files, inline, unroll) def run_KafkaRewrite(self): files = ["JCECipher_syn_rewrite.java", "OpenSSLCipher_syn_rewrite.java", "CipherFactory.java", "ICipher_rewrite.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "Kafka_nobox/" + s, files) + files = ["Kafka_nobox/" + s for s in files] inline = 2 unroll = 35 # inline = 1 diff --git a/test/test_big_benchmark_axioms.py b/test/test_big_benchmark_axioms.py index 02b84ff..04e4f00 100644 --- a/test/test_big_benchmark_axioms.py +++ b/test/test_big_benchmark_axioms.py @@ -17,7 +17,7 @@ class TestJava(TestCommon): def __test(self, fs, inline, unroll, adp_conc=False, arr=32, cbits=-1, irange=-1): - _fs = map(lambda f: os.path.join(tests, f), fs) + _fs = [os.path.join(tests, f) for f in fs] options = ["--bnd-inline-amnt", str(inline), "--bnd-unroll-amnt", str(unroll), "--bnd-arr-size", str(arr), "--slv-timeout", str(timeout)] if adp_conc: options += ["--slv-randassign", "--slv-simple-inputs"] @@ -93,7 +93,7 @@ def test_runModels(self): # (self.run_PasswordManagerModel, 'PasswordManagerTest'), # (self.run_KafkaModel, 'Kafka_Tester') ] - results = map(lambda x: [x], reduce(lambda x,y: x + y, self.run_tests(modelTests, [], tmp_output))) + results = [[x] for x in reduce(lambda x,y: x + y, self.run_tests(modelTests, [], tmp_output))] writer.writerows(results) modelResults.close() @@ -113,63 +113,63 @@ def test_runRewrites(self): # (self.run_PasswordManagerRewrite, 'PasswordManagerTest'), # (self.run_KafkaRewrite, 'Kafka_Tester') ] - results = map(lambda x: [x], reduce(lambda x,y: x + y, self.run_tests(rewriteTests, [], tmp_output))) + results = [[x] for x in reduce(lambda x,y: x + y, self.run_tests(rewriteTests, [], tmp_output))] writer.writerows(results) tmp_output.close() modelResults.close() def run_SuffixArrayModel(self): files = ["SuffixArray_loops2.java", "SuffixArrayTest.java", "model/"] - files = map(lambda s: "SuffixArray_bigger/" + s, files) + files = ["SuffixArray_bigger/" + s for s in files] inline = 3 unroll = 8 return self.__test(files, inline, unroll) def run_SuffixArrayRewrite(self): files = ["SuffixArray_loops2.java", "SuffixArrayTest.java", "rewrite/"] - files = map(lambda s: "SuffixArray_bigger/" + s, files) + files = ["SuffixArray_bigger/" + s for s in files] inline = 3 unroll = 8 return self.__test(files, inline, unroll) def run_HashMap1Model(self): files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "model/", "shared/"] - files = map(lambda s: "HashMap1_bigger/" + s, files) + files = ["HashMap1_bigger/" + s for s in files] inline = 1 unroll = 5 return self.__test(files, inline, unroll, irange=43) def run_HashMap1Rewrite(self): files = ["HashTable_loops.java", "HashTableNode.java", "HashTableTest.java", "rewrite/", "shared/"] - files = map(lambda s: "HashMap1_bigger/" + s, files) + files = ["HashMap1_bigger/" + s for s in files] inline = 1 unroll = 5 return self.__test(files, inline, unroll, irange=43) def run_HashMap2Model(self): files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "model/", "shared/"] - files = map(lambda s: "HashMap2_bigger/" + s, files) + files = ["HashMap2_bigger/" + s for s in files] inline = 1 unroll = 2 return self.__test(files, inline, unroll, cbits=2, irange=8) def run_HashMap2Rewrite(self): files = ["Bucketing_syn.java", "BucketingTest.java", "HashTable.java", "Pair.java", "rewrite/", "shared/"] - files = map(lambda s: "HashMap2_bigger/" + s, files) + files = ["HashMap2_bigger/" + s for s in files] inline = 1 unroll = 2 return self.__test(files, inline, unroll, cbits=2, irange=8) def run_EasyCSVModel(self): files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "EasyCSV_bigger/" + s, files) + files = ["EasyCSV_bigger/" + s for s in files] inline = 3 unroll = 5 return self.__test(files, inline, unroll) def run_EasyCSVRewrite(self): files = ["CsvDocument_syn.java", "CodeAssertion.java", "CsvColumn.java", "CsvColumnTest.java", "CsvConfiguration.java", "CsvDocumentTest.java", "CsvRow.java", "CsvRowTest.java", "Tester.java", "rewrite/", "shared/"] - files = map(lambda s: "EasyCSV_bigger/" + s, files) + files = ["EasyCSV_bigger/" + s for s in files] inline = 3 unroll = 5 # return self.__test(files, inline, unroll, True) @@ -177,7 +177,7 @@ def run_EasyCSVRewrite(self): def run_RomListModel(self): files = ["RomlistParser_syn_rewrite.java", "RomlistGame.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "RomList_bigger/" + s, files) + files = ["RomList_bigger/" + s for s in files] inline = 2 unroll = 26 return self.__test(files, inline, unroll, True) @@ -185,7 +185,7 @@ def run_RomListModel(self): def run_RomListRewrite(self): files = ["RomlistParser_syn_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite/", "shared/"] # files = ["RomlistParser_rewrite.java", "RomlistGame.java", "Tester.java", "rewrite_bigger/", "shared/"] - files = map(lambda s: "RomList_bigger/" + s, files) + files = ["RomList_bigger/" + s for s in files] inline = 2 unroll = 26 # unroll = 19 @@ -195,7 +195,7 @@ def run_RomListRewrite(self): def run_ComparatorModel(self): files = ["CommunicationWithFiles_syn_rewrite.java", "Comparator_rewrite.java", "Tester.java", "model/", "shared/"] # files = ["CommunicationWithFiles_syn_model.java", "Comparator_model.java", "Tester.java", "model/", "shared/"] - files = map(lambda s: "Comparator_bigger/" + s, files) + files = ["Comparator_bigger/" + s for s in files] inline = 2 unroll = 10 return self.__test(files, inline, unroll, True) @@ -204,7 +204,7 @@ def run_ComparatorModel(self): def run_ComparatorRewrite(self): files = ["CommunicationWithFiles_syn_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared/"] # files = ["CommunicationWithFiles_rewrite.java", "Comparator_rewrite.java", "Tester.java", "rewrite/", "shared_bigger/"] - files = map(lambda s: "Comparator_bigger/" + s, files) + files = ["Comparator_bigger/" + s for s in files] inline = 2 #2 unroll = 10 #10 return self.__test(files, inline, unroll, True) @@ -212,7 +212,7 @@ def run_ComparatorRewrite(self): def run_PasswordManagerModel(self): files = ["Cryptographer_syn_model.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "model/", "shared/"] - files = map(lambda s: "PasswordManager_bigger/" + s, files) + files = ["PasswordManager_bigger/" + s for s in files] inline = 2 unroll = 16 return self.__test(files, inline, unroll) @@ -220,35 +220,35 @@ def run_PasswordManagerModel(self): def run_PasswordManagerRewrite(self): files = ["Cryptographer_syn_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] # files = ["Cryptographer_rewrite.java", "PasswordManager_syn.java", "PasswordMap.java", "PasswordManagerTest.java", "rewrite/", "shared/"] - files = map(lambda s: "PasswordManager_bigger/" + s, files) + files = ["PasswordManager_bigger/" + s for s in files] inline = 2 unroll = 16 return self.__test(files, inline, unroll) def run_CipherFactoryModel(self): files = ["CryptoManager_syn_model.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_model.java", "ICipherFactory.java", "ICryptoManager.java", "model/", "shared/"] - files = map(lambda s: "CipherFactory_bigger/" + s, files) + files = ["CipherFactory_bigger/" + s for s in files] inline = 3 unroll = 9 return self.__test(files, inline, unroll) def run_CipherFactoryRewrite(self): files = ["CryptoManager_syn_rewrite.java", "CipherFactoryTester.java", "ConfigurableCipherFactory.java", "DefaultCipherFactory_rewrite.java", "ICipherFactory.java", "ICryptoManager.java", "rewrite/", "shared/"] - files = map(lambda s: "CipherFactory_bigger/" + s, files) + files = ["CipherFactory_bigger/" + s for s in files] inline = 3 unroll = 9 return self.__test(files, inline, unroll) def run_KafkaModel(self): files = ["JCECipher_syn.java", "OpenSSLCipher_syn.java", "CipherFactory.java", "ICipher_model.java", "Tester_model.java", "model/", "shared/"] - files = map(lambda s: "Kafka_biggest/" + s, files) + files = ["Kafka_biggest/" + s for s in files] inline = 2 unroll = 35 return self.__test(files, inline, unroll) def run_KafkaRewrite(self): files = ["JCECipher_syn_rewrite.java", "OpenSSLCipher_syn_rewrite.java", "CipherFactory.java", "ICipher_rewrite.java", "Tester_rewrite.java", "rewrite/", "shared/"] - files = map(lambda s: "Kafka_biggest/" + s, files) + files = ["Kafka_biggest/" + s for s in files] inline = 2 unroll = 35 # inline = 1 diff --git a/test/test_erroneous.py b/test/test_erroneous.py index 66bde20..225308e 100644 --- a/test/test_erroneous.py +++ b/test/test_erroneous.py @@ -28,7 +28,7 @@ def test_mains(self): def __test(self, fs): append_b = lambda f: os.path.join(benchmarks, f) - _fs = map(append_b, fs) + _fs = [append_b(f) for f in fs] ret = java_sk.main.main(_fs) self.assertNotEqual(ret, 0) diff --git a/test/test_java.py b/test/test_java.py index f986472..6600526 100644 --- a/test/test_java.py +++ b/test/test_java.py @@ -17,7 +17,7 @@ class TestJava(TestCommon): def __test(self, fs, using_model=False): append_b = lambda f: os.path.join(benchmarks, f) - _fs = map(append_b, fs) + _fs = [append_b(f) for f in fs] if using_model: _fs.extend(java_sk.util.get_files_from_path(model_dir, "java")) print(fs) diff --git a/test/test_java_precisely.py b/test/test_java_precisely.py index e0108bc..5d600c2 100644 --- a/test/test_java_precisely.py +++ b/test/test_java_precisely.py @@ -13,7 +13,7 @@ class TestMini(TestCommon): def __test(self, fs): append_b = lambda f: os.path.join(jp, f) - _fs = map(append_b, fs) + _fs = [append_b(f) for f in fs] ret = java_sk.main.main(_fs) self.assertEqual(ret, 0) diff --git a/test/test_lib.py b/test/test_lib.py index 84a1367..ef4cdbd 100644 --- a/test/test_lib.py +++ b/test/test_lib.py @@ -11,7 +11,7 @@ class TestJava(TestCommon): def __test(self, fs): - _fs = map(lambda f: os.path.join(tests, f), fs + ['../../model/']) + _fs = [os.path.join(tests, f) for f in fs + ['../../model/']] ret = java_sk.main.main(_fs, '30') self.assertEqual(ret, 0) diff --git a/test/test_mini.py b/test/test_mini.py index e8b153a..c1f4bbb 100644 --- a/test/test_mini.py +++ b/test/test_mini.py @@ -11,7 +11,7 @@ class TestMini(TestCommon): def __test(self, fs): - _fs = map(lambda f: os.path.join(benchmarks, f), fs) + _fs = [os.path.join(benchmarks, f) for f in fs] ret = java_sk.main.main(_fs, '30') self.assertEqual(ret, 0) diff --git a/test/test_new_ast.py b/test/test_new_ast.py index fa9f5c6..564fc99 100644 --- a/test/test_new_ast.py +++ b/test/test_new_ast.py @@ -11,7 +11,7 @@ class TestJava(TestCommon): def __test(self, fs): - _fs = map(lambda f: os.path.join(tests, f), fs) + _fs = [os.path.join(tests, f) for f in fs] ret = java_sk.main.main(_fs, '30') self.assertEqual(ret, 0) From bf4a68e15495eaa7e5b3b7704336cdd1ace6c388 Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 20:34:03 -0500 Subject: [PATCH 06/12] Hacks around python 2/3 xrange. --- java_sk/encoder.py | 2 ++ java_sk/psketch.py | 2 ++ java_sk/rewrite/desugar.py | 2 ++ java_sk/sketch.py | 2 ++ java_sk/translator.py | 2 ++ jskparser/ast/dataflow/dataflow.py | 2 ++ jskparser/ast/expr/methodcallexpr.py | 2 ++ jskparser/ast/visit/sourcevisitor.py | 2 ++ jskparser/ast/visit/symtabgen.py | 2 ++ test/axioms/ArrayList/run.py | 2 ++ test/axioms/HashMap/run.py | 2 ++ test/axioms/Stack/run.py | 2 ++ test/axioms/String/run.py | 2 ++ 13 files changed, 26 insertions(+) diff --git a/java_sk/encoder.py b/java_sk/encoder.py index 082b650..e9c9a61 100644 --- a/java_sk/encoder.py +++ b/java_sk/encoder.py @@ -5,6 +5,8 @@ import cStringIO except: # so sue me. import io as cStringIO +try: xrange +except: xrange = range import math import os import copy as cp diff --git a/java_sk/psketch.py b/java_sk/psketch.py index 1c6e657..84aba44 100755 --- a/java_sk/psketch.py +++ b/java_sk/psketch.py @@ -1,6 +1,8 @@ #! /usr/bin/env python from __future__ import absolute_import +try: xrange +except: xrange = range import multiprocessing import os import logging diff --git a/java_sk/rewrite/desugar.py b/java_sk/rewrite/desugar.py index bcbeb9e..661f2e7 100644 --- a/java_sk/rewrite/desugar.py +++ b/java_sk/rewrite/desugar.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: xrange +except: xrange = range import logging import lib.const as C diff --git a/java_sk/sketch.py b/java_sk/sketch.py index 13495f7..f082236 100755 --- a/java_sk/sketch.py +++ b/java_sk/sketch.py @@ -2,6 +2,8 @@ from __future__ import absolute_import from __future__ import print_function +try: xrange +except: xrange = range import multiprocessing import os import logging diff --git a/java_sk/translator.py b/java_sk/translator.py index a7430a8..ac63364 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -3,6 +3,8 @@ from __future__ import print_function try: unicode except: unicode = u"".__class__ +try: xrange +except: xrange = range from functools import reduce import sys diff --git a/jskparser/ast/dataflow/dataflow.py b/jskparser/ast/dataflow/dataflow.py index 9b8b999..4bfb616 100644 --- a/jskparser/ast/dataflow/dataflow.py +++ b/jskparser/ast/dataflow/dataflow.py @@ -4,6 +4,8 @@ from __future__ import print_function try: unicode except: unicode = u"".__class__ +try: xrange +except: xrange = range from ..utils import utils from ..body.methoddeclaration import MethodDeclaration diff --git a/jskparser/ast/expr/methodcallexpr.py b/jskparser/ast/expr/methodcallexpr.py index fcaac19..84c878d 100644 --- a/jskparser/ast/expr/methodcallexpr.py +++ b/jskparser/ast/expr/methodcallexpr.py @@ -3,6 +3,8 @@ from __future__ import absolute_import try: unicode except: unicode = u"".__class__ +try: xrange +except: xrange = range import itertools from . import _import diff --git a/jskparser/ast/visit/sourcevisitor.py b/jskparser/ast/visit/sourcevisitor.py index cd1de57..b58ce00 100644 --- a/jskparser/ast/visit/sourcevisitor.py +++ b/jskparser/ast/visit/sourcevisitor.py @@ -6,6 +6,8 @@ import cStringIO except: # so sue me. import io as cStringIO +try: xrange +except: xrange = range from . import visit as v from .. import Operators as op diff --git a/jskparser/ast/visit/symtabgen.py b/jskparser/ast/visit/symtabgen.py index 568c1bd..c7ec933 100644 --- a/jskparser/ast/visit/symtabgen.py +++ b/jskparser/ast/visit/symtabgen.py @@ -1,4 +1,6 @@ from __future__ import absolute_import +try: xrange +except: xrange = range from . import visit as v from .. import JAVA_LANG diff --git a/test/axioms/ArrayList/run.py b/test/axioms/ArrayList/run.py index 67ef28a..c36d5fd 100644 --- a/test/axioms/ArrayList/run.py +++ b/test/axioms/ArrayList/run.py @@ -1,5 +1,7 @@ from __future__ import absolute_import from __future__ import print_function +try: xrange +except: xrange = range import subprocess import re import time diff --git a/test/axioms/HashMap/run.py b/test/axioms/HashMap/run.py index 67ef28a..c36d5fd 100644 --- a/test/axioms/HashMap/run.py +++ b/test/axioms/HashMap/run.py @@ -1,5 +1,7 @@ from __future__ import absolute_import from __future__ import print_function +try: xrange +except: xrange = range import subprocess import re import time diff --git a/test/axioms/Stack/run.py b/test/axioms/Stack/run.py index 5def10c..40a6a57 100644 --- a/test/axioms/Stack/run.py +++ b/test/axioms/Stack/run.py @@ -1,5 +1,7 @@ from __future__ import absolute_import from __future__ import print_function +try: xrange +except: xrange = range import subprocess import re diff --git a/test/axioms/String/run.py b/test/axioms/String/run.py index e7393dc..c7b919d 100644 --- a/test/axioms/String/run.py +++ b/test/axioms/String/run.py @@ -1,5 +1,7 @@ from __future__ import absolute_import from __future__ import print_function +try: xrange +except: xrange = range import subprocess import re import time From 165737aac90514461c5202620e0d55bf1018bfeb Mon Sep 17 00:00:00 2001 From: natebragg Date: Mon, 18 Feb 2019 21:01:09 -0500 Subject: [PATCH 07/12] Force int conversion, for python 3 compatibility. --- java_sk/translator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java_sk/translator.py b/java_sk/translator.py index ac63364..859124b 100644 --- a/java_sk/translator.py +++ b/java_sk/translator.py @@ -1518,7 +1518,7 @@ def trans_fld(self, fld): if isinstance(typ_cls, ClassOrInterfaceDeclaration) and typ_cls.axiom: ty = u'Object' - if isinstance(fld.typee, ReferenceType) and fld.typee.arrayCount > 0: + if isinstance(fld.typee, ReferenceType) and int(fld.typee.arrayCount) > 0: if self._is_ax_cls: if len(fld.name) > 7 and fld.name[0:7]=='_array_': ty = 'Array_{}'.format(self.trans_ty(fld.typee)) From cbfd2af1ee642fc4c9a944082cd8e872fe808c5e Mon Sep 17 00:00:00 2001 From: natebragg Date: Tue, 19 Feb 2019 10:40:04 -0500 Subject: [PATCH 08/12] A couple more python 3 nuances. The `universal_newlines` flag is ignored by python 2, but without it, python 3 yields a bytestring here, which is a monkey wrench in whatever uses the result. The call to "zip" in python 3 yields an iterator, which can only be consumed once, and isn't memoized, so the subsequent uses of `cls` fail to do anything. --- jskparser/ast/utils/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jskparser/ast/utils/utils.py b/jskparser/ast/utils/utils.py index 1c74ae3..825ccb7 100644 --- a/jskparser/ast/utils/utils.py +++ b/jskparser/ast/utils/utils.py @@ -361,7 +361,7 @@ def unpack_class_file(nm): except: cmd = ['/usr/libexec/java_home'] try: - JAVA_HOME = subprocess.check_output(cmd).strip(' \n') + JAVA_HOME = subprocess.check_output(cmd, universal_newlines=True).strip(' \n') except (OSError, subprocess.CalledProcessError) as e: logging.error('Unable to set JAVA_HOME: {} {}'.format(e, getattr(e, 'output', ''))) raise Exception('Unable to set JAVA_HOME') @@ -371,7 +371,7 @@ def unpack_class_file(nm): cmd = ['jar', 'xf', RT_JAR, nm] logging.debug(' '.join(cmd)) try: - subprocess.check_output(cmd) + subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as e: logging.error('Unable to extract "{}" from RT_JAR "{}": {}'.format(nm, RT_JAR, e.output)) @@ -381,7 +381,7 @@ def get_descriptors(nm): cmd = ['javap', '-s', nm] logging.debug(' '.join(cmd)) try: - cls = subprocess.check_output(cmd) + cls = subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as e: logging.error('Unable to dissassemble "{}": {}'.format(nm, e.output)) @@ -390,7 +390,7 @@ def get_descriptors(nm): cls = [x.strip() for x in cls.split('\n') if x] # this is a cool bit of sorcery to pair names with their descriptors - cls = zip(*[iter(cls)]*2) + cls = list(zip(*[iter(cls)]*2)) flds = [d for d in cls if '(' not in d[0] and 'static {};' not in d[0]] # print 'flds:', flds From 79b53a2687fce3f4baa029a2c6275b395596a6be Mon Sep 17 00:00:00 2001 From: natebragg Date: Tue, 19 Feb 2019 11:44:51 -0500 Subject: [PATCH 09/12] Silence deprecation warnings due to a python 3 change to modifier syntax. --- java_sk/glob2/fnmatch.py | 2 +- jskparser/jskparser/glob2/fnmatch.py | 2 +- lib/glob2/fnmatch.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/java_sk/glob2/fnmatch.py b/java_sk/glob2/fnmatch.py index b87878b..1d1e477 100644 --- a/java_sk/glob2/fnmatch.py +++ b/java_sk/glob2/fnmatch.py @@ -112,4 +112,4 @@ def translate(pat): res = '%s([%s])' % (res, stuff) else: res = res + re.escape(c) - return res + '\Z(?ms)' + return '(?ms)' + res + '\Z' diff --git a/jskparser/jskparser/glob2/fnmatch.py b/jskparser/jskparser/glob2/fnmatch.py index b87878b..1d1e477 100644 --- a/jskparser/jskparser/glob2/fnmatch.py +++ b/jskparser/jskparser/glob2/fnmatch.py @@ -112,4 +112,4 @@ def translate(pat): res = '%s([%s])' % (res, stuff) else: res = res + re.escape(c) - return res + '\Z(?ms)' + return '(?ms)' + res + '\Z' diff --git a/lib/glob2/fnmatch.py b/lib/glob2/fnmatch.py index b87878b..1d1e477 100644 --- a/lib/glob2/fnmatch.py +++ b/lib/glob2/fnmatch.py @@ -112,4 +112,4 @@ def translate(pat): res = '%s([%s])' % (res, stuff) else: res = res + re.escape(c) - return res + '\Z(?ms)' + return '(?ms)' + res + '\Z' From 5eb60f9ba1519856085799e8916079826da73398 Mon Sep 17 00:00:00 2001 From: natebragg Date: Tue, 19 Feb 2019 11:56:58 -0500 Subject: [PATCH 10/12] Typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eb491d9..3d0362e 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ such as `repeat` and `minrepeat`. To read JSketch, again, you should generate our parser first: ```sh -cd parser +cd jskparser make ``` From 298bb57c369f072487026ef63c8ee2b0695b8289 Mon Sep 17 00:00:00 2001 From: natebragg Date: Tue, 19 Feb 2019 17:45:38 -0500 Subject: [PATCH 11/12] Some more python 3 compatibility changes. Avoiding name shadowing, iterating a changing structure, and concatenating dictionaries. --- java_sk/encoder.py | 16 ++++++++-------- jskparser/ast/node.py | 2 +- jskparser/ast/visit/symtabgen.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/java_sk/encoder.py b/java_sk/encoder.py index e9c9a61..08d5d3f 100644 --- a/java_sk/encoder.py +++ b/java_sk/encoder.py @@ -104,7 +104,7 @@ def find_main(self): mtds = [] for c in self.clss: m = utils.extract_nodes([MethodDeclaration], c) - mtds.extend([m for m in m if m.name == u'main']) + mtds.extend([md for md in m if md.name == u'main']) # do we care if main is static? # mtds.extend(filter(lambda m: td.isStatic(m) and m.name == u'main', m)) lenn = len(mtds) @@ -417,7 +417,7 @@ def gen_adt_constructor(mtd): typ = self.tltr.trans_ty(t) if isinstance(t, ReferenceType) and t.arrayCount > 0: typ = "Array_"+typ - if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls: + if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [axc.name for axc in self.ax_clss] and not self.is_ax_cls: typ = u'Object' # if p.typee.name in p.symtab: @@ -446,7 +446,7 @@ def gen_obj_constructor(mtd): ptyps = [] ptyps_name = [] for t in mtd_param_typs: - if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [c.name for c in self.ax_clss] and not self.is_ax_cls: + if isinstance(t, ReferenceType) and isinstance(t.typee, ClassOrInterfaceType) and str(t.typee) in [axc.name for axc in self.ax_clss] and not self.is_ax_cls: typ = u'Object' else: typ = self.tltr.trans_ty(t) @@ -554,7 +554,7 @@ def gen_obj_constructor(mtd): buf.write(self.to_func(m) + os.linesep) # add bang functions for non-pure methods - for (m,i) in zip(adt_mtds, xrange(len(adt_mtds))): + for (m,i) in list(zip(adt_mtds, xrange(len(adt_mtds)))): if not m.pure: if not m.constructor: mtd = cp.copy(m) @@ -595,8 +595,8 @@ def gen_obj_constructor(mtd): # updates n's symbol table to include parents symbol table items def cpy_sym(n, *args): - if n.parentNode: n.symtab = dict(n.parentNode.symtab.items() + - n.symtab.items()) + if n.parentNode: n.symtab = dict(list(n.parentNode.symtab.items()) + + list(n.symtab.items())) # Iterates through ADT constructors # Creates a dictionary of xforms using constructor names @@ -813,14 +813,14 @@ def set_param_names(a, xf, adt_mtds, depth, xf_sym, name, xnames): # add a symbol table items to xf # this will give it access to the argument names of a # then updates xf children with - xf.symtab = dict(a.symtab.items() + xf.symtab.items()) + xf.symtab = dict(list(a.symtab.items()) + list(xf.symtab.items())) for c in xf.childrenNodes: utils.walk(cpy_sym, c) # NOT SURE WHY THIS IS NEEDED # without this it isn't able to resolve the string type of the # function. not sure why... - a.symtab = dict(xf.symtab.items() + a.symtab.items()) + a.symtab = dict(list(xf.symtab.items()) + list(a.symtab.items())) for c in a.childrenNodes: utils.walk(cpy_sym, c) diff --git a/jskparser/ast/node.py b/jskparser/ast/node.py index b45a35d..d11f9c4 100644 --- a/jskparser/ast/node.py +++ b/jskparser/ast/node.py @@ -249,7 +249,7 @@ def add_parent_post(self, p, recurse=True): if self not in p.childrenNodes: p.childrenNodes.append(self) self.parentNode = p if p.symtab and self.symtab: - self.symtab = dict(p.symtab.items() + self.symtab.items()) + self.symtab = dict(list(p.symtab.items()) + list(self.symtab.items())) elif p.symtab: self.symtab = copy.copy(p.symtab) diff --git a/jskparser/ast/visit/symtabgen.py b/jskparser/ast/visit/symtabgen.py index c7ec933..67cbce7 100644 --- a/jskparser/ast/visit/symtabgen.py +++ b/jskparser/ast/visit/symtabgen.py @@ -163,7 +163,7 @@ def visit(self, node): # Catch args that are actually Axiom Declarations if p.method: p.method.symtab.update(node.symtab) - node.symtab = dict(p.method.symtab.items() + node.symtab.items()) + node.symtab = dict(list(p.method.symtab.items()) + list(node.symtab.items())) if node.body: node.body.accept(self) # print node.symtab From 39fd61801b5db84b23c1325d0723e272754b4fc9 Mon Sep 17 00:00:00 2001 From: natebragg Date: Wed, 20 Feb 2019 09:44:18 -0500 Subject: [PATCH 12/12] Re-encode as utf8, so open() in python 3 doesn't reject it. --- test/axioms/benchmarks/HashMap2/HashTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/axioms/benchmarks/HashMap2/HashTable.java b/test/axioms/benchmarks/HashMap2/HashTable.java index 259e247..5f07649 100644 --- a/test/axioms/benchmarks/HashMap2/HashTable.java +++ b/test/axioms/benchmarks/HashMap2/HashTable.java @@ -1,7 +1,7 @@ package Interfaing; public interface HashTable { - // put key­value pair into the table + // put key­value pair into the table public void put(K key, V value); // get value paired with key, return null if