From cf421b7be956cd1ff659eaf43d0502b06a87f059 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 8 Apr 2010 17:09:25 -0500 Subject: [PATCH] 2007-04-17: Added functionality for CDEFS. Still needs changes to dbToRecordtypeH. --- src/dbHost/DBD/Parser.pm | 4 ++++ src/dbHost/DBD/Recordtype.pm | 13 ++++++++++++- src/dbHost/test/Recordtype.pl | 8 +++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/dbHost/DBD/Parser.pm b/src/dbHost/DBD/Parser.pm index 7e8c21d29..376d66626 100644 --- a/src/dbHost/DBD/Parser.pm +++ b/src/dbHost/DBD/Parser.pm @@ -161,6 +161,10 @@ sub parse_recordtype { $dbd->add($rtyp); popContext("recordtype($name)"); return; + } + elsif (m/\G % (.*) \n/oxgc) { + print " Recordtype-Cdef: $1\n" if $debug; + $rtyp->add_cdef($1); } else { m/\G (.*) $/moxgc or dieContext("Unexpected end of input"); dieContext("Syntax error in '$1'"); diff --git a/src/dbHost/DBD/Recordtype.pm b/src/dbHost/DBD/Recordtype.pm index dd361ce47..0d0152d6d 100644 --- a/src/dbHost/DBD/Recordtype.pm +++ b/src/dbHost/DBD/Recordtype.pm @@ -11,6 +11,7 @@ sub init { $this->{FIELD_INDEX} = {}; $this->{DEVICE_LIST} = []; $this->{DEVICE_INDEX} = {}; + $this->{CDEFS} = []; return $this; } @@ -72,6 +73,15 @@ sub device { return $this->{DEVICE_INDEX}->{$choice}; } +sub add_cdef { + my ($this, $cdef) = @_; + push @{$this->{CDEFS}}, $cdef; +} + +sub cdefs { + return @{shift->{CDEFS}}; +} + sub toDeclaration { my $this = shift; my @fields = map { @@ -79,7 +89,8 @@ sub toDeclaration { } $this->fields; my $name = $this->name; $name .= "Record" unless $name eq "dbCommon"; - return "typedef struct $name {\n" . + my $cdefs = join("\n", $this->cdefs); + return "$cdefs\ntypedef struct $name {\n" . join("\n", @fields) . "\n} $name;\n"; } diff --git a/src/dbHost/test/Recordtype.pl b/src/dbHost/test/Recordtype.pl index a0545b8c0..b403ba103 100644 --- a/src/dbHost/test/Recordtype.pl +++ b/src/dbHost/test/Recordtype.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -use Test::More tests => 14; +use Test::More tests => 17; use DBD::Recordtype; use DBD::Recfield; @@ -46,3 +46,9 @@ is_deeply \@devices, [$dev1], 'Device list'; is $rtyp->device('test device'), $dev1, 'Device name lookup'; +is $rtyp->cdefs, 0, 'No cdefs yet'; +$rtyp->add_cdef("cdef"); +is $rtyp->cdefs, 1, 'First cdef added'; + +my @cdefs = $rtyp->cdefs; +is_deeply \@cdefs, ["cdef"], 'cdef list';