Commit fc0543f4 by alokp@chromium.org

This patch reverts r1203, but in slightly different way. It seems there is a…

This patch reverts r1203, but in slightly different way. It seems there is a problem with the config of memory bots. The usage of std::locale in ANGLE is fine. Review URL: https://codereview.appspot.com/6392052 git-svn-id: https://angleproject.googlecode.com/svn/trunk@1205 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 39a94266
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
'compiler/preprocessor/new/Macro.h', 'compiler/preprocessor/new/Macro.h',
'compiler/preprocessor/new/MacroExpander.cpp', 'compiler/preprocessor/new/MacroExpander.cpp',
'compiler/preprocessor/new/MacroExpander.h', 'compiler/preprocessor/new/MacroExpander.h',
'compiler/preprocessor/new/numeric_lex.h',
'compiler/preprocessor/new/pp_utils.h', 'compiler/preprocessor/new/pp_utils.h',
'compiler/preprocessor/new/Preprocessor.cpp', 'compiler/preprocessor/new/Preprocessor.cpp',
'compiler/preprocessor/new/Preprocessor.h', 'compiler/preprocessor/new/Preprocessor.h',
......
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 1200 #define BUILD_REVISION 1205
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -7,31 +7,8 @@ ...@@ -7,31 +7,8 @@
#include "Token.h" #include "Token.h"
#include <cassert> #include <cassert>
#include <cerrno>
#include <cfloat>
#include <cstdlib>
#include <sstream>
template<typename IntType> #include "numeric_lex.h"
static bool atoi_t(const std::string& str, IntType* value)
{
std::ios::fmtflags base = std::ios::dec;
if ((str.size() >= 2) &&
(str[0] == '0') &&
((str[1] == 'x') || (str[1] == 'X')))
{
base = std::ios::hex;
}
else if ((str.size() >= 1) && (str[0] == '0'))
{
base = std::ios::oct;
}
std::istringstream stream(str);
stream.setf(base, std::ios::basefield);
stream >> (*value);
return !stream.fail();
}
namespace pp namespace pp
{ {
...@@ -79,31 +56,19 @@ void Token::setExpansionDisabled(bool disable) ...@@ -79,31 +56,19 @@ void Token::setExpansionDisabled(bool disable)
bool Token::iValue(int* value) const bool Token::iValue(int* value) const
{ {
assert(type == CONST_INT); assert(type == CONST_INT);
return atoi_t(text, value); return numeric_lex_int(text, value);
} }
bool Token::uValue(unsigned int* value) const bool Token::uValue(unsigned int* value) const
{ {
assert(type == CONST_INT); assert(type == CONST_INT);
return atoi_t(text, value); return numeric_lex_int(text, value);
} }
bool Token::fValue(float* value) const bool Token::fValue(float* value) const
{ {
assert(type == CONST_FLOAT); assert(type == CONST_FLOAT);
return numeric_lex_float(text, value);
errno = 0;
double dValue = strtod(text.c_str(), NULL);
// Note that we do not need to check for negative numbers because the
// minus sign is never part of the token.
if ((errno == ERANGE) || (dValue > FLT_MAX))
{
errno = 0;
*value = FLT_MAX;
return false;
}
*value = static_cast<float>(dValue);
return true;
} }
std::ostream& operator<<(std::ostream& out, const Token& token) std::ostream& operator<<(std::ostream& out, const Token& token)
......
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// numeric_lex.h: Functions to extract numeric values from string.
#ifndef COMPILER_PREPROCESSOR_NUMERIC_LEX_H_
#define COMPILER_PREPROCESSOR_NUMERIC_LEX_H_
#include <sstream>
namespace pp {
inline std::ios::fmtflags numeric_base_int(const std::string& str)
{
if ((str.size() >= 2) &&
(str[0] == '0') &&
(str[1] == 'x' || str[1] == 'X'))
{
return std::ios::hex;
}
else if ((str.size() >= 1) && (str[0] == '0'))
{
return std::ios::oct;
}
return std::ios::dec;
}
// The following functions parse the given string to extract a numerical
// value of the given type. These functions assume that the string is
// of the correct form. They can only fail if the parsed value is too big,
// in which case false is returned.
template<typename IntType>
bool numeric_lex_int(const std::string& str, IntType* value)
{
std::istringstream stream(str);
// This should not be necessary, but MSVS has a buggy implementation.
// It returns incorrect results if the base is not specified.
stream.setf(numeric_base_int(str), std::ios::basefield);
stream >> (*value);
return !stream.fail();
}
template<typename FloatType>
bool numeric_lex_float(const std::string& str, FloatType* value)
{
std::istringstream stream(str);
// Force "C" locale so that decimal character is always '.', and
// not dependent on the current locale.
stream.imbue(std::locale::classic());
stream >> (*value);
return !stream.fail();
}
} // namespace pp.
#endif // COMPILER_PREPROCESSOR_NUMERIC_LEX_H_
...@@ -369,6 +369,10 @@ ...@@ -369,6 +369,10 @@
> >
</File> </File>
<File <File
RelativePath=".\numeric_lex.h"
>
</File>
<File
RelativePath=".\pp_utils.h" RelativePath=".\pp_utils.h"
> >
</File> </File>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment