Added:
/branches/0.5/doc
/branches/0.5/doc/Makefile
/branches/0.5/doc/_static
/branches/0.5/doc/_templates
/branches/0.5/doc/conf.py
/branches/0.5/doc/customization.rst
/branches/0.5/doc/features.rst
/branches/0.5/doc/index.rst
/branches/0.5/doc/intro.rst
/branches/0.5/doc/quick-server
/branches/0.5/doc/usage.rst
/branches/0.5/java2python/mod/includes.py
Modified:
/branches/0.5/bin/j2py
/branches/0.5/java2python/compiler/__init__.py
/branches/0.5/java2python/compiler/template.py
/branches/0.5/java2python/compiler/visitor.py
/branches/0.5/java2python/config/__init__.py
/branches/0.5/java2python/config/default.py
/branches/0.5/java2python/mod/basic.py
/branches/0.5/test/Assign2.java
/branches/0.5/test/Expr1.java
/branches/0.5/test/Makefile
/branches/0.5/test/testconfig.py
=======================================
--- /dev/null
+++ /branches/0.5/doc/Makefile Mon Jul 26 18:14:27 2010
@@ -0,0 +1,130 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER))
$(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp
devhelp epub latex latexpdf text man changes linkcheck doctest
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or
PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " changes to make an overview of all changed/added/deprecated
items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if
enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/java2python.qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/java2python.qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/java2python"
+ @echo "# ln -s $(BUILDDIR)/devhelp
$$HOME/.local/share/devhelp/java2python"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ make -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
=======================================
--- /dev/null
+++ /branches/0.5/doc/conf.py Mon Jul 26 18:14:27 2010
@@ -0,0 +1,222 @@
+# -*- coding: utf-8 -*-
+#
+# java2python documentation build configuration file, created by
+# sphinx-quickstart on Mon Jul 26 14:04:17 2010.
+#
+# This file is execfile()d with the current directory set to its
containing dir.
+#
+# Note that not all possible configuration values are present in this
+# autogenerated file.
+#
+# All configuration values have a default; values that are commented out
+# serve to show the default.
+
+import sys, os
+
+# If extensions (or modules to document with autodoc) are in another
directory,
+# add these directories to sys.path here. If the directory is relative to
the
+# documentation root, use os.path.abspath to make it absolute, like shown
here.
+#sys.path.insert(0, os.path.abspath('.'))
+
+# -- General configuration
-----------------------------------------------------
+
+# If your documentation needs a minimal Sphinx version, state it here.
+#needs_sphinx = '1.0'
+
+# Add any Sphinx extension module names here, as strings. They can be
extensions
+# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'java2python'
+copyright = u'2010, Troy Melhase'
+
+# The version info for the project you're documenting, acts as replacement
for
+# |version| and |release|, also used in various other places throughout the
+# built documents.
+#
+# The short X.Y version.
+version = '0.5'
+# The full version, including alpha/beta/rc tags.
+release = '0.5'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to
some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all
documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- Options for HTML output
---------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages. See the documentation for
+# a list of builtin themes.
+html_theme = 'default'
+
+# Theme options are theme-specific and customize the look and feel of a
theme
+# further. For a list of options available for each theme, see the
+# documentation.
+#html_theme_options = {}
+
+# Add any paths that contain custom themes here, relative to this
directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents. If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar. Default is the same as
html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the
top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of
the
+# docs. This file should be a Windows icon file (.ico) being 16x16 or
32x32
+# pixels large.
+#html_favicon = None
+
+# Add any paths that contain custom static files (such as style sheets)
here,
+# relative to this directory. They are copied after the builtin static
files,
+# so a file named "default.css" will overwrite the builtin "default.css".
+html_static_path = ['_static']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page
bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is
True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is
True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages
will
+# contain a <link> tag referring to it. The value of this option must be
the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'java2pythondoc'
+
+
+# -- Options for LaTeX output
--------------------------------------------------
+
+# The paper size ('letter' or 'a4').
+#latex_paper_size = 'letter'
+
+# The font size ('10pt', '11pt' or '12pt').
+#latex_font_size = '10pt'
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass
[howto/manual]).
+latex_documents = [
+ ('index', 'java2python.tex', u'java2python Documentation',
+ u'Troy Melhase', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the
top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are
parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Additional stuff for the LaTeX preamble.
+#latex_preamble = ''
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output
--------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+ ('index', 'java2python', u'java2python Documentation',
+ [u'Troy Melhase'], 1)
+]
+
+
+rst_epilog = """
+.. |j2py| replace:: java2python
+
+"""
=======================================
--- /dev/null
+++ /branches/0.5/doc/customization.rst Mon Jul 26 18:14:27 2010
@@ -0,0 +1,14 @@
+.. _customization:
+
+Customization
+=============
+
+Basic Customization
+-------------------
+basic and advanced... wouldn't it be great?
+
+
+Advanced Customization
+----------------------
+
+There are two ways to further customize the behavior of |j2py|.
=======================================
--- /dev/null
+++ /branches/0.5/doc/features.rst Mon Jul 26 18:14:27 2010
@@ -0,0 +1,41 @@
+.. _features:
+
+********************
+Translation Features
+********************
+
+The |j2py| package can translate any syntactically valid Java source
+code file. The generated Python code is not guaranteed to run, nor is
+guaranteed to be valid syntatically valid Python. However, |j2py|
+works well many cases, and in some of those, it creates perfectly
+usable and workable Python code.
+
+The remainder of this chapter describes how Java language features are
+translated into Python constructs.
+
+
+General Approach
+================
+
+The approach taken by |j2py| is to favor readability over correctness
+for two reasons: first, it is quite rare that Java source code will
+work correctly without modification because of semantic and run-time
+differences, and second, |j2py| is meant to aid in one-time and
+ongoing translation projects.
+
+
+What Works Well (Unless You Try Really Hard to Break It)
+========================================================
+
+
+What Works Mostly (Or Sometimes if You're Lucky)
+================================================
+
+
+What Works Barely (Or Not at All)
+=================================
+
+
+A (Mostly) Complete List
+=========================
+
=======================================
--- /dev/null
+++ /branches/0.5/doc/index.rst Mon Jul 26 18:14:27 2010
@@ -0,0 +1,30 @@
+.. java2python documentation master file, created by
+ sphinx-quickstart on Mon Jul 26 14:04:17 2010.
+ You can adapt this file completely to your liking, but it should at
least
+ contain the root `toctree` directive.
+
+java2python |release| Documentation
+===================================
+
+Welcome! This is the documentation for java2python |release|, last
updated |today|.
+
+
+Contents:
+
+.. toctree::
+ :maxdepth: 2
+ :numbered:
+
+ intro.rst
+ features.rst
+ usage.rst
+ customization.rst
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+
=======================================
--- /dev/null
+++ /branches/0.5/doc/intro.rst Mon Jul 26 18:14:27 2010
@@ -0,0 +1,9 @@
+.. _intro:
+
+Introduction
+============
+
+wah wah wah
+
+it's like a pedal.
+
=======================================
--- /dev/null
+++ /branches/0.5/doc/quick-server Mon Jul 26 18:14:27 2010
@@ -0,0 +1,4 @@
+#!/bin/bash
+cd _build/dirhtml && python -m SimpleHTTPServer
+
+
=======================================
--- /dev/null
+++ /branches/0.5/doc/usage.rst Mon Jul 26 18:14:27 2010
@@ -0,0 +1,106 @@
+.. _usage:
+
+*****
+Usage
+*****
+
+Basic Invocation
+================
+
+The simplest way to invoke |j2py| is with the :command:`j2py` command
+and the name of an input file::
+
+ $ j2py SourceFile.java
+
+The input file may also be specified with the :option:`-i`
(or :option:`--input`) option.
+
+The generated source code will be written to ``stdout`` by default.
+It can be redirected via the shell or by specifying the :option:`-o`
+(or :option:`--output`) option and a filename.
+
+If no input filename is given (or if the input filename is ``-``),
+:command:`j2py` reads from ``stdin``.
+
+
+Options and Arguments
+=====================
+
+The :command:`j2py` command accepts several options that control its
+behavior. To change code generation behavior, refer to the
+:ref:`customization` chapter.
+
+
+Code generation:
+
+
+ * .. option:: -i NAME, --input NAME
+
+ Read from the specified file. Specify ``-`` for ``stdin``. If
+ not given the command will read from ``stdin``.
+
+ * .. option:: -o NAME, --output NAME
+
+ Write to the specified file. Specify ``-`` for ``stdout``. If
+ not given the command will write to ``stdout``.
+
+ * .. option:: -l LEVEL, --loglevel LEVEL
+
+ Set the logging package to the specified log level. The log level
+ may given as an integer (e.g., ``50`` for critical) or by name
+ (e.g., ``CRTICIAL``, ``Critical``, or ``critical``).
+
+ * .. option:: -c NAME, --config NAME
+
+ Use the specified configuration module or file. This option may
+ be repeated.
+
+ Configuration values are retrieved in reverse order, i.e., from
+ the final value given to the first given, with the default
+ configuration referenced last.
+
+ * .. option:: -n, --nodefaults
+
+ Ignore the default configuration module.
+
+ * .. option:: -r, --nocolor
+
+ Disable colorized output.
+
+ This option has no effect on Windows systems because colorized
+ output is always disabled in those environments.
+
+Development:
+
+
+ * .. option:: -p, --python-tree
+
+ Print a representation of the internal Python code tree.
+ Representation is written to ``stderr``.
+
+ * .. option:: -j, --java-ast
+
+ Print a representation of the Java abstract syntax tree.
+ Representation is written to ``stderr``.
+
+ * .. option:: -f, --profile
+
+ Profile execution and print the results to ``stederr``.
+
+ * .. option:: -s, --skip-source
+
+ Do not write generated source. This most useful in development of
+ |j2py| itself and when combined with :option:`-p` and/or
+ :option:`-j`.
+
+
+Meta:
+
+ * .. option:: -h, --help
+
+ Show a help message and exit
+
+ * .. option:: --version
+
+ Show the program version number and exit.
+
+
=======================================
--- /dev/null
+++ /branches/0.5/java2python/mod/includes.py Mon Jul 26 18:14:27 2010
@@ -0,0 +1,27 @@
+def bsr(value, bits):
+ """ bsr(value, bits) -> value shifted right by bits
+
+ This function is here because an expression in the original java
+ source contained the token '>>>' and/or '>>>=' (bit shift right
+ and/or bit shift right assign). In place of these, the python
+ source code below contains calls to this function.
+
+ Copyright 2003 Jeffrey Clement. See pyrijnadel.py for license and
+ original source.
+ """
+ minint = -2147483648
+ if bits == 0:
+ return value
+ elif bits == 31:
+ if value & minint:
+ return 1
+ else:
+ return 0
+ elif bits < 0 or bits > 31:
+ raise ValueError('bad shift count')
+ tmp = (value & 0x7FFFFFFE) // 2**bits
+ if (value & minint):
+ return (tmp | (0x40000000 // 2**(bits-1)))
+ else:
+ return tmp
+
=======================================
--- /branches/0.5/bin/j2py Mon Jul 19 15:02:15 2010
+++ /branches/0.5/bin/j2py Mon Jul 26 18:14:27 2010
@@ -149,7 +149,7 @@
help='Write to OUTPUTFILE. May use - for stdout.',
metavar='OUTPUTFILE', default=None)
parser.add_option('-c', '--config', dest='configs',
- help='Use CONFIG module (not file). May be repeated.',
+ help='Use CONFIG file or module. May be repeated.',
metavar='CONFIG', default=[],
action='append')
parser.add_option('-n', '--nodefaults', dest='includedefaults',
=======================================
--- /branches/0.5/java2python/compiler/__init__.py Sat Jul 24 01:19:21 2010
+++ /branches/0.5/java2python/compiler/__init__.py Mon Jul 26 18:14:27 2010
@@ -9,33 +9,34 @@
)
-def buildAST(source, config=None):
- lexer = Lexer(LocalSourceStream(source))
- parser = Parser(LocalTokenStream(lexer))
-
- def setNodeRecognizers(node):
- node.parser = parser
+
+def makeRecognizersCallback(lexer, parser):
+ def setRecognizers(node):
node.lexer = lexer
-
- parser.setTreeAdaptor(LocalTreeAdaptor(setNodeRecognizers))
+ node.parser = parser
+ return setRecognizers
+
+
+def buildAST(source, config=None):
+ lexer = Lexer(LocalSourceStream(source))
+ parser = Parser(LocalTokenStream(lexer))
+ adapter = LocalTreeAdaptor(makeRecognizersCallback(lexer, parser))
+ parser.setTreeAdaptor(adapter)
scope = parser.javaSource()
return scope.tree
def transformAST(tree, config):
- for selector, call in config.handlers('astTransforms'):
+ for selector, call in config.last('astTransforms', ()):
for node in walkTreeSelector(tree, selector):
call(node, config)
-
def buildJavaDocAST(source):
from java2python.lang.JavaDocLexer import JavaDocLexer
from java2python.lang.JavaDocParser import JavaDocParser
-
lexer = JavaDocLexer(LocalSourceStream(source))
parser = JavaDocParser(LocalTokenStream(lexer))
-
scope = parser.commentBody()
return scope.tree
=======================================
--- /branches/0.5/java2python/compiler/template.py Sat Jul 24 12:54:43 2010
+++ /branches/0.5/java2python/compiler/template.py Mon Jul 26 18:14:27 2010
@@ -103,12 +103,18 @@
def configHandler(self, part, suffix='Handler', default=None):
""" Returns the config handler for this type of template. """
name = '{0}{1}{2}'.format(self.typeName, part, suffix)
- return self.config.handler(name, default)
-
- def configHandlers(self, part, suffix='Handlers', default=None):
+ return self.config.last(name, default)
+
+ def configHandlers(self, part, suffix='Handlers'):
""" Returns config handlers for this type of template """
name = '{0}{1}{2}'.format(self.typeName, part, suffix)
- return self.config.handlers(name, default)
+ for handler in self.config.last(name, ()):
+ if isinstance(handler, (basestring, )):
+ def wrapper(*args, **kwds):
+ yield handler
+ yield wrapper
+ else:
+ yield handler
def configTransformers(self, visitor):
name = visitor.factoryTypeName
=======================================
--- /branches/0.5/java2python/compiler/visitor.py Sat Jul 24 12:54:43 2010
+++ /branches/0.5/java2python/compiler/visitor.py Mon Jul 26 18:14:27 2010
@@ -243,6 +243,12 @@
class MethodContent(Base):
""" MethodContent -> accepts trees for blocks within methods. """
+ def acceptBreak(self, node, memo):
+ """ Accept and process a break statement. """
+ if node.parent and node.parent.type in (tokens.CASE, tokens.DEFAULT):
+ return
+ breakStat = self.factory.statement('break', parent=self)
+
def acceptWhile(self, node, memo):
""" Accept and process a while block. """
# WHILE - PARENTESIZED_EXPR - BLOCK_SCOPE
@@ -470,6 +476,7 @@
self.parameters.append(param)
return self
+
class Expression(Base):
""" Class -> accepts trees for expression objects. """
@@ -507,6 +514,22 @@
acceptShiftLeft = equalityExpression
acceptMod = equalityExpression
+ def acceptBitShiftRight(self, node, memo):
+ expr = self.factory.expr
+ self.fs = 'bsr(' + FS.l + ', ' + FS.r + ')'
+ self.left, self.right = visitors = expr(parent=self), expr()
+ self.zipWalk(node.children, visitors, memo)
+ module = self.parents(lambda x:x.isModule).next()
+ module.needsBsrFunc = True
+
+ def acceptBitShiftRightAssign(self, node, memo):
+ expr = self.factory.expr
+ self.fs = FS.l + ' = bsr(' + FS.l + ', ' + FS.r + ')'
+ self.left, self.right = visitors = expr(parent=self), expr()
+ self.zipWalk(node.children, visitors, memo)
+ module = self.parents(lambda x:x.isModule).next()
+ module.needsBsrFunc = True
+
def assignExpression(self, node, memo):
""" Accept and processes an assignment expression (Python statement). """
expr = self.factory.expr
@@ -542,7 +565,6 @@
self.left = self.factory.expr(parent=self)
self.left.walk(node.firstChildOfType(tokens.TYPE), memo)
-
def acceptClassConstructorCall(self, node, memo):
""" Accept and process a class constructor call. """
self.acceptMethodCall(node, memo) # probably wrong
=======================================
--- /branches/0.5/java2python/config/__init__.py Mon Jul 19 16:53:47 2010
+++ /branches/0.5/java2python/config/__init__.py Mon Jul 26 18:14:27 2010
@@ -1,5 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from functools import reduce
+from imp import load_source
+from os import path
class Config(object):
@@ -9,36 +12,20 @@
def __init__(self, names):
self.configs = [self.load(name) for name in names]
- def __iter__(self):
- return iter(self.configs)
-
def every(self, key, default=None):
- return [getattr(config, key, default) for config in self]
+ return [getattr(config, key, default) for config in self.configs]
def last(self, key, default=None):
- for config in reversed(list(self)):
+ for config in reversed(self.configs):
if hasattr(config, key):
return getattr(config, key)
return default
- def handler(self, key, default=None):
- handler = self.last(key, default)
- return handler
-
- def handlers(self, key, default=None):
- handlers = self.last(key, default)
- if handlers is default:
- return
- for handler in handlers:
- yield handler
-
@staticmethod
def load(name):
- """ load(name) -> import and return a module by name in dotted form.
-
- Copied from the Python lib docs.
- """
- mod = __import__(name)
- for comp in name.split('.')[1:]:
- mod = getattr(mod, comp)
+ """ import and return a module from dotted form or filename. """
+ if path.exists(name):
+ mod = load_source(str(hash(name)), name)
+ else:
+ mod = reduce(getattr, name.split('.')[1:], __import__(name))
return mod
=======================================
--- /branches/0.5/java2python/config/default.py Sat Jul 24 01:19:21 2010
+++ /branches/0.5/java2python/config/default.py Mon Jul 26 18:14:27 2010
@@ -31,6 +31,7 @@
basic.configImports,
basic.commentedImports,
basic.commentedPackageName,
+ basic.insertBsr,
]
@@ -75,7 +76,7 @@
# These generator-functions yield base types for classes.
classBaseHandlers = [
- basic.mapClassType,
+ basic.mapClassType
]
=======================================
--- /branches/0.5/java2python/mod/basic.py Sat Jul 24 01:19:21 2010
+++ /branches/0.5/java2python/mod/basic.py Mon Jul 26 18:14:27 2010
@@ -66,6 +66,7 @@
return text
+
def mapClassType(obj):
bases = obj.bases or ('object', )
for name in bases:
@@ -107,3 +108,15 @@
def globalNameCounter(original, counter=count()):
return '__{0}_{1}'.format(original, counter.next())
+
+
+def getBsrSrc():
+ from inspect import getsource
+ from java2python.mod.includes import bsr
+ return getsource(bsr)
+
+
+def insertBsr(module):
+ if getattr(module, 'needsBsrFunc', False):
+ for line in getBsrSrc().split('\n'):
+ yield line
=======================================
--- /branches/0.5/test/Assign2.java Thu Jul 1 15:12:49 2010
+++ /branches/0.5/test/Assign2.java Mon Jul 26 18:14:27 2010
@@ -5,5 +5,6 @@
x >>>= 1;
System.out.println(x);
+ x >>>= 3;
}
}
=======================================
--- /branches/0.5/test/Expr1.java Sat Jul 24 01:19:21 2010
+++ /branches/0.5/test/Expr1.java Mon Jul 26 18:14:27 2010
@@ -128,8 +128,10 @@
System.out.println(!false ? 1 : 0);
System.out.println( (Integer) x );
-/*
-*/
+
+
+ x = 7;
+ System.out.println(x >>> 1);
}
}
=======================================
--- /branches/0.5/test/Makefile Sat Jul 24 01:19:21 2010
+++ /branches/0.5/test/Makefile Mon Jul 26 18:14:27 2010
@@ -14,7 +14,7 @@
#@echo cd Package1 && ../../bin/j2py -i Class1.java -o Class1.py
$(java_sources):
- @javac $@ && ../bin/j2py -i $@ -o $(basename $@).py -c testconfig
+ @javac $@ && ../bin/j2py -i $@ -o $(basename $@).py -c ./testconfig.py
@chmod u+x $(basename $@).py
@bash ./compare_outputs.sh "java -ea $(basename $@)" "python $(basename
$@).py" "$@" && rm "$(basename $@).py" "$(basename $@).class"
=======================================
--- /branches/0.5/test/testconfig.py Mon Jul 12 16:39:08 2010
+++ /branches/0.5/test/testconfig.py Mon Jul 26 18:14:27 2010
@@ -1,26 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from java2python.config import default
-## lines written at the beginning of each generated module. this value
-## is cumulative, so when user-defined configuration modules specify
-## this value, those lines are written after these.
-modulePreamble = [
-# 'from threading import Lock',
-# 'from overloading import overloaded',
-# 'from java2python.config.examples import Annotation, Enum',
- ]
-
-
-def addOverloading(obj):
- yield 'from overloading import overloaded'
-
-
-modulePrologueHandlers = [
- addOverloading,
- ]
-
-moduleStringImports = [
+modulePrologueHandlers = default.modulePrologueHandlers + [
'from overloading import overloaded',
]
@@ -44,24 +27,3 @@
(r'(.*?)outer\.cls', r'\1outer'),
(r'from java\.util import \*', ''),
]
-
-
-
-enumConstantHandlers = [
-# 'java2python.mods.enums.pyStrings',
- 'java2python.mods.enums.minJava',
-
-]
-
-classHandlers = [
- #'java2python.mods.classes.sortMethods',
- 'java2python.mods.classes.updateConstructor',
-
- 'java2python.mods.classes.convertProperties',
- 'java2python.mods.classes.overloadMethods',
- 'java2python.mods.simpleDocString',
- 'java2python.mods.classes.insertModifiersAsComments',
- 'java2python.mods.classes.updateBases',
- 'java2python.mods.classes.updateAnnotation',
-
-]