2 * File: ElftosbLexer.cpp
4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
7 #include "ElftosbLexer.h"
11 using namespace elftosb;
13 ElftosbLexer::ElftosbLexer(istream & inputStream)
14 : yyFlexLexer(&inputStream), m_line(1), m_blob(0), m_blobFirstLine(0)
18 void ElftosbLexer::getSymbolValue(YYSTYPE * value)
24 *value = m_symbolValue;
27 void ElftosbLexer::addSourceName(std::string * ident)
29 m_sources.push_back(*ident);
32 bool ElftosbLexer::isSourceName(std::string * ident)
34 string_vector_t::iterator it = find(m_sources.begin(), m_sources.end(), *ident);
35 return it != m_sources.end();
38 void ElftosbLexer::LexerError(const char * msg)
40 throw elftosb::lexical_error(msg);
43 //! Reads the \a in string and writes to the \a out string. These strings can be the same
44 //! string since the read head is always in front of the write head.
46 //! \param[in] in Input string containing C-style escape sequences.
47 //! \param[out] out Output string. All escape sequences in the input string have been converted
48 //! to the actual characters. May point to the same string as \a in.
49 //! \return The length of the resulting \a out string. This length is necessary because
50 //! the string may have contained escape sequences that inserted null characters.
51 int ElftosbLexer::processStringEscapes(const char * in, char * out)
60 // start of an escape sequence
64 case 0: // end of the string, bail
68 // start of a hex char escape sequence
70 // read high and low nibbles, checking for end of string
76 if (isHexDigit(hi) && isHexDigit(lo))
78 if (hi >= '0' && hi <= '9')
80 else if (hi >= 'A' && hi <= 'F')
81 c = (hi - 'A' + 10) << 4;
82 else if (hi >= 'a' && hi <= 'f')
83 c = (hi - 'a' + 10) << 4;
85 if (lo >= '0' && lo <= '9')
87 else if (lo >= 'A' && lo <= 'F')
89 else if (lo >= 'a' && lo <= 'f')
97 // not hex digits, the \x must have wanted an 'x' char
138 // copy all other chars directly
144 // place terminating null char on output