Commit Graph

18 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 4cdfcae75d Don't map a file:line:col triplet that is inside the preamble range to
a "loaded" location of the precompiled preamble.

Instead, handle specially locations of preprocessed entities:
-When looking up for preprocessed entities, map main file locations inside the
 preamble range to a preamble loaded location.
-When getting the source range of a preprocessing cursor, map preamble loaded
 locations back to main file locations.

Fixes rdar://10175093 & http://llvm.org/PR10999

llvm-svn: 140519
2011-09-26 08:01:41 +00:00
Argyrios Kyrtzidis b4199b659b For SourceManager::isBeforeInTranslationUnit, a location pointing
inside a macro argument should be regarded as coming before
the location of the expanded tokens.

llvm-svn: 140053
2011-09-19 20:39:57 +00:00
Argyrios Kyrtzidis 80f78b961a [libclang] Fix annotation and getting a "macro expansion" cursor
for a builtin macro expansion.

llvm-svn: 139298
2011-09-08 17:18:41 +00:00
Argyrios Kyrtzidis 035674d33c [libclang] Annotate correctly macro argument tokens.
llvm-svn: 137961
2011-08-18 18:03:34 +00:00
Chandler Carruth 9e4704ab07 Update all of the libclang code corresponding to the preprocessor
MacroInstantiation -> MacroExpansion rename. Internally, everything is
switched.

Introduce a new cursor kind enum with the new name, but retain the old
name as an alias so that we don't break backwards compatibility.

Also update the debug printing routine to use 'macro expansions' as its
explicitly not guaranteed to be stable, and mechanically switch the test
cases over to that.

llvm-svn: 135140
2011-07-14 08:41:15 +00:00
Douglas Gregor 37aa4938c8 Introduce a new libclang API, clang_isFileMultipleIncludeGuarded(),
which determines whether a particular file is actually a header that
is intended to be guarded from multiple inclusions within the same
translation unit.

llvm-svn: 130808
2011-05-04 00:14:37 +00:00
Douglas Gregor 229bebdeb5 ntroduce clang_getSpellingLocation() into libclang, to provide the
location where we're spelling a token even within a
macro. clang_getInstantiationLocation() tells where we instantiated
the macro.

I'm still not thrilled with the CXSourceLocation/CXSourceRange APIs,
since they gloss over macro-instantiation information.

Take 2: this time, adjusted tests appropriately and used a "simple"
approach to the spelling location.

llvm-svn: 118495
2010-11-09 06:24:54 +00:00
Douglas Gregor adfdccf1f3 Improve the implementation of libclang's token-annotation logic for
entities in the preprocessing record. Previously, we would only end up
getting the first token of a preprocessing record annotated
correctly. For example, given

  #include "foo.h"

we would only get the '#' annotated as an inclusion directive; the
'include' and '"foo.h"' tokens would be given the general 'processing
directive' annotation.

Now, we get proper annotations for entities in the preprocessing
record.

llvm-svn: 117001
2010-10-21 06:10:04 +00:00
Douglas Gregor 796d76a663 Extend the preprocessing record and libclang with support for
inclusion directives, keeping track of every #include, #import,
etc. in the translation unit. We keep track of the source location and
kind of the inclusion, how the file name was spelled, and the
underlying file to which the inclusion resolved.

llvm-svn: 116952
2010-10-20 22:00:55 +00:00
Ted Kremenek aa01481d78 Always recurse into sub-cursors when annotating tokens, as this information is used for annotating macro arguments. This finishes up <rdar://problem/8044584>.
llvm-svn: 111066
2010-08-14 02:50:46 +00:00
Ted Kremenek f4ade0ae3f As a heuristic, annotate tokens (via clang_annotateTokens) that are the arguments of a macro instantiation using the closest cursor with the same spelling location. Because macro arguments can get token pasted in any arbitrary order, we use the annotation map to paper over the token -> cursor annotations during our post-processing stage. This fixes most of <rdar://problem/8044584>, but still doesn't work for assert().
llvm-svn: 111062
2010-08-14 01:14:06 +00:00
Douglas Gregor e56c353eb1 Try to appease MSVC's standard library
llvm-svn: 98878
2010-03-18 21:28:30 +00:00
Douglas Gregor 5810ead358 Try to appease MSVC
llvm-svn: 98875
2010-03-18 21:25:12 +00:00
Douglas Gregor 78ae2481b6 Explicitly link macro instantiations to macro definitions in the
preprocessing record. Use that link with clang_getCursorReferenced()
and clang_getCursorDefinition() to match instantiations of a macro to
the definition of the macro.

llvm-svn: 98842
2010-03-18 18:23:03 +00:00
Douglas Gregor 06d6d32762 Expose macro definitions as CIndex cursors. These can still only be
generated by clang_annotateTokens().

llvm-svn: 98837
2010-03-18 18:04:21 +00:00
Douglas Gregor 065f8d11ca Introduce the notion of a "preprocessing record", which keeps track of
the macro definitions and macro instantiations that are found
during preprocessing. Preprocessing records are *not* generated by
default; rather, we provide a PPCallbacks subclass that hooks into the
existing callback mechanism to record this activity.

The only client of preprocessing records is CIndex, which keeps track
of macro definitions and instantations so that they can be exposed via
cursors. At present, only token annotation uses these facilities, and
only for macro instantiations; both will change in the near
future. However, with this change, token annotation properly annotates
macro instantiations that do not produce any tokens and instantiations
of macros that are later undef'd, improving our consistency.

Preprocessing directives that are not macro definitions are still
handled by clang_annotateTokens() via re-lexing, so that we don't have
to track every preprocessing directive in the preprocessing record.

Performance impact of preprocessing records is still TBD, although it
is limited to CIndex and therefore out of the path of the main compiler.

llvm-svn: 98836
2010-03-18 17:52:52 +00:00
Douglas Gregor 02ded2a56c More token-annotation experimentation, preprocessing the annotated
token sequence to detect macro instantiations (that produce at least
token). WIP.

llvm-svn: 98826
2010-03-18 15:23:44 +00:00
Douglas Gregor 92a524fd47 Experimental stab at using relexing to identify preprocessor
directives while annotating tokens in CIndex. This functionality
should probably be factored out of this routine, but we're not there
yet. 

llvm-svn: 98786
2010-03-18 00:42:48 +00:00