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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
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):
print
"no constructor declared"
# create one
self
.
class_entry
=
entry
self
.
entry
=
constructor
self
.
type
=
constructor
.
type
def
generate_result_code
(
self
,
code
):
...
...
@@ -2387,6 +2388,7 @@ class SimpleCallNode(CallNode):
expected_type
,
env
)
# Insert coerced 'self' argument into argument list.
self
.
args
.
insert
(
0
,
self
.
coerced_self
)
entry
=
self
.
function
.
entry
self
.
analyse_c_function_call
(
env
)
def
function_type
(
self
):
...
...
@@ -2407,6 +2409,22 @@ class SimpleCallNode(CallNode):
self
.
type
=
PyrexTypes
.
error_type
self
.
result_code
=
"<error>"
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
max_nargs
=
len
(
func_type
.
args
)
expected_nargs
=
max_nargs
-
func_type
.
optional_arg_count
...
...
@@ -2421,18 +2439,13 @@ class SimpleCallNode(CallNode):
expected_str
=
"at least "
+
expected_str
else
:
expected_str
=
"at most "
+
str
(
max_nargs
)
error
(
self
.
pos
,
"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>"
return
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
)
#error(self.pos,
# "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>"
return
0
# Coerce arguments
for
i
in
range
(
min
(
max_nargs
,
actual_nargs
)):
formal_type
=
func_type
.
args
[
i
].
type
...
...
@@ -2459,6 +2472,12 @@ class SimpleCallNode(CallNode):
# Check gil
if
not
func_type
.
nogil
:
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
):
return
self
.
c_call_code
()
...
...
Cython/Compiler/Symtab.py
View file @
18560bcc
...
...
@@ -172,6 +172,7 @@ class Entry(object):
self.type = type
self.pos = pos
self.init = init
self.overloaded_alternatives = []
def redeclared(self, pos):
error(pos, "'%s'
does
not
match
previous
declaration
" % self.name)
...
...
@@ -301,15 +302,21 @@ class Scope(object):
# 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)
entries = self.entries
overloaded = False
if name and name in entries:
if visibility == 'extern':
warning(pos, "'%s'
redeclared
" % name, 0)
elif visibility != 'ignore':
error(pos, "'%s'
redeclared
" % name)
overloaded = True
#error(pos, "'%s'
redeclared
" % name)
entry = Entry(name, cname, type, pos = pos)
entry.in_cinclude = self.in_cinclude
if 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
entry.scope = self
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