[PATCH] D33135: [ASTMatchers] Add support for floatLiterals

Peter Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 7 14:37:37 PDT 2017


Lekensteyn updated this revision to Diff 101816.
Lekensteyn marked 8 inline comments as done.
Lekensteyn added a comment.

diff from previous version:

  diff --git a/include/clang/ASTMatchers/Dynamic/Parser.h b/include/clang/ASTMatchers/Dynamic/Parser.h
  index 0d0c2ba540..5ec4a9abf4 100644
  --- a/include/clang/ASTMatchers/Dynamic/Parser.h
  +++ b/include/clang/ASTMatchers/Dynamic/Parser.h
  @@ -22,7 +22,7 @@
   /// <Literal>           := <StringLiteral> | <Boolean> | <Double> | <Unsigned>
   /// <StringLiteral>     := "quoted string"
   /// <Boolean>           := true | false
  -/// <Double>            := 1.0 | 2e-3 | 3.45e67
  +/// <Double>            := [0-9]+.[0-9]* | [0-9]+.[0-9]*[eE][-+]?[0-9]+
   /// <Unsigned>          := [0-9]+
   /// <NamedValue>        := <Identifier>
   /// <MatcherExpression> := <Identifier>(<ArgumentList>) |
  diff --git a/lib/ASTMatchers/Dynamic/Parser.cpp b/lib/ASTMatchers/Dynamic/Parser.cpp
  index 669e5ca44f..ff5c5fb657 100644
  --- a/lib/ASTMatchers/Dynamic/Parser.cpp
  +++ b/lib/ASTMatchers/Dynamic/Parser.cpp
  @@ -130,8 +130,8 @@ private:
   
       case '0': case '1': case '2': case '3': case '4':
       case '5': case '6': case '7': case '8': case '9':
  -      // Parse an unsigned literal.
  -      consumeUnsignedLiteral(&Result);
  +      // Parse an unsigned and float literal.
  +      consumeNumberLiteral(&Result);
         break;
   
       default:
  @@ -176,8 +176,8 @@ private:
       return Result;
     }
   
  -  /// \brief Consume an unsigned literal.
  -  void consumeUnsignedLiteral(TokenInfo *Result) {
  +  /// \brief Consume an unsigned and float literal.
  +  void consumeNumberLiteral(TokenInfo *Result) {
       bool isFloatingLiteral = false;
       unsigned Length = 1;
       if (Code.size() > 1) {
  @@ -205,8 +205,9 @@ private:
   
       if (isFloatingLiteral) {
         char *end;
  +      errno = 0;
         double doubleValue = strtod(Result->Text.str().c_str(), &end);
  -      if (*end == 0) {
  +      if (*end == 0 && errno == 0) {
           Result->Kind = TokenInfo::TK_Literal;
           Result->Value = doubleValue;
           return;


https://reviews.llvm.org/D33135

Files:
  include/clang/ASTMatchers/Dynamic/Diagnostics.h
  include/clang/ASTMatchers/Dynamic/Parser.h
  include/clang/ASTMatchers/Dynamic/VariantValue.h
  lib/ASTMatchers/Dynamic/Diagnostics.cpp
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Parser.cpp
  lib/ASTMatchers/Dynamic/VariantValue.cpp
  unittests/ASTMatchers/Dynamic/ParserTest.cpp
  unittests/ASTMatchers/Dynamic/VariantValueTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33135.101816.patch
Type: text/x-patch
Size: 11583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170607/14117eb2/attachment-0001.bin>


More information about the cfe-commits mailing list