]> git.pld-linux.org Git - packages/ctags.git/blob - ctags-5.8-ocaml-crash.patch
- rel 5; add fixes and improvements from FC
[packages/ctags.git] / ctags-5.8-ocaml-crash.patch
1 diff -up ctags-5.8/ocaml.c.me ctags-5.8/ocaml.c
2 --- ctags-5.8/ocaml.c.me        2012-08-02 12:42:21.652211192 +0200
3 +++ ctags-5.8/ocaml.c   2012-08-02 13:06:59.751283639 +0200
4 @@ -72,6 +72,7 @@ typedef enum {
5         OcaKEYWORD_if,
6         OcaKEYWORD_in,
7         OcaKEYWORD_let,
8 +       OcaKEYWORD_value,
9         OcaKEYWORD_match,
10         OcaKEYWORD_method,
11         OcaKEYWORD_module,
12 @@ -145,7 +146,7 @@ static const ocaKeywordDesc OcamlKeyword
13         { "try"       , OcaKEYWORD_try       }, 
14         { "type"      , OcaKEYWORD_type      }, 
15         { "val"       , OcaKEYWORD_val       }, 
16 -       { "value"     , OcaKEYWORD_let       }, /* just to handle revised syntax */
17 +       { "value"     , OcaKEYWORD_value     }, /* just to handle revised syntax */
18         { "virtual"   , OcaKEYWORD_virtual   }, 
19         { "while"     , OcaKEYWORD_while     }, 
20         { "with"      , OcaKEYWORD_with      }, 
21 @@ -297,7 +298,6 @@ static void eatComment (lexingState * st
22                         if (st->cp == NULL)
23                                 return;
24                         c = st->cp;
25 -                       continue;
26                 }
27                 /* we've reached the end of the comment */
28                 else if (*c == ')' && lastIsStar)
29 @@ -308,13 +308,33 @@ static void eatComment (lexingState * st
30                 {
31                         st->cp = c;
32                         eatComment (st);
33 +
34                         c = st->cp;
35 +                       if (c == NULL)
36 +                           return;
37 +
38                         lastIsStar = FALSE;
39 +            c++;
40                 }
41 +               /* OCaml has a rule which says :
42 +                *
43 +                *   "Comments do not occur inside string or character literals.
44 +                *    Nested comments are handled correctly."
45 +                *
46 +                * So if we encounter a string beginning, we must parse it to
47 +                * get a good comment nesting (bug ID: 3117537)
48 +                */
49 +        else if (*c == '"')
50 +        {
51 +            st->cp = c;
52 +            eatString (st);
53 +            c = st->cp;
54 +        }
55                 else
56 +        {
57                         lastIsStar = '*' == *c;
58 -
59 -               c++;
60 +            c++;
61 +        }
62         }
63  
64         st->cp = c;
65 @@ -554,8 +574,7 @@ static int getLastNamedIndex ( void )
66  
67         for (i = stackIndex - 1; i >= 0; --i)
68         {
69 -               if (stack[i].contextName->buffer &&
70 -                       strlen (stack[i].contextName->buffer) > 0)
71 +        if (vStringLength (stack[i].contextName) > 0)
72                 {
73                         return i;
74                 }
75 @@ -866,6 +885,11 @@ static void prepareTag (tagEntryInfo * t
76         tag->kindName = OcamlKinds[kind].name;
77         tag->kind = OcamlKinds[kind].letter;
78  
79 +       if (kind == K_MODULE)
80 +       {
81 +               tag->lineNumberEntry = TRUE;
82 +               tag->lineNumber = 1;
83 +       }
84         parentIndex = getLastNamedIndex ();
85         if (parentIndex >= 0)
86         {
87 @@ -880,9 +904,12 @@ static void prepareTag (tagEntryInfo * t
88   * more information to it in the future */
89  static void addTag (vString * const ident, int kind)
90  {
91 -       tagEntryInfo toCreate;
92 -       prepareTag (&toCreate, ident, kind);
93 -       makeTagEntry (&toCreate);
94 +       if (OcamlKinds [kind].enabled  &&  ident != NULL  &&  vStringLength (ident) > 0)
95 +       {
96 +               tagEntryInfo toCreate;
97 +               prepareTag (&toCreate, ident, kind);
98 +               makeTagEntry (&toCreate);
99 +       }
100  }
101  
102  boolean needStrongPoping = FALSE;
103 @@ -942,15 +969,17 @@ static void typeRecord (vString * const
104  }
105  
106  /* handle :
107 - * exception ExceptionName ... */
108 + * exception ExceptionName of ... */
109  static void exceptionDecl (vString * const ident, ocaToken what)
110  {
111         if (what == OcaIDENTIFIER)
112         {
113                 addTag (ident, K_EXCEPTION);
114         }
115 -       /* don't know what to do on else... */
116 -
117 +    else /* probably ill-formed, give back to global scope */
118 +    { 
119 +        globalScope (ident, what);
120 +    }
121         toDoNext = &globalScope;
122  }
123  
124 @@ -1006,7 +1035,6 @@ static void constructorValidation (vStri
125   */
126  static void typeDecl (vString * const ident, ocaToken what)
127  {
128 -
129         switch (what)
130         {
131                 /* parameterized */
132 @@ -1046,7 +1074,6 @@ static void typeDecl (vString * const id
133   * let typeRecord handle it. */
134  static void typeSpecification (vString * const ident, ocaToken what)
135  {
136 -
137         switch (what)
138         {
139         case OcaIDENTIFIER:
140 @@ -1243,8 +1270,14 @@ static void localLet (vString * const id
141   * than the let definitions.
142   * Used after a match ... with, or a function ... or fun ...
143   * because their syntax is similar.  */
144 -static void matchPattern (vString * const UNUSED (ident), ocaToken what)
145 +static void matchPattern (vString * const ident, ocaToken what)
146  {
147 +    /* keep track of [], as it
148 +     * can be used in patterns and can
149 +     * mean the end of match expression in
150 +     * revised syntax */
151 +    static int braceCount = 0;
152 +
153         switch (what)
154         {
155         case Tok_To:
156 @@ -1252,6 +1285,14 @@ static void matchPattern (vString * cons
157                 toDoNext = &mayRedeclare;
158                 break;
159  
160 +    case Tok_BRL:
161 +        braceCount++;
162 +        break;
163 +
164 +    case OcaKEYWORD_value:
165 +               popLastNamed ();
166 +        globalScope (ident, what);
167 +        break;
168  
169         case OcaKEYWORD_in:
170                 popLastNamed ();
171 @@ -1269,6 +1310,11 @@ static void mayRedeclare (vString * cons
172  {
173         switch (what)
174         {
175 +    case OcaKEYWORD_value:
176 +        /* let globalScope handle it */
177 +        globalScope (ident, what);
178 +        break;
179 +
180         case OcaKEYWORD_let:
181         case OcaKEYWORD_val:
182                 toDoNext = localLet;
183 @@ -1388,6 +1434,7 @@ static void classSpecif (vString * const
184   * nearly a copy/paste of globalLet. */
185  static void methodDecl (vString * const ident, ocaToken what)
186  {
187 +
188         switch (what)
189         {
190         case Tok_PARL:
191 @@ -1435,6 +1482,7 @@ vString *lastModule;
192   */
193  static void moduleSpecif (vString * const ident, ocaToken what)
194  {
195 +
196         switch (what)
197         {
198         case OcaKEYWORD_functor:
199 @@ -1566,7 +1614,7 @@ static void globalScope (vString * const
200  {
201         /* Do not touch, this is used only by the global scope
202          * to handle an 'and' */
203 -       static parseNext previousParser = NULL;
204 +       static parseNext previousParser = &globalScope;
205  
206         switch (what)
207         {
208 @@ -1608,6 +1656,7 @@ static void globalScope (vString * const
209                 /* val is mixed with let as global
210                  * to be able to handle mli & new syntax */
211         case OcaKEYWORD_val:
212 +       case OcaKEYWORD_value:
213         case OcaKEYWORD_let:
214                 cleanupPreviousParser ();
215                 toDoNext = &globalLet;
216 @@ -1617,7 +1666,7 @@ static void globalScope (vString * const
217         case OcaKEYWORD_exception:
218                 cleanupPreviousParser ();
219                 toDoNext = &exceptionDecl;
220 -               previousParser = NULL;
221 +               previousParser = &globalScope;
222                 break;
223  
224                 /* must be a #line directive, discard the
225 @@ -1769,7 +1818,7 @@ static void computeModuleName ( void )
226         if (isLowerAlpha (moduleName->buffer[0]))
227                 moduleName->buffer[0] += ('A' - 'a');
228  
229 -       makeSimpleTag (moduleName, OcamlKinds, K_MODULE);
230 +       addTag (moduleName, K_MODULE);
231         vStringDelete (moduleName);
232  }
233  
234 @@ -1779,6 +1828,7 @@ static void initStack ( void )
235         int i;
236         for (i = 0; i < OCAML_MAX_STACK_SIZE; ++i)
237                 stack[i].contextName = vStringNew ();
238 +    stackIndex = 0;
239  }
240  
241  static void clearStack ( void )
242 @@ -1794,8 +1844,8 @@ static void findOcamlTags (void)
243         lexingState st;
244         ocaToken tok;
245  
246 -       computeModuleName ();
247         initStack ();
248 +       computeModuleName ();
249         tempIdent = vStringNew ();
250         lastModule = vStringNew ();
251         lastClass = vStringNew ();
This page took 0.067207 seconds and 3 git commands to generate.