Commit 1c96a947 authored by Robert Bradshaw's avatar Robert Bradshaw

initial merge

parents c1131235 5aab5520
......@@ -25,8 +25,9 @@ class CCodeWriter:
in_try_finally = 0
def __init__(self, outfile_name):
self.f = open_new_file(outfile_name)
def __init__(self, f):
#self.f = open_new_file(outfile_name)
self.f = f
self.level = 0
self.bol = 1
self.marker = None
......@@ -101,6 +102,7 @@ class CCodeWriter:
def init_labels(self):
self.label_counter = 0
self.labels_used = {}
self.return_label = self.new_label()
self.new_error_label()
self.continue_label = None
......@@ -156,9 +158,17 @@ class CCodeWriter:
self.set_all_labels(new_labels)
return old_labels
def use_label(self, lbl):
self.labels_used[lbl] = 1
def put_label(self, lbl):
if lbl in self.labels_used:
self.putln("%s:;" % lbl)
def put_goto(self, lbl):
self.use_label(lbl)
self.putln("goto %s;" % lbl)
def put_var_declarations(self, entries, static = 0, dll_linkage = None,
definition = True):
for entry in entries:
......@@ -167,30 +177,23 @@ class CCodeWriter:
def put_var_declaration(self, entry, static = 0, dll_linkage = None,
definition = True):
#print "Code.put_var_declaration:", entry.name, "definition =", definition
#print "Code.put_var_declaration:", entry.name, "definition =", definition ###
visibility = entry.visibility
if visibility == 'private' and not definition:
return
if not entry.used and visibility == "private":
return
storage_class = ""
if visibility == 'extern':
storage_class = Naming.extern_c_macro
elif visibility == 'public':
if definition:
storage_class = ""
else:
if not definition:
storage_class = Naming.extern_c_macro
elif visibility == 'private':
if static:
storage_class = "static"
else:
storage_class = ""
else:
storage_class = ""
if storage_class:
self.put("%s " % storage_class)
#if visibility == 'extern' or visibility == 'public' and not definition:
# self.put("%s " % Naming.extern_c_macro)
#elif static and visibility <> 'public':
# self.put("static ")
if visibility <> 'public':
dll_linkage = None
self.put(entry.type.declaration_code(entry.cname,
......@@ -209,10 +212,6 @@ class CCodeWriter:
def as_pyobject(self, cname, type):
return typecast(py_object_type, type, cname)
#if type.is_extension_type and type.base_type:
# return "(PyObject *)" + cname
#else:
# return cname
def put_incref(self, cname, type):
self.putln("Py_INCREF(%s);" % self.as_pyobject(cname, type))
......@@ -257,8 +256,9 @@ class CCodeWriter:
self.putln("Py_XDECREF(%s); %s = 0;" % (
self.entry_as_pyobject(entry), entry.cname))
def put_var_decrefs(self, entries):
def put_var_decrefs(self, entries, used_only = 0):
for entry in entries:
if not used_only or entry.used:
if entry.xdecref_cleanup:
self.put_var_xdecref(entry)
else:
......@@ -295,13 +295,15 @@ class CCodeWriter:
term))
def error_goto(self, pos):
lbl = self.error_label
self.use_label(lbl)
return "{%s = %s[%s]; %s = %s; goto %s;}" % (
Naming.filename_cname,
Naming.filetable_cname,
self.lookup_filename(pos[0]),
Naming.lineno_cname,
pos[1],
self.error_label)
lbl)
def lookup_filename(self, filename):
try:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -8,6 +8,7 @@ from types import ListType, TupleType
from Scanning import PyrexScanner
import Nodes
import ExprNodes
from ModuleNode import ModuleNode
from Errors import error, InternalError
def p_ident(s, message = "Expected an identifier"):
......@@ -435,13 +436,7 @@ def p_atom(s):
elif sy == '`':
return p_backquote_expr(s)
elif sy == 'INT':
digits = s.systring
if digits[:2] == "0x":
value = long(digits[2:], 16)
elif digits[:1] == "0":
value = int(digits, 8)
else:
value = int(s.systring)
value = s.systring
s.next()
return ExprNodes.IntNode(pos, value = value)
elif sy == 'LONG':
......@@ -539,7 +534,7 @@ def p_string_literal(s):
elif c == '\n':
pass
else:
chars.append(systr[1:])
chars.append(r'\\' + systr[1:])
elif sy == 'NEWLINE':
chars.append(r'\n')
elif sy == 'END_STRING':
......@@ -764,7 +759,6 @@ def p_expression_or_assignment(s):
if len(nodes) == 1:
return nodes[0]
else:
#return Nodes.StatListNode(nodes[0].pos, stats = nodes)
return Nodes.ParallelAssignmentNode(nodes[0].pos, stats = nodes)
def flatten_parallel_assignments(input, output):
......@@ -1480,19 +1474,19 @@ def p_exception_value_clause(s):
if s.sy == '?':
exc_check = 1
s.next()
exc_val = p_exception_value(s)
exc_val = p_simple_expr(s) #p_exception_value(s)
return exc_val, exc_check
def p_exception_value(s):
sign = ""
if s.sy == "-":
sign = "-"
s.next()
if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'):
s.systring = sign + s.systring
return p_atom(s)
else:
s.error("Exception value must be an int or float literal or NULL")
#def p_exception_value(s):
# sign = ""
# if s.sy == "-":
# sign = "-"
# s.next()
# if s.sy in ('INT', 'LONG', 'FLOAT', 'NULL'):
# s.systring = sign + s.systring
# return p_atom(s)
# else:
# s.error("Exception value must be an int or float literal or NULL")
c_arg_list_terminators = ('*', '**', '.', ')')
c_arg_list_trailers = ('.', '*', '**')
......@@ -1894,7 +1888,7 @@ def p_module(s, pxd, full_module_name):
if s.sy <> 'EOF':
s.error("Syntax error in statement [%s,%s]" % (
repr(s.sy), repr(s.systring)))
return Nodes.ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
return ModuleNode(pos, doc = doc, body = body, full_module_name = full_module_name)
#----------------------------------------------
#
......
......@@ -262,14 +262,14 @@ class CType(PyrexType):
from_py_function = None
class CSimpleType(CType):
#
# Base class for all unstructured C types.
#
pass
#class CSimpleType(CType):
# #
# # Base class for all unstructured C types.
# #
# pass
class CVoidType(CSimpleType):
class CVoidType(CType):
is_void = 1
def __repr__(self):
......@@ -316,9 +316,6 @@ class CNumericType(CType):
u = "unsigned "
return "<CNumericType %s%s>" % (u, rank_to_type_name[self.rank])
def assignable_from_resolved_type(self, src_type):
return src_type.is_numeric or src_type is error_type
def declaration_code(self, entity_code,
for_display = 0, dll_linkage = None, pyrex = 0):
if self.signed:
......@@ -328,8 +325,6 @@ class CNumericType(CType):
base = public_decl(u + rank_to_type_name[self.rank], dll_linkage)
return "%s %s" % (base, entity_code)
# return "%s%s %s" % (u, rank_to_type_name[self.rank], entity_code)
class CIntType(CNumericType):
......@@ -342,6 +337,9 @@ class CIntType(CNumericType):
CNumericType.__init__(self, rank, signed, pymemberdef_typecode)
self.is_returncode = is_returncode
def assignable_from_resolved_type(self, src_type):
return src_type.is_int or src_type.is_enum or src_type is error_type
class CBIntType(CIntType):
......@@ -390,6 +388,9 @@ class CFloatType(CNumericType):
def __init__(self, rank, pymemberdef_typecode = None):
CNumericType.__init__(self, rank, 1, pymemberdef_typecode)
def assignable_from_resolved_type(self, src_type):
return src_type.is_numeric or src_type is error_type
class CArrayType(CType):
# base_type CType Element type
......@@ -464,6 +465,8 @@ class CPtrType(CType):
return 1
elif self.base_type.is_cfunction and other_type.is_cfunction:
return self.base_type.same_as(other_type)
elif other_type.is_array:
return self.base_type.same_as(other_type.base_type)
elif not other_type.is_ptr:
return 0
elif self.base_type.is_void:
......@@ -651,14 +654,16 @@ class CStructOrUnionType(CType):
return self.is_complete()
class CEnumType(CIntType):
class CEnumType(CType):
# name string
# cname string or None
# typedef_flag boolean
is_enum = 1
signed = 1
rank = 2
#signed = 1
#rank = 2
to_py_function = "PyInt_FromLong"
from_py_function = "PyInt_AsLong"
def __init__(self, name, cname, typedef_flag):
self.name = name
......@@ -743,7 +748,6 @@ c_int_type = CIntType(2, 1, "T_INT")
c_long_type = CIntType(3, 1, "T_LONG")
c_longlong_type = CLongLongType(4, 1, "T_LONGLONG")
c_py_ssize_t_type = CPySSizeTType(5, 1)
c_bint_type = CBIntType(2, 1, "T_INT")
c_uchar_type = CIntType(0, 0, "T_UBYTE")
......
......@@ -60,6 +60,7 @@ class Entry:
# interned_cname string C name of interned name string
# pystring_cname string C name of Python version of string literal
# is_interned boolean For string const entries, value is interned
# used boolean
borrowed = 0
init = ""
......@@ -90,6 +91,7 @@ class Entry:
interned_cname = None
pystring_cname = None
is_interned = 0
used = 0
def __init__(self, name, cname, type, pos = None, init = None):
self.name = name
......@@ -354,6 +356,7 @@ class Scope:
# Add an entry for a string constant.
cname = self.new_const_cname()
entry = Entry("", cname, c_char_array_type, init = value)
entry.used = 1
self.const_entries.append(entry)
return entry
......@@ -398,6 +401,7 @@ class Scope:
self.temp_counter = n + 1
cname = "%s%d" % (Naming.pyrex_prefix, n)
entry = Entry("", cname, type)
entry.used = 1
if type.is_pyobject:
entry.init = "0"
self.cname_to_entry[entry.cname] = entry
......@@ -550,6 +554,7 @@ class ModuleScope(Scope):
# intern_map {string : string} Mapping from Python names to interned strs
# interned_names [string] Interned names pending generation of declarations
# all_pystring_entries [Entry] Python string consts from all scopes
# types_imported {PyrexType : 1} Set of types for which import code generated
def __init__(self, name, parent_module, context):
self.parent_module = parent_module
......@@ -574,6 +579,7 @@ class ModuleScope(Scope):
self.intern_map = {}
self.interned_names = []
self.all_pystring_entries = []
self.types_imported = {}
def qualifying_scope(self):
return self.parent_module
......@@ -639,6 +645,8 @@ class ModuleScope(Scope):
# None if previously declared as something else.
entry = self.lookup_here(name)
if entry:
if entry.is_pyglobal and entry.as_module is scope:
return entry # Already declared as the same module
if not (entry.is_pyglobal and not entry.as_module):
# SAGE -- I put this here so Pyrex
# cimport's work across directories.
......@@ -1038,6 +1046,8 @@ class CClassScope(ClassScope):
if visibility in ('public', 'readonly'):
if type.pymemberdef_typecode:
self.public_attr_entries.append(entry)
if name == "__weakref__":
error(pos, "Special attribute __weakref__ cannot be exposed to Python")
else:
error(pos,
"C attribute of type '%s' cannot be accessed from Python" % type)
......
version = '0.9.4.1'
version = '0.9.5.1a'
......@@ -4,7 +4,8 @@
verbose = 0
gcc_pendantic = True
gcc_warnings_are_errors = False
gcc_warnings_are_errors = True
gcc_all_warnings = True
import os
from Pyrex.Utils import replace_suffix
......@@ -23,6 +24,9 @@ if gcc_pendantic:
compiler_options.extend(["-pedantic", "-Wno-long-long"])
if gcc_warnings_are_errors:
compiler_options.append("-Werror")
if gcc_all_warnings:
compiler_options.append("-Wall")
compiler_options.append("-Wno-unused-function")
linkers = ["gcc", "g++"]
linker_options = \
......@@ -45,6 +49,7 @@ def c_compile(c_file, verbose_flag = 0, cplus = 0, obj_suffix = ".o"):
args = [compiler] + compiler_options + include_options + [c_file, "-o", o_file]
if verbose_flag or verbose:
print " ".join(args)
#print compiler, args ###
status = os.spawnvp(os.P_WAIT, compiler, args)
if status <> 0:
raise CCompilerError("C compiler returned status %s" % status)
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment