retdec
intel_hex_tokenizer.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_FILEFORMAT_FILE_FORMAT_INTEL_HEX_INTEL_HEX_PARSER_INTEL_HEX_TOKENIZER_H
8 #define RETDEC_FILEFORMAT_FILE_FORMAT_INTEL_HEX_INTEL_HEX_PARSER_INTEL_HEX_TOKENIZER_H
9 
10 #include <fstream>
11 #include <string>
12 #include <vector>
13 
14 namespace retdec {
15 namespace fileformat {
16 
21 {
22  public:
24  struct REC_TYPE
25  {
26  enum : unsigned
27  {
28  RT_DATA = 0,
34  RT_ERROR
35  };
36  };
37 
38  unsigned byteCount = 0;
39  unsigned recordType = 0;
40  std::string address;
41  std::string data;
42  std::string checksum;
43  std::string errorDesc;
44  bool checksumValid = false;
45 
48  int addStringByTwo(const std::string &str);
49  void controlChecksum();
51 };
52 
57 {
58  private:
59  std::ifstream fstr;
60  std::istream *source = nullptr;
61 
64  std::string readN(unsigned n);
65  IntelHexToken makeErrorToken(const std::string &errorMessage);
67  public:
72 
75  bool openFile(const std::string &pathToFile);
76  bool setInputStream(std::istream &inputStream);
78 };
79 
80 } // namespace fileformat
81 } // namespace retdec
82 
83 #endif
The Token class - output of tokenizer.
Definition: intel_hex_tokenizer.h:21
std::string data
Data.
Definition: intel_hex_tokenizer.h:41
int addStringByTwo(const std::string &str)
Definition: intel_hex_tokenizer.cpp:25
std::string address
Address of data.
Definition: intel_hex_tokenizer.h:40
std::string checksum
Checksum in ASCII.
Definition: intel_hex_tokenizer.h:42
unsigned recordType
Type of record.
Definition: intel_hex_tokenizer.h:39
void controlChecksum()
Definition: intel_hex_tokenizer.cpp:45
unsigned byteCount
Size of data in bytes.
Definition: intel_hex_tokenizer.h:38
std::string errorDesc
Error description in case of REC_TYPE::RT_ERROR.
Definition: intel_hex_tokenizer.h:43
bool checksumValid
True if checksum is valid. False by default.
Definition: intel_hex_tokenizer.h:44
The Tokenizer class - Intel HEX lexical analysis.
Definition: intel_hex_tokenizer.h:57
IntelHexToken getToken()
Definition: intel_hex_tokenizer.cpp:92
std::ifstream fstr
Definition: intel_hex_tokenizer.h:59
IntelHexToken makeErrorToken(const std::string &errorMessage)
Definition: intel_hex_tokenizer.cpp:80
bool setInputStream(std::istream &inputStream)
Definition: intel_hex_tokenizer.cpp:179
std::istream * source
Definition: intel_hex_tokenizer.h:60
bool openFile(const std::string &pathToFile)
Definition: intel_hex_tokenizer.cpp:168
std::string readN(unsigned n)
Definition: intel_hex_tokenizer.cpp:63
Definition: archive_wrapper.h:19
Possible Token types.
Definition: intel_hex_tokenizer.h:25
@ RT_EOFILE
Definition: intel_hex_tokenizer.h:29
@ RT_DATA
Definition: intel_hex_tokenizer.h:28
@ RT_EXT_LINADDR
Definition: intel_hex_tokenizer.h:32
@ RT_ERROR
Definition: intel_hex_tokenizer.h:34
@ RT_EXT_SEGADDR
Definition: intel_hex_tokenizer.h:30
@ RT_START_SEGADDR
Definition: intel_hex_tokenizer.h:31
@ RT_START_LINADDR
Definition: intel_hex_tokenizer.h:33