From 7bec7c1b60a63980964c6480c29b735ab2443246 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 8 Apr 2014 19:15:47 +0100 Subject: [PATCH] Further shift operator regression fixes --- .../test-suite/cpp11_template_double_brackets.i | 2 ++ Source/Swig/scanner.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/cpp11_template_double_brackets.i b/Examples/test-suite/cpp11_template_double_brackets.i index 981ff1e74..ba5caa5c5 100644 --- a/Examples/test-suite/cpp11_template_double_brackets.i +++ b/Examples/test-suite/cpp11_template_double_brackets.i @@ -48,4 +48,6 @@ public: // Test shifts are still working %inline %{ int shift_init1 = 4 << 2 >> 1; +int shift_init2 = 4 >> 2 << 1 << 1 >> 2; %} + diff --git a/Source/Swig/scanner.c b/Source/Swig/scanner.c index 178e7626c..d8c3f7f3f 100644 --- a/Source/Swig/scanner.c +++ b/Source/Swig/scanner.c @@ -297,7 +297,7 @@ static void brackets_clear(Scanner *s) { * brackets_increment() * * Increases the number of brackets at the current depth. - * Usually called when '<' was found. + * Usually called when a single '<' is found. * ----------------------------------------------------------------------------- */ static void brackets_increment(Scanner *s) { int *count = brackets_count(s); @@ -309,7 +309,7 @@ static void brackets_increment(Scanner *s) { * brackets_decrement() * * Decreases the number of brackets at the current depth. - * Usually called when '>' was found. + * Usually called when a single '>' is found. * ----------------------------------------------------------------------------- */ static void brackets_decrement(Scanner *s) { int *count = brackets_count(s); @@ -333,7 +333,7 @@ static void brackets_reset(Scanner *s) { * brackets_push() * * Increases the depth of brackets. - * Usually called when '(' was found. + * Usually called when '(' is found. * ----------------------------------------------------------------------------- */ static void brackets_push(Scanner *s) { int *newInt = malloc(sizeof(int)); @@ -345,7 +345,7 @@ static void brackets_push(Scanner *s) { * brackets_pop() * * Decreases the depth of brackets. - * Usually called when ')' was found. + * Usually called when ')' is found. * ----------------------------------------------------------------------------- */ static void brackets_pop(Scanner *s) { if (Len(s->brackets) > 0) /* protect against unbalanced ')' brackets */ @@ -360,7 +360,7 @@ static void brackets_pop(Scanner *s) { * ----------------------------------------------------------------------------- */ static int brackets_allow_shift(Scanner *s) { int *count = brackets_count(s); - return !count || (*count < 0); + return !count || (*count <= 0); } /* ----------------------------------------------------------------------------- @@ -892,15 +892,17 @@ static int look(Scanner *s) { } break; case 61: - brackets_decrement(s); - if ((c = nextchar(s)) == 0) + if ((c = nextchar(s)) == 0) { + brackets_decrement(s); return SWIG_TOKEN_GREATERTHAN; + } if (c == '>' && brackets_allow_shift(s)) state = 250; else if (c == '=') return SWIG_TOKEN_GTEQUAL; else { retract(s, 1); + brackets_decrement(s); return SWIG_TOKEN_GREATERTHAN; } break; @@ -1353,7 +1355,6 @@ static int look(Scanner *s) { break; case 250: /* RSHIFT, RSEQUAL */ - brackets_decrement(s); if ((c = nextchar(s)) == 0) return SWIG_TOKEN_RSHIFT; else if (c == '=')