Commit Graph

95 Commits

Author SHA1 Message Date
Chris Lattner a8a2c82f55 Move ASTStreamer.h into "clang/Sema/ASTStreamer.h"
llvm-svn: 39478
2007-05-21 17:38:36 +00:00
Chris Lattner 5ab15f154d Steve pointed out that testcases like this (with a macro expansion):
#define friendlystruct fs

  struct A { int X; };

  void test2(struct A friendlystruct, int C) {
    return friendlystruct + (C     *40);
  }

were getting diagnosed like this:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~             ^ ~~~~~~~~~~~

The problem is that getCharacterData returns a pointer to the macro expansion,
not to the macro instantiation.  Instead, use getLogicalLoc to get a pointer
to the instatiation location, so we relex the macro id.  We now get:

t.c:7:27: error: invalid operands to binary expression ('struct A' and 'int')
    return friendlystruct + (C     *40);
           ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~

oooh ahh. :)

llvm-svn: 39465
2007-05-20 18:08:36 +00:00
Chris Lattner beeb9bc51d improve const correctness
llvm-svn: 39460
2007-05-19 08:07:42 +00:00
Chris Lattner ebd1b33477 Use the new source ranges tracking feature to highlight the important pieces
of a subexpression when emitting a diagnostic.  Consider this example:

struct A { int X; };

void test1(void *P, int C) {
  return ((C*40) + *P) / 42+P;
}

void test2(struct A friendlystruct, int C) {
  return (C     *40) + friendlystruct;
}

void test3(struct A friendlystruct, int C) {
  return friendlystruct + test2(friendlystruct
                               , C);
}


clang now produces this output:

t.c:4:18: error: invalid operands to binary expression ('int' and 'void')
  return ((C*40) + *P) / 42+P;
          ~~~~~~ ^ ~~

This shows the important pieces of a nested (and potentially very complex)
expression.


t.c:8:18: error: invalid operands to binary expression ('int' and 'struct A')
  return (C     *40) + friendlystruct;
         ~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~

This shows that tabs in source files (after the 'C') and multichar tokens
(friendlystruct) are handled correctly.



t.c:12:25: error: invalid operands to binary expression ('struct A' and 'void')
  return friendlystruct + test2(friendlystruct
         ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~

This shows how multiline ranges are printed.  Any part of the range that is
not on the same line as the carat is just ignored.  This also shows that
trailing spaces on the line aren't highlighted.

llvm-svn: 39459
2007-05-19 08:06:14 +00:00
Chris Lattner f8d3197831 Change the structure of the code that emits the ^ marker in a diagnostic,
but there is no functionality change yet.

llvm-svn: 39458
2007-05-19 07:25:55 +00:00
Steve Naroff 71ce2e061d Bug #:
Submitted by:
Reviewed by:
An important, but truly mind numbing change.

Added 6 flavors of Sema::Diag() that take 1 or two SourceRanges. Considered
adding 3 flavors (using default args), however this wasn't as clear.

Removed 2 flavors of Sema::Diag() that took LexerToken's (they weren't used).

Changed all the typechecking routines to pass the appropriate range(s).

Hacked the diagnostic machinery and driver to acccommodate the new data.

What's left? A FIXME in clang.c to use the ranges. Chris offered to do the
honors:-) Which includes taking us to the end of an identifier:-)

llvm-svn: 39456
2007-05-18 22:53:50 +00:00
Chris Lattner 3dc3d775fb Rename type::getAsString to getAsStringInternal. Add a new
QualType::getAsString() that returns a string, which is much easier
for clients to use.  Convert clients to use it.

llvm-svn: 39449
2007-05-16 18:07:12 +00:00
Chris Lattner 36982e4367 Add support for inserting up to 10 strings in a diagnostic, with %0, %1, %2,
etc.

llvm-svn: 39447
2007-05-16 17:49:37 +00:00
Steve Naroff 17f76e04d2 Bug #:
Submitted by:
Reviewed by:
Work on finishing up typechecking for simple assignments (=) and function
calls. Here is an overview:
- implemented type checking for function calls (in Sema::ParseCallExpr).
- refactored UsualAssignmentConversions to return the result of the conversion.
This enum will allow all clients to emit different diagnostics based on context.
- fixed bug in Expr::isLvalue()...it wasn't handling arrays properly. Also
changed the name to isModifiableLvalue, which is consistent with the function on QualType.
- Added 6 diagnostics (3 errors, 3 extensions).

llvm-svn: 39432
2007-05-03 21:03:48 +00:00
Chris Lattner 739e739b81 Remove the clang::SourceBuffer class, switch to the llvm::MemoryBuffer class.
llvm-svn: 39426
2007-04-29 07:12:06 +00:00
Chris Lattner ae7fdad1c5 Teach the driver to filter out warnings and notes that come from system headers.
Switch -pedantic back on by default.

llvm-svn: 39423
2007-04-28 07:23:46 +00:00
Steve Naroff 0af9120905 Bug #:
Submitted by:
Reviewed by:
- Disabled -pedantic for now (until it ignores system headers).
- Removed convertSignedWithGreaterRankThanUnsigned() and convertFloatingRankToComplexType().
The logic is now inlined in maxIntegerType and maxComplexType().
- Removed getIntegerRank/getFloatingRank from the private interface. These
are now really private helpers:-)
- Declare maxIntegerType/maxFloatingType static. maxComplexType const.
- Added an enum for the floating ranks.
- Several fixed to getIntegerRank: add Bool, Char, and a clause for enums.

llvm-svn: 39421
2007-04-27 21:51:21 +00:00
Steve Naroff e471889d53 Bug #:
Submitted by:
Reviewed by:
More typechecking, refactoring...
- Implemented the following routines...CheckAdditiveOperands,
CheckCommaOperands, CheckLogicalOperands.
- Added maxComplexType, maxFloatingType, & maxIntegerType to ASTContext.
Ranking helper functions moved to ASTContext as well (they are private:-)
- Simplified UsualArithmeticConversions using the new ASTContext hooks.
- Fixed isAssignmentOp()...is was preventing comma exprs from ever being created:-(
- Changed a GCC compat extension to truly be an extension (and turned extensions
on by default). This now produces a warning by default.

llvm-svn: 39418
2007-04-27 18:30:00 +00:00
Chris Lattner bb73acd560 Support both tiger and leopard. Yes, this code is a hack :)
llvm-svn: 39359
2007-03-19 19:06:33 +00:00
Steve Naroff 3273c22863 Bug #:
Submitted by:
Reviewed by:
This is a "small" checkin.  #include_next wasn't working properly on
Leopard. This is because the driver has some hard coded paths that
don't work on Leopard. The real fix is to derive them, however I don't
think we need to solve this now. At this point, anyone working on clang
should be able to use Leopard. This fix removed 11 errors processing
"carbon.h". The bug that bubbles up to the top is in MergeFunctionDecl().
As part of digging into this part of Sema, I rearranged some methods
(and changed the visibility).

llvm-svn: 39356
2007-03-14 21:52:03 +00:00
Steve Naroff 2c055d2b2b Go back to having the clang driver create ASTContext explicitly, passing
it to Sema/ASTStreamer (separating the lifetime of ASTContext from
the lifetime of Sema). One day it might be useful to consider creating
a context object implicitly if one isn't provided (using default arguments in
Sema's constructor). At this point, adding this convenience isn't necessary.

llvm-svn: 39346
2007-02-28 19:32:13 +00:00
Steve Naroff 38d31b47b0 Make Sema's use of the preprocessor explicit (rather than assume
the prerocessor will be available via ASTContext).
- Removed the public data member "PP" in ASTContext.
- Changed ASTContext's contructor to take TargetInfo/IdentifierTable explicitly.
- Implicitly create an ASTContext in Sema's constructor. This simplifies
the clients job (and makes ASTContext more private).
--As a side effect, added a "PrintStats" hook to Sema.

To support this level of encapsulation, ASTContext is always dynamically
allocated (by Sema). Previously, ASTContext was being allocated on the
stack. I don't believe this should be a performance issue (since ASTContext
is fairly course grain and tied to the lifetime of Sema currently).

llvm-svn: 39345
2007-02-28 01:22:02 +00:00
Chris Lattner 739fa67f19 Revert accidental commit
llvm-svn: 39314
2007-01-27 02:20:41 +00:00
Chris Lattner baf33665fb adjust to change in SmallSet interface
llvm-svn: 39313
2007-01-27 02:14:08 +00:00
Chris Lattner 4f6a75809c fix printing of unprototyped function decls.
llvm-svn: 39310
2007-01-26 21:19:14 +00:00
Chris Lattner 4eb445d2a1 start gather stats on types processed. carbon.h currently yields:
*** AST Context Stats:
  30594 types total.
    19 builtin types
    3929 pointer types
    308 array types
    18883 function types with proto
    8 function types with no proto
    2988 typename (typedef) types
    4459 tagged types
      1476 struct types
      80 union types
      0 class types
      2903 enum types
  83298 slow type lookups

Next up, making type canonicalization not trivially silly.

llvm-svn: 39305
2007-01-26 01:27:23 +00:00
Chris Lattner 371f154c4f adjust to api change
llvm-svn: 39269
2007-01-22 07:41:51 +00:00
Chris Lattner 20ae9f6622 pretty print ... as well
llvm-svn: 39263
2007-01-21 23:48:06 +00:00
Chris Lattner 7f24b2abb8 Pretty print function prototypes as well.
llvm-svn: 39262
2007-01-21 23:46:27 +00:00
Chris Lattner ef1387808f Pretty print the function prototype. For example, print:
void (*signal(int arga, void (*argb)(double Y)))(void* Z) {}

as:

void (*signal(int arga, void (*argb)(double)))(void *) {
}

go C :)

llvm-svn: 39261
2007-01-21 23:11:09 +00:00
Chris Lattner 30b4b5cad8 default to -fsyntax-only
llvm-svn: 39254
2007-01-21 19:03:55 +00:00
Chris Lattner 3e7592ea78 Add support for -fno-operator-names, patch by Bill.
llvm-svn: 39245
2006-12-04 07:48:37 +00:00
Chris Lattner d6775fa217 add note in the output
llvm-svn: 39212
2006-11-21 06:36:58 +00:00
Chris Lattner 00348acace clear file info after processing one file, it shouldn't carry over to the
next.

llvm-svn: 39211
2006-11-21 06:34:57 +00:00
Chris Lattner 2ea9dd7fc0 ProcessInputFile no longer mutates LangInfo.
llvm-svn: 39210
2006-11-21 06:18:11 +00:00
Chris Lattner ad7cdd37b3 simplify the Preprocessor ctor.
llvm-svn: 39208
2006-11-21 06:08:20 +00:00
Chris Lattner 96327eaa52 first step refactoring driver so that it can process multiple input files
at once.

llvm-svn: 39207
2006-11-21 05:52:55 +00:00
Chris Lattner 38495cb2e7 -fsyntax-only is synonym for -parse-ast for now.
llvm-svn: 39202
2006-11-21 04:07:21 +00:00
Chris Lattner b0e7a06e53 Add some standard include paths for C++.
llvm-svn: 39200
2006-11-21 03:40:37 +00:00
Chris Lattner 229ce60fc9 split the ParseFunctionDefinition action into two actions, one which is
called before and one which is called after function definition parsing.

llvm-svn: 39196
2006-11-21 01:21:07 +00:00
Chris Lattner da8aa7b3a8 implement RTTI for Decl objects, eliminate some hokey virtual methods.
llvm-svn: 39185
2006-11-19 23:12:30 +00:00
Chris Lattner cb6a382b67 introduce a new ASTContext class to hold long-lived ast nodes.
llvm-svn: 39161
2006-11-10 06:20:45 +00:00
Chris Lattner c62b6c232f eliminate EmptyAction, merging it into MinimalAction instead.
llvm-svn: 39134
2006-11-05 18:44:26 +00:00
Chris Lattner 0663d2afd9 start factoring actions into two flavors: minimal and semantic actions.
llvm-svn: 39133
2006-11-05 18:39:59 +00:00
Chris Lattner ca96b89772 rename some options
llvm-svn: 39131
2006-11-05 18:00:10 +00:00
Chris Lattner 9fe24d75d2 for now -fsyntax-only builds all the AST's but doesn't print them.
llvm-svn: 39129
2006-11-05 07:59:55 +00:00
Chris Lattner 71e23ce2e1 Add AST node, AST building, actions, and printing for 'for' stmts.
llvm-svn: 39113
2006-11-04 20:18:38 +00:00
Chris Lattner 72b7d39d78 remove full locinfo AST nodes for now. They just clutter the implementation
and should be implemented with an ASTBuilder subclass anyway.

llvm-svn: 39107
2006-11-04 06:37:16 +00:00
Chris Lattner 9916c5ca7e Remove GNU C++ min/max operator extension support, they have been removed
from gcc mainline.

llvm-svn: 39067
2006-10-27 05:24:37 +00:00
Chris Lattner 6d9a685d75 Make the driver print function bodies at -parse-print-ast
llvm-svn: 39048
2006-10-25 05:11:20 +00:00
Chris Lattner 911d0fef03 Return an error code if an error occurs.
llvm-svn: 39041
2006-10-25 03:15:08 +00:00
Chris Lattner ca1a1ed4cb Add -F option
llvm-svn: 39036
2006-10-22 07:34:56 +00:00
Chris Lattner 07b019a1bc add #include
llvm-svn: 39034
2006-10-22 07:28:56 +00:00
Chris Lattner b84f986f45 gnu90 is default again
llvm-svn: 39023
2006-10-20 06:13:18 +00:00
Chris Lattner 2f9888e2ca switch to gnu99 by default
llvm-svn: 39019
2006-10-20 05:03:55 +00:00