eRPC Generator (erpcgen)  Rev. 1.7.2
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 #include <FlexLexer.h>
20 #include <fstream>
21 #include <string>
22 #include <vector>
23 
25 // Definitions
27 
28 #ifndef YY_BUF_SIZE
29 #define YY_BUF_SIZE 16384
30 #endif
31 
33 // Classes
35 
36 namespace erpcgen {
37 
38 class ErpcLexer;
39 }
40 #include "erpcgen_parser.tab.hpp"
41 
42 using namespace std;
43 
44 namespace erpcgen {
45 
50 {
51 public:
62  CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
63  : m_savedFile(savedFile)
64  , m_previous(NULL)
65  , m_line(1)
66  , m_column(0)
67  , m_fileName(fileName)
68  , m_currentFolderPath(currentFolderPath)
69  {
70  }
71 
78  {
79  m_savedFile->close();
80  m_savedFile.safe_delete();
81  }
82 
83  smart_ptr<std::ifstream> m_savedFile;
85  int m_line;
86  int m_column;
87  std::string m_fileName;
88  std::string m_currentFolderPath;
89 };
90 
99 class ErpcLexer : public yyFlexLexer
100 {
101 public:
110  ErpcLexer(const char *inputFile);
111 
115  ~ErpcLexer();
116 
124  virtual Token *getNextToken();
125 
131  inline token_loc_t &getLocation() { return m_location; }
132 
140  void pushFile(const std::string &fileName);
141 
145  void popFile();
146 
152  inline std::string &getFileName() { return m_currentFileInfo->m_fileName; }
153 
159  uint16_t getIdlCrc16() { return m_idlCrc16; }
160 
161 protected:
165  uint32_t m_indents;
166  uint16_t m_idlCrc16;
175  virtual void LexerError(const char *msg);
176 
189  int processStringEscapes(const char *in, char *out);
190 
196  virtual int yylex();
197 
215  CurrentFileInfo *openFile(const std::string &fileName);
216 };
217 
218 } // namespace erpcgen
219 
220 #endif // _EMBEDDED_RPC__ERPCLEXER_H_
CurrentFileInfo * m_currentFileInfo
Definition: ErpcLexer.h:164
Lexical scanner class for erpcgen interface files.
Definition: ErpcLexer.h:99
CurrentFileInfo * m_previous
Definition: ErpcLexer.h:84
std::string & getFileName()
return current file name
Definition: ErpcLexer.h:152
std::string m_fileName
Definition: ErpcLexer.h:87
STL namespace.
std::string m_currentFolderPath
Definition: ErpcLexer.h:88
~CurrentFileInfo()
Destructor.
Definition: ErpcLexer.h:77
Abstract base class for values of arbitrary types.
Definition: Value.h:21
token_loc_t m_location
Definition: ErpcLexer.h:163
token_loc_t & getLocation()
returns the current token&#39;s location in loc.
Definition: ErpcLexer.h:131
uint16_t getIdlCrc16()
This function returns crc16 of all used IDL files.
Definition: ErpcLexer.h:159
uint32_t m_indents
Definition: ErpcLexer.h:165
CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
Constructor.
Definition: ErpcLexer.h:62
Value * m_value
Definition: ErpcLexer.h:162
Encapsulates all information about a token.
Definition: Token.h:60
int m_column
Definition: ErpcLexer.h:86
int m_line
Definition: ErpcLexer.h:85
Token location in the source file.
Definition: Token.h:25
uint16_t m_idlCrc16
Definition: ErpcLexer.h:166
Definition: AstNode.h:25
smart_ptr< std::ifstream > m_savedFile
Definition: ErpcLexer.h:83
This class contains necessary information about analyzed file.
Definition: ErpcLexer.h:49