eRPC Generator (erpcgen)  Rev. 1.9.0
NXP Semiconductors
ErpcLexer.h
1 /*
2  * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  */
9 
10 // This header just wraps the standard flex C++ header to make it easier to include
11 // without having to worry about redefinitions of the class name every time.
12 
13 #ifndef _EMBEDDED_RPC__ERPCLEXER_H_
14 #define _EMBEDDED_RPC__ERPCLEXER_H_
15 
16 #undef yyFlexLexer
17 #include "AstNode.h"
18 #include "ParseErrors.h"
19 
20 #include <FlexLexer.h>
21 #include <fstream>
22 #include <string>
23 #include <vector>
24 
26 // Definitions
28 
29 #ifndef YY_BUF_SIZE
30 #define YY_BUF_SIZE 16384
31 #endif
32 
34 // Classes
36 
37 namespace erpcgen {
38 
39 class ErpcLexer;
40 }
41 #include "erpcgen_parser.tab.hpp"
42 
43 using namespace std;
44 
45 namespace erpcgen {
46 
51 {
52 public:
63  CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
64  : m_savedFile(savedFile)
65  , m_previous(NULL)
66  , m_line(1)
67  , m_column(0)
68  , m_fileName(fileName)
69  , m_currentFolderPath(currentFolderPath)
70  {
71  }
72 
79  {
80  m_savedFile->close();
81  m_savedFile.safe_delete();
82  }
83 
84  smart_ptr<std::ifstream> m_savedFile;
86  int m_line;
87  int m_column;
88  std::string m_fileName;
89  std::string m_currentFolderPath;
90 };
91 
100 class ErpcLexer : public yyFlexLexer
101 {
102 public:
111  ErpcLexer(const char *inputFile);
112 
116  ~ErpcLexer();
117 
125  virtual Token *getNextToken();
126 
132  inline token_loc_t &getLocation() { return m_location; }
133 
141  void pushFile(const std::string &fileName);
142 
146  void popFile();
147 
153  inline std::string &getFileName() { return m_currentFileInfo->m_fileName; }
154 
160  uint16_t getIdlCrc16() { return m_idlCrc16; }
161 
162 protected:
165  uint32_t m_indents;
167  uint16_t m_idlCrc16;
176  virtual void LexerError(const char *msg);
177 
190  int processStringEscapes(const char *in, char *out);
191 
197  virtual int yylex();
198 
216  CurrentFileInfo *openFile(const std::string &fileName);
217 };
218 
219 } // namespace erpcgen
220 
221 #endif // _EMBEDDED_RPC__ERPCLEXER_H_
CurrentFileInfo * m_currentFileInfo
Definition: ErpcLexer.h:166
Lexical scanner class for erpcgen interface files.
Definition: ErpcLexer.h:100
CurrentFileInfo * m_previous
Definition: ErpcLexer.h:85
std::string & getFileName()
return current file name
Definition: ErpcLexer.h:153
std::string m_fileName
Definition: ErpcLexer.h:88
STL namespace.
std::string m_currentFolderPath
Definition: ErpcLexer.h:89
~CurrentFileInfo()
Destructor.
Definition: ErpcLexer.h:78
Abstract base class for values of arbitrary types.
Definition: Value.h:27
token_loc_t m_location
Definition: ErpcLexer.h:164
token_loc_t & getLocation()
returns the current token&#39;s location in loc.
Definition: ErpcLexer.h:132
uint16_t getIdlCrc16()
This function returns crc16 of all used IDL files.
Definition: ErpcLexer.h:160
uint32_t m_indents
Definition: ErpcLexer.h:165
CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
Constructor.
Definition: ErpcLexer.h:63
Value * m_value
Definition: ErpcLexer.h:163
Encapsulates all information about a token.
Definition: Token.h:60
int m_column
Definition: ErpcLexer.h:87
int m_line
Definition: ErpcLexer.h:86
Token location in the source file.
Definition: Token.h:25
uint16_t m_idlCrc16
Definition: ErpcLexer.h:167
Definition: AstNode.h:26
smart_ptr< std::ifstream > m_savedFile
Definition: ErpcLexer.h:84
This class contains necessary information about analyzed file.
Definition: ErpcLexer.h:50