Skip to content

Commit

Permalink
Merge pull request nasa#1169 from jphickey/fix-1166-stubgen-ifdef-cpl…
Browse files Browse the repository at this point in the history
…usplus

Fix nasa#1166, recognize ifdef __cplusplus
  • Loading branch information
astrogeco committed Nov 3, 2021
2 parents 56ad768 + f2fbc90 commit 4a2cadd
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions ut_assert/scripts/generate_stubs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
my $file = "";
my $file_boilerplate;
my $file_variadic;
my @ifdef_level = (1);

# All header files start with some legal boilerplate comments
# Take the first one and save it, so it can be put into the output.
Expand All @@ -125,7 +126,31 @@
# so it will be in a single "line" in the result.
chomp if (s/\\$//);
}
push(@lines, $_);

# detect "#ifdef" lines - some may need to be recognized.
# at the very least, any C++-specific bits need to be skipped.
# for now this just specifically looks for __cplusplus
if (/^\#(if\w+)\s+(.*)$/) {
my $check = $1;
my $cond = $2;
my $result = $ifdef_level[0];

if ($cond eq "__cplusplus" && $check eq "ifdef") {
$result = 0;
}

unshift(@ifdef_level, $result);
}
elsif (/^\#else/) {
# invert the last preprocessor condition
$ifdef_level[0] = $ifdef_level[0] ^ $ifdef_level[1];
}
elsif (/^\#endif/) {
shift(@ifdef_level);
}
elsif ($ifdef_level[0]) {
push(@lines, $_) ;
}
}
close(HDR);

Expand Down Expand Up @@ -164,7 +189,6 @@
next if (/\btypedef\b/); # ignore typedefs
next if (/\bstatic inline\b/); # ignore


# discard "extern" qualifier
# (but other qualifiers like "const" are OK and should be preserved, as
# it is part of return type).
Expand Down Expand Up @@ -408,4 +432,3 @@

print "Generated $stubfile\n";
}

0 comments on commit 4a2cadd

Please sign in to comment.