Commit Graph

173 Commits

Author SHA1 Message Date
Chris Lattner a30be59fa2 Fix a nasty corner case that Neil noticed in PR1900, where we would
incorrectly apply the multiple include optimization to files with 
guards like:

#if !defined(x) MACRO

where MACRO could expand to different things in different contexts.
Thanks Neil!

llvm-svn: 45716
2008-01-07 19:50:27 +00:00
Nate Begeman f7c3ff6f80 Fix typo
llvm-svn: 45682
2008-01-07 04:01:26 +00:00
Chris Lattner 5b12ab8c93 Don't attribute in file headers anymore. See llvmdev for the
discussion of this change.

llvm-svn: 45410
2007-12-29 19:59:25 +00:00
Ted Kremenek 230bd918b2 Interned MainFileID within SourceManager. Since SourceManager is referenced by
both Preprocessor and ASTContext, we no longer need to explicitly pass
MainFileID around in function calls that also pass either Preprocessor or
ASTContext. This resulted in some nice cleanups in the ASTConsumers and the
driver.

llvm-svn: 45228
2007-12-19 22:51:13 +00:00
Ted Kremenek 1daa3cfbae TargetInfo no longer includes a reference to SourceManager.
Moved all clients of Diagnostics to use FullSourceLoc instead of SourceLocation.
Added many utility methods to FullSourceLoc to provide shorthand for:

    FullLoc.getManager().someMethod(FullLoc.getLocation());
    
instead we have:

    FullLoc.someMethod();
    
Modified TextDiagnostics (and related classes) to use this short-hand.

llvm-svn: 44957
2007-12-12 22:39:36 +00:00
Ted Kremenek d4e5fbacab Mega-patch: ripped SourceManager out of Diagnostic/DiagnosticClient. Now
SourceManager is passed by reference, allowing the SourceManager to be
associated with a specific translation unit, and not the entire execution
of the driver.

Modified all users of Diagnostics to comply with this new interface.

Integrated SourceManager as a member variable of TargetInfo. TargetInfo will
eventually be associated with a single translation unit (just like
SourceManager).

Made the SourceManager reference in ASTContext private. Provided accessor
getSourceManager() for clients to use instead. Modified clients to comply with
new interface.

llvm-svn: 44878
2007-12-11 21:27:55 +00:00
Chris Lattner 615315f307 Add dumping support for locations, make -dumptokens print out the location
info of each token.

llvm-svn: 44741
2007-12-09 20:31:55 +00:00
Chris Lattner 9fcdc52243 Fix PR1820, an incredibly subtle macro expansion bug that Neil discovered.
Neil, please review this fix.

llvm-svn: 44285
2007-11-23 06:50:21 +00:00
Chris Lattner 609d413363 fix a bug Steve noticed, where a #import of the main file itself would fail.
llvm-svn: 44178
2007-11-15 19:07:47 +00:00
Steve Naroff 68754c59bc Since we are all working on Leopard, change the built-in MacOS X version number (__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) to target Leopard. This is only a short term solution, until the clang driver implements the "-mmacosx-version-min" flag (which will compute this value based on the target).
llvm-svn: 43981
2007-11-10 18:06:36 +00:00
Steve Naroff 6d40db0dde Implement a more sensible strategy for ObjC built-in types (addressing a long standing FIXME in Sema::GetObjcIdType()).
This removes several gross hacks to work around the previous "lazy" behavior.

Two notes:
- MinimalActions still needs to be taught about the built-in types (This breaks one of the -noop test cases). I started this, then added a FIXME.
- I didn't convert Sema::GetObjcProtoType() yet.

llvm-svn: 43567
2007-10-31 18:42:27 +00:00
Steve Naroff ac0216385f Checking in some code that is still under construction.
I need to (finally) change the way Class/id/SEL/IMP are built-in...the current approach of doing it in the preprocessor is "broken". The other problem is Sema::GetObjcIdType/GetObjcSelType/GetObjcClassType, the hooks that initialize ASTContext lazily. These built-in types need to be done up front...

llvm-svn: 43557
2007-10-31 16:03:04 +00:00
Steve Naroff 37e011ce43 Add some plumbing to help cope with rewriting "id<p>", "Class<p>*".
llvm-svn: 43543
2007-10-31 04:38:33 +00:00
Steve Naroff 5cdcd9b61c Stop pre-defining objc_msgSend/objc_getClass in the preprocessor. Instead, I generate these declaration on the fly when rewriting a message expression.
llvm-svn: 43529
2007-10-30 23:14:51 +00:00
Chris Lattner 39afd571a0 Avoid using macro expansions, which causes these to come out in -E mode.
llvm-svn: 43505
2007-10-30 17:45:43 +00:00
Steve Naroff c77380b46f Incorporate some feedback from Chris...
llvm-svn: 43285
2007-10-24 01:09:48 +00:00
Steve Naroff e670dbb9e6 - Add rewrite rule for @class.
- Add setter/getter to ObjcClassDecl.
- Predefined key runtime functions.

llvm-svn: 43257
2007-10-23 20:20:08 +00:00
Steve Naroff 0f7a2d2dd1 Predefine all the ObjC goodies from <objc/objc.h>. Removed all the ObjC goodies from the respective test files. Moving forward, it will be very nice to assume these builtin!
llvm-svn: 43077
2007-10-17 17:53:50 +00:00
Chris Lattner ed2a9eb820 resolve a fixme, by moving __builtin_va_list to a more logical
place and making it correctly parameterized on the target.

llvm-svn: 42830
2007-10-10 17:48:53 +00:00
Chris Lattner 5d45178179 Add a dummy for the id typedef. Steve, plz fill this in. :)
llvm-svn: 42819
2007-10-09 22:58:09 +00:00
Chris Lattner 1f1b0dbc28 Make a significant change to invert the control flow handling
predefined macros.  Previously, these were handled by the driver,
now they are handled by the preprocessor.

Some fallout of this:

1. Instead of preprocessing two buffers (the predefines, then the 
   main source file)  we now start preprocessing the main source 
   file and inject the predefines as a "psuedo #include" from the
   main source file.
2. #1 allows us to nuke the Lexer::IsMainFile flag and simplify
   Preprocessor::isInPrimaryFile.
3. The driver doesn't have to know about standard #defines, the
   preprocessor knows, which is nice for people wanting to define
   their own drivers.
4. This allows us to put normal tokens in the predefine buffer,
   for example a definition for __builtin_va_list that is 
   target-specific, and a typedef for id in objc.

llvm-svn: 42818
2007-10-09 22:10:18 +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 c43ddc84a3 improve layering:
Now instead of IdentifierInfo knowing anything about MacroInfo,
only the preprocessor knows.  This makes MacroInfo truly private
to the Lex library (and its direct clients) instead of being 
accessed in the Basic library.

llvm-svn: 42727
2007-10-07 08:44:20 +00:00
Chris Lattner 259716a6e1 change calls to getMacroInfo into hasMacroDefinition() where possible.
llvm-svn: 42726
2007-10-07 08:04:56 +00:00
Chris Lattner d05e44e74e If we see an invalid #ifdef directive, enter a conditional compilation region
so that we don't emit an error on the #endif.  Suggestion by Neil.

llvm-svn: 42258
2007-09-24 05:14:57 +00:00
Chris Lattner a263393d11 Add #include required on win32.
llvm-svn: 41686
2007-09-03 18:30:32 +00:00
Chris Lattner f97dbcb4ba Fix a scoping bug that apple gcc doesn't catch for some reason.
llvm-svn: 40450
2007-07-23 22:23:52 +00:00
Chris Lattner 43eafb4ed5 implement a missing feature in the #include handler, where
it did not handle <xyz> headers coming from macro expansions.
This requires special treatment, as the include name is lexed
as multiple tokens, which require reassembly before processing.

llvm-svn: 40418
2007-07-23 04:56:47 +00:00
Chris Lattner 93ab9f134e refactor the interface to Preprocessor::GetIncludeFilenameSpelling,
no functionality changes.

llvm-svn: 40414
2007-07-23 04:15:27 +00:00
Chris Lattner 32e6d64176 fix a bug getting the spelling of an identifier token
that required cleaning.  If the token required cleaning,
don't include the cleaned tokens in the returned length.

llvm-svn: 40410
2007-07-22 22:50:09 +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 77e9de50a1 simplify the lexer ctor to take a SLoc instead of a sloc and a redundant buffer*.
llvm-svn: 40104
2007-07-20 16:52:03 +00:00
Chris Lattner dc5c055fd1 Reimplement SourceLocation. Instead of having a
fileid/offset pair, it now contains a bit discriminating between
mapped locations and file locations.  This separates the tables for
macros and files in SourceManager, and allows better separation of
concepts in the rest of the compiler.  This allows us to have *many*
macro instantiations before running out of 'addressing space'.

This is also more efficient, because testing whether something is a
macro expansion is now a bit test instead of a table lookup (which
also used to require having a srcmgr around, now it doesn't).

This is fully functional, but there are several refinements and
optimizations left.

llvm-svn: 40103
2007-07-20 16:37:10 +00:00
Chris Lattner 24dbee71ab Fix a stringizing bug that Neil noticed. We should preprocess this:
#define t(x) #x
t(a
c)

to "a c", not "ac".

llvm-svn: 40060
2007-07-19 16:11:58 +00:00
Chris Lattner 5c98379b1c Correctly respect C99 5.1.1.2p4 when searching for the first '(' of
a function-like macro invocation.  Patch contributed by Neil Booth.

llvm-svn: 40026
2007-07-19 00:07:36 +00:00
Chris Lattner 8a7003cd9f Add a new Preprocessor::AdvanceToTokenCharacter method which, given a sloc
specifying the start of a token and a logical (phase 3) character number,
returns a sloc representing the input character corresponding to it.

llvm-svn: 39905
2007-07-16 06:48:38 +00:00
Chris Lattner c02c4abe5b Cache macro expander objects to avoid thrashing malloc in heavy expansion situations.
This doesn't significantly improve carbon.h, but it does speed up
INPUTS/macro_pounder_obj.c by 48%

llvm-svn: 39864
2007-07-15 00:25:26 +00:00
Chris Lattner 564f478595 switch function-like macros from using a vector for their arguments to an
explicitly new'd array.  The array never mutates once created, so a vector
is overkill.

llvm-svn: 39862
2007-07-14 22:46:43 +00:00
Chris Lattner f40fe99118 expose an iterator interface to getReplacementTokens instead of the datastructure itself.
llvm-svn: 39860
2007-07-14 22:11:41 +00:00
Chris Lattner a3834341c5 split function-like and object-like macro body parsing to make the
code more obvious.

llvm-svn: 39859
2007-07-14 21:54:03 +00:00
Chris Lattner f9aba2c2b4 remove use of alloca.
llvm-svn: 39815
2007-07-13 17:10:38 +00:00
Gabor Greif 441b3d47be Solaris needs an included header for alloca
llvm-svn: 39797
2007-07-13 08:21:39 +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 53621a535d Implement support for formal arguments. We can now compile this:
int test(int X, short Y, float Z) {
  return (int)(X*Y+Z);
}

to:

define i32 @test(i32 %X, i16 %Y, float %Z) {
entry:
        %promote = sext i16 %Y to i32           ; <i32> [#uses=1]
        %mul = mul i32 %promote, %X             ; <i32> [#uses=1]
        %promote3 = sitofp i32 %mul to float            ; <float> [#uses=1]
        %add = add float %promote3, %Z          ; <float> [#uses=1]
        %conv = fptosi float %add to i32                ; <i32> [#uses=1]
        ret i32 %conv
}

with:

$ clang -emit-llvm t.c | llvm-as | opt -std-compile-opts | llvm-dis

llvm-svn: 39652
2007-06-13 20:44:40 +00:00
Steve Naroff a8fd973aa0 Bug #:
Submitted by:
Reviewed by:
Implement semantic analysis for vector_size attribute!
We now produce the following diagnostics...

[administrators-powerbook59:~/llvm/tools/clang] admin% ../../Debug/bin/clang vector.c
vector.c:2:29: error: attribute requires precisely 1 argument
typedef int __attribute__(( vector_size )) tVecp;
                            ^
vector.c:7:32: error: attribute requires precisely 1 argument
extern int foo __attribute__(( vector_size ));
                               ^
vector.c:8:34: error: attribute requires precisely 1 argument
extern float bar __attribute__(( vector_size(16,18) ));
                                 ^
vector.c:11:34: error: vector_size requires integer constant (attribute ignored)
extern char foo2 __attribute__(( vector_size(16.2) ));
                                 ^           ~~~~
vector.c:21:47: error: invalid vector type 'struct s'
struct s { int a; } structVar __attribute__(( vector_size(16) ));

llvm-svn: 39643
2007-06-11 00:35:03 +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
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 7c718bd5a4 Include the filename being looked up in an error message. This gives us stuff
like this:
t3.c:5:10: error: 'vers2.h' file not found
#include xstr(INCFILE(2).h)
         ^

instead of:

t3.c:5:10: error: file not found
#include xstr(INCFILE(2).h)
         ^

which is useful if the #include name is generated through macro expansion.

llvm-svn: 39398
2007-04-10 06:02:46 +00:00
Chris Lattner b055f2ddfc switch to using iterators instead of stringmap visitors.
llvm-svn: 39336
2007-02-11 08:19:57 +00:00
Chris Lattner 54d032bb76 CStringMap -> StringMap.
llvm-svn: 39334
2007-02-08 19:24:25 +00:00