~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/lib/parsers/qmake/qmake_yacc.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* A Bison parser, made by GNU Bison 2.3.  */
2
 
 
3
 
/* Skeleton interface for Bison LALR(1) parsers in C++
4
 
 
5
 
   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
6
 
 
7
 
   This program is free software; you can redistribute it and/or modify
8
 
   it under the terms of the GNU General Public License as published by
9
 
   the Free Software Foundation; either version 2, or (at your option)
10
 
   any later version.
11
 
 
12
 
   This program is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
   GNU General Public License for more details.
16
 
 
17
 
   You should have received a copy of the GNU General Public License
18
 
   along with this program; if not, write to the Free Software
19
 
   Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 
   Boston, MA 02110-1301, USA.  */
21
 
 
22
 
/* As a special exception, you may create a larger work that contains
23
 
   part or all of the Bison parser skeleton and distribute that work
24
 
   under terms of your choice, so long as that work isn't itself a
25
 
   parser generator using the skeleton or a modified version thereof
26
 
   as a parser skeleton.  Alternatively, if you modify or redistribute
27
 
   the parser skeleton itself, you may (at your option) remove this
28
 
   special exception, which will cause the skeleton and the resulting
29
 
   Bison output files to be licensed under the GNU General Public
30
 
   License without this special exception.
31
 
 
32
 
   This special exception was added by the Free Software Foundation in
33
 
   version 2.2 of Bison.  */
34
 
 
35
 
/* C++ LALR(1) parser skeleton written by Akim Demaille.  */
36
 
 
37
 
#ifndef PARSER_HEADER_H
38
 
# define PARSER_HEADER_H
39
 
 
40
 
#include <string>
41
 
#include <iostream>
42
 
#include "stack.hh"
43
 
 
44
 
namespace QMake
45
 
{
46
 
  class position;
47
 
  class location;
48
 
}
49
 
 
50
 
/* First part of user declarations.  */
51
 
#line 1 "qmake.yy"
52
 
 
53
 
/***************************************************************************
54
 
 *   Copyright (C) 2005 by Alexander Dymo                                  *
55
 
 *   adymo@kdevelop.org                                                    *
56
 
 *   Copyright (C) 2006 by Andreas Pakulat                                 *
57
 
 *   apaku@gmx.de                                                          *
58
 
 *                                                                         *
59
 
 *   This program is free software; you can redistribute it and/or modify  *
60
 
 *   it under the terms of the GNU Library General Public License as       *
61
 
 *   published by the Free Software Foundation; either version 2 of the    *
62
 
 *   License, or (at your option) any later version.                       *
63
 
 *                                                                         *
64
 
 *   This program is distributed in the hope that it will be useful,       *
65
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
66
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
67
 
 *   GNU General Public License for more details.                          *
68
 
 *                                                                         *
69
 
 *   You should have received a copy of the GNU Library General Public     *
70
 
 *   License along with this program; if not, write to the                 *
71
 
 *   Free Software Foundation, Inc.,                                       *
72
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
73
 
 ***************************************************************************/
74
 
 
75
 
/**
76
 
@file qmake.yy
77
 
QMake Parser
78
 
 
79
 
Simple LALR parser which builds the syntax tree (see @ref QMake::AST).
80
 
 
81
 
@todo Recognize comments after statements like:
82
 
SOURCES = foo #regognize me
83
 
 
84
 
@fixme Parser fails on files that do not end with a newline
85
 
@fixme 1 shift/reduce conflict in "line_body" rule
86
 
*/
87
 
 
88
 
#include <qvaluestack.h>
89
 
#include "qmakeast.h"
90
 
#include <qregexp.h>
91
 
 
92
 
#define YYSTYPE_IS_DECLARED
93
 
 
94
 
namespace QMake
95
 
{
96
 
    class Lexer;
97
 
 
98
 
/**
99
 
The yylval type.
100
 
*/
101
 
struct Result {
102
 
    Result(): node(0) {}
103
 
 
104
 
    /**Type of semantic value for simple grammar rules.*/
105
 
    QString value;
106
 
    /**Type of semantic value for grammar rules which are parts of AST.*/
107
 
    AST *node;
108
 
    /**Type of semantic value for "multiline_values" grammar rule.
109
 
    Each line of multiline value is stored as a string in the list.
110
 
 
111
 
    For example we have in .pro file:
112
 
    @code
113
 
    SOURCE = foo1.cpp \
114
 
        foo2.cpp \
115
 
        foo3.cpp foo4.cpp
116
 
    @endcode
117
 
    The string list will be populated with three strings:
118
 
    <pre>
119
 
    foo1.cpp
120
 
    foo2.cpp
121
 
    foo3.cpp foo4.cpp
122
 
    </pre>
123
 
    */
124
 
    QStringList values;
125
 
    QString indent;
126
 
};
127
 
 
128
 
#define YYSTYPE Result
129
 
typedef Result YYSTYPE;
130
 
}
131
 
 
132
 
extern int QMakelex( QMake::Result* yylval, QMake::Lexer* lexer );
133
 
 
134
 
/**
135
 
The stack to store ProjectAST pointers when a new child
136
 
ProjectAST is created and filled with statements.
137
 
 
138
 
Parser creates root ProjectAST for a .pro file, pushes it onto the stack and starts
139
 
adding statements. Each statement is added as a child StatementAST to the ProjectAST
140
 
currently on the top in the stack.
141
 
 
142
 
When a scope or function scope statement is parsed, the child ProjectAST is created
143
 
and pushed onto the stack. Therefore all statements which belong to the scope
144
 
or function scope are added as childs to their direct parent (scope or function scope).
145
 
*/
146
 
//QValueStack<ProjectAST*> projects;
147
 
 
148
 
/**
149
 
The current depth of AST node is stored here.
150
 
AST depth is important to know because automatic indentation can
151
 
be easily implemented (the parser itself looses all information
152
 
about indentation).
153
 
*/
154
 
// int depth = 0;
155
 
 
156
 
/*
157
 
To debug this parser, put the line below into the next bison file section.
158
 
Don't forget to uncomment "yydebug = 1" line in qmakedriver.cpp.
159
 
%debug
160
 
*/
161
 
 
162
 
 
163
 
/* Line 35 of lalr1.cc.  */
164
 
#line 165 "qmake_yacc.hpp"
165
 
 
166
 
#include "location.hh"
167
 
 
168
 
/* Enabling traces.  */
169
 
#ifndef YYDEBUG
170
 
# define YYDEBUG 1
171
 
#endif
172
 
 
173
 
/* Enabling verbose error messages.  */
174
 
#ifdef YYERROR_VERBOSE
175
 
# undef YYERROR_VERBOSE
176
 
# define YYERROR_VERBOSE 1
177
 
#else
178
 
# define YYERROR_VERBOSE 0
179
 
#endif
180
 
 
181
 
/* Enabling the token table.  */
182
 
#ifndef YYTOKEN_TABLE
183
 
# define YYTOKEN_TABLE 1
184
 
#endif
185
 
 
186
 
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
187
 
   If N is 0, then set CURRENT to the empty location which ends
188
 
   the previous symbol: RHS[0] (always defined).  */
189
 
 
190
 
#ifndef YYLLOC_DEFAULT
191
 
# define YYLLOC_DEFAULT(Current, Rhs, N)                \
192
 
do {                                                    \
193
 
  if (N)                                                \
194
 
    {                                                   \
195
 
      (Current).begin = (Rhs)[1].begin;                 \
196
 
      (Current).end   = (Rhs)[N].end;                   \
197
 
    }                                                   \
198
 
  else                                                  \
199
 
    {                                                   \
200
 
      (Current).begin = (Current).end = (Rhs)[0].end;   \
201
 
    }                                                   \
202
 
} while (false)
203
 
#endif
204
 
 
205
 
namespace QMake
206
 
{
207
 
 
208
 
  /// A Bison parser.
209
 
  class Parser
210
 
  {
211
 
  public:
212
 
    /// Symbol semantic values.
213
 
#ifndef YYSTYPE
214
 
    typedef int semantic_type;
215
 
#else
216
 
    typedef YYSTYPE semantic_type;
217
 
#endif
218
 
    /// Symbol locations.
219
 
    typedef location location_type;
220
 
    /// Tokens.
221
 
    struct token
222
 
    {
223
 
      /* Tokens.  */
224
 
   enum yytokentype {
225
 
     ID_SIMPLE = 258,
226
 
     EQ = 259,
227
 
     PLUSEQ = 260,
228
 
     MINUSEQ = 261,
229
 
     STAREQ = 262,
230
 
     TILDEEQ = 263,
231
 
     LBRACE = 264,
232
 
     RBRACE = 265,
233
 
     COLON = 266,
234
 
     NEWLINE = 267,
235
 
     COMMENT = 268,
236
 
     CONT = 269,
237
 
     COMMENT_CONT = 270,
238
 
     RCURLY = 271,
239
 
     LCURLY = 272,
240
 
     ID_ARGS = 273,
241
 
     QUOTED_VARIABLE_VALUE = 274,
242
 
     VARIABLE_VALUE = 275,
243
 
     LIST_WS = 276,
244
 
     ENDOFFILE = 277
245
 
   };
246
 
 
247
 
    };
248
 
    /// Token type.
249
 
    typedef token::yytokentype token_type;
250
 
 
251
 
    /// Build a parser object.
252
 
    Parser (QMake::Lexer* lexer_yyarg, QValueStack<ProjectAST*>& projects_yyarg, int depth_yyarg);
253
 
    virtual ~Parser ();
254
 
 
255
 
    /// Parse.
256
 
    /// \returns  0 iff parsing succeeded.
257
 
    virtual int parse ();
258
 
 
259
 
    /// The current debugging stream.
260
 
    std::ostream& debug_stream () const;
261
 
    /// Set the current debugging stream.
262
 
    void set_debug_stream (std::ostream &);
263
 
 
264
 
    /// Type for debugging levels.
265
 
    typedef int debug_level_type;
266
 
    /// The current debugging level.
267
 
    debug_level_type debug_level () const;
268
 
    /// Set the current debugging level.
269
 
    void set_debug_level (debug_level_type l);
270
 
 
271
 
  private:
272
 
    /// Report a syntax error.
273
 
    /// \param loc    where the syntax error is found.
274
 
    /// \param msg    a description of the syntax error.
275
 
    virtual void error (const location_type& loc, const std::string& msg);
276
 
 
277
 
    /// Generate an error message.
278
 
    /// \param state   the state where the error occurred.
279
 
    /// \param tok     the look-ahead token.
280
 
    virtual std::string yysyntax_error_ (int yystate);
281
 
 
282
 
#if YYDEBUG
283
 
    /// \brief Report a symbol value on the debug stream.
284
 
    /// \param yytype       The token type.
285
 
    /// \param yyvaluep     Its semantic value.
286
 
    /// \param yylocationp  Its location.
287
 
    virtual void yy_symbol_value_print_ (int yytype,
288
 
                                         const semantic_type* yyvaluep,
289
 
                                         const location_type* yylocationp);
290
 
    /// \brief Report a symbol on the debug stream.
291
 
    /// \param yytype       The token type.
292
 
    /// \param yyvaluep     Its semantic value.
293
 
    /// \param yylocationp  Its location.
294
 
    virtual void yy_symbol_print_ (int yytype,
295
 
                                   const semantic_type* yyvaluep,
296
 
                                   const location_type* yylocationp);
297
 
#endif /* ! YYDEBUG */
298
 
 
299
 
 
300
 
    /// State numbers.
301
 
    typedef int state_type;
302
 
    /// State stack type.
303
 
    typedef stack<state_type>    state_stack_type;
304
 
    /// Semantic value stack type.
305
 
    typedef stack<semantic_type> semantic_stack_type;
306
 
    /// location stack type.
307
 
    typedef stack<location_type> location_stack_type;
308
 
 
309
 
    /// The state stack.
310
 
    state_stack_type yystate_stack_;
311
 
    /// The semantic value stack.
312
 
    semantic_stack_type yysemantic_stack_;
313
 
    /// The location stack.
314
 
    location_stack_type yylocation_stack_;
315
 
 
316
 
    /// Internal symbol numbers.
317
 
    typedef unsigned char token_number_type;
318
 
    /* Tables.  */
319
 
    /// For a state, the index in \a yytable_ of its portion.
320
 
    static const signed char yypact_[];
321
 
    static const signed char yypact_ninf_;
322
 
 
323
 
    /// For a state, default rule to reduce.
324
 
    /// Unless\a  yytable_ specifies something else to do.
325
 
    /// Zero means the default is an error.
326
 
    static const unsigned char yydefact_[];
327
 
 
328
 
    static const signed char yypgoto_[];
329
 
    static const signed char yydefgoto_[];
330
 
 
331
 
    /// What to do in a state.
332
 
    /// \a yytable_[yypact_[s]]: what to do in state \a s.
333
 
    /// - if positive, shift that token.
334
 
    /// - if negative, reduce the rule which number is the opposite.
335
 
    /// - if zero, do what YYDEFACT says.
336
 
    static const signed char yytable_[];
337
 
    static const signed char yytable_ninf_;
338
 
 
339
 
    static const unsigned char yycheck_[];
340
 
 
341
 
    /// For a state, its accessing symbol.
342
 
    static const unsigned char yystos_[];
343
 
 
344
 
    /// For a rule, its LHS.
345
 
    static const unsigned char yyr1_[];
346
 
    /// For a rule, its RHS length.
347
 
    static const unsigned char yyr2_[];
348
 
 
349
 
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
350
 
    /// For a symbol, its name in clear.
351
 
    static const char* const yytname_[];
352
 
#endif
353
 
 
354
 
#if YYERROR_VERBOSE
355
 
    /// Convert the symbol name \a n to a form suitable for a diagnostic.
356
 
    virtual std::string yytnamerr_ (const char *n);
357
 
#endif
358
 
 
359
 
#if YYDEBUG
360
 
    /// A type to store symbol numbers and -1.
361
 
    typedef signed char rhs_number_type;
362
 
    /// A `-1'-separated list of the rules' RHS.
363
 
    static const rhs_number_type yyrhs_[];
364
 
    /// For each rule, the index of the first RHS symbol in \a yyrhs_.
365
 
    static const unsigned char yyprhs_[];
366
 
    /// For each rule, its source line number.
367
 
    static const unsigned short int yyrline_[];
368
 
    /// For each scanner token number, its symbol number.
369
 
    static const unsigned short int yytoken_number_[];
370
 
    /// Report on the debug stream that the rule \a r is going to be reduced.
371
 
    virtual void yy_reduce_print_ (int r);
372
 
    /// Print the state stack on the debug stream.
373
 
    virtual void yystack_print_ ();
374
 
#endif
375
 
 
376
 
    /// Convert a scanner token number \a t to a symbol number.
377
 
    token_number_type yytranslate_ (int t);
378
 
 
379
 
    /// \brief Reclaim the memory associated to a symbol.
380
 
    /// \param yymsg        Why this token is reclaimed.
381
 
    /// \param yytype       The symbol type.
382
 
    /// \param yyvaluep     Its semantic value.
383
 
    /// \param yylocationp  Its location.
384
 
    inline void yydestruct_ (const char* yymsg,
385
 
                             int yytype,
386
 
                             semantic_type* yyvaluep,
387
 
                             location_type* yylocationp);
388
 
 
389
 
    /// Pop \a n symbols the three stacks.
390
 
    inline void yypop_ (unsigned int n = 1);
391
 
 
392
 
    /* Constants.  */
393
 
    static const int yyeof_;
394
 
    /* LAST_ -- Last index in TABLE_.  */
395
 
    static const int yylast_;
396
 
    static const int yynnts_;
397
 
    static const int yyempty_;
398
 
    static const int yyfinal_;
399
 
    static const int yyterror_;
400
 
    static const int yyerrcode_;
401
 
    static const int yyntokens_;
402
 
    static const unsigned int yyuser_token_number_max_;
403
 
    static const token_number_type yyundef_token_;
404
 
 
405
 
    /* Debugging.  */
406
 
    int yydebug_;
407
 
    std::ostream* yycdebug_;
408
 
 
409
 
 
410
 
    /* User arguments.  */
411
 
    QMake::Lexer* lexer;
412
 
    QValueStack<ProjectAST*>& projects;
413
 
    int depth;
414
 
  };
415
 
}
416
 
 
417
 
 
418
 
#endif /* ! defined PARSER_HEADER_H */