Fix for UBSan build
[platform/upstream/doxygen.git] / src / constexp.l
1 /******************************************************************************
2  *
3  * $Id: constexp.l,v 1.11 2001/03/19 19:27:40 root Exp $
4  *
5  *
6  * Copyright (C) 1997-2012 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 %{
20
21 #include "constexp.h"  
22 #include "cppvalue.h"
23 #include "ce_parse.h" // generated header file
24
25 #define YY_NEVER_INTERACTIVE 1
26 #define YY_NO_INPUT 1
27   
28 QCString    g_strToken;  
29 CPPValue    g_resultValue;
30 int         g_constExpLineNr;
31 QCString    g_constExpFileName;
32
33 static const char *g_inputString;
34 static int         g_inputPosition;
35
36 #undef  YY_INPUT
37 #define YY_INPUT(buf,result,max_size) result=yyread(buf,max_size);
38
39 static int yyread(char *buf,int max_size)
40 {
41   int c=0;
42   while( c < max_size && g_inputString[g_inputPosition] )
43   {
44     *buf = g_inputString[g_inputPosition++] ;
45     c++; buf++;
46   }
47   return c;
48 }
49
50 %}
51
52 CONSTSUFFIX ([uU][lL]?[lL]?)|([lL][lL]?[uU]?)
53
54 %option nounput
55
56 %%
57
58 "?"                                { return TOK_QUESTIONMARK; }
59 ":"                                { return TOK_COLON; }
60 "||"                               { return TOK_OR; }
61 "&&"                               { return TOK_AND; }
62 "|"                                { return TOK_BITWISEOR; }
63 "^"                                { return TOK_BITWISEXOR; }
64 "&"                                { return TOK_AMPERSAND; }
65 "!="                               { return TOK_NOTEQUAL; }
66 "=="                               { return TOK_EQUAL; }
67 "<"                                { return TOK_LESSTHAN; }
68 ">"                                { return TOK_GREATERTHAN; }
69 "<="                               { return TOK_LESSTHANOREQUALTO; }
70 ">="                               { return TOK_GREATERTHANOREQUALTO; }
71 "<<"                               { return TOK_SHIFTLEFT; }
72 ">>"                               { return TOK_SHIFTRIGHT; }
73 "+"                                { return TOK_PLUS; }
74 "-"                                { return TOK_MINUS; }
75 "*"                                { return TOK_STAR; }
76 "/"                                { return TOK_DIVIDE; }
77 "%"                                { return TOK_MOD; }
78 "~"                                { return TOK_TILDE; }
79 "!"                                { return TOK_NOT; }
80 "("                                { return TOK_LPAREN; }
81 ")"                                { return TOK_RPAREN; }
82 "'"(([^\'\n\r\\]+)|(\\(([ntvbrfa\\?'\"])|([0-9]+)|([xX][0-9a-fA-F]+))))"'"   { 
83                                      g_strToken=yytext;  
84                                      return TOK_CHARACTER; 
85                                    }
86 0[0-7]*{CONSTSUFFIX}?              { g_strToken=yytext; 
87                                      return TOK_OCTALINT; 
88                                    }
89 [1-9][0-9]*{CONSTSUFFIX}?          { g_strToken=yytext; 
90                                      return TOK_DECIMALINT; 
91                                    }
92 (0x|0X)[0-9a-fA-F]+{CONSTSUFFIX}?  { g_strToken=yytext+2; 
93                                      return TOK_HEXADECIMALINT; 
94                                    }
95 (([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+))([eE]([\-\+])?[0-9]+)?([fFlL])? { 
96                                      g_strToken=yytext; return TOK_FLOAT; 
97                                    }
98 ([0-9]+[eE])([\-\+])?[0-9]+([fFlL])? { 
99                                      g_strToken=yytext; return TOK_FLOAT; 
100                                    }
101 .                                  
102 \n
103
104 %%
105
106 bool parseCppExpression(const char *fileName,int lineNr,const QCString &s)
107 {
108   //printf("Expression: `%s'\n",s.data());
109   g_constExpFileName = fileName;
110   g_constExpLineNr = lineNr;
111   g_inputString = s;
112   g_inputPosition = 0;
113   cppExpYYrestart( cppExpYYin );
114   cppExpYYparse();
115   //printf("Result: %ld\n",(long)g_resultValue);
116   return (long)g_resultValue!=0;
117 }
118
119 extern "C" {
120   int cppExpYYwrap() { return 1; }
121 }