eRPC Generator (erpcgen)  Rev. 1.7.0
NXP Semiconductors
ErpcLexer.h
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
4  * Copyright 2016 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 // This header just wraps the standard flex C++ header to make it easier to include
37 // without having to worry about redefinitions of the class name every time.
38 
39 #ifndef _EMBEDDED_RPC__ERPCLEXER_H_
40 #define _EMBEDDED_RPC__ERPCLEXER_H_
41 
42 #undef yyFlexLexer
43 #include "AstNode.h"
44 #include "ParseErrors.h"
45 #include <FlexLexer.h>
46 #include <fstream>
47 #include <string>
48 #include <vector>
49 
51 // Definitions
53 
54 #ifndef YY_BUF_SIZE
55 #define YY_BUF_SIZE 16384
56 #endif
57 
59 // Classes
61 
62 namespace erpcgen {
63 
64 class ErpcLexer;
65 }
66 #include "erpcgen_parser.tab.hpp"
67 
68 using namespace std;
69 
70 namespace erpcgen {
71 
76 {
77 public:
88  CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
89  : m_savedFile(savedFile)
90  , m_previous(NULL)
91  , m_line(1)
92  , m_column(0)
93  , m_fileName(fileName)
94  , m_currentFolderPath(currentFolderPath)
95  {
96  }
97 
104  {
105  m_savedFile->close();
106  m_savedFile.safe_delete();
107  }
108 
109  smart_ptr<std::ifstream> m_savedFile;
111  int m_line;
112  int m_column;
113  std::string m_fileName;
114  std::string m_currentFolderPath;
115 };
116 
125 class ErpcLexer : public yyFlexLexer
126 {
127 public:
136  ErpcLexer(const char *inputFile);
137 
141  ~ErpcLexer();
142 
150  virtual Token *getNextToken();
151 
157  inline token_loc_t &getLocation() { return m_location; }
158 
166  void pushFile(const std::string &fileName);
167 
171  void popFile();
172 
178  inline std::string &getFileName() { return m_currentFileInfo->m_fileName; }
179 
185  uint16_t getIdlCrc16() { return m_idlCrc16; }
186 
187 protected:
191  uint32_t m_indents;
192  uint16_t m_idlCrc16;
201  virtual void LexerError(const char *msg);
202 
215  int processStringEscapes(const char *in, char *out);
216 
222  virtual int yylex();
223 
241  CurrentFileInfo *openFile(const std::string &fileName);
242 };
243 
244 } // namespace erpcgen
245 
246 #endif // _EMBEDDED_RPC__ERPCLEXER_H_
CurrentFileInfo * m_currentFileInfo
Definition: ErpcLexer.h:190
Lexical scanner class for erpcgen interface files.
Definition: ErpcLexer.h:125
CurrentFileInfo * m_previous
Definition: ErpcLexer.h:110
std::string & getFileName()
return current file name
Definition: ErpcLexer.h:178
std::string m_fileName
Definition: ErpcLexer.h:113
STL namespace.
std::string m_currentFolderPath
Definition: ErpcLexer.h:114
~CurrentFileInfo()
Destructor.
Definition: ErpcLexer.h:103
Abstract base class for values of arbitrary types.
Definition: Value.h:47
token_loc_t m_location
Definition: ErpcLexer.h:189
token_loc_t & getLocation()
returns the current token&#39;s location in loc.
Definition: ErpcLexer.h:157
uint16_t getIdlCrc16()
This function returns crc16 of all used IDL files.
Definition: ErpcLexer.h:185
uint32_t m_indents
Definition: ErpcLexer.h:191
CurrentFileInfo(std::ifstream *savedFile, std::string fileName, std::string currentFolderPath)
Constructor.
Definition: ErpcLexer.h:88
Value * m_value
Definition: ErpcLexer.h:188
Encapsulates all information about a token.
Definition: Token.h:86
int m_column
Definition: ErpcLexer.h:112
int m_line
Definition: ErpcLexer.h:111
Token location in the source file.
Definition: Token.h:51
uint16_t m_idlCrc16
Definition: ErpcLexer.h:192
Definition: AstNode.h:51
smart_ptr< std::ifstream > m_savedFile
Definition: ErpcLexer.h:109
This class contains necessary information about analyzed file.
Definition: ErpcLexer.h:75