Skip to content

Commit

Permalink
[sipify] uniform die messages
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jun 7, 2017
1 parent fa9f202 commit 8d2f72c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scripts/sipify.pl
Expand Up @@ -85,6 +85,10 @@ sub dbg_info {
}
}

sub exit_with_error {
die "! Sipify error in $headerfile at line :: $LINE_IDX\n! $_[0]\n";
}

sub write_header_footer {
push @OUTPUT, "/************************************************************************\n";
push @OUTPUT, " * This file has been generated automatically from *\n";
Expand Down Expand Up @@ -403,7 +407,7 @@ sub detect_comment_block{
my $opening_line = '';
while ( $opening_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
$opening_line = pop(@OUTPUT);
$#OUTPUT >= 0 or die 'could not reach opening definition';
$#OUTPUT >= 0 or exit_with_error('could not reach opening definition');
}
dbg_info("removed multiline definition of SIP_SKIP method");
$MULTILINE_DEFINITION = 0;
Expand Down Expand Up @@ -500,7 +504,7 @@ sub detect_comment_block{

# Skip opening curly bracket, incrementing hereunder
my $skip = read_line();
$skip =~ m/^\s*{\s*$/ || die "Unexpected content on line $skip";
$skip =~ m/^\s*{\s*$/ or exit_with_error("expecting { after class definition");
$GLOB_BRACKET_NESTING_IDX[$#GLOB_BRACKET_NESTING_IDX]++;

$COMMENT = '';
Expand All @@ -521,7 +525,7 @@ sub detect_comment_block{
if ($#ACCESS > 0){
pop(@GLOB_BRACKET_NESTING_IDX);
pop(@ACCESS);
die "Class $CLASSNAME[$#CLASSNAME] in $headerfile at line $LINE_IDX should be exported with appropriate [LIB]_EXPORT macro. If this should not be available in python, wrap it in a `#ifndef SIP_RUN` block."
exit_with_error("Class $CLASSNAME[$#CLASSNAME] should be exported with appropriate [LIB]_EXPORT macro. If this should not be available in python, wrap it in a `#ifndef SIP_RUN` block.")
if $EXPORTED[-1] == 0;
pop @EXPORTED;
}
Expand Down Expand Up @@ -592,13 +596,13 @@ sub detect_comment_block{
write_output("ENU1", "$LINE\n");
if ($LINE =~ m/\{((\s*\w+)(\s*=\s*[\w\s\d<|]+.*?)?(,?))+\s*\}/){
# one line declaration
$LINE !~ m/=/ or die 'spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.';
$LINE !~ m/=/ or exit_with_error("spify.pl does not handle enum one liners with value assignment. Use multiple lines instead.");
next;
}
else
{
$LINE = read_line();
$LINE =~ m/^\s*\{\s*$/ || die "Unexpected content: enum should be followed by {\nline: $LINE";
$LINE =~ m/^\s*\{\s*$/ or exit_with_error('Unexpected content: enum should be followed by {');
write_output("ENU2", "$LINE\n");
while ($LINE_IDX < $LINE_COUNT){
$LINE = read_line();
Expand Down Expand Up @@ -633,7 +637,7 @@ sub detect_comment_block{

# remove static const value assignment
# https://regex101.com/r/DyWkgn/4
$LINE !~ m/^\s*const static \w+/ or die "const static should be written static const in $CLASSNAME[$#CLASSNAME] at line $LINE_IDX";
$LINE !~ m/^\s*const static \w+/ or exit_with_error("const static should be written static const in $CLASSNAME[$#CLASSNAME]");
$LINE =~ s/^(\s*static const(?:expr)? \w+(?:<(?:[\w()<>, ]|::)+>)? \w+) = .*([|;])\s*(\/\/.*)?$/$1;/;
if ( defined $2 && $2 =~ m/\|/ ){
dbg_info("multiline const static assignment");
Expand Down Expand Up @@ -678,7 +682,7 @@ sub detect_comment_block{
while ( $virtual_line !~ m/^[^()]*\(([^()]*\([^()]*\)[^()]*)*[^()]*$/){
$virtual_line_idx--;
$virtual_line = $INPUT_LINES[$virtual_line_idx];
$virtual_line_idx >= 0 or die 'could not reach opening definition';
$virtual_line_idx >= 0 or exit_with_error('could not reach opening definition');
}
if ( $virtual_line !~ m/^(\s*)virtual\b(.*)$/ ){
my $idx = $#OUTPUT-$LINE_IDX+$virtual_line_idx+2;
Expand Down

0 comments on commit 8d2f72c

Please sign in to comment.