Merge
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 27 May 2008 11:41:55 +0000 (13:41 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Tue, 27 May 2008 11:41:55 +0000 (13:41 +0200)
1  2 
Cython/CodeWriter.py
Cython/Compiler/ExprNodes.py
Cython/Compiler/Main.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/Nodes.py
Cython/Compiler/Parsing.py
Cython/Compiler/Scanning.py

index c490fb71fde93c89bc52d1b9a100964a94b9a387,0000000000000000000000000000000000000000..283d080e703575204e51f801b1f447694231c9ed
mode 100644,000000..100644
--- /dev/null
@@@ -1,205 -1,0 +1,205 @@@
-         self.comma_seperated_list(node.args)
-         if node.ends_with_comma:
 +from Cython.Compiler.Visitor import TreeVisitor
 +from Cython.Compiler.Nodes import *
 +
 +"""
 +Serializes a Cython code tree to Cython code. This is primarily useful for
 +debugging and testing purposes.
 +
 +The output is in a strict format, no whitespace or comments from the input
 +is preserved (and it could not be as it is not present in the code tree).
 +"""
 +
 +class LinesResult(object):
 +    def __init__(self):
 +        self.lines = []
 +        self.s = u""
 +        
 +    def put(self, s):
 +        self.s += s
 +    
 +    def newline(self):
 +        self.lines.append(self.s)
 +        self.s = u""
 +    
 +    def putline(self, s):
 +        self.put(s)
 +        self.newline()
 +
 +class CodeWriter(TreeVisitor):
 +
 +    indent_string = u"    "
 +    
 +    def __init__(self, result = None):
 +        super(CodeWriter, self).__init__()
 +        if result is None:
 +            result = LinesResult()
 +        self.result = result
 +        self.numindents = 0
 +    
 +    def write(self, tree):
 +        self.visit(tree)
 +    
 +    def indent(self):
 +        self.numindents += 1
 +    
 +    def dedent(self):
 +        self.numindents -= 1
 +    
 +    def startline(self, s = u""):
 +        self.result.put(self.indent_string * self.numindents + s)
 +    
 +    def put(self, s):
 +        self.result.put(s)
 +    
 +    def endline(self, s = u""):
 +        self.result.putline(s)
 +
 +    def line(self, s):
 +        self.startline(s)
 +        self.endline()
 +    
 +    def comma_seperated_list(self, items, output_rhs=False):
 +        if len(items) > 0:
 +            for item in items[:-1]:
 +                self.visit(item)
 +                if output_rhs and item.rhs is not None:
 +                    self.put(u" = ")
 +                    self.visit(item.rhs)
 +                self.put(u", ")
 +            self.visit(items[-1])
 +    
 +    def visit_Node(self, node):
 +        raise AssertionError("Node not handled by serializer: %r" % node)
 +    
 +    def visit_ModuleNode(self, node):
 +        self.visitchildren(node)
 +    
 +    def visit_StatListNode(self, node):
 +        self.visitchildren(node)
 +
 +    def visit_FuncDefNode(self, node):
 +        self.startline(u"def %s(" % node.name)
 +        self.comma_seperated_list(node.args)
 +        self.endline(u"):")
 +        self.indent()
 +        self.visit(node.body)
 +        self.dedent()
 +    
 +    def visit_CArgDeclNode(self, node):
 +        if node.base_type.name is not None:
 +            self.visit(node.base_type)
 +            self.put(u" ")
 +        self.visit(node.declarator)
 +        if node.default is not None:
 +            self.put(u" = ")
 +            self.visit(node.default)
 +    
 +    def visit_CNameDeclaratorNode(self, node):
 +        self.put(node.name)
 +    
 +    def visit_CSimpleBaseTypeNode(self, node):
 +        # See Parsing.p_sign_and_longness
 +        if node.is_basic_c_type:
 +            self.put(("unsigned ", "", "signed ")[node.signed])
 +            if node.longness < 0:
 +                self.put("short " * -node.longness)
 +            elif node.longness > 0:
 +                self.put("long " * node.longness)
 +            
 +        self.put(node.name)
 +    
 +    def visit_SingleAssignmentNode(self, node):
 +        self.startline()
 +        self.visit(node.lhs)
 +        self.put(u" = ")
 +        self.visit(node.rhs)
 +        self.endline()
 +    
 +    def visit_NameNode(self, node):
 +        self.put(node.name)
 +    
 +    def visit_IntNode(self, node):
 +        self.put(node.value)
 +        
 +    def visit_IfStatNode(self, node):
 +        # The IfClauseNode is handled directly without a seperate match
 +        # for clariy.
 +        self.startline(u"if ")
 +        self.visit(node.if_clauses[0].condition)
 +        self.endline(":")
 +        self.indent()
 +        self.visit(node.if_clauses[0].body)
 +        self.dedent()
 +        for clause in node.if_clauses[1:]:
 +            self.startline("elif ")
 +            self.visit(clause.condition)
 +            self.endline(":")
 +            self.indent()
 +            self.visit(clause.body)
 +            self.dedent()
 +        if node.else_clause is not None:
 +            self.line("else:")
 +            self.indent()
 +            self.visit(node.else_clause)
 +            self.dedent()
 +
 +    def visit_PassStatNode(self, node):
 +        self.startline(u"pass")
 +        self.endline()
 +    
 +    def visit_PrintStatNode(self, node):
 +        self.startline(u"print ")
++        self.comma_seperated_list(node.arg_tuple.args)
++        if not node.append_newline:
 +            self.put(u",")
 +        self.endline()
 +
 +    def visit_BinopNode(self, node):
 +        self.visit(node.operand1)
 +        self.put(u" %s " % node.operator)
 +        self.visit(node.operand2)
 +    
 +    def visit_CVarDefNode(self, node):
 +        self.startline(u"cdef ")
 +        self.visit(node.base_type)
 +        self.put(u" ")
 +        self.comma_seperated_list(node.declarators, output_rhs=True)
 +        self.endline()
 +
 +    def visit_ForInStatNode(self, node):
 +        self.startline(u"for ")
 +        self.visit(node.target)
 +        self.put(u" in ")
 +        self.visit(node.iterator.sequence)
 +        self.endline(u":")
 +        self.indent()
 +        self.visit(node.body)
 +        self.dedent()
 +        if node.else_clause is not None:
 +            self.line(u"else:")
 +            self.indent()
 +            self.visit(node.else_clause)
 +            self.dedent()
 +
 +    def visit_SequenceNode(self, node):
 +        self.comma_seperated_list(node.args) # Might need to discover whether we need () around tuples...hmm...
 +    
 +    def visit_SimpleCallNode(self, node):
 +        self.put(node.function.name + u"(")
 +        self.comma_seperated_list(node.args)
 +        self.put(")")
 +
 +    def visit_ExprStatNode(self, node):
 +        self.startline()
 +        self.visit(node.expr)
 +        self.endline()
 +    
 +    def visit_InPlaceAssignmentNode(self, node):
 +        self.startline()
 +        self.visit(node.lhs)
 +        self.put(" %s= " % node.operator)
 +        self.visit(node.rhs)
 +        self.endline()
 +    
 +    
 +
Simple merge
index c5e9fb63ac52d5106edebb0601530d825be14de1,0782f52f43c8a2e0a73615fb6e1e8d84d3add49d..5d45408741604ae2d7fe3720cbcd7cbd10f77454
@@@ -7,9 -7,15 +7,15 @@@ if sys.version_info[:2] < (2, 2)
      sys.stderr.write("Sorry, Cython requires Python 2.2 or later\n")
      sys.exit(1)
  
+ try:
+     set
+ except NameError:
+     # Python 2.3
+     from sets import Set as set
  from time import time
  import Version
 -from Scanning import PyrexScanner
 +from Scanning import PyrexScanner, FileSourceDescriptor
  import Errors
  from Errors import PyrexError, CompileError, error
  import Parsing
Simple merge
Simple merge
Simple merge
index 1474f84c895d2fae4bc7c94c9837852ba590b043,bb338a5eb182819b6cfc0502b4e58dd4db335e6f..6a39639f2e8b3a55dce915e8ac12d596b031237b
@@@ -15,10 -15,8 +15,10 @@@ from Cython import Plex, Util
  from Cython.Plex import Scanner
  from Cython.Plex.Errors import UnrecognizedInput
  from Errors import CompileError, error
- from Lexicon import string_prefixes, make_lexicon
+ from Lexicon import string_prefixes, raw_prefixes, make_lexicon
  
 +from Cython import Utils
 +
  plex_version = getattr(Plex, '_version', None)
  #print "Plex version:", plex_version ###