Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
18560bcc
Commit
18560bcc
authored
Jul 08, 2009
by
DaniloFreitas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Function overloading
parent
164ae885
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
15 deletions
+41
-15
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+32
-13
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+9
-2
No files found.
Cython/Compiler/ExprNodes.py
View file @
18560bcc
...
@@ -1090,6 +1090,7 @@ class NewExprNode(AtomicExprNode):
...
@@ -1090,6 +1090,7 @@ class NewExprNode(AtomicExprNode):
print
"no constructor declared"
print
"no constructor declared"
# create one
# create one
self
.
class_entry
=
entry
self
.
class_entry
=
entry
self
.
entry
=
constructor
self
.
type
=
constructor
.
type
self
.
type
=
constructor
.
type
def
generate_result_code
(
self
,
code
):
def
generate_result_code
(
self
,
code
):
...
@@ -2387,6 +2388,7 @@ class SimpleCallNode(CallNode):
...
@@ -2387,6 +2388,7 @@ class SimpleCallNode(CallNode):
expected_type
,
env
)
expected_type
,
env
)
# Insert coerced 'self' argument into argument list.
# Insert coerced 'self' argument into argument list.
self
.
args
.
insert
(
0
,
self
.
coerced_self
)
self
.
args
.
insert
(
0
,
self
.
coerced_self
)
entry
=
self
.
function
.
entry
self
.
analyse_c_function_call
(
env
)
self
.
analyse_c_function_call
(
env
)
def
function_type
(
self
):
def
function_type
(
self
):
...
@@ -2407,6 +2409,22 @@ class SimpleCallNode(CallNode):
...
@@ -2407,6 +2409,22 @@ class SimpleCallNode(CallNode):
self
.
type
=
PyrexTypes
.
error_type
self
.
type
=
PyrexTypes
.
error_type
self
.
result_code
=
"<error>"
self
.
result_code
=
"<error>"
return
return
if
not
self
.
analyse_args
(
env
,
func_type
):
entry
=
self
.
function
.
entry
has_overloaded
=
0
for
overloaded
in
entry
.
overloaded_alternatives
:
if
self
.
analyse_args
(
env
,
overloaded
.
type
.
base_type
):
has_overloaded
=
1
break
if
not
has_overloaded
:
error
(
self
.
pos
,
"Call with wrong number of arguments"
)
# "Call with wrong number of arguments (expected %s, got %s)"
# % (expected_str, actual_nargs))
self
.
args
=
None
self
.
type
=
PyrexTypes
.
error_type
self
.
result_code
=
"<error>"
def
analyse_args
(
self
,
env
,
func_type
):
# Check no. of args
# Check no. of args
max_nargs
=
len
(
func_type
.
args
)
max_nargs
=
len
(
func_type
.
args
)
expected_nargs
=
max_nargs
-
func_type
.
optional_arg_count
expected_nargs
=
max_nargs
-
func_type
.
optional_arg_count
...
@@ -2421,18 +2439,13 @@ class SimpleCallNode(CallNode):
...
@@ -2421,18 +2439,13 @@ class SimpleCallNode(CallNode):
expected_str
=
"at least "
+
expected_str
expected_str
=
"at least "
+
expected_str
else
:
else
:
expected_str
=
"at most "
+
str
(
max_nargs
)
expected_str
=
"at most "
+
str
(
max_nargs
)
error
(
self
.
pos
,
#error(self.pos,
"Call with wrong number of arguments (expected %s, got %s)"
# "Call with wrong number of arguments (expected %s, got %s)"
%
(
expected_str
,
actual_nargs
))
# % (expected_str, actual_nargs))
self
.
args
=
None
#self.args = None
self
.
type
=
PyrexTypes
.
error_type
#self.type = PyrexTypes.error_type
self
.
result_code
=
"<error>"
#self.result_code = "<error>"
return
return
0
if
func_type
.
optional_arg_count
and
expected_nargs
!=
actual_nargs
:
self
.
has_optional_args
=
1
self
.
is_temp
=
1
self
.
opt_arg_struct
=
env
.
allocate_temp
(
func_type
.
op_arg_struct
.
base_type
)
env
.
release_temp
(
self
.
opt_arg_struct
)
# Coerce arguments
# Coerce arguments
for
i
in
range
(
min
(
max_nargs
,
actual_nargs
)):
for
i
in
range
(
min
(
max_nargs
,
actual_nargs
)):
formal_type
=
func_type
.
args
[
i
].
type
formal_type
=
func_type
.
args
[
i
].
type
...
@@ -2459,6 +2472,12 @@ class SimpleCallNode(CallNode):
...
@@ -2459,6 +2472,12 @@ class SimpleCallNode(CallNode):
# Check gil
# Check gil
if
not
func_type
.
nogil
:
if
not
func_type
.
nogil
:
self
.
gil_check
(
env
)
self
.
gil_check
(
env
)
if
func_type
.
optional_arg_count
and
expected_nargs
!=
actual_nargs
:
self
.
has_optional_args
=
1
self
.
is_temp
=
1
self
.
opt_arg_struct
=
env
.
allocate_temp
(
func_type
.
op_arg_struct
.
base_type
)
env
.
release_temp
(
self
.
opt_arg_struct
)
return
1
def
calculate_result_code
(
self
):
def
calculate_result_code
(
self
):
return
self
.
c_call_code
()
return
self
.
c_call_code
()
...
...
Cython/Compiler/Symtab.py
View file @
18560bcc
...
@@ -172,6 +172,7 @@ class Entry(object):
...
@@ -172,6 +172,7 @@ class Entry(object):
self.type = type
self.type = type
self.pos = pos
self.pos = pos
self.init = init
self.init = init
self.overloaded_alternatives = []
def redeclared(self, pos):
def redeclared(self, pos):
error(pos, "'%s'
does
not
match
previous
declaration
" % self.name)
error(pos, "'%s'
does
not
match
previous
declaration
" % self.name)
...
@@ -301,15 +302,21 @@ class Scope(object):
...
@@ -301,15 +302,21 @@ class Scope(object):
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
# See http://www.gnu.org/software/libc/manual/html_node/Reserved-Names.html#Reserved-Names
warning(pos, "'%s'
is
a
reserved
name
in
C
.
" % cname, -1)
warning(pos, "'%s'
is
a
reserved
name
in
C
.
" % cname, -1)
entries = self.entries
entries = self.entries
overloaded = False
if name and name in entries:
if name and name in entries:
if visibility == 'extern':
if visibility == 'extern':
warning(pos, "'%s'
redeclared
" % name, 0)
warning(pos, "'%s'
redeclared
" % name, 0)
elif visibility != 'ignore':
elif visibility != 'ignore':
error(pos, "'%s'
redeclared
" % name)
overloaded = True
#error(pos, "'%s'
redeclared
" % name)
entry = Entry(name, cname, type, pos = pos)
entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude
entry.in_cinclude = self.in_cinclude
if name:
if name:
entry.qualified_name = self.qualify_name(name)
entry.qualified_name = self.qualify_name(name)
if overloaded:
entries[name].overloaded_alternatives.append(entry)
#print entries[name].overloaded_alternatives
else:
entries[name] = entry
entries[name] = entry
entry.scope = self
entry.scope = self
entry.visibility = visibility
entry.visibility = visibility
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment