comparison src/gearsTools/generate_stub.pl @ 386:aa97e53b167c

updatge localCode from each cbc files
author anatofuz
date Mon, 27 Jul 2020 19:17:36 +0900
parents f0c51aac6bed
children ba8f847f4769
comparison
equal deleted inserted replaced
385:4e9638616d31 386:aa97e53b167c
61 my %generic; 61 my %generic;
62 my %dataGearVarType; 62 my %dataGearVarType;
63 my %codeGear; 63 my %codeGear;
64 my $implementation; 64 my $implementation;
65 my $interface; 65 my $interface;
66 my %filename2localCodes;
66 67
67 # interface definision 68 # interface definision
68 # 69 #
69 # typedef struct Stack<Type, Impl>{ 70 # typedef struct Stack<Type, Impl>{
70 # Type* stack; 71 # Type* stack;
92 # Gearef(context, Stack)->next = C_stackTest3; 93 # Gearef(context, Stack)->next = C_stackTest3;
93 # goto meta(context, nodeStack->push); 94 # goto meta(context, nodeStack->push);
94 95
95 sub getDataGear { 96 sub getDataGear {
96 my ($filename) = @_; 97 my ($filename) = @_;
98
99 setFilename2CodeGear($filename);
100
97 my ($codeGearName, $name, $inTypedef,$described_data_gear); 101 my ($codeGearName, $name, $inTypedef,$described_data_gear);
98 open my $fd,"<",$filename or die("can't open $filename $!"); 102 open my $fd,"<",$filename or die("can't open $filename $!");
99 while (<$fd>) { 103 while (<$fd>) {
100 if (! $inTypedef) { 104 if (! $inTypedef) {
101 if (/^typedef struct (\w+)\s*<(.*)>/) { 105 if (/^typedef struct (\w+)\s*<(.*)>/) {
396 my $inMain = 0 ; 400 my $inMain = 0 ;
397 my $inCode = 0 ; 401 my $inCode = 0 ;
398 my %stub; 402 my %stub;
399 my $codeGearName; 403 my $codeGearName;
400 my %localVarType; 404 my %localVarType;
401 my %localCode;
402 405
403 while (<$in>) { 406 while (<$in>) {
404 if (! $inTypedef && ! $inStub && ! $inMain) { 407 if (! $inTypedef && ! $inStub && ! $inMain) {
405 if (/^typedef struct (\w+)\s*\{/) { 408 if (/^typedef struct (\w+)\s*\{/) {
406 $inTypedef = 1; 409 $inTypedef = 1;
408 $inMain = 1; 411 $inMain = 1;
409 } elsif(/^#interface "(.*)"/) { 412 } elsif(/^#interface "(.*)"/) {
410 my $interfaceHeader = $1; 413 my $interfaceHeader = $1;
411 # #interface not write 414 # #interface not write
412 next unless ($interfaceHeader =~ /context.h/); 415 next unless ($interfaceHeader =~ /context.h/);
413 } elsif (/extern\s+_\_code\s+(\w+)\((.*)\)/) {
414 $localCode{$1} = 1;
415 } elsif (/^\s\s*_\_code\s+(\w+)\((.*)\)(.*)/) {
416 $localCode{$1} = 1;
417 } elsif (/^\s\s*_\_code *\(\s*\*\s*(\w+)\)\((.*)\)(.*)/) {
418 $localCode{$1} = 1;
419 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { 416 } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) {
420 $inCode = 1; 417 $inCode = 1;
421 $localCode{$inCode} = 0;
422 %localVarType = {}; 418 %localVarType = {};
423 $codeGearName = $1; 419 $codeGearName = $1;
424 my $args = $2; 420 my $args = $2;
425 my $tail = $3; 421 my $tail = $3;
426 if ($codeGearName =~ /_stub$/) { 422 if ($codeGearName =~ /_stub$/) {
644 # convert it to the meta call form with two arugments, that is context and enum Code 640 # convert it to the meta call form with two arugments, that is context and enum Code
645 my $prev = $1; 641 my $prev = $1;
646 my $next = $2; 642 my $next = $2;
647 my @args = split(/,/, $3); 643 my @args = split(/,/, $3);
648 my $v = 0; 644 my $v = 0;
649 if (defined $localCode{$next}) { 645 if (findFromFilename2CodeGear($filename, $next)) {
650 print $fd $_; next; 646 print $fd $_; next;
651 } 647 }
652 for my $n ( @{$dataGearVar{$codeGearName}} ) { 648 for my $n ( @{$dataGearVar{$codeGearName}} ) {
653 # continuation arguments 649 # continuation arguments
654 $v = 1 if ( $n eq $next); 650 $v = 1 if ( $n eq $next);
721 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName}); 717 $stub{$prevCodeGearName."_stub"} = &generateStub($fd,$prevCodeGearName,$dataGearName{$codeGearName});
722 } 718 }
723 } 719 }
724 } 720 }
725 721
722
723 # create localCode from each cbc files
724 sub setFilename2CodeGear {
725 my ($filename) = @_;
726 open my $fh, '<', $filename;
727 while (my $line = <$fh>) {
728 if ($line =~ /extern\s+_\_code\s+(\w+)\((.*)\)/) {
729 push(@{$filename2localCodes{$filename}},$1);
730 } elsif ($line =~ /^\s\s*_\_code\s+(\w+)\((.*)\)(.*)/) {
731 push(@{$filename2localCodes{$filename}},$1);
732 } elsif ($line =~ /^\s\s*_\_code *\(\s*\*\s*(\w+)\)\((.*)\)(.*)/) {
733 push(@{$filename2localCodes{$filename}},$1);
734 } elsif ($line =~ /^\_\_code (\w+)\((.*)\)(.*)/) {
735 push(@{$filename2localCodes{$filename}},$1);
736 }
737 }
738 close $fh;
739 }
740
741 sub findFromFilename2CodeGear {
742 my ($filename, $cgname) = @_;
743
744 my @result = grep { /^$cgname$/ } @{$filename2localCodes{$filename}};
745 return @result;
746 }
747
726 # end 748 # end