Author: paultcochrane
Date: Wed May 9 05:17:06 2007
New Revision: 18486
Modified:
trunk/lib/Parrot/Ops2c/Utils.pm
trunk/lib/Parrot/Ops2pm/Utils.pm
trunk/lib/Parrot/Vtable.pm
Log:
[lib] Further guard header macro updates. Patch courtesy of Mark Glines <mark
at glines dot org>
Modified: trunk/lib/Parrot/Ops2c/Utils.pm
==============================================================================
--- trunk/lib/Parrot/Ops2c/Utils.pm (original)
+++ trunk/lib/Parrot/Ops2c/Utils.pm Wed May 9 05:17:06 2007
@@ -6,6 +6,7 @@
use lib ("lib/");
use Parrot::OpLib::core;
use Parrot::OpsFile;
+use File::Spec;
=head1 NAME
@@ -283,10 +284,14 @@
open my $HEADER, '>', $self->{header}
or die "ops2c.pl: Cannot open header file '$self->{header}' for
writing: $!!\n";
+ $self->_print_guard_prefix($HEADER);
+
$self->_print_preamble_header($HEADER);
$self->_print_run_core_func_decl_header($HEADER);
+ $self->_print_guard_suffix($HEADER);
+
_print_coda($HEADER);
close $HEADER or die "Unable to close handle to $self->{header}:
$!";
@@ -325,6 +330,38 @@
}
}
+# given a headerfile name like "include/parrot/oplib/core_ops.h", this
+# returns a string like "PARROT_OPLIB_CORE_OPS_H_GUARD"
+sub _generate_guard_macro_name {
+ my $self = shift;
+ my $fn = $$self{header};
+ $fn =~ s/\.h$//;
+ my @path = File::Spec->splitdir($fn);
+ shift @path if $path[0] eq 'include';
+ shift @path if $path[0] eq 'parrot';
+ return uc(join('_', 'parrot', @path, 'h', 'guard'));
+
+}
+
+sub _print_guard_prefix {
+ my ($self, $fh) = @_;
+ my $guardname = $self->_generate_guard_macro_name();
+ print $fh <<END_C;
+#ifndef $guardname
+#define $guardname
+
+END_C
+}
+
+sub _print_guard_suffix {
+ my ($self, $fh) = @_;
+ my $guardname = $self->_generate_guard_macro_name();
+ print $fh <<END_C;
+
+#endif /* $guardname */
+END_C
+}
+
sub _print_coda {
my $fh = shift;
print $fh <<END_C;
Modified: trunk/lib/Parrot/Ops2pm/Utils.pm
==============================================================================
--- trunk/lib/Parrot/Ops2pm/Utils.pm (original)
+++ trunk/lib/Parrot/Ops2pm/Utils.pm Wed May 9 05:17:06 2007
@@ -611,7 +611,7 @@
print $OUT <<END_C;
} parrot_opcode_enums;
-#endif
+#endif /* PARROT_OPS_H_GUARD */
END_C
Modified: trunk/lib/Parrot/Vtable.pm
==============================================================================
--- trunk/lib/Parrot/Vtable.pm (original)
+++ trunk/lib/Parrot/Vtable.pm Wed May 9 05:17:06 2007
@@ -317,7 +317,7 @@
NULL
};
-#endif
+#endif /* PARROT_IN_OBJECTS_C */
EOM
$macros;