Commit Graph

32 Commits

Author SHA1 Message Date
Christopher Lamb 42e69f219d Support floating point literals of the form "1e-16f" which specify an exponent but no decimal point.
llvm-svn: 44431
2007-11-29 06:06:27 +00:00
Ted Kremenek 9924ca2e14 Removed potential buffer overrun (spotted by Neil Booth) when NumericLiteralParser
converts a parsed literal into an APFloat. We are still performing a copy of the
string, which hopefully will be removed eventually for performance reasons. This
version now is at least safe.

Changed rounding in APFloat construction in NumericLiteralParser from rmTowardsZero
to rmNearestTiesToEven.

llvm-svn: 44422
2007-11-29 00:54:29 +00:00
Ted Kremenek fbb08bc2e2 Added optional pass-by-reference argument "isExact" to
NumericLiteralParser::GetFloatValue(). Upon method return, this flag has the value
true if the returned APFloat can exactly represent the number in the parsed text,
and false otherwise.

Modified the implementation of GetFloatValue() to parse literals using APFloat's
convertFromString method (which allows us to set the value of isExact).

llvm-svn: 44339
2007-11-26 23:12:30 +00:00
Chris Lattner e6c7a858b0 Fix a bug handling hex floats in c90 mode, pointed out by Neil.
llvm-svn: 44120
2007-11-14 16:14:50 +00:00
Anders Carlsson cbfc4b8824 Add support for Pascal strings.
llvm-svn: 42974
2007-10-15 02:50:23 +00:00
Chris Lattner 98c1f7cfde Switch lexer/pp over to new Token::is/isNot api
llvm-svn: 42799
2007-10-09 18:02:16 +00:00
Chris Lattner c2d09cfe75 work around bugs and missing features in apfloat.
llvm-svn: 42235
2007-09-22 18:38:30 +00:00
Chris Lattner ec0a6d9be5 Use APFloat for the representation of FP immediates, ask the target
for *which* apfloat to use for a particular type.

llvm-svn: 42234
2007-09-22 18:29:59 +00:00
Chris Lattner 78b6221ff9 Eliminate some VC++ warnings, patch by Hartmut Kaiser!
llvm-svn: 41685
2007-09-03 18:28:41 +00:00
Chris Lattner ed045421a8 1.0 is double, 1.0F is a float.
llvm-svn: 41412
2007-08-26 03:29:23 +00:00
Chris Lattner f55ab18663 1) refactor some code.
2) Add support for lexing imaginary constants (a GCC extension):

t.c:5:10: warning: imaginary constants are an extension
  A = 1.0iF;
         ^

3) Make the 'invalid suffix' diagnostic pointer more accurate:

t.c:6:10: error: invalid suffix 'qF' on floating constant
  A = 1.0qF;
         ^

instead of:

t.c:6:10: error: invalid suffix 'qF' on floating constant
  A = 1.0qF;
      ^

llvm-svn: 41411
2007-08-26 01:58:14 +00:00
Chris Lattner 146762e7a4 At one point there were going to be lexer and parser tokens.
Since that point is now long gone, we should rename LexerToken to
Token, as it is the only kind of token we have.

llvm-svn: 40105
2007-07-20 16:59:19 +00:00
Chris Lattner 59fd8012a0 strtod is more portable than strtof apparently. Instead of making this conditional,
just always use strtod.  This is temporary code anyway.

llvm-svn: 39972
2007-07-17 15:27:33 +00:00
Gabor Greif bea1390e68 cheap change to fix solaris compilation. I can make this a static inline if desired
llvm-svn: 39970
2007-07-17 11:05:49 +00:00
Chris Lattner bb1b44f004 Make octal constant lexing use AdvanceToTokenCharacter to give more
accurate diagnostics.  For test/Lexer/comments.c we now emit:

int x = 000000080;  /* expected-error {{invalid digit}} */
               ^
constants.c:7:4: error: invalid digit '8' in octal constant
00080;             /* expected-error {{invalid digit}} */
   ^


The last line is due to an escaped newline.  The full line looks like:

int y = 0000\
00080;             /* expected-error {{invalid digit}} */


Previously, we emitted:
constants.c:4:9: error: invalid digit '8' in octal constant
int x = 000000080;  /* expected-error {{invalid digit}} */
        ^
constants.c:6:9: error: invalid digit '8' in octal constant
int y = 0000\
        ^

which isn't too bad, but the new way is better for the user,
regardless of whether there is an escaped newline or not.

All the other lexer-related diagnostics should switch over 
to using AdvanceToTokenCharacter where appropriate.  Help
wanted :).

This implements test/Lexer/constants.c.

llvm-svn: 39906
2007-07-16 06:55:01 +00:00
Steve Naroff 97b9e91eb7 Bug #:
Submitted by:
Reviewed by:
Added primitive support for 32-bit floating point literals.

llvm-svn: 39719
2007-07-09 23:53:58 +00:00
Chris Lattner 23b7eb677d Finally bite the bullet and make the major change: split the clang namespace
out of the llvm namespace.  This makes the clang namespace be a sibling of
llvm instead of being a child.

The good thing about this is that it makes many things unambiguous.  The
bad things is that many things in the llvm namespace (notably data structures
like smallvector) now require an llvm:: qualifier.  IMO, libsystem and libsupport
should be split out of llvm into their own namespace in the future, which will fix
this issue.

llvm-svn: 39659
2007-06-15 23:05:46 +00:00
Chris Lattner 3f4b6e3623 Fix lexing octal escapes like:
void foo() {
"\0";
}

llvm-svn: 39638
2007-06-09 06:20:47 +00:00
Chris Lattner de12ae2fd7 Add support for binary literals:
http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html#Binary-constants

llvm-svn: 39621
2007-06-08 22:42:30 +00:00
Chris Lattner 328fa5c913 Emit better diagnostics for out of range digits:
diag.c:1:9: error: invalid digit '8' in octal constant
int x = 000080;
        ^
diag.c:2:9: error: invalid digit 'A' in decimal constant
int z = 1000080ABC;
        ^

instead of:

diag.c:1:9: error: invalid suffix '80' on integer constant
int x = 000080;
        ^
diag.c:2:9: error: invalid suffix 'ABC' on integer constant
int z = 1000080ABC;
        ^

llvm-svn: 39605
2007-06-08 17:12:06 +00:00
Chris Lattner 67ca9252f8 Implement Sema::ParseNumericConstant for integer constants in terms of APInt
and correctly in terms of C99 6.4.4.1p5.

llvm-svn: 39473
2007-05-21 01:08:44 +00:00
Chris Lattner 812eda8259 implement octal escape sequences.
llvm-svn: 39463
2007-05-20 05:17:04 +00:00
Chris Lattner c10adde406 Implement hex escape sequences in string and character literals, e.g. L"\x12345"
llvm-svn: 39462
2007-05-20 05:00:58 +00:00
Chris Lattner 2f5add6272 Implement support for performing semantic analysis of character literals.
llvm-svn: 39390
2007-04-05 06:57:15 +00:00
Chris Lattner 531efa43d8 Ah, this is already correctly rejected!
llvm-svn: 39386
2007-04-04 06:49:26 +00:00
Chris Lattner 871b4e101c Minor enhancements to GetIntegerValue(APInt):
* Detect overflow correctly.  When it occurs, return the truncated value.
  * Add fixme for radix analysis.

llvm-svn: 39382
2007-04-04 06:36:34 +00:00
Chris Lattner 5b743d3801 Add some really simplistic code for turning a ppnumber into an APInt. Much
improvement is needed!

llvm-svn: 39381
2007-04-04 05:52:58 +00:00
Steve Naroff f1e53698a4 Bug #:
Submitted by:
Reviewed by:

Type Checking...round 2. This checkin "breaks" parsing carbon.h. I imagine
that this will be true for the next week or so. Nevertheless, this round of
changes includes the following:

- Hacked various Expr classes to pass the appropriate TypeRef. Still have
a few more classes to touch.
- Implement type checking for ParseArraySubscriptExpr and ParseMemberReferenceExpr.
- Added a debug hook to derive the class name for Stmt/Expr nodes. Currently a
linear search...could easily optimize if important.
- Changed the name of TaggedType->TagType. Now we have TagType and TagDecl (which
are easier to remember).
- Fixed a bug in StringLiteral conversion I did a couple weeks ago. hadError was
not initialized (oops).
- changed Sema::Diag to return true. This streamlines the type checking code
considerably.
- Added many diagnositics.

This should be it!

llvm-svn: 39361
2007-03-23 22:27:02 +00:00
Steve Naroff 4f88b3113e Bug #:
Submitted by:
Reviewed by:
Move string literal parsing from Sema=>LiteralSupport. This consolidates
all the quirky parsing code within the Lexer subsystem (yeah!). This
simplifies Sema and (more importantly) allows future parsers
(i.e. subclasses of Action) to benefit from this code.

llvm-svn: 39354
2007-03-13 22:37:02 +00:00
Steve Naroff f2fb89e759 Bug #:
Submitted by:
Reviewed by:
Misc. cleanup/polish of NumericLiteralParser and it's two clients, the
C preprocessor and AST builder...

llvm-svn: 39353
2007-03-13 20:29:44 +00:00
Steve Naroff 451d8f1626 Bug #:
Submitted by:
Reviewed by:
-Converted the preprocessor to use NumericLiteralParser.
-Several minor changes to LiteralSupport interface/implementation.
-Added an error diagnostic for floating point usage in pp expr's.

llvm-svn: 39352
2007-03-12 23:22:38 +00:00
Steve Naroff 09ef474197 Bug #:
Submitted by:
Reviewed by:
Moved numeric literal support from SemaExpr.cpp to LiteralSupport.[h,cpp]
in Lex. This will allow it to be used by both Sema and Preprocessor (and
should be the last major refactoring of this sub-system).. Over
time, it will be reused by anyone implementing an actions module (i.e.
any subclass of llvm::clang::Action. Minor changes to IntegerLiteral in Expr.h.
More to come...

llvm-svn: 39351
2007-03-09 23:16:33 +00:00