Blame SOURCES/ctags-5.8-ocaml-crash.patch

96f760
diff -up ctags-5.8/ocaml.c.me ctags-5.8/ocaml.c
96f760
--- ctags-5.8/ocaml.c.me	2012-08-02 12:42:21.652211192 +0200
96f760
+++ ctags-5.8/ocaml.c	2012-08-02 13:06:59.751283639 +0200
96f760
@@ -72,6 +72,7 @@ typedef enum {
96f760
 	OcaKEYWORD_if,
96f760
 	OcaKEYWORD_in,
96f760
 	OcaKEYWORD_let,
96f760
+	OcaKEYWORD_value,
96f760
 	OcaKEYWORD_match,
96f760
 	OcaKEYWORD_method,
96f760
 	OcaKEYWORD_module,
96f760
@@ -145,7 +146,7 @@ static const ocaKeywordDesc OcamlKeyword
96f760
 	{ "try"       , OcaKEYWORD_try       }, 
96f760
 	{ "type"      , OcaKEYWORD_type      }, 
96f760
 	{ "val"       , OcaKEYWORD_val       }, 
96f760
-	{ "value"     , OcaKEYWORD_let       }, /* just to handle revised syntax */
96f760
+	{ "value"     , OcaKEYWORD_value     }, /* just to handle revised syntax */
96f760
 	{ "virtual"   , OcaKEYWORD_virtual   }, 
96f760
 	{ "while"     , OcaKEYWORD_while     }, 
96f760
 	{ "with"      , OcaKEYWORD_with      }, 
96f760
@@ -297,7 +298,6 @@ static void eatComment (lexingState * st
96f760
 			if (st->cp == NULL)
96f760
 				return;
96f760
 			c = st->cp;
96f760
-			continue;
96f760
 		}
96f760
 		/* we've reached the end of the comment */
96f760
 		else if (*c == ')' && lastIsStar)
96f760
@@ -308,13 +308,33 @@ static void eatComment (lexingState * st
96f760
 		{
96f760
 			st->cp = c;
96f760
 			eatComment (st);
96f760
+
96f760
 			c = st->cp;
96f760
+			if (c == NULL)
96f760
+			    return;
96f760
+
96f760
 			lastIsStar = FALSE;
96f760
+            c++;
96f760
 		}
96f760
+		/* OCaml has a rule which says :
96f760
+		 *
96f760
+		 *   "Comments do not occur inside string or character literals.
96f760
+		 *    Nested comments are handled correctly."
96f760
+		 *
96f760
+		 * So if we encounter a string beginning, we must parse it to
96f760
+		 * get a good comment nesting (bug ID: 3117537)
96f760
+		 */
96f760
+        else if (*c == '"')
96f760
+        {
96f760
+            st->cp = c;
96f760
+            eatString (st);
96f760
+            c = st->cp;
96f760
+        }
96f760
 		else
96f760
+        {
96f760
 			lastIsStar = '*' == *c;
96f760
-
96f760
-		c++;
96f760
+            c++;
96f760
+        }
96f760
 	}
96f760
 
96f760
 	st->cp = c;
96f760
@@ -554,8 +574,7 @@ static int getLastNamedIndex ( void )
96f760
 
96f760
 	for (i = stackIndex - 1; i >= 0; --i)
96f760
 	{
96f760
-		if (stack[i].contextName->buffer &&
96f760
-			strlen (stack[i].contextName->buffer) > 0)
96f760
+        if (vStringLength (stack[i].contextName) > 0)
96f760
 		{
96f760
 			return i;
96f760
 		}
96f760
@@ -866,6 +885,11 @@ static void prepareTag (tagEntryInfo * t
96f760
 	tag->kindName = OcamlKinds[kind].name;
96f760
 	tag->kind = OcamlKinds[kind].letter;
96f760
 
96f760
+	if (kind == K_MODULE)
96f760
+	{
96f760
+		tag->lineNumberEntry = TRUE;
96f760
+		tag->lineNumber = 1;
96f760
+	}
96f760
 	parentIndex = getLastNamedIndex ();
96f760
 	if (parentIndex >= 0)
96f760
 	{
96f760
@@ -880,9 +904,12 @@ static void prepareTag (tagEntryInfo * t
96f760
  * more information to it in the future */
96f760
 static void addTag (vString * const ident, int kind)
96f760
 {
96f760
-	tagEntryInfo toCreate;
96f760
-	prepareTag (&toCreate, ident, kind);
96f760
-	makeTagEntry (&toCreate);
96f760
+	if (OcamlKinds [kind].enabled  &&  ident != NULL  &&  vStringLength (ident) > 0)
96f760
+	{
96f760
+		tagEntryInfo toCreate;
96f760
+		prepareTag (&toCreate, ident, kind);
96f760
+		makeTagEntry (&toCreate);
96f760
+	}
96f760
 }
96f760
 
96f760
 boolean needStrongPoping = FALSE;
96f760
@@ -942,15 +969,17 @@ static void typeRecord (vString * const
96f760
 }
96f760
 
96f760
 /* handle :
96f760
- * exception ExceptionName ... */
96f760
+ * exception ExceptionName of ... */
96f760
 static void exceptionDecl (vString * const ident, ocaToken what)
96f760
 {
96f760
 	if (what == OcaIDENTIFIER)
96f760
 	{
96f760
 		addTag (ident, K_EXCEPTION);
96f760
 	}
96f760
-	/* don't know what to do on else... */
96f760
-
96f760
+    else /* probably ill-formed, give back to global scope */
96f760
+    { 
96f760
+        globalScope (ident, what);
96f760
+    }
96f760
 	toDoNext = &globalScope;
96f760
 }
96f760
 
96f760
@@ -1006,7 +1035,6 @@ static void constructorValidation (vStri
96f760
  */
96f760
 static void typeDecl (vString * const ident, ocaToken what)
96f760
 {
96f760
-
96f760
 	switch (what)
96f760
 	{
96f760
 		/* parameterized */
96f760
@@ -1046,7 +1074,6 @@ static void typeDecl (vString * const id
96f760
  * let typeRecord handle it. */
96f760
 static void typeSpecification (vString * const ident, ocaToken what)
96f760
 {
96f760
-
96f760
 	switch (what)
96f760
 	{
96f760
 	case OcaIDENTIFIER:
96f760
@@ -1243,8 +1270,14 @@ static void localLet (vString * const id
96f760
  * than the let definitions.
96f760
  * Used after a match ... with, or a function ... or fun ...
96f760
  * because their syntax is similar.  */
96f760
-static void matchPattern (vString * const UNUSED (ident), ocaToken what)
96f760
+static void matchPattern (vString * const ident, ocaToken what)
96f760
 {
96f760
+    /* keep track of [], as it
96f760
+     * can be used in patterns and can
96f760
+     * mean the end of match expression in
96f760
+     * revised syntax */
96f760
+    static int braceCount = 0;
96f760
+
96f760
 	switch (what)
96f760
 	{
96f760
 	case Tok_To:
96f760
@@ -1252,6 +1285,14 @@ static void matchPattern (vString * cons
96f760
 		toDoNext = &mayRedeclare;
96f760
 		break;
96f760
 
96f760
+    case Tok_BRL:
96f760
+        braceCount++;
96f760
+        break;
96f760
+
96f760
+    case OcaKEYWORD_value:
96f760
+		popLastNamed ();
96f760
+        globalScope (ident, what);
96f760
+        break;
96f760
 
96f760
 	case OcaKEYWORD_in:
96f760
 		popLastNamed ();
96f760
@@ -1269,6 +1310,11 @@ static void mayRedeclare (vString * cons
96f760
 {
96f760
 	switch (what)
96f760
 	{
96f760
+    case OcaKEYWORD_value:
96f760
+        /* let globalScope handle it */
96f760
+        globalScope (ident, what);
96f760
+        break;
96f760
+
96f760
 	case OcaKEYWORD_let:
96f760
 	case OcaKEYWORD_val:
96f760
 		toDoNext = localLet;
96f760
@@ -1388,6 +1434,7 @@ static void classSpecif (vString * const
96f760
  * nearly a copy/paste of globalLet. */
96f760
 static void methodDecl (vString * const ident, ocaToken what)
96f760
 {
96f760
+
96f760
 	switch (what)
96f760
 	{
96f760
 	case Tok_PARL:
96f760
@@ -1435,6 +1482,7 @@ vString *lastModule;
96f760
  */
96f760
 static void moduleSpecif (vString * const ident, ocaToken what)
96f760
 {
96f760
+
96f760
 	switch (what)
96f760
 	{
96f760
 	case OcaKEYWORD_functor:
96f760
@@ -1566,7 +1614,7 @@ static void globalScope (vString * const
96f760
 {
96f760
 	/* Do not touch, this is used only by the global scope
96f760
 	 * to handle an 'and' */
96f760
-	static parseNext previousParser = NULL;
96f760
+	static parseNext previousParser = &globalScope;
96f760
 
96f760
 	switch (what)
96f760
 	{
96f760
@@ -1608,6 +1656,7 @@ static void globalScope (vString * const
96f760
 		/* val is mixed with let as global
96f760
 		 * to be able to handle mli & new syntax */
96f760
 	case OcaKEYWORD_val:
96f760
+	case OcaKEYWORD_value:
96f760
 	case OcaKEYWORD_let:
96f760
 		cleanupPreviousParser ();
96f760
 		toDoNext = &globalLet;
96f760
@@ -1617,7 +1666,7 @@ static void globalScope (vString * const
96f760
 	case OcaKEYWORD_exception:
96f760
 		cleanupPreviousParser ();
96f760
 		toDoNext = &exceptionDecl;
96f760
-		previousParser = NULL;
96f760
+		previousParser = &globalScope;
96f760
 		break;
96f760
 
96f760
 		/* must be a #line directive, discard the
96f760
@@ -1769,7 +1818,7 @@ static void computeModuleName ( void )
96f760
 	if (isLowerAlpha (moduleName->buffer[0]))
96f760
 		moduleName->buffer[0] += ('A' - 'a');
96f760
 
96f760
-	makeSimpleTag (moduleName, OcamlKinds, K_MODULE);
96f760
+	addTag (moduleName, K_MODULE);
96f760
 	vStringDelete (moduleName);
96f760
 }
96f760
 
96f760
@@ -1779,6 +1828,7 @@ static void initStack ( void )
96f760
 	int i;
96f760
 	for (i = 0; i < OCAML_MAX_STACK_SIZE; ++i)
96f760
 		stack[i].contextName = vStringNew ();
96f760
+    stackIndex = 0;
96f760
 }
96f760
 
96f760
 static void clearStack ( void )
96f760
@@ -1794,8 +1844,8 @@ static void findOcamlTags (void)
96f760
 	lexingState st;
96f760
 	ocaToken tok;
96f760
 
96f760
-	computeModuleName ();
96f760
 	initStack ();
96f760
+	computeModuleName ();
96f760
 	tempIdent = vStringNew ();
96f760
 	lastModule = vStringNew ();
96f760
 	lastClass = vStringNew ();