mirror of https://github.com/CGAL/cgal
- Formatting changes.
- Using template text $CGAL_header_template and $Filtered_exact_template. - New subroutine output_args_list() that factorize print loops for arguments.
This commit is contained in:
parent
518c561f89
commit
aab858eeed
|
|
@ -32,21 +32,62 @@ $num_built_in_predicates=$#predicates+1; # Number of built-in predicates.
|
|||
|
||||
# We _must_ manipulate the fields of the struct predicate using these
|
||||
# constants: (aren't there structs in Perl ? Are packs the way to go ? )
|
||||
# $CGAL_pos=0;
|
||||
# $template_type_pos=1;
|
||||
# $inline_pos=2;
|
||||
# $ret_type_pos=3;
|
||||
$fct_name_pos=4;
|
||||
$eps_pos=5;
|
||||
$body_pos=6;
|
||||
$new_body_pos=7;
|
||||
$args_pos=8;
|
||||
|
||||
# ($CGAL_pos, $template_type_pos, $inline_pos, $ret_type_pos)=(0..3);
|
||||
($fct_name_pos, $eps_pos, $body_pos, $new_body_pos, $args_pos)=(4..8);
|
||||
|
||||
# Useful regexps.
|
||||
$C_symbol_re='[a-zA-Z_]\w*'; # A pure C symbol name.
|
||||
$CGAL_symbol_re='(?:CGAL::|)'.$C_symbol_re; # Idem with eventually 'CGAL::'
|
||||
|
||||
# Some template data.
|
||||
$CGAL_header_template=
|
||||
"// ======================================================================
|
||||
//
|
||||
// Copyright (c) 1999 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// file : FILE_FIELD
|
||||
// package : Interval_arithmetic
|
||||
// author(s) : Sylvain Pion <Sylvain.Pion\@sophia.inria.fr>
|
||||
//
|
||||
// coordinator : INRIA Sophia-Antipolis (<Mariette.Yvinec\@sophia.inria.fr>)
|
||||
// ======================================================================
|
||||
|
||||
// This file is automatically generated by the script
|
||||
// examples/Interval_arithmetic/filtered_predicate_converter.
|
||||
|
||||
#ifndef NEW_PROTECT_NAME
|
||||
#define NEW_PROTECT_NAME\n\n";
|
||||
|
||||
$Filtered_exact_template=
|
||||
"#ifndef CGAL_CFG_NO_EXPLICIT_TEMPLATE_FUNCTION_ARGUMENT_SPECIFICATION
|
||||
template < class CGAL_IA_CT, class CGAL_IA_ET, class CGAL_IA_CACHE >
|
||||
#endif
|
||||
INLINE_DIRECTIVE
|
||||
RETURN_TYPE
|
||||
FUNCTION_NAME(ARGUMENTS_CALL)
|
||||
{
|
||||
CGAL::FPU_CW_t backup = CGAL::FPU_get_and_set_cw(CGAL::FPU_cw_up);
|
||||
try
|
||||
{
|
||||
RETURN_TYPE result = FUNCTION_NAME(ARGUMENTS_INTERVAL);
|
||||
CGAL::FPU_set_cw(backup);
|
||||
return result;
|
||||
}
|
||||
catch (CGAL::Interval_nt_advanced::unsafe_comparison)
|
||||
{
|
||||
CGAL::FPU_set_cw(backup);
|
||||
return FUNCTION_NAME(ARGUMENTS_EXACT);
|
||||
}
|
||||
}\n\n";
|
||||
|
||||
# Parse the command line options.
|
||||
sub parse_command_line {
|
||||
|
|
@ -80,16 +121,13 @@ sub warning {
|
|||
|
||||
# Treats the CGAL header.
|
||||
sub treat_CGAL_header {
|
||||
# skip the old header.
|
||||
my ($directory, $new_protect_macro);
|
||||
my $directory = "Arithmetic_filter";
|
||||
my $new_protect_macro = "CGAL_ARITHMETIC_FILTER_";
|
||||
if ($static_version) {
|
||||
$new_protect_macro="CGAL_STATIC_ADAPTATIF_FILTER_";
|
||||
$directory="Static_adaptatif_filter";
|
||||
}
|
||||
else {
|
||||
$new_protect_macro="CGAL_ARITHMETIC_FILTER_";
|
||||
$directory="Arithmetic_filter";
|
||||
}
|
||||
# skip the old header.
|
||||
while (<FI>) {
|
||||
# get $file_name from the "file:" field in the headers.
|
||||
$file_name = $1 if m#// file[\s]*: include/CGAL/(.*)#;
|
||||
|
|
@ -105,29 +143,10 @@ sub treat_CGAL_header {
|
|||
}
|
||||
|
||||
# put the new header.
|
||||
print FO
|
||||
"// ======================================================================
|
||||
//
|
||||
// Copyright (c) 1999 The CGAL Consortium
|
||||
//
|
||||
// This software and related documentation is part of an INTERNAL release
|
||||
// of the Computational Geometry Algorithms Library (CGAL). It is not
|
||||
// intended for general use.
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// release :
|
||||
// release_date :
|
||||
//
|
||||
// file : include/CGAL/$directory/$file_name
|
||||
// package : Interval_arithmetic
|
||||
// author(s) : Sylvain Pion <Sylvain.Pion\@sophia.inria.fr>
|
||||
//
|
||||
// coordinator : INRIA Sophia-Antipolis (<Mariette.Yvinec\@sophia.inria.fr>)
|
||||
// ======================================================================
|
||||
|
||||
// This file is automatically generated by the script
|
||||
// examples/Interval_arithmetic/filtered_predicate_converter.\n\n";
|
||||
$_ = $CGAL_header_template;
|
||||
s#FILE_FIELD#include/CGAL/$directory/$file_name#ms;
|
||||
s#NEW_PROTECT_NAME#$new_protect_name#msg;
|
||||
print FO;
|
||||
}
|
||||
|
||||
# Skips a "CGAL_NO_FILTER" section.
|
||||
|
|
@ -135,43 +154,34 @@ sub skip_no_filter_section {
|
|||
while (<FI>) { last if m#//CGAL_NO_FILTER_END#; }
|
||||
}
|
||||
|
||||
# Output "$before$_$after$after_not_last" for each arg, except last.
|
||||
sub output_args_list {
|
||||
my ($before, $after, $after_not_last, @args) = @_;
|
||||
my $output="";
|
||||
foreach (@args) {
|
||||
$output.="$before$_$after";
|
||||
$output.= $after_not_last unless $_ eq $args[$#args];
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
# Print the Filtered_exact<> version of a predicate.
|
||||
sub print_filtered_exact {
|
||||
# This version doesn't need the template type, the body, nor the epsilons.
|
||||
my ($CGAL, $t, $inline, $ret_type, $fct_name, $e, $b, $nb, @args) = @_;
|
||||
# Print the function declaration
|
||||
# The template line would be more pretty without the MipsPro hack...
|
||||
print FO
|
||||
"#ifndef CGAL_CFG_NO_EXPLICIT_TEMPLATE_FUNCTION_ARGUMENT_SPECIFICATION
|
||||
template < class CGAL_IA_CT, class CGAL_IA_ET, class CGAL_IA_CACHE >
|
||||
#endif\n";
|
||||
print FO "/* $inline */\n" if $inline; # No inline by default.
|
||||
print FO "$ret_type\n";
|
||||
print FO "$fct_name(\n";
|
||||
foreach (@args) {
|
||||
print FO " const ${CGAL}Filtered_exact ";
|
||||
print FO "<CGAL_IA_CT, CGAL_IA_ET, CGAL_IA_CACHE> &$_";
|
||||
print FO ($_ eq $args[$#args] ? ")\n" : ",\n");
|
||||
}
|
||||
# Print the body
|
||||
print FO "{
|
||||
${CGAL}FPU_CW_t backup = ${CGAL}FPU_get_and_set_cw(${CGAL}FPU_cw_up);
|
||||
try
|
||||
{
|
||||
$ret_type result = $fct_name(\n";
|
||||
foreach (@args) {
|
||||
print FO "\t\t$_.interval()", ($_ eq $args[$#args] ? ");\n" : ",\n");
|
||||
}
|
||||
print FO " ${CGAL}FPU_set_cw(backup);
|
||||
return result;
|
||||
}
|
||||
catch (${CGAL}Interval_nt_advanced::unsafe_comparison)
|
||||
{
|
||||
${CGAL}FPU_set_cw(backup);
|
||||
return $fct_name(\n";
|
||||
foreach (@args) {
|
||||
print FO "\t\t$_.exact()", ($_ eq $args[$#args] ? ");\n }\n}\n\n" : ",\n");
|
||||
}
|
||||
my ($CGAL, $t, $inline, $ret_type, $fct_name, $e, $b, $n, @args) = @_;
|
||||
my $args_call = output_args_list("\n const ${CGAL}Filtered_exact <CGAL_IA_CT, CGAL_IA_ET, CGAL_IA_CACHE> &", "", ",", @args);
|
||||
my $args_inter = output_args_list("\n\t\t", ".interval()", ",", @args);
|
||||
my $args_exact = output_args_list("\n\t\t", ".exact()", ",", @args);
|
||||
|
||||
# Derive the function declaration from the template text.
|
||||
$_=$Filtered_exact_template;
|
||||
s#CGAL::#$CGAL#msg;
|
||||
s#INLINE_DIRECTIVE#/* $inline */#ms; # No inline by default.
|
||||
s#RETURN_TYPE#$ret_type#msg;
|
||||
s#FUNCTION_NAME#$fct_name#msg;
|
||||
s#ARGUMENTS_CALL#$args_call#ms;
|
||||
s#ARGUMENTS_INTERVAL#$args_inter#ms;
|
||||
s#ARGUMENTS_EXACT#$args_exact#ms;
|
||||
print FO;
|
||||
}
|
||||
|
||||
# Returns the new function
|
||||
|
|
@ -180,10 +190,8 @@ sub give_new_body {
|
|||
my $new_body="inline\n"; # inline by default since it's not template.
|
||||
|
||||
$new_body.="$ret_type\n";
|
||||
$new_body.="${fct_name}_SAF(\n";
|
||||
foreach (@args) {
|
||||
$new_body.=" const $new_t &$_,\n";
|
||||
}
|
||||
$new_body.="${fct_name}_SAF(";
|
||||
$new_body.=output_args_list("\n const $new_t &", "", ",", @args).",\n";
|
||||
for $i (0 .. $eps-1) {
|
||||
$new_body.=" $const double & epsilon_$i";
|
||||
$new_body.= ($i eq $eps-1 ? ")" : ",\n");
|
||||
|
|
@ -221,11 +229,8 @@ sub print_static_adaptatif {
|
|||
# Print the function declaration
|
||||
print FO "inline\n"; # inline by default since it's not template.
|
||||
print FO "$ret_type\n";
|
||||
print FO "$fct_name(\n";
|
||||
foreach (@args) {
|
||||
print FO " const ${CGAL}Static_adaptatif_filter &$_";
|
||||
print FO ($_ eq $args[$#args] ? ")\n" : ",\n");
|
||||
}
|
||||
print FO "$fct_name(";
|
||||
print FO output_args_list("\n const ${CGAL}Static_adaptatif_filter &", "", ",", @args).")\n";
|
||||
# Print the body
|
||||
print FO "{
|
||||
bool tried = false;
|
||||
|
|
@ -234,22 +239,17 @@ letstry:
|
|||
try
|
||||
{
|
||||
// Check the bounds. All arguments must be <= _bound.
|
||||
if (\n";
|
||||
foreach (@args) {
|
||||
print FO " fabs($_) > _bound";
|
||||
print FO ($_ eq $args[$#args] ? ")\n" : " ||\n");
|
||||
}
|
||||
if (";
|
||||
print FO output_args_list("\n fabs(", ") > _bound", " ||", @args).")\n";
|
||||
print FO " throw (${CGAL}Static_adaptatif_filter::unsafe_comparison);
|
||||
// Try the epsilon variant of the predicate.
|
||||
return ${fct_name}_SAF(\n";
|
||||
foreach (@args) {
|
||||
print FO "\t\t$_.value(),\n";
|
||||
}
|
||||
return ${fct_name}_SAF(";
|
||||
print FO output_args_list("\n\t\t", ".value()", ",", @args).",";
|
||||
for $i (0 .. $eps-1) {
|
||||
print FO "\t\tFilter_epsilon_$fct_name"."_".scalar(@args)."_$i";
|
||||
print FO ($i eq $eps-1 ? ");\n" : ",\n");
|
||||
print FO "\n\t\tFilter_epsilon_$fct_name"."_".scalar(@args)."_$i";
|
||||
print FO ($i eq $eps-1 ? ");" : ",");
|
||||
}
|
||||
print FO " }
|
||||
print FO "\n }
|
||||
catch (${CGAL}Static_adaptatif_filter::unsafe_comparison)
|
||||
{
|
||||
// It failed once, we re-adjust (bound, epsilons).
|
||||
|
|
@ -257,10 +257,8 @@ letstry:
|
|||
{
|
||||
tried = true;
|
||||
// Recompute _bound (tighter or larger).
|
||||
_bound = 0;\n";
|
||||
foreach (@args) {
|
||||
print FO " _bound = max(_bound, fabs($_));\n";
|
||||
}
|
||||
_bound = 0;";
|
||||
print FO output_args_list("\n _bound = max(_bound, fabs(", "));", "", @args)."\n";
|
||||
print FO "
|
||||
// recompute epsilons: \"just\" call it over Static_filter_error.
|
||||
// That's the tricky part that might not work for everything.
|
||||
|
|
@ -279,10 +277,8 @@ letstry:
|
|||
goto letstry;
|
||||
}
|
||||
// This scheme definitely fails => exact computation (filtered_exact<> ?).
|
||||
return $fct_name(\n";
|
||||
foreach (@args) {
|
||||
print FO "\t\t$_.exact()", ($_ eq $args[$#args] ? ");\n }\n}\n\n" : ",\n");
|
||||
}
|
||||
return $fct_name(";
|
||||
print FO output_args_list("\n\t\t", ".exact()", ",", @args).");\n }\n}\n\n";
|
||||
|
||||
return $eps;
|
||||
}
|
||||
|
|
@ -465,8 +461,6 @@ sub main {
|
|||
open(FO, ">$opt_o") || die "Couldn't open output file \"$opt_o\"\n";
|
||||
treat_CGAL_header();
|
||||
parse_input_code();
|
||||
print FO "#ifndef $new_protect_name\n";
|
||||
print FO "#define $new_protect_name\n\n";
|
||||
print_predicates();
|
||||
print FO "#endif // $new_protect_name\n";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue