[geany/geany] 733b10: Merge branch 'universal-ctags-fixes'

Colomban Wendling git-noreply at xxxxx
Sun Jun 14 22:10:09 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Sun, 14 Jun 2015 22:10:09 UTC
Commit:      733b10efc4f3d757726376e453e880d6409db62d
             https://github.com/geany/geany/commit/733b10efc4f3d757726376e453e880d6409db62d

Log Message:
-----------
Merge branch 'universal-ctags-fixes'

Import some various parser fixes from Universal CTags.


Modified Paths:
--------------
    tagmanager/ctags/get.c
    tagmanager/ctags/json.c
    tagmanager/ctags/python.c
    tagmanager/ctags/read.c
    tagmanager/ctags/read.h
    tagmanager/ctags/vstring.c
    tagmanager/ctags/vstring.h
    tests/ctags/Makefile.am
    tests/ctags/c-digraphs.c
    tests/ctags/c-digraphs.c.tags
    tests/ctags/c-trigraphs.c
    tests/ctags/c-trigraphs.c.tags
    tests/ctags/dotted-names.json
    tests/ctags/dotted-names.json.tags
    tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py
    tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags

Modified: tagmanager/ctags/get.c
43 lines changed, 40 insertions(+), 3 deletions(-)
===================================================================
@@ -648,8 +648,6 @@ extern int cppGetc (void)
 
 				if (next == NEWLINE)
 					continue;
-				else if (next == '?')
-					cppUngetc (next);
 				else
 					fileUngetc (next);
 				break;
@@ -675,13 +673,49 @@ extern int cppGetc (void)
 						case '-':          c = '~';       break;
 						case '=':          c = '#';       goto process;
 						default:
+							fileUngetc ('?');
 							fileUngetc (next);
-							cppUngetc ('?');
 							break;
 					}
 				}
 			} break;
 
+			/* digraphs:
+			 * input:  <:  :>  <%  %>  %:  %:%:
+			 * output: [   ]   {   }   #   ##
+			 */
+			case '<':
+			{
+				int next = fileGetc ();
+				switch (next)
+				{
+					case ':':	c = '['; break;
+					case '%':	c = '{'; break;
+					default: fileUngetc (next);
+				}
+				goto enter;
+			}
+			case ':':
+			{
+				int next = fileGetc ();
+				if (next == '>')
+					c = ']';
+				else
+					fileUngetc (next);
+				goto enter;
+			}
+			case '%':
+			{
+				int next = fileGetc ();
+				switch (next)
+				{
+					case '>':	c = '}'; break;
+					case ':':	c = '#'; goto process;
+					default: fileUngetc (next);
+				}
+				goto enter;
+			}
+
 			default:
 				if (c == '@' && Cpp.hasAtLiteralStrings)
 				{
@@ -692,7 +726,10 @@ extern int cppGetc (void)
 						c = skipToEndOfString (TRUE);
 						break;
 					}
+					else
+						fileUngetc (next);
 				}
+			enter:
 				Cpp.directive.accept = FALSE;
 				if (directive)
 					ignore = handleDirective (c);


Modified: tagmanager/ctags/json.c
10 lines changed, 1 insertions(+), 9 deletions(-)
===================================================================
@@ -227,15 +227,7 @@ static void pushScope (tokenInfo *const token,
 static void popScope (tokenInfo *const token,
 					  const tokenInfo *const parent)
 {
-	char *dot = strrchr (token->scope->buffer, '.');
-
-	if (! dot)
-		vStringClear (token->scope);
-	else
-	{
-		*dot = 0;
-		token->scope->length = dot - token->scope->buffer;
-	}
+	vStringTruncate (token->scope, vStringLength (parent->scope));
 	token->scopeKind = parent->scopeKind;
 }
 


Modified: tagmanager/ctags/python.c
18 lines changed, 6 insertions(+), 12 deletions(-)
===================================================================
@@ -463,10 +463,8 @@ static boolean constructParentString(NestingLevels *nls, int indent,
 	return is_class;
 }
 
-/* Check whether parent's indentation level is higher than the current level and
- * if so, remove it.
- */
-static void checkParent(NestingLevels *nls, int indent, vString *parent)
+/* Check indentation level and truncate nesting levels accordingly */
+static void checkIndent(NestingLevels *nls, int indent)
 {
 	int i;
 	NestingLevel *n;
@@ -474,14 +472,10 @@ static void checkParent(NestingLevels *nls, int indent, vString *parent)
 	for (i = 0; i < nls->n; i++)
 	{
 		n = nls->levels + i;
-		/* is there a better way to compare two vStrings? */
-		if (n && strcmp(vStringValue(parent), vStringValue(n->name)) == 0)
+		if (n && indent <= n->indentation)
 		{
-			if (indent <= n->indentation)
-			{
-				/* remove this level by clearing its name */
-				vStringClear(n->name);
-			}
+			/* truncate levels */
+			nls->n = i;
 			break;
 		}
 	}
@@ -749,7 +743,7 @@ static void findPythonTags (void)
 			continue;
 		}
 		
-		checkParent(nesting_levels, indent, parent);
+		checkIndent(nesting_levels, indent);
 
 		/* Find global and class variables */
 		variable = findVariable(line);


Modified: tagmanager/ctags/read.c
12 lines changed, 8 insertions(+), 4 deletions(-)
===================================================================
@@ -428,7 +428,12 @@ static int iFileGetc (void)
 
 extern void fileUngetc (int c)
 {
-    File.ungetch = c;
+    const size_t len = sizeof File.ungetchBuf / sizeof File.ungetchBuf[0];
+
+    Assert (File.ungetchIdx < len);
+    /* we cannot rely on the assertion that might be disabled in non-debug mode */
+    if (File.ungetchIdx < len)
+	File.ungetchBuf[File.ungetchIdx++] = c;
 }
 
 static vString *iFileGetLine (void)
@@ -468,10 +473,9 @@ extern int fileGetc (void)
      *	other processing on it, though, because we already did that the
      *	first time it was read through fileGetc ().
      */
-    if (File.ungetch != '\0')
+    if (File.ungetchIdx > 0)
     {
-	c = File.ungetch;
-	File.ungetch = '\0';
+	c = File.ungetchBuf[--File.ungetchIdx];
 	return c;	    /* return here to avoid re-calling debugPutc () */
     }
     do


Modified: tagmanager/ctags/read.h
3 lines changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -70,7 +70,8 @@ typedef struct sInputFile {
     MIO		*mio;		/* stream used for reading the file */
     unsigned long lineNumber;	/* line number in the input file */
     MIOPos	filePosition;	/* file position of current line */
-    int		ungetch;	/* a single character that was ungotten */
+    unsigned int ungetchIdx;
+    int		ungetchBuf[3];	/* characters that were ungotten */
     boolean	eof;		/* have we reached the end of file? */
     boolean	newLine;	/* will the next character begin a new line? */
 


Modified: tagmanager/ctags/vstring.c
13 lines changed, 10 insertions(+), 3 deletions(-)
===================================================================
@@ -54,11 +54,18 @@ extern boolean vStringAutoResize (vString *const string)
     return ok;
 }
 
+extern void vStringTruncate (vString *const string, const size_t length)
+{
+	Assert (length <= string->length);
+	string->length = length;
+	vStringTerminate (string);
+	DebugStatement ( memset (string->buffer + string->length, 0,
+	                         string->size - string->length); )
+}
+
 extern void vStringClear (vString *const string)
 {
-    string->length = 0;
-    string->buffer [0] = '\0';
-	DebugStatement ( memset (string->buffer, 0, string->size); )
+	vStringTruncate (string, 0);
 }
 
 extern void vStringDelete (vString *const string)


Modified: tagmanager/ctags/vstring.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -77,6 +77,7 @@ extern void vStringCopyS (vString *const string, const char *const s);
 extern void vStringNCopyS (vString *const string, const char *const s, const size_t length);
 extern void vStringCopyToLower (vString *const dest, const vString *const src);
 extern void vStringSetLength (vString *const string);
+extern void vStringTruncate (vString *const string, const size_t length);
 
 #endif	/* _VSTRING_H */
 


Modified: tests/ctags/Makefile.am
4 lines changed, 4 insertions(+), 0 deletions(-)
===================================================================
@@ -108,6 +108,8 @@ test_sources = \
 	bug960316.v						\
 	bug961001.v						\
 	byte.f							\
+	c-digraphs.c					\
+	c-trigraphs.c					\
 	case_sensitivity.php			\
 	char-selector.f90				\
 	classes.php						\
@@ -134,6 +136,7 @@ test_sources = \
 	debian_432872.f90				\
 	directives.c					\
 	dopbl2.f						\
+	dotted-names.json				\
 	enum.c							\
 	enum.f90						\
 	enum.java						\
@@ -235,6 +238,7 @@ test_sources = \
 	pure_elem.f95					\
 	py_constructor_arglist.py		\
 	py-skipped-string.py			\
+	python-anonymous-nestlevel_ctags-bug-356.py	\
 	qualified_types.f90				\
 	random.sql						\
 	readlob.sql						\


Modified: tests/ctags/c-digraphs.c
35 lines changed, 35 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,35 @@
+
+/* simple trigraphs */
+%:define A 1
+%:define B 2
+%:define STRINGIFY_INTERN(x) %:x
+%:define STRINGIFY(x) STRINGIFY_INTERN(x)
+
+%:define M3_INIT(a, b, c) <% a, b, c %>
+typedef int matrix3<:3:>;
+
+struct str <%
+  char *buf;
+  unsigned int len, size;
+%>;
+
+int main(void)
+<%
+  const char *hello = STRINGIFY(hello);
+  matrix3 m = M3_INIT(1, 2, 3);
+
+  return m<:2:>;
+%>
+
+%:if 0
+#define bug4
+%:endif
+
+
+/* test the same with untaken preprocessor paths (as they are then not read by
+ * the C parser but get.c) */
+#if 0
+%:define if0d_A 1
+%:define if0d_B 2
+#endif
+


Modified: tests/ctags/c-digraphs.c.tags
12 lines changed, 12 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,12 @@
+# format=tagmanager
+A�65536�0
+B�65536�0
+M3_INIT�131072�(a, b, c)�0
+STRINGIFY�131072�(x)�0
+STRINGIFY_INTERN�131072�(x)�0
+buf�64�str�0�char
+len�64�str�0�int
+main�16�(void)�0�int
+matrix3�4096�0�int
+size�64�str�0�int
+str�2048�0


Modified: tests/ctags/c-trigraphs.c
56 lines changed, 56 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,56 @@
+
+/* simple trigraphs */
+??=define A 1
+??=define B 2
+??=define STRINGIFY_INTERN(x) ??=x
+??=define STRINGIFY(x) STRINGIFY_INTERN(x)
+
+/* doesn't expand to anything that makes sense, but as "???" is not a valid
+ * trigraph it should not prevent "??/" to match */
+??=define D 4 ???/
+#define bug1
+??=define E ?????/
+#define bug2
+
+/* \ isn't interpreted for trigraphs */
+??=define F ???\??/
+extern int bug3 = ??-0;
+
+??=define M3_INIT(a, b, c) ??< a, b, c ??>
+typedef int matrix3??(3??);
+
+struct str ??<
+  char *buf;
+  unsigned int len, size;
+??>;
+
+int main(void)
+??<
+  const char *hello = STRINGIFY(hello);
+  matrix3 m = M3_INIT(1, 2, 3);
+
+  return m??(2??);
+??>
+
+/* FIXME: how to test "??'" ("^"), "??!" ("|") and "??-" ("~")?
+ *        I can't think of a construct CTags cares about using those */
+
+??=if 0
+#define bug4
+??=endif
+
+
+/* test the same with untaken preprocessor paths (as they are then not read by
+ * the C parser but get.c) */
+#if 0
+
+??=define if0d_A 1
+??=define if0d_B 2
+??=define if0d_C 4 ???/
+#define bug5
+??=define I ?????/
+#define bug6
+??=define I ??????????/
+#define bug7
+
+#endif


Modified: tests/ctags/c-trigraphs.c.tags
15 lines changed, 15 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,15 @@
+# format=tagmanager
+A�65536�0
+B�65536�0
+D�65536�0
+E�65536�0
+F�65536�0
+M3_INIT�131072�(a, b, c)�0
+STRINGIFY�131072�(x)�0
+STRINGIFY_INTERN�131072�(x)�0
+buf�64�str�0�char
+len�64�str�0�int
+main�16�(void)�0�int
+matrix3�4096�0�int
+size�64�str�0�int
+str�2048�0


Modified: tests/ctags/dotted-names.json
25 lines changed, 25 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,25 @@
+{
+  "first.name": "John",
+  "last.name": "Smith",
+  "is.alive": true,
+  "age": 25,
+  "height_cm": 167.6,
+  "address": {
+    "street.address": "21 2nd Street",
+    "city": "New York",
+    "state": "NY",
+    "postal.code": "10021-3100"
+  },
+  "phone.numbers": [
+    {
+      "type": "home",
+      "number": "212 555-1234"
+    },
+    {
+      "type": "office",
+      "number": "646 555-4567"
+    }
+  ],
+  "children": [],
+  "spouse": null
+}


Modified: tests/ctags/dotted-names.json.tags
20 lines changed, 20 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,20 @@
+# format=tagmanager
+0�64�phone.numbers�0
+1�64�phone.numbers�0
+address�64�0
+age�64�0
+children�64�0
+city�64�address�0
+first.name�64�0
+height_cm�64�0
+is.alive�64�0
+last.name�64�0
+number�64�phone.numbers.0�0
+number�64�phone.numbers.1�0
+phone.numbers�64�0
+postal.code�64�address�0
+spouse�64�0
+state�64�address�0
+street.address�64�address�0
+type�64�phone.numbers.0�0
+type�64�phone.numbers.1�0


Modified: tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py
6 lines changed, 6 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,6 @@
+class Testclass():
+    def main(self):
+        variable = True
+
+if __name__ == "__main__":
+    module_level_attribute = True


Modified: tests/ctags/python-anonymous-nestlevel_ctags-bug-356.py.tags
4 lines changed, 4 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,4 @@
+# format=tagmanager
+Testclass�1�0
+main�128�(self)�Testclass�0
+module_level_attribute�16384�0



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list