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
Boxiang Sun
cython
Commits
d18be9ae
Commit
d18be9ae
authored
Mar 16, 2012
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support pure 'init' code in utility code files
parent
f69ac182
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
15 deletions
+13
-15
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+13
-15
No files found.
Cython/Compiler/Code.py
View file @
d18be9ae
...
@@ -82,13 +82,13 @@ class UtilityCodeBase(object):
...
@@ -82,13 +82,13 @@ class UtilityCodeBase(object):
# remember correct line numbers as least until after templating
# remember correct line numbers as least until after templating
code
=
'
\
n
'
*
begin_lineno
+
'
\
n
'
.
join
(
lines
)
code
=
'
\
n
'
*
begin_lineno
+
'
\
n
'
.
join
(
lines
)
if
type
==
'
P
roto'
:
if
type
==
'
p
roto'
:
utility
[
0
]
=
code
utility
[
0
]
=
code
elif
type
==
'
Code
'
:
elif
type
==
'
impl
'
:
utility
[
1
]
=
code
utility
[
1
]
=
code
else
:
else
:
all_tags
=
utility
[
2
]
all_tags
=
utility
[
2
]
all_tags
[
type
.
lower
()
]
=
code
all_tags
[
type
]
=
code
if
tags
:
if
tags
:
all_tags
=
utility
[
2
]
all_tags
=
utility
[
2
]
...
@@ -112,9 +112,10 @@ class UtilityCodeBase(object):
...
@@ -112,9 +112,10 @@ class UtilityCodeBase(object):
comment = '
/
'
comment = '
/
'
replace_comments = re.compile(r'
^
\
s
*//
.
*|^
\
s
*/
\
*
[
^*
]
*
\
*/
').sub
replace_comments = re.compile(r'
^
\
s
*//
.
*|^
\
s
*/
\
*
[
^*
]
*
\
*/
').sub
match_special = re.compile(
match_special = re.compile(
(r'
^%
(
C
)
s
{
5
,
30
}
\
s
*
((
?
:
\
w
|
\
.)
+
)
\
s
*%
(
C
)
s
{
5
,
30
}
|
'
(r'
^%
(
C
)
s
{
5
,
30
}
\
s
*
(
?
P
<
name
>
(
?
:
\
w
|
\
.)
+
)
\
s
*%
(
C
)
s
{
5
,
30
}
|
'
r'
^%
(
C
)
s
+@
(
requires
)
\
s
*
:
\
s
*
(
(
?
:
\
w
|
[.:])
+
)
' # add more tag names here at need
r'
^%
(
C
)
s
+@
(
?
P
<
tag
>
requires
)
\
s
*
:
\
s
*
(
?
P
<
value
>
(
?
:
\
w
|
[.:])
+
)
' # add more tag names here at need
) % {'
C
':comment}).match
) % {'
C
':comment}).match
match_type = re.compile('
(.
+
)[.](
proto
|
impl
|
init
|
cleanup
)
$
').match
f = Utils.open_source_file(filename, encoding='
UTF
-
8
')
f = Utils.open_source_file(filename, encoding='
UTF
-
8
')
try:
try:
...
@@ -131,25 +132,22 @@ class UtilityCodeBase(object):
...
@@ -131,25 +132,22 @@ class UtilityCodeBase(object):
for lineno, line in enumerate(all_lines):
for lineno, line in enumerate(all_lines):
m = match_special(line)
m = match_special(line)
if m:
if m:
if m.group(1):
if m.group('
name
'):
name = m.group(1)
cls._add_utility(utility, type, lines, begin_lineno, tags)
cls._add_utility(utility, type, lines, begin_lineno, tags)
begin_lineno = lineno + 1
begin_lineno = lineno + 1
del lines[:]
del lines[:]
tags.clear()
tags.clear()
if name.endswith(".proto"):
name = m.group('
name
')
name = name[:-6]
mtype = match_type(name)
type = '
Proto
'
if mtype:
elif name.endswith(".cleanup"):
name, type = mtype.groups()
name = name[:-8]
type = '
cleanup
'
else:
else:
type = '
Code
'
type = '
impl
'
utility = utilities.setdefault(name, [None, None, {}])
utility = utilities.setdefault(name, [None, None, {}])
else:
else:
tags.setdefault(m.group(
2), set()).add(m.group(3
))
tags.setdefault(m.group(
'
tag
'), set()).add(m.group('
value
'
))
lines.append('') # keep line number correct
lines.append('') # keep line number correct
else:
else:
lines.append(replace_comments('', line).rstrip())
lines.append(replace_comments('', line).rstrip())
...
...
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