Pull out the number parsing logic
authorqining <qining@google.com>
Thu, 1 Sep 2016 18:27:04 +0000 (14:27 -0400)
committerqining <qining@google.com>
Thu, 8 Sep 2016 22:42:54 +0000 (18:42 -0400)
commit1773b95737a78bbe12f4011511d90da9d605808f
treebc8f2743fa18b24cc55f1e03ba8134b3746ffef3
parenta35919c008872de5fac12022ee475b1a04c595f8
Pull out the number parsing logic

Pull out the number parsing logic from
AssemblyContext::binaryEncodeNumericLiteral() to utilities.

The new utility function: `ParseAndEncodeNumber()` now accepts:
  * number text to parse
  * number type
  * a emit function, which is a function which will be called with each
    parsed uint32 word.
  * a pointer to std::string to be overwritten with error messages.
    (pass nullptr if expect no error message)
and returns:
  * an enum result type to indicate the status

Type/Structs moved to utility:
  * template<typename T> class ClampToZeroIfUnsignedType

New type:
* enum EncodeNumberStatus: success or error code
* NumberType: hold the number type information for the number to be parsed.
 * several helper functions are also added for NumberType.

Functions moved to utility:
  * Helpers:
    * template<typename T> checkRangeAndIfHexThenSignExtend() -> CheckRangeAndIfHex....()
  * Interfaces:
    * template<typename T> parseNumber() -> ParseNumber()
    * binaryEncodeIntegerLiteral() -> ParseAndEncodeIntegerNumber()
    * binaryEncodeFloatingPointLiteral() -> ParseAndEncodeFloatingPointNumber()
    * binaryEncodeNumericLiteral() -> ParseAndEncodeNumber()

Tests added/moved to test/ParseNumber.cpp, including tests for:
* ParseNumber(): This is moved from TextToBinary.cpp to ParseNumber.cpp
* ParseAndEncodeIntegerNumber(): New added
* ParseAndEncodeFloatingPointNumber(): New added
* ParseAndEncodeNumber(): New added

Note that the error messages are kept almost the same as before, but
they may be inappropriate for an utility function. Those will be fixed
in another CL.
source/CMakeLists.txt
source/text.cpp
source/text_handler.cpp
source/text_handler.h
source/util/hex_float.h
source/util/parse_number.cpp [new file with mode: 0644]
source/util/parse_number.h [new file with mode: 0644]
test/CMakeLists.txt
test/ParseNumber.cpp [new file with mode: 0644]
test/TextToBinary.cpp