[geany/geany] b83961: Merge branch 'ctags/make'

Colomban Wendling git-noreply at xxxxx
Mon Apr 20 18:04:47 UTC 2015


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 20 Apr 2015 18:04:47 UTC
Commit:      b839611e517f9ae853fc1eb9232ff3452a7e36bd
             https://github.com/geany/geany/commit/b839611e517f9ae853fc1eb9232ff3452a7e36bd

Log Message:
-----------
Merge branch 'ctags/make'

Import make parser improvements from fishman/ctags#272


Modified Paths:
--------------
    tagmanager/ctags/make.c
    tests/ctags/Makefile.am
    tests/ctags/make-comment-in-rule.mak
    tests/ctags/make-comment-in-rule.mak.tags
    tests/ctags/make-gnumake-pattern-rules.mak
    tests/ctags/make-gnumake-pattern-rules.mak.tags
    tests/ctags/make-multi-target.mak
    tests/ctags/make-multi-target.mak.tags
    tests/ctags/make-target-with-parentheses.mak
    tests/ctags/make-target-with-parentheses.mak.tags
    tests/ctags/make-variable-on-cmdline.mak
    tests/ctags/make-variable-on-cmdline.mak.tags
    tests/ctags/simple.mak.tags

Modified: tagmanager/ctags/make.c
178 lines changed, 65 insertions(+), 113 deletions(-)
===================================================================
@@ -59,25 +59,23 @@ static void skipLine (void)
 		fileUngetc (c);
 }
 
-static int skipToNonWhite (void)
+static int skipToNonWhite (int c)
 {
-	int c;
-	do
+	while (c != '\n' && isspace (c))
 		c = nextChar ();
-	while (c != '\n' && isspace (c));
 	return c;
 }
 
 static boolean isIdentifier (int c)
 {
-	return (boolean)(c != '\0' && (isalnum (c)  ||  strchr (".-_/", c) != NULL));
+	return (boolean)(c != '\0' && (isalnum (c)  ||  strchr (".-_/$(){}%", c) != NULL));
 }
 
 static boolean isSpecialTarget (vString *const name)
 {
 	size_t i = 0;
 	/* All special targets begin with '.'. */
-	if (vStringChar (name, i++) != '.') {
+	if (vStringLength (name) < 1 || vStringChar (name, i++) != '.') {
 		return FALSE;
 	}
 	while (i < vStringLength (name)) {
@@ -105,67 +103,27 @@ static void newMacro (vString *const name)
 	makeSimpleTag (name, MakeKinds, K_MACRO);
 }
 
-static void newMacroFromDefine (vString *const name)
-{
-	/* name is something like "define JAVAHPP_RULE", find the space and jump to the next char */
-	char *name_val = strchr (vStringValue (name), ' ');
-
-	if (name_val != NULL) {
-		vStringCopyS (name, name_val + 1);
-		makeSimpleTag (name, MakeKinds, K_MACRO);
-	}
-}
-
 static void readIdentifier (const int first, vString *const id)
 {
+	int depth = 0;
 	int c = first;
-	int c_prev = first;
-	int c_next = first;
 	vStringClear (id);
-	while (isIdentifier (c) || c == ' ')
+	while (isIdentifier (c) || (depth > 0 && c != EOF && c != '\n'))
 	{
-		c_next = nextChar ();
-		if (c == ' ') {
-			/* add the space character only if the previous and
-			 * next character are valid identifiers */
-			if (isIdentifier (c_prev) && isIdentifier (c_next))
-				vStringPut (id, c);
-		}
-		else {
-			vStringPut (id, c);
-		}
-		c_prev = c;
-		c = c_next;
+		if (c == '(' || c == '}')
+			depth++;
+		else if (depth > 0 && (c == ')' || c == '}'))
+			depth--;
+		vStringPut (id, c);
+		c = nextChar ();
 	}
 	fileUngetc (c);
 	vStringTerminate (id);
 }
 
-static void skipToMatch (const char *const pair)
-{
-	const int begin = pair [0], end = pair [1];
-	const unsigned long inputLineNumber = getInputLineNumber ();
-	int matchLevel = 1;
-	int c = '\0';
-
-	while (matchLevel > 0)
-	{
-		c = nextChar ();
-		if (c == begin)
-			++matchLevel;
-		else if (c == end)
-			--matchLevel;
-		else if (c == '\n' || c == EOF)
-			break;
-	}
-	if (c == EOF)
-		verbose ("%s: failed to find match for '%c' at line %lu\n",
-				getInputFileName (), begin, inputLineNumber);
-}
-
 static void findMakeTags (void)
 {
-	vString *name = vStringNew ();
+	stringList *identifiers = stringListNew ();
 	boolean newline = TRUE;
 	boolean in_define = FALSE;
 	boolean in_rule = FALSE;
@@ -178,14 +136,15 @@ static void findMakeTags (void)
 		{
 			if (in_rule)
 			{
-				if (c == '\t')
+				if (c == '\t' || (c = skipToNonWhite (c)) == '#')
 				{
-					skipLine ();  /* skip rule */
-					continue;
+					skipLine ();  /* skip rule or comment */
+					c = nextChar ();
 				}
-				else
+				else if (c != '\n')
 					in_rule = FALSE;
 			}
+			stringListClear (identifiers);
 			variable_possible = (boolean)(!in_rule);
 			newline = FALSE;
 		}
@@ -195,77 +154,70 @@ static void findMakeTags (void)
 			continue;
 		else if (c == '#')
 			skipLine ();
-		else if (c == '(')
-			skipToMatch ("()");
-		else if (c == '{')
-			skipToMatch ("{}");
-		else if (c == ':')
+		else if (variable_possible && c == '?')
 		{
-			variable_possible = TRUE;
-			in_rule = TRUE;
+			c = nextChar ();
+			fileUngetc (c);
+			variable_possible = (c == '=');
+		}
+		else if (variable_possible && c == ':' &&
+				 stringListCount (identifiers) > 0)
+		{
+			c = nextChar ();
+			fileUngetc (c);
+			if (c != '=')
+			{
+				unsigned int i;
+				for (i = 0; i < stringListCount (identifiers); i++)
+					newTarget (stringListItem (identifiers, i));
+				stringListClear (identifiers);
+				in_rule = TRUE;
+			}
+		}
+		else if (variable_possible && c == '=' &&
+				 stringListCount (identifiers) == 1)
+		{
+			newMacro (stringListItem (identifiers, 0));
+			skipLine ();
+			in_rule = FALSE;
 		}
 		else if (variable_possible && isIdentifier (c))
 		{
+			vString *name = vStringNew ();
 			readIdentifier (c, name);
-			if (strncmp (vStringValue (name), "endef", 5) == 0)
-				in_define = FALSE;
-			else if (in_define)
-				skipLine ();
-			else if (strncmp (vStringValue (name), "define", 6) == 0  &&
-				isIdentifier (c))
+			stringListAdd (identifiers, name);
+
+			if (stringListCount (identifiers) == 1)
 			{
-				in_define = TRUE;
-				c = skipToNonWhite ();
-				newMacroFromDefine (name);
-				skipLine ();
-			}
-			else {
-				c = skipToNonWhite ();
-				if (strchr (":?+", c) != NULL)
+				if (in_define && ! strcmp (vStringValue (name), "endef"))
+					in_define = FALSE;
+				else if (in_define)
+					skipLine ();
+				else if (! strcmp (vStringValue (name), "define"))
 				{
-					boolean append = (boolean)(c == '+');
-					boolean was_colon = (c == ':');
-					c = nextChar ();
-					if (was_colon)
+					in_define = TRUE;
+					c = skipToNonWhite (nextChar ());
+					vStringClear (name);
+					/* all remaining characters on the line are the name -- even spaces */
+					while (c != EOF && c != '\n')
 					{
-						if (c == '=')
-						{
-							newMacro (name);
-							in_rule = FALSE;
-							skipLine ();
-						}
-						else
-						{
-							in_rule = TRUE;
-							newTarget (name);
-						}
+						vStringPut (name, c);
+						c = nextChar ();
 					}
-					else if (append)
-					{
-						skipLine ();
-						continue;
-					}
-					else
-					{
+					if (c == '\n')
 						fileUngetc (c);
-					}
-				}
-				else if (c == '=')
-				{
+					vStringTerminate (name);
+					vStringStripTrailing (name);
 					newMacro (name);
-					in_rule = FALSE;
-					skipLine ();
-				}
-				else
-				{
-					fileUngetc (c);
 				}
+				else if (! strcmp (vStringValue (name), "export"))
+					stringListClear (identifiers);
 			}
 		}
 		else
 			variable_possible = FALSE;
 	}
-	vStringDelete (name);
+	stringListDelete (identifiers);
 }
 
 extern parserDefinition* MakefileParser (void)


Modified: tests/ctags/Makefile.am
5 lines changed, 5 insertions(+), 0 deletions(-)
===================================================================
@@ -200,6 +200,11 @@ test_sources = \
 	line_directives.c				\
 	local.c							\
 	macros.c						\
+	make-comment-in-rule.mak		\
+	make-gnumake-pattern-rules.mak	\
+	make-multi-target.mak			\
+	make-target-with-parentheses.mak	\
+	make-variable-on-cmdline.mak	\
 	masm.asm						\
 	matlab_backtracking.m			\
 	matlab_test.m					\


Modified: tests/ctags/make-comment-in-rule.mak
17 lines changed, 17 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,17 @@
+# all this is one single rule
+all:
+	a=1; echo "$$a"
+# foo
+	b=2; echo "$$b"
+  # foo
+	c=3; echo "$$c"
+
# foo
+	d=4; echo "$$d"
+
# foo
+	e=5; echo "$$e"
+
+
+	f=6; echo "$$f"
+ # foo
+
+	g=7; echo "$$g"


Modified: tests/ctags/make-comment-in-rule.mak.tags
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,2 @@
+# format=tagmanager
+all�16�0


Modified: tests/ctags/make-gnumake-pattern-rules.mak
8 lines changed, 8 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,8 @@
+%.o: %.c
+	touch $@
+
+%.p %.q: %.d
+	touch $@
+
+%a b%:
+	touch $@


Modified: tests/ctags/make-gnumake-pattern-rules.mak.tags
6 lines changed, 6 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,6 @@
+# format=tagmanager
+%.o�16�0
+%.p�16�0
+%.q�16�0
+%a�16�0
+b%�16�0


Modified: tests/ctags/make-multi-target.mak
8 lines changed, 8 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,8 @@
+
+all: foo bar
+
+foo bar: baz
+	echo $@
+
+baz:
+	echo $@


Modified: tests/ctags/make-multi-target.mak.tags
5 lines changed, 5 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,5 @@
+# format=tagmanager
+all�16�0
+bar�16�0
+baz�16�0
+foo�16�0


Modified: tests/ctags/make-target-with-parentheses.mak
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1 @@
+$(obj)/raid6int1.c:   F := 6


Modified: tests/ctags/make-target-with-parentheses.mak.tags
3 lines changed, 3 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,3 @@
+# format=tagmanager
+$(obj)/raid6int1.c�16�0
+F�65536�0


Modified: tests/ctags/make-variable-on-cmdline.mak
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,2 @@
+fixme:
+	cmd -g FOO=BAR


Modified: tests/ctags/make-variable-on-cmdline.mak.tags
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,2 @@
+# format=tagmanager
+fixme�16�0


Modified: tests/ctags/simple.mak.tags
5 lines changed, 2 insertions(+), 3 deletions(-)
===================================================================
@@ -1,15 +1,14 @@
 # format=tagmanager
+$(obj)/raid6int1.c�16�0
 A�65536�0
 B�65536�0
 C�65536�0
 D�65536�0
 E�65536�0
-ENV_VAR1�65536�0
-ENV_VAR2�65536�0
 F�65536�0
 G�65536�0
 H�65536�0
+I�65536�0
 a.o�16�0
 b.o�16�0
 default�16�0
-export I�65536�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