Utilities: fixed an issue related to parsing 'conditional defines'.

Tue, 09 Feb 2021 08:33:41 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 09 Feb 2021 08:33:41 +0100
changeset 8087
db518728761c
parent 8086
eff504bb6dec
child 8088
7c454b82b6ed

Utilities: fixed an issue related to parsing 'conditional defines'.

eric6/Utilities/ClassBrowsers/pyclbr.py file | annotate | diff | comparison | revisions
eric6/Utilities/ModuleParser.py file | annotate | diff | comparison | revisions
--- a/eric6/Utilities/ClassBrowsers/pyclbr.py	Mon Feb 08 19:31:39 2021 +0100
+++ b/eric6/Utilities/ClassBrowsers/pyclbr.py	Tue Feb 09 08:33:41 2021 +0100
@@ -436,7 +436,7 @@
     conditionalsstack = []  # stack of indents of conditional defines
     deltastack = []
     deltaindent = 0
-    deltaindentcalculated = 0
+    deltaindentcalculated = False
     
     lineno, last_lineno_pos = 1, 0
     i = 0
@@ -479,7 +479,7 @@
                     if not deltaindentcalculated:
                         deltastack.append(thisindent - conditionalsstack[-1])
                         deltaindent = reduce(lambda x, y: x + y, deltastack)
-                        deltaindentcalculated = 1
+                        deltaindentcalculated = True
                     thisindent -= deltaindent
                 else:
                     while (
@@ -489,7 +489,7 @@
                         del conditionalsstack[-1]
                         if deltastack:
                             del deltastack[-1]
-                    deltaindentcalculated = 0
+                    deltaindentcalculated = False
             # close all classes indented at least as much
             while classstack and classstack[-1][1] >= thisindent:
                 del classstack[-1]
@@ -564,6 +564,23 @@
                                     n = d[c]
                     names.append(n)
                 inherit = names
+            # modify indentation level for conditional defines
+            if conditionalsstack:
+                if thisindent > conditionalsstack[-1]:
+                    if not deltaindentcalculated:
+                        deltastack.append(thisindent - conditionalsstack[-1])
+                        deltaindent = reduce(lambda x, y: x + y, deltastack)
+                        deltaindentcalculated = True
+                    thisindent -= deltaindent
+                else:
+                    while (
+                        conditionalsstack and
+                        conditionalsstack[-1] >= thisindent
+                    ):
+                        del conditionalsstack[-1]
+                        if deltastack:
+                            del deltastack[-1]
+                    deltaindentcalculated = False
             # remember this class
             cur_class = Class(module, class_name, inherit,
                               file, lineno)
@@ -673,7 +690,7 @@
                 if deltastack:
                     del deltastack[-1]
             conditionalsstack.append(thisindent)
-            deltaindentcalculated = 0
+            deltaindentcalculated = False
         
         elif m.start("CodingLine") >= 0:
             # a coding statement
--- a/eric6/Utilities/ModuleParser.py	Mon Feb 08 19:31:39 2021 +0100
+++ b/eric6/Utilities/ModuleParser.py	Tue Feb 09 08:33:41 2021 +0100
@@ -737,6 +737,23 @@
                                         n = m.name
                             names.append(n)
                     inherit = names
+                # modify indentation level for conditional defines
+                if conditionalsstack:
+                    if thisindent > conditionalsstack[-1]:
+                        if not deltaindentcalculated:
+                            deltastack.append(thisindent - conditionalsstack[-1])
+                            deltaindent = reduce(lambda x, y: x + y, deltastack)
+                            deltaindentcalculated = True
+                        thisindent -= deltaindent
+                    else:
+                        while (
+                            conditionalsstack and
+                            conditionalsstack[-1] >= thisindent
+                        ):
+                            del conditionalsstack[-1]
+                            if deltastack:
+                                del deltastack[-1]
+                        deltaindentcalculated = False
                 # remember this class
                 cur_class = Class(self.name, class_name, inherit,
                                   self.file, lineno)

eric ide

mercurial