1//===- ScriptScanner.h ----------------------------------------------------===//
2//
3//                     The MCLinker Project
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef MCLD_SCRIPT_SCRIPTSCANNER_H_
10#define MCLD_SCRIPT_SCRIPTSCANNER_H_
11
12#ifndef __FLEX_LEXER_H
13#ifdef ANDROID
14#include "mcld/Script/FlexLexer.h"
15#else
16#include <FlexLexer.h>
17#endif
18#endif
19
20#ifndef YY_DECL
21#define YY_DECL                                            \
22  mcld::ScriptParser::token_type mcld::ScriptScanner::lex( \
23      mcld::ScriptParser::semantic_type* yylval,           \
24      mcld::ScriptParser::location_type* yylloc,           \
25      const mcld::ScriptFile& pScriptFile)
26#endif
27
28#include "mcld/Script/ScriptFile.h"
29#include "ScriptParser.h"
30#include <stack>
31
32namespace mcld {
33
34/** \class ScriptScanner
35 *
36 */
37class ScriptScanner : public yyFlexLexer {
38 public:
39  explicit ScriptScanner(std::istream* yyin = NULL, std::ostream* yyout = NULL);
40
41  virtual ~ScriptScanner();
42
43  virtual ScriptParser::token_type lex(ScriptParser::semantic_type* yylval,
44                                       ScriptParser::location_type* yylloc,
45                                       const ScriptFile& pScriptFile);
46
47  void setLexState(ScriptFile::Kind pKind);
48
49  void popLexState();
50
51 private:
52  void enterComments(ScriptParser::location_type& pLocation);
53
54 private:
55  ScriptFile::Kind m_Kind;
56  std::stack<ScriptFile::Kind> m_StateStack;
57};
58
59}  // namespace mcld
60
61#endif  // MCLD_SCRIPT_SCRIPTSCANNER_H_
62