mirror of https://github.com/CGAL/cgal
- New functions parse_function_declaration() and
put_new_function_declaration(), to split the main loop into something readable.
This commit is contained in:
parent
116eb8ac59
commit
fd466ab00a
|
|
@ -22,13 +22,12 @@
|
|||
# $new_protect_name: equivalent to CGAL_ARITHMETIC_FILTER_BASIC_H.
|
||||
|
||||
$in_decl=0;
|
||||
$after_template=0;
|
||||
$result_type="";
|
||||
@args=();
|
||||
|
||||
# A sub routine to treat the CGAL header: the first parsing step.
|
||||
# Treats the CGAL header.
|
||||
sub treat_CGAL_header {
|
||||
# We skip the old header.
|
||||
# skip the old header.
|
||||
while (<>)
|
||||
{
|
||||
# get $file_name from the "file:" field in the headers.
|
||||
|
|
@ -44,7 +43,7 @@ sub treat_CGAL_header {
|
|||
}
|
||||
}
|
||||
|
||||
# We put the new header.
|
||||
# put the new header.
|
||||
print
|
||||
"// ======================================================================
|
||||
//
|
||||
|
|
@ -104,7 +103,6 @@ sub check_known_type {
|
|||
# Puts the new body
|
||||
sub put_new_body {
|
||||
local ($result_type, $function_name, @args) = @_;
|
||||
check_known_type($result_type);
|
||||
print
|
||||
"{
|
||||
CGAL::FPU_CW_t backup = CGAL::FPU_get_and_set_cw(CGAL::FPU_cw_up);
|
||||
|
|
@ -137,6 +135,62 @@ sub put_new_body {
|
|||
";
|
||||
}
|
||||
|
||||
# Treat the declaration of a function.
|
||||
sub parse_function_declaration {
|
||||
local $inline_decl, $return_type, $last_arg, $function_name;
|
||||
while (<>) {
|
||||
if (/(CGAL_.*INLINE|inline)/) {
|
||||
$inline_decl=$1;
|
||||
}
|
||||
|
||||
if ( /\(/ ) { $in_decl=1; }
|
||||
if (! $in_decl) {
|
||||
if (! (/inline/i)) {
|
||||
$return_type = $_;
|
||||
chop($return_type);
|
||||
check_known_type($return_type);
|
||||
}
|
||||
}
|
||||
if ($in_decl)
|
||||
{
|
||||
@a = split /[,\)]/; # Stores the arguments names in @args.
|
||||
foreach (@a) {
|
||||
s/^.*\(//;
|
||||
next if /^$/;
|
||||
/(\w+)\s*$/;
|
||||
push(@args, $1);
|
||||
$last_arg=$1;
|
||||
}
|
||||
}
|
||||
if (/\(/) {
|
||||
/([a-zA-Z_]\w*)\s*\(/;
|
||||
$function_name=$1;
|
||||
}
|
||||
last if /\)/;
|
||||
}
|
||||
local (@a) = ($inline_decl, $return_type, $function_name, $last_arg, @args);
|
||||
return (@a);
|
||||
}
|
||||
|
||||
# Print the new function declaration.
|
||||
sub put_new_function_declaration {
|
||||
local ($inline_decl, $return_type, $function_name, $last_arg, @args) = @_;
|
||||
# The template line would be more pretty without the MipsPro hack...
|
||||
print
|
||||
"#ifndef CGAL_CFG_NO_EXPLICIT_TEMPLATE_FUNCTION_ARGUMENT_SPECIFICATION
|
||||
template < class CGAL_IA_CT, class CGAL_IA_ET, class CGAL_IA_CACHE >
|
||||
#endif\n";
|
||||
# By default, we do not inline the filtered version.
|
||||
print "/* $inline_decl */\n" if $inline_decl;
|
||||
print "$return_type\n";
|
||||
print "$function_name(\n";
|
||||
foreach (@args) {
|
||||
print " const CGAL::Filtered_exact ";
|
||||
print "<CGAL_IA_CT, CGAL_IA_ET, CGAL_IA_CACHE> &$_";
|
||||
if ($_ eq $last_arg) { print ")\n"; } else { print ",\n"; }
|
||||
}
|
||||
}
|
||||
|
||||
# Main program:
|
||||
|
||||
treat_CGAL_header();
|
||||
|
|
@ -153,47 +207,22 @@ while (<>)
|
|||
if (/^{/) {
|
||||
skip_old_body();
|
||||
put_new_body($result_type, $function_name, @args);
|
||||
$after_template=0;
|
||||
$in_decl=0;
|
||||
@args=();
|
||||
next;
|
||||
}
|
||||
|
||||
if ($after_template)
|
||||
{
|
||||
s/(CGAL_KERNEL_.*INLINE)/\/\/ $1/; # Comment the INLINE line.
|
||||
s/inline/\/\/ inline/; # Comment the INLINE line.
|
||||
if ( /\(/ ) { $in_decl=1; }
|
||||
if (! $in_decl) {
|
||||
if (! (/inline/i)) {
|
||||
$result_type = $_;
|
||||
chop($result_type);
|
||||
# print "RESULT_TYPE = $result_type\n";
|
||||
}
|
||||
}
|
||||
if ($in_decl)
|
||||
{
|
||||
@a = split /[,\)]/; # Stores the arguments names in @args.
|
||||
foreach (@a) {
|
||||
s/^.*\(//;
|
||||
next if /^$/;
|
||||
/(\w+)\s*$/;
|
||||
push(@args, $1);
|
||||
$last_arg=$1;
|
||||
}
|
||||
s/const/\n const/g; # Split lines.
|
||||
s/[RF]T/CGAL::Filtered_exact <CGAL_IA_CT, CGAL_IA_ET, CGAL_IA_CACHE>/g;
|
||||
}
|
||||
if (/\(/) {
|
||||
/([a-zA-Z_]\w*)\s*\(/;
|
||||
$function_name=$1;
|
||||
# print "Function name: $function_name\n";
|
||||
}
|
||||
# Treat next template function.
|
||||
if (/template/) {
|
||||
($inline_decl, $result_type, $function_name, $last_arg, @args)
|
||||
= parse_function_declaration();
|
||||
put_new_function_declaration($inline_decl, $result_type,
|
||||
$function_name, $last_arg, @args);
|
||||
next;
|
||||
}
|
||||
if (/template/) { $after_template = 1; }
|
||||
s/template\s*<\s*class\s*[RF]T\s*>/#ifndef CGAL_CFG_NO_EXPLICIT_TEMPLATE_FUNCTION_ARGUMENT_SPECIFICATION\ntemplate < class CGAL_IA_CT, class CGAL_IA_ET, class CGAL_IA_CACHE >\n#endif/;
|
||||
|
||||
# Basically for the rest, we just copy everything,
|
||||
# just update the protect macro name.
|
||||
s/$old_protect_name/$new_protect_name/g;
|
||||
|
||||
print $_;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue