For efficiency, we only track one level of macro instantiations: if a token was
-produced by multiple instantiations, we only track the source and ultimate
-destination. Though we could track the intermediate instantiation points, this
-would require extra bookkeeping and no known client would benefit substantially
-from this.
-
The Clang front-end inherently depends on the location of a token being
tracked correctly. If it is ever incorrect, the front-end may get confused and
die. The reason for this is that the notion of the 'spelling' of a Token in
diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html
index c855a5057a62d..9ac35e1dc2dc2 100644
--- a/docs/LanguageExtensions.html
+++ b/docs/LanguageExtensions.html
@@ -27,6 +27,7 @@ td {
__builtin_shufflevector is used to expression generic vector
+
__builtin_shufflevector is used to express generic vector
permutation/shuffle/swizzle operations. This builtin is also very important for
the implementation of various target-specific header files like
<xmmintrin.h>.
@@ -310,6 +311,47 @@ with the same element type as vec1/vec2 but that has an element count equal to
the number of indices specified.
+
Query for this feature with __has_builtin(__builtin_shufflevector).
+
+
+
__builtin_unreachable
+
+
+
__builtin_unreachable is used to indicate that a specific point in
+the program cannot be reached, even if the compiler might otherwise think it
+can. This is useful to improve optimization and eliminates certain warnings.
+For example, without the __builtin_unreachable in the example below,
+the compiler assumes that the inline asm can fall through and prints a "function
+declared 'noreturn' should not return" warning.
+
The __builtin_unreachable() builtin has completely undefined behavior. Since
+it has undefined behavior, it is a statement that it is never reached and the
+optimizer can take advantage of this to produce better code. This builtin takes
+no arguments and produces a void result.
+
+
+
Query for this feature with __has_builtin(__builtin_unreachable).
Clang provides a number of ways to control which code constructs cause it to
emit errors and warning messages, and how they are displayed to the console.
-
Controlling How Clang Displays Diagnostics
+
Controlling How Clang Displays Diagnostics
When Clang emits a diagnostic, it includes rich information in the output,
and gives you fine-grain control over which information is printed. Clang has
@@ -394,18 +400,64 @@ it:
All diagnostics are mapped into one of these 5 classes:
-The two major classes are control from the command line and control via pragmas
-in your code.
+
+
Ignored
+
Note
+
Warning
+
Error
+
Fatal
+
+
Controlling Diagnostics via Command Line Flags
-W flags, -pedantic, etc
-
pragma GCC diagnostic
+
Controlling Diagnostics via Pragmas
+
+
Clang can also control what diagnostics are enabled through the use of
+pragmas in the source code. This is useful for turning off specific warnings
+in a section of source code. Clang supports GCC's pragma for compatibility
+with existing source code, as well as several extensions.
+
+
The pragma may control any warning that can be used from the command line.
+Warnings may be set to ignored, warning, error, or fatal. The following
+example code will tell Clang or GCC to ignore the -Wall warnings:
+
+
+#pragma GCC diagnostic ignored "-Wall"
+
+
+
In addition to all of the functionality of provided by GCC's pragma, Clang
+also allows you to push and pop the current warning state. This is particularly
+useful when writing a header file that will be compiled by other people, because
+you don't know what warning flags they build with.
+
+
In the below example
+-Wmultichar is ignored for only a single line of code, after which the
+diagnostics return to whatever state had previously existed.
+
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wmultichar"
+
+char b = 'df'; // no warning.
+
+#pragma clang diagnostic pop
+
+
+
The push and pop pragmas will save and restore the full diagnostic state of
+the compiler, regardless of how it was set. That means that it is possible to
+use push and pop around GCC compatible diagnostics and Clang will push and pop
+them appropriately, while GCC will ignore the pushes and pops as unknown
+pragmas. It should be noted that while Clang supports the GCC pragma, Clang and
+GCC do not support the exact same set of warnings, so even when using GCC
+compatible #pragmas there is no guarantee that they will have identical behaviour
+on both compilers.
Precompiled Headers
@@ -465,6 +517,50 @@ for headers that are directly included within a source file. For example:
test.h since test.h was included directly in the source file
and not specified on the command line using -include.
+
Relocatable PCH Files
+
It is sometimes necessary to build a precompiled header from headers that
+are not yet in their final, installed locations. For example, one might build a
+precompiled header within the build tree that is then meant to be installed
+alongside the headers. Clang permits the creation of "relocatable" precompiled
+headers, which are built with a given path (into the build directory) and can
+later be used from an installed location.
+
+
To build a relocatable precompiled header, place your headers into a
+subdirectory whose structure mimics the installed location. For example, if you
+want to build a precompiled header for the header mylib.h that
+will be installed into /usr/include, create a subdirectory
+build/usr/include and place the header mylib.h into
+that subdirectory. If mylib.h depends on other headers, then
+they can be stored within build/usr/include in a way that mimics
+the installed location.
+
+
Building a relocatable precompiled header requires two additional arguments.
+First, pass the --relocatable-pch flag to indicate that the
+resulting PCH file should be relocatable. Second, pass
+-isysroot /path/to/build, which makes all includes for your
+library relative to the build directory. For example:
When loading the relocatable PCH file, the various headers used in the PCH
+file are found from the system header root. For example, mylib.h
+can be found in /usr/include/mylib.h. If the headers are installed
+in some other system root, the -isysroot option can be used provide
+a different system root from which the headers will be based. For example,
+-isysroot /Developer/SDKs/MacOSX10.4u.sdk will look for
+mylib.h in
+/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h.
+
+
Relocatable precompiled headers are intended to be used in a limited number
+of cases where the compilation environment is tightly controlled and the
+precompiled header cannot be generated after headers have been installed.
+Relocatable precompiled headers also have some performance impact, because
+the difference in location between the header locations at PCH build time vs.
+at the time of PCH use requires one of the PCH optimizations,
+stat() caching, to be disabled. However, this change is only
+likely to affect PCH files that reference a large number of headers.
C Language Features
@@ -500,7 +596,6 @@ variants "__asm__" and "__typeof__" are recognized in all modes.
The Apple "blocks" extension is recognized by default in gnu* modes
on some platforms; it can be enabled in any mode with the "-fblocks"
option.
-
Some warnings are different.
Differences between *89 and *99 modes:
diff --git a/docs/libIndex.html b/docs/libIndex.html
new file mode 100644
index 0000000000000..5693de80a8685
--- /dev/null
+++ b/docs/libIndex.html
@@ -0,0 +1,267 @@
+
+
+ The Index Library
+
+
+
+
+
+
+
+
+
+
The Index library is meant to provide the basic infrastructure for
+ cross-translation-unit analysis and is primarily focused on indexing
+ related functionality. It provides an API for clients that need to
+ accurately map the AST nodes of the ASTContext to the locations in the source files.
+It also allows them to analyze information across multiple translation units.
+
+
As a "general rule", ASTContexts are considered the primary source of
+information that a client wants about a translation unit. There will be no such class as an
+ "indexing database" that stores, for example, source locations of identifiers separately from ASTContext.
+All the information that a client needs from a translation unit will be extracted from the ASTContext.
+
+
Classes
+
+
Entity
+
+
To be able to reason about semantically the same Decls that are contained in multiple ASTContexts, the 'Entity' class was introduced.
+An Entity is an ASTContext-independent "token" that can be created from a Decl (and a typename in the future) with
+the purpose to "resolve" it into a Decl belonging to another ASTContext. Some examples to make the concept of Entities more clear:
+
+
+t1.c:
+
+void foo(void);
+void bar(void);
+
+
+
+
+t2.c:
+
+void foo(void) {
+}
+
+
+
+
+Translation unit t1.c contains 2 Entities foo and bar, while t2.c contains 1 Entity foo.
+Entities are uniqued in such a way that the Entity* pointer for t1.c/foo is the same as the Entity* pointer for t2.c/foo.
+An Entity doesn't convey any information about the declaration, it is more like an opaque pointer used only to get the
+associated Decl out of an ASTContext so that the actual information for the declaration can be accessed.
+Another important aspect of Entities is that they can only be created/associated for declarations that are visible outside the
+translation unit. This means that for:
+
+
+t3.c:
+
+static void foo(void);
+
+
+
+there can be no Entity (if you ask for the Entity* of the static function foo you'll get a null pointer).
+This is for 2 reasons:
+
+
To preserve the invariant that the same Entity* pointers refer to the same semantic Decls.
+ In the above example t1.c/foo and t2.c/foo are the same, while t3.c/foo is different.
+
The purpose of Entity is to get the same semantic Decl from multiple ASTContexts. For a Decl that is not visible
+ outside of its own translation unit, you don't need an Entity since it won't appear in another ASTContext.
+
+
+
+
ASTLocation
+
+Encapsulates a "point" in the AST tree of the ASTContext.
+It represents either a Decl*, or a Stmt* along with its immediate Decl* parent.
+An example for its usage is that libIndex will provide the references of foo in the form of ASTLocations,
+"pointing" at the expressions that reference foo.
+
+
DeclReferenceMap
+
+Accepts an ASTContext and creates a mapping from NamedDecls to the ASTLocations that reference them (in the same ASTContext).
+
+
Functions
+
+
ResolveLocationInAST
+
+A function that accepts an ASTContext and a SourceLocation which it resolves into an ASTLocation.
+
+
AST Files
+
+The precompiled headers implementation of clang (PCH) is ideal for storing an ASTContext in a compact form that
+will be loaded later for AST analysis. An "AST file" refers to a translation unit that was "compiled" into a precompiled header file.
+
+
index-test tool
+
+
Usage
+
+A command-line tool that exercises the libIndex API, useful for testing its features.
+As input it accepts multiple AST files (representing multiple translation units) and a few options:
+
+
+
+ -point-at [file:line:column]
+
+Resolves a [file:line:column] triplet into a ASTLocation from the first AST file. If no other option is specified, it prints the ASTLocation.
+It also prints a declaration's associated doxygen comment, if one is available.
+
+
+
+
+ -print-refs
+
+Prints the ASTLocations that reference the declaration that was resolved out of the [file:line:column] triplet
+
+
+
+
+ -print-defs
+
+Prints the ASTLocations that define the resolved declaration
+
+
+
+
+ -print-decls
+
+Prints the ASTLocations that declare the resolved declaration
+
+
+
Examples
+
+
+Here's an example of using index-test:
+
+
+
+We have 3 files,
+
+
+
+foo.h:
+
+extern int global_var;
+
+void foo_func(int param1);
+void bar_func(void);
+
+
+
+
diff --git a/docs/tools/Makefile b/docs/tools/Makefile
index 90eb7768f531b..12696ef0b659b 100644
--- a/docs/tools/Makefile
+++ b/docs/tools/Makefile
@@ -21,6 +21,7 @@ SRC_DOC_DIR=
DST_HTML_DIR=html/
DST_MAN_DIR=man/man1/
DST_PS_DIR=ps/
+CLANG_VERSION := trunk
# If we are in BUILD_FOR_WEBSITE mode, default to the all target.
all:: html man ps
@@ -39,6 +40,8 @@ else
LEVEL := ../../../..
include $(LEVEL)/Makefile.common
+CLANG_VERSION := $(shell cat $(PROJ_SRC_DIR)/../../VER)
+
SRC_DOC_DIR=$(PROJ_SRC_DIR)/
DST_HTML_DIR=$(PROJ_OBJ_DIR)/
DST_MAN_DIR=$(PROJ_OBJ_DIR)/
@@ -66,7 +69,7 @@ $(DST_HTML_DIR)%.html: %.pod $(DST_HTML_DIR)/.dir
--podpath=. --infile=$< --outfile=$@ --title=$*
$(DST_MAN_DIR)%.1: %.pod $(DST_MAN_DIR)/.dir
- pod2man --release "clang 1.0" --center="Clang Tools Documentation" $< $@
+ pod2man --release "clang $(CLANG_VERSION)" --center="Clang Tools Documentation" $< $@
$(DST_PS_DIR)%.ps: $(DST_MAN_DIR)%.1 $(DST_PS_DIR)/.dir
groff -Tps -man $< > $@
diff --git a/docs/tools/clang.pod b/docs/tools/clang.pod
index c520f93997e53..daa7387989309 100644
--- a/docs/tools/clang.pod
+++ b/docs/tools/clang.pod
@@ -378,8 +378,7 @@ Show commands to run and use verbose output.
=over
-=item
-B<-fshow-column>
+=item B<-fshow-column>
B<-fshow-source-location>
B<-fcaret-diagnostics>
B<-fdiagnostics-fixit-info>
@@ -428,13 +427,14 @@ Do not search the standard system directories for include files.
=cut
## TODO, but do we really want people using this stuff?
-=item B<-idirafter>I
-=item B<-iquote>I
-=item B<-isystem>I
-=item B<-iprefix>I
-=item B<-iwithprefix>I
-=item B<-iwithprefixbefore>I
-=item B<-isysroot>
+#=item B<-idirafter>I
+#=item B<-iquote>I
+#=item B<-isystem>I
+#=item B<-iprefix>I
+#=item B<-iwithprefix>I
+#=item B<-iwithprefixbefore>I
+#=item B<-isysroot>
+
=pod
@@ -445,21 +445,21 @@ Do not search the standard system directories for include files.
=cut
### TODO someday.
-=head2 Warning Control Options
-=over
-=back
-=head2 Code Generation and Optimization Options
-=over
-=back
-=head2 Assembler Options
-=over
-=back
-=head2 Linker Options
-=over
-=back
-=head2 Static Analyzer Options
-=over
-=back
+#=head2 Warning Control Options
+#=over
+#=back
+#=head2 Code Generation and Optimization Options
+#=over
+#=back
+#=head2 Assembler Options
+#=over
+#=back
+#=head2 Linker Options
+#=over
+#=back
+#=head2 Static Analyzer Options
+#=over
+#=back
=pod
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
new file mode 100644
index 0000000000000..3178017e45be8
--- /dev/null
+++ b/include/clang-c/Index.h
@@ -0,0 +1,220 @@
+/*===-- clang-c/Index.h - Indexing Public C Interface -------------*- C -*-===*\
+|* *|
+|* The LLVM Compiler Infrastructure *|
+|* *|
+|* This file is distributed under the University of Illinois Open Source *|
+|* License. See LICENSE.TXT for details. *|
+|* *|
+|*===----------------------------------------------------------------------===*|
+|* *|
+|* This header provides a public inferface to a Clang library for extracting *|
+|* high-level symbol information from source files without exposing the full *|
+|* Clang C++ API. *|
+|* *|
+\*===----------------------------------------------------------------------===*/
+
+#ifndef CLANG_C_INDEX_H
+#define CLANG_C_INDEX_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ Clang indeX abstractions. The backing store for the following API's will be
+ clangs AST file (currently based on PCH). AST files are created as follows:
+
+ "clang -emit-ast -o ".
+
+ Naming Conventions: To avoid namespace pollution, data types are prefixed
+ with "CX" and functions are prefixed with "clang_".
+*/
+typedef void *CXIndex; /* An indexing instance. */
+
+typedef void *CXTranslationUnit; /* A translation unit instance. */
+
+typedef void *CXDecl; /* A specific declaration within a translation unit. */
+typedef void *CXStmt; /* A specific statement within a function/method */
+
+/* Cursors represent declarations, definitions, and references. */
+enum CXCursorKind {
+ /* Declarations */
+ CXCursor_FirstDecl = 1,
+ CXCursor_TypedefDecl = 2,
+ CXCursor_StructDecl = 3,
+ CXCursor_UnionDecl = 4,
+ CXCursor_ClassDecl = 5,
+ CXCursor_EnumDecl = 6,
+ CXCursor_FieldDecl = 7,
+ CXCursor_EnumConstantDecl = 8,
+ CXCursor_FunctionDecl = 9,
+ CXCursor_VarDecl = 10,
+ CXCursor_ParmDecl = 11,
+ CXCursor_ObjCInterfaceDecl = 12,
+ CXCursor_ObjCCategoryDecl = 13,
+ CXCursor_ObjCProtocolDecl = 14,
+ CXCursor_ObjCPropertyDecl = 15,
+ CXCursor_ObjCIvarDecl = 16,
+ CXCursor_ObjCInstanceMethodDecl = 17,
+ CXCursor_ObjCClassMethodDecl = 18,
+ CXCursor_LastDecl = 18,
+
+ /* Definitions */
+ CXCursor_FirstDefn = 32,
+ CXCursor_FunctionDefn = 32,
+ CXCursor_ObjCClassDefn = 33,
+ CXCursor_ObjCCategoryDefn = 34,
+ CXCursor_ObjCInstanceMethodDefn = 35,
+ CXCursor_ObjCClassMethodDefn = 36,
+ CXCursor_LastDefn = 36,
+
+ /* References */
+ CXCursor_FirstRef = 40, /* Decl references */
+ CXCursor_ObjCSuperClassRef = 40,
+ CXCursor_ObjCProtocolRef = 41,
+ CXCursor_ObjCClassRef = 42,
+
+ CXCursor_ObjCSelectorRef = 43, /* Expression references */
+ CXCursor_ObjCIvarRef = 44,
+ CXCursor_VarRef = 45,
+ CXCursor_FunctionRef = 46,
+ CXCursor_EnumConstantRef = 47,
+ CXCursor_MemberRef = 48,
+ CXCursor_LastRef = 48,
+
+ /* Error conditions */
+ CXCursor_FirstInvalid = 70,
+ CXCursor_InvalidFile = 70,
+ CXCursor_NoDeclFound = 71,
+ CXCursor_NotImplemented = 72,
+ CXCursor_LastInvalid = 72
+};
+
+/* A cursor into the CXTranslationUnit. */
+
+typedef struct {
+ enum CXCursorKind kind;
+ CXDecl decl;
+ CXStmt stmt; /* expression reference */
+} CXCursor;
+
+/* A unique token for looking up "visible" CXDecls from a CXTranslationUnit. */
+typedef void *CXEntity;
+
+CXIndex clang_createIndex();
+void clang_disposeIndex(CXIndex);
+
+const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
+
+CXTranslationUnit clang_createTranslationUnit(
+ CXIndex, const char *ast_filename
+);
+void clang_disposeTranslationUnit(CXTranslationUnit);
+
+/*
+ Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
+ within a translation unit, issuing a 'callback' for each one.
+
+ void printObjCInterfaceNames(CXTranslationUnit X, CXCursor C) {
+ if (clang_getCursorKind(C) == Cursor_Declaration) {
+ CXDecl D = clang_getCursorDecl(C);
+ if (clang_getDeclKind(D) == CXDecl_ObjC_interface)
+ printf("@interface %s in file %s on line %d column %d\n",
+ clang_getDeclSpelling(D), clang_getCursorSource(C),
+ clang_getCursorLine(C), clang_getCursorColumn(C));
+ }
+ }
+ static void usage {
+ clang_loadTranslationUnit(CXTranslationUnit, printObjCInterfaceNames);
+ }
+*/
+typedef void *CXClientData;
+typedef void (*CXTranslationUnitIterator)(CXTranslationUnit, CXCursor,
+ CXClientData);
+void clang_loadTranslationUnit(CXTranslationUnit, CXTranslationUnitIterator,
+ CXClientData);
+
+/*
+ Usage: clang_loadDeclaration(). Will load the declaration, issuing a
+ 'callback' for each declaration/reference within the respective declaration.
+
+ For interface declarations, this will index the super class, protocols,
+ ivars, methods, etc. For structure declarations, this will index the fields.
+ For functions, this will index the parameters (and body, for function
+ definitions), local declarations/references.
+
+ void getInterfaceDetails(CXDecl X, CXCursor C) {
+ switch (clang_getCursorKind(C)) {
+ case Cursor_ObjC_ClassRef:
+ CXDecl SuperClass = clang_getCursorDecl(C);
+ case Cursor_ObjC_ProtocolRef:
+ CXDecl AdoptsProtocol = clang_getCursorDecl(C);
+ case Cursor_Declaration:
+ CXDecl AnIvarOrMethod = clang_getCursorDecl(C);
+ }
+ }
+ static void usage() {
+ if (clang_getDeclKind(D) == CXDecl_ObjC_interface) {
+ clang_loadDeclaration(D, getInterfaceDetails);
+ }
+ }
+*/
+typedef void (*CXDeclIterator)(CXDecl, CXCursor, CXClientData);
+
+void clang_loadDeclaration(CXDecl, CXDeclIterator, CXClientData);
+
+/*
+ * CXEntity Operations.
+ */
+const char *clang_getDeclarationName(CXEntity);
+const char *clang_getURI(CXEntity);
+CXEntity clang_getEntity(const char *URI);
+/*
+ * CXDecl Operations.
+ */
+CXCursor clang_getCursorFromDecl(CXDecl);
+CXEntity clang_getEntityFromDecl(CXDecl);
+const char *clang_getDeclSpelling(CXDecl);
+unsigned clang_getDeclLine(CXDecl);
+unsigned clang_getDeclColumn(CXDecl);
+const char *clang_getDeclSource(CXDecl);
+
+/*
+ * CXCursor Operations.
+ */
+CXCursor clang_getCursor(CXTranslationUnit, const char *source_name,
+ unsigned line, unsigned column);
+
+enum CXCursorKind clang_getCursorKind(CXCursor);
+unsigned clang_isDeclaration(enum CXCursorKind);
+unsigned clang_isReference(enum CXCursorKind);
+unsigned clang_isDefinition(enum CXCursorKind);
+unsigned clang_isInvalid(enum CXCursorKind);
+
+unsigned clang_getCursorLine(CXCursor);
+unsigned clang_getCursorColumn(CXCursor);
+const char *clang_getCursorSource(CXCursor);
+const char *clang_getCursorSpelling(CXCursor);
+
+/* for debug/testing */
+const char *clang_getCursorKindSpelling(enum CXCursorKind Kind);
+void clang_getDefinitionSpellingAndExtent(CXCursor,
+ const char **startBuf,
+ const char **endBuf,
+ unsigned *startLine,
+ unsigned *startColumn,
+ unsigned *endLine,
+ unsigned *endColumn);
+
+/*
+ * If CXCursorKind == Cursor_Reference, then this will return the referenced
+ * declaration.
+ * If CXCursorKind == Cursor_Declaration, then this will return the declaration.
+ */
+CXDecl clang_getCursorDecl(CXCursor);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
diff --git a/include/clang/AST/APValue.h b/include/clang/AST/APValue.h
index 5d5abfe011d4f..94d258d9e4e6d 100644
--- a/include/clang/AST/APValue.h
+++ b/include/clang/AST/APValue.h
@@ -37,16 +37,16 @@ public:
};
private:
ValueKind Kind;
-
- struct ComplexAPSInt {
- APSInt Real, Imag;
+
+ struct ComplexAPSInt {
+ APSInt Real, Imag;
ComplexAPSInt() : Real(1), Imag(1) {}
};
struct ComplexAPFloat {
APFloat Real, Imag;
ComplexAPFloat() : Real(0.0), Imag(0.0) {}
};
-
+
struct LV {
Expr* Base;
uint64_t Offset;
@@ -57,16 +57,17 @@ private:
Vec() : Elts(0), NumElts(0) {}
~Vec() { delete[] Elts; }
};
-
+
enum {
- MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ?
+ MaxSize = (sizeof(ComplexAPSInt) > sizeof(ComplexAPFloat) ?
sizeof(ComplexAPSInt) : sizeof(ComplexAPFloat))
};
-
- /// Data - space for the largest member in units of void*. This is an effort
- /// to ensure that the APSInt/APFloat values have proper alignment.
- void *Data[(MaxSize+sizeof(void*)-1)/sizeof(void*)];
-
+
+ union {
+ void *Aligner;
+ char Data[MaxSize];
+ };
+
public:
APValue() : Kind(Uninitialized) {}
explicit APValue(const APSInt &I) : Kind(Uninitialized) {
@@ -93,7 +94,7 @@ public:
~APValue() {
MakeUninit();
}
-
+
ValueKind getKind() const { return Kind; }
bool isUninit() const { return Kind == Uninitialized; }
bool isInt() const { return Kind == Int; }
@@ -102,54 +103,54 @@ public:
bool isComplexFloat() const { return Kind == ComplexFloat; }
bool isLValue() const { return Kind == LValue; }
bool isVector() const { return Kind == Vector; }
-
+
void print(llvm::raw_ostream &OS) const;
void dump() const;
-
+
APSInt &getInt() {
assert(isInt() && "Invalid accessor");
- return *(APSInt*)(void*)Data;
+ return *(APSInt*)(char*)Data;
}
const APSInt &getInt() const {
return const_cast(this)->getInt();
}
-
+
APFloat &getFloat() {
assert(isFloat() && "Invalid accessor");
- return *(APFloat*)(void*)Data;
+ return *(APFloat*)(char*)Data;
}
const APFloat &getFloat() const {
return const_cast(this)->getFloat();
}
-
+
APValue &getVectorElt(unsigned i) const {
assert(isVector() && "Invalid accessor");
- return ((Vec*)(void*)Data)->Elts[i];
+ return ((Vec*)(char*)Data)->Elts[i];
}
unsigned getVectorLength() const {
assert(isVector() && "Invalid accessor");
return ((Vec*)(void *)Data)->NumElts;
}
-
+
APSInt &getComplexIntReal() {
assert(isComplexInt() && "Invalid accessor");
- return ((ComplexAPSInt*)(void*)Data)->Real;
+ return ((ComplexAPSInt*)(char*)Data)->Real;
}
const APSInt &getComplexIntReal() const {
return const_cast(this)->getComplexIntReal();
}
-
+
APSInt &getComplexIntImag() {
assert(isComplexInt() && "Invalid accessor");
- return ((ComplexAPSInt*)(void*)Data)->Imag;
+ return ((ComplexAPSInt*)(char*)Data)->Imag;
}
const APSInt &getComplexIntImag() const {
return const_cast(this)->getComplexIntImag();
}
-
+
APFloat &getComplexFloatReal() {
assert(isComplexFloat() && "Invalid accessor");
- return ((ComplexAPFloat*)(void*)Data)->Real;
+ return ((ComplexAPFloat*)(char*)Data)->Real;
}
const APFloat &getComplexFloatReal() const {
return const_cast(this)->getComplexFloatReal();
@@ -157,7 +158,7 @@ public:
APFloat &getComplexFloatImag() {
assert(isComplexFloat() && "Invalid accessor");
- return ((ComplexAPFloat*)(void*)Data)->Imag;
+ return ((ComplexAPFloat*)(char*)Data)->Imag;
}
const APFloat &getComplexFloatImag() const {
return const_cast(this)->getComplexFloatImag();
@@ -171,44 +172,44 @@ public:
assert(isLValue() && "Invalid accessor");
return ((const LV*)(const void*)Data)->Offset;
}
-
+
void setInt(const APSInt &I) {
assert(isInt() && "Invalid accessor");
- *(APSInt*)(void*)Data = I;
+ *(APSInt*)(char*)Data = I;
}
void setFloat(const APFloat &F) {
assert(isFloat() && "Invalid accessor");
- *(APFloat*)(void*)Data = F;
+ *(APFloat*)(char*)Data = F;
}
void setVector(const APValue *E, unsigned N) {
assert(isVector() && "Invalid accessor");
- ((Vec*)(void*)Data)->Elts = new APValue[N];
- ((Vec*)(void*)Data)->NumElts = N;
+ ((Vec*)(char*)Data)->Elts = new APValue[N];
+ ((Vec*)(char*)Data)->NumElts = N;
for (unsigned i = 0; i != N; ++i)
- ((Vec*)(void*)Data)->Elts[i] = E[i];
+ ((Vec*)(char*)Data)->Elts[i] = E[i];
}
void setComplexInt(const APSInt &R, const APSInt &I) {
- assert(R.getBitWidth() == I.getBitWidth() &&
+ assert(R.getBitWidth() == I.getBitWidth() &&
"Invalid complex int (type mismatch).");
assert(isComplexInt() && "Invalid accessor");
- ((ComplexAPSInt*)(void*)Data)->Real = R;
- ((ComplexAPSInt*)(void*)Data)->Imag = I;
+ ((ComplexAPSInt*)(char*)Data)->Real = R;
+ ((ComplexAPSInt*)(char*)Data)->Imag = I;
}
void setComplexFloat(const APFloat &R, const APFloat &I) {
- assert(&R.getSemantics() == &I.getSemantics() &&
+ assert(&R.getSemantics() == &I.getSemantics() &&
"Invalid complex float (type mismatch).");
assert(isComplexFloat() && "Invalid accessor");
- ((ComplexAPFloat*)(void*)Data)->Real = R;
- ((ComplexAPFloat*)(void*)Data)->Imag = I;
+ ((ComplexAPFloat*)(char*)Data)->Real = R;
+ ((ComplexAPFloat*)(char*)Data)->Imag = I;
}
void setLValue(Expr *B, uint64_t O) {
assert(isLValue() && "Invalid accessor");
- ((LV*)(void*)Data)->Base = B;
- ((LV*)(void*)Data)->Offset = O;
+ ((LV*)(char*)Data)->Base = B;
+ ((LV*)(char*)Data)->Offset = O;
}
-
+
const APValue &operator=(const APValue &RHS);
-
+
private:
void MakeUninit();
void MakeInt() {
@@ -218,27 +219,27 @@ private:
}
void MakeFloat() {
assert(isUninit() && "Bad state change");
- new ((APFloat*)(void*)Data) APFloat(0.0);
+ new ((void*)(char*)Data) APFloat(0.0);
Kind = Float;
}
void MakeVector() {
assert(isUninit() && "Bad state change");
- new ((Vec*)(void*)Data) Vec();
+ new ((void*)(char*)Data) Vec();
Kind = Vector;
}
void MakeComplexInt() {
assert(isUninit() && "Bad state change");
- new ((ComplexAPSInt*)(void*)Data) ComplexAPSInt();
+ new ((void*)(char*)Data) ComplexAPSInt();
Kind = ComplexInt;
}
void MakeComplexFloat() {
assert(isUninit() && "Bad state change");
- new ((ComplexAPFloat*)(void*)Data) ComplexAPFloat();
+ new ((void*)(char*)Data) ComplexAPFloat();
Kind = ComplexFloat;
}
void MakeLValue() {
assert(isUninit() && "Bad state change");
- new ((LV*)(void*)Data) LV();
+ new ((void*)(char*)Data) LV();
Kind = LValue;
}
};
@@ -247,7 +248,7 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const APValue &V) {
V.print(OS);
return OS;
}
-
+
} // end namespace clang.
#endif
diff --git a/include/clang/AST/ASTConsumer.h b/include/clang/AST/ASTConsumer.h
index 6dc7e13d8f70c..af6bf30b6882d 100644
--- a/include/clang/AST/ASTConsumer.h
+++ b/include/clang/AST/ASTConsumer.h
@@ -36,27 +36,27 @@ public:
ASTConsumer() : SemaConsumer(false) { }
virtual ~ASTConsumer() {}
-
+
/// Initialize - This is called to initialize the consumer, providing the
/// ASTContext and the Action.
virtual void Initialize(ASTContext &Context) {}
-
+
/// HandleTopLevelDecl - Handle the specified top-level declaration. This is
/// called by the parser to process every top-level Decl*. Note that D can
/// be the head of a chain of Decls (e.g. for `int a, b` the chain will have
/// two elements). Use Decl::getNextDeclarator() to walk the chain.
virtual void HandleTopLevelDecl(DeclGroupRef D);
-
+
/// HandleTranslationUnit - This method is called when the ASTs for entire
/// translation unit have been parsed.
- virtual void HandleTranslationUnit(ASTContext &Ctx) {}
-
+ virtual void HandleTranslationUnit(ASTContext &Ctx) {}
+
/// HandleTagDeclDefinition - This callback is invoked each time a TagDecl
/// (e.g. struct, union, enum, class) is completed. This allows the client to
/// hack on the type, which can occur at any point in the file (because these
/// can be defined in declspecs).
virtual void HandleTagDeclDefinition(TagDecl *D) {}
-
+
/// \brief Callback invoked at the end of a translation unit to
/// notify the consumer that the given tentative definition should
/// be completed.
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 041a0f33ad4d7..63f909146e927 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -22,6 +22,7 @@
#include "clang/AST/PrettyPrinter.h"
#include "clang/AST/TemplateName.h"
#include "clang/AST/Type.h"
+#include "clang/AST/CanonicalType.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/OwningPtr.h"
@@ -43,24 +44,26 @@ namespace clang {
class TargetInfo;
// Decls
class Decl;
+ class FieldDecl;
+ class ObjCIvarDecl;
+ class ObjCIvarRefExpr;
class ObjCPropertyDecl;
class RecordDecl;
class TagDecl;
+ class TemplateTypeParmDecl;
class TranslationUnitDecl;
class TypeDecl;
class TypedefDecl;
- class TemplateTypeParmDecl;
- class FieldDecl;
- class ObjCIvarRefExpr;
- class ObjCIvarDecl;
-
+ class UnresolvedUsingDecl;
+ class UsingDecl;
+
namespace Builtin { class Context; }
-
+
/// ASTContext - This class holds long-lived AST nodes (such as types and
/// decls) that can be referred to throughout the semantic analysis of a file.
-class ASTContext {
+class ASTContext {
std::vector Types;
- llvm::FoldingSet ExtQualTypes;
+ llvm::FoldingSet ExtQualNodes;
llvm::FoldingSet ComplexTypes;
llvm::FoldingSet PointerTypes;
llvm::FoldingSet BlockPointerTypes;
@@ -70,17 +73,21 @@ class ASTContext {
llvm::FoldingSet ConstantArrayTypes;
llvm::FoldingSet IncompleteArrayTypes;
std::vector VariableArrayTypes;
- std::vector DependentSizedArrayTypes;
- std::vector DependentSizedExtVectorTypes;
+ llvm::FoldingSet DependentSizedArrayTypes;
+ llvm::FoldingSet DependentSizedExtVectorTypes;
llvm::FoldingSet VectorTypes;
llvm::FoldingSet FunctionNoProtoTypes;
llvm::FoldingSet FunctionProtoTypes;
+ llvm::FoldingSet DependentTypeOfExprTypes;
+ llvm::FoldingSet DependentDecltypeTypes;
llvm::FoldingSet TemplateTypeParmTypes;
llvm::FoldingSet TemplateSpecializationTypes;
llvm::FoldingSet QualifiedNameTypes;
llvm::FoldingSet TypenameTypes;
- llvm::FoldingSet ObjCQualifiedInterfaceTypes;
+ llvm::FoldingSet ObjCInterfaceTypes;
llvm::FoldingSet ObjCObjectPointerTypes;
+ llvm::FoldingSet ObjCProtocolListTypes;
+ llvm::FoldingSet ElaboratedTypes;
llvm::FoldingSet QualifiedTemplateNames;
llvm::FoldingSet DependentTemplateNames;
@@ -97,46 +104,109 @@ class ASTContext {
llvm::DenseMap ASTRecordLayouts;
llvm::DenseMap ObjCLayouts;
+ /// \brief Mapping from ObjCContainers to their ObjCImplementations.
+ llvm::DenseMap ObjCImpls;
+
llvm::DenseMap SignedFixedWidthIntTypes;
llvm::DenseMap UnsignedFixedWidthIntTypes;
-
+
/// BuiltinVaListType - built-in va list type.
/// This is initially null and set by Sema::LazilyCreateBuiltin when
/// a builtin that takes a valist is encountered.
QualType BuiltinVaListType;
/// ObjCIdType - a pseudo built-in typedef type (set by Sema).
- QualType ObjCIdType;
- const RecordType *IdStructType;
-
+ QualType ObjCIdTypedefType;
+
/// ObjCSelType - another pseudo built-in typedef type (set by Sema).
QualType ObjCSelType;
const RecordType *SelStructType;
-
+
/// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
QualType ObjCProtoType;
const RecordType *ProtoStructType;
/// ObjCClassType - another pseudo built-in typedef type (set by Sema).
- QualType ObjCClassType;
- const RecordType *ClassStructType;
-
+ QualType ObjCClassTypedefType;
+
QualType ObjCConstantStringType;
RecordDecl *CFConstantStringTypeDecl;
RecordDecl *ObjCFastEnumerationStateTypeDecl;
-
- /// \brief Keeps track of all declaration attributes.
+
+ /// \brief The type for the C FILE type.
+ TypeDecl *FILEDecl;
+
+ /// \brief The type for the C jmp_buf type.
+ TypeDecl *jmp_bufDecl;
+
+ /// \brief The type for the C sigjmp_buf type.
+ TypeDecl *sigjmp_bufDecl;
+
+ /// \brief Keeps track of all declaration attributes.
///
/// Since so few decls have attrs, we keep them in a hash map instead of
/// wasting space in the Decl class.
llvm::DenseMap DeclAttrs;
-
+
+ /// \brief Keeps track of the static data member templates from which
+ /// static data members of class template specializations were instantiated.
+ ///
+ /// This data structure stores the mapping from instantiations of static
+ /// data members to the static data member representations within the
+ /// class template from which they were instantiated along with the kind
+ /// of instantiation or specialization (a TemplateSpecializationKind - 1).
+ ///
+ /// Given the following example:
+ ///
+ /// \code
+ /// template
+ /// struct X {
+ /// static T value;
+ /// };
+ ///
+ /// template
+ /// T X::value = T(17);
+ ///
+ /// int *x = &X::value;
+ /// \endcode
+ ///
+ /// This mapping will contain an entry that maps from the VarDecl for
+ /// X::value to the corresponding VarDecl for X::value (within the
+ /// class template X) and will be marked TSK_ImplicitInstantiation.
+ llvm::DenseMap
+ InstantiatedFromStaticDataMember;
+
+ /// \brief Keeps track of the UnresolvedUsingDecls from which UsingDecls
+ /// where created during instantiation.
+ ///
+ /// For example:
+ /// \code
+ /// template
+ /// struct A {
+ /// void f();
+ /// };
+ ///
+ /// template
+ /// struct B : A {
+ /// using A::f;
+ /// };
+ ///
+ /// template struct B;
+ /// \endcode
+ ///
+ /// This mapping will contain an entry that maps from the UsingDecl in
+ /// B to the UnresolvedUsingDecl in B.
+ llvm::DenseMap
+ InstantiatedFromUnresolvedUsingDecl;
+
+ llvm::DenseMap InstantiatedFromUnnamedFieldDecl;
+
TranslationUnitDecl *TUDecl;
/// SourceMgr - The associated SourceManager object.
SourceManager &SourceMgr;
-
+
/// LangOpts - The language options used to create the AST associated with
/// this ASTContext object.
LangOptions LangOpts;
@@ -144,17 +214,17 @@ class ASTContext {
/// \brief Whether we have already loaded comment source ranges from an
/// external source.
bool LoadedExternalComments;
-
+
/// MallocAlloc/BumpAlloc - The allocator objects used to create AST objects.
bool FreeMemory;
llvm::MallocAllocator MallocAlloc;
llvm::BumpPtrAllocator BumpAlloc;
-
+
/// \brief Mapping from declarations to their comments, once we have
/// already looked up the comment associated with a given declaration.
llvm::DenseMap DeclComments;
-
-public:
+
+public:
TargetInfo &Target;
IdentifierTable &Idents;
SelectorTable &Selectors;
@@ -163,41 +233,73 @@ public:
llvm::OwningPtr ExternalSource;
clang::PrintingPolicy PrintingPolicy;
+ // Typedefs which may be provided defining the structure of Objective-C
+ // pseudo-builtins
+ QualType ObjCIdRedefinitionType;
+ QualType ObjCClassRedefinitionType;
+
/// \brief Source ranges for all of the comments in the source file,
/// sorted in order of appearance in the translation unit.
std::vector Comments;
-
+
SourceManager& getSourceManager() { return SourceMgr; }
const SourceManager& getSourceManager() const { return SourceMgr; }
void *Allocate(unsigned Size, unsigned Align = 8) {
return FreeMemory ? MallocAlloc.Allocate(Size, Align) :
BumpAlloc.Allocate(Size, Align);
}
- void Deallocate(void *Ptr) {
+ void Deallocate(void *Ptr) {
if (FreeMemory)
- MallocAlloc.Deallocate(Ptr);
+ MallocAlloc.Deallocate(Ptr);
}
const LangOptions& getLangOptions() const { return LangOpts; }
-
- FullSourceLoc getFullLoc(SourceLocation Loc) const {
+
+ FullSourceLoc getFullLoc(SourceLocation Loc) const {
return FullSourceLoc(Loc,SourceMgr);
}
/// \brief Retrieve the attributes for the given declaration.
Attr*& getDeclAttrs(const Decl *D) { return DeclAttrs[D]; }
-
+
/// \brief Erase the attributes corresponding to the given declaration.
void eraseDeclAttrs(const Decl *D) { DeclAttrs.erase(D); }
-
+
+ /// \brief If this variable is an instantiated static data member of a
+ /// class template specialization, returns the templated static data member
+ /// from which it was instantiated.
+ MemberSpecializationInfo *getInstantiatedFromStaticDataMember(VarDecl *Var);
+
+ /// \brief Note that the static data member \p Inst is an instantiation of
+ /// the static data member template \p Tmpl of a class template.
+ void setInstantiatedFromStaticDataMember(VarDecl *Inst, VarDecl *Tmpl,
+ TemplateSpecializationKind TSK);
+
+ /// \brief If this using decl is instantiated from an unresolved using decl,
+ /// return it.
+ UnresolvedUsingDecl *getInstantiatedFromUnresolvedUsingDecl(UsingDecl *UUD);
+
+ /// \brief Note that the using decl \p Inst is an instantiation of
+ /// the unresolved using decl \p Tmpl of a class template.
+ void setInstantiatedFromUnresolvedUsingDecl(UsingDecl *Inst,
+ UnresolvedUsingDecl *Tmpl);
+
+
+ FieldDecl *getInstantiatedFromUnnamedFieldDecl(FieldDecl *Field);
+
+ void setInstantiatedFromUnnamedFieldDecl(FieldDecl *Inst, FieldDecl *Tmpl);
+
TranslationUnitDecl *getTranslationUnitDecl() const { return TUDecl; }
+
const char *getCommentForDecl(const Decl *D);
-
+
// Builtin Types.
QualType VoidTy;
QualType BoolTy;
QualType CharTy;
- QualType WCharTy; // [C++ 3.9.1p5], integer type in C99.
+ QualType WCharTy; // [C++ 3.9.1p5], integer type in C99.
+ QualType Char16Ty; // [C++0x 3.9.1p5], integer type in C99.
+ QualType Char32Ty; // [C++0x 3.9.1p5], integer type in C99.
QualType SignedCharTy, ShortTy, IntTy, LongTy, LongLongTy, Int128Ty;
QualType UnsignedCharTy, UnsignedShortTy, UnsignedIntTy, UnsignedLongTy;
QualType UnsignedLongLongTy, UnsignedInt128Ty;
@@ -207,6 +309,7 @@ public:
QualType OverloadTy;
QualType DependentTy;
QualType UndeducedAutoTy;
+ QualType ObjCBuiltinIdTy, ObjCBuiltinClassTy;
ASTContext(const LangOptions& LOpts, SourceManager &SM, TargetInfo &t,
IdentifierTable &idents, SelectorTable &sels,
@@ -232,23 +335,52 @@ public:
//===--------------------------------------------------------------------===//
// Type Constructors
//===--------------------------------------------------------------------===//
-
- /// getAddSpaceQualType - Return the uniqued reference to the type for an
- /// address space qualified type with the specified type and address space.
- /// The resulting type has a union of the qualifiers from T and the address
- /// space. If T already has an address space specifier, it is silently
+
+private:
+ /// getExtQualType - Return a type with extended qualifiers.
+ QualType getExtQualType(const Type *Base, Qualifiers Quals);
+
+public:
+ /// getAddSpaceQualType - Return the uniqued reference to the type for an
+ /// address space qualified type with the specified type and address space.
+ /// The resulting type has a union of the qualifiers from T and the address
+ /// space. If T already has an address space specifier, it is silently
/// replaced.
QualType getAddrSpaceQualType(QualType T, unsigned AddressSpace);
-
+
/// getObjCGCQualType - Returns the uniqued reference to the type for an
/// objc gc qualified type. The retulting type has a union of the qualifiers
/// from T and the gc attribute.
- QualType getObjCGCQualType(QualType T, QualType::GCAttrTypes gcAttr);
-
+ QualType getObjCGCQualType(QualType T, Qualifiers::GC gcAttr);
+
+ /// getRestrictType - Returns the uniqued reference to the type for a
+ /// 'restrict' qualified type. The resulting type has a union of the
+ /// qualifiers from T and 'restrict'.
+ QualType getRestrictType(QualType T) {
+ return T.withFastQualifiers(Qualifiers::Restrict);
+ }
+
+ /// getVolatileType - Returns the uniqued reference to the type for a
+ /// 'volatile' qualified type. The resulting type has a union of the
+ /// qualifiers from T and 'volatile'.
+ QualType getVolatileType(QualType T);
+
+ /// getConstType - Returns the uniqued reference to the type for a
+ /// 'const' qualified type. The resulting type has a union of the
+ /// qualifiers from T and 'const'.
+ ///
+ /// It can be reasonably expected that this will always be
+ /// equivalent to calling T.withConst().
+ QualType getConstType(QualType T) { return T.withConst(); }
+
+ /// getNoReturnType - Add the noreturn attribute to the given type which must
+ /// be a FunctionType or a pointer to an allowable type or a BlockPointer.
+ QualType getNoReturnType(QualType T);
+
/// getComplexType - Return the uniqued reference to the type for a complex
/// number with the specified element type.
QualType getComplexType(QualType T);
-
+
/// getPointerType - Return the uniqued reference to the type for a pointer to
/// the specified type.
QualType getPointerType(QualType T);
@@ -274,15 +406,17 @@ public:
/// variable array of the specified element type.
QualType getVariableArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals);
-
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
+
/// getDependentSizedArrayType - Returns a non-unique reference to
/// the type for a dependently-sized array of the specified element
/// type. FIXME: We will need these to be uniqued, or at least
/// comparable, at some point.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts,
ArrayType::ArraySizeModifier ASM,
- unsigned EltTypeQuals);
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
/// getIncompleteArrayType - Returns a unique reference to the type for a
/// incomplete array of the specified element type.
@@ -295,7 +429,23 @@ public:
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize,
ArrayType::ArraySizeModifier ASM,
unsigned EltTypeQuals);
-
+
+ /// getConstantArrayWithExprType - Return a reference to the type for a
+ /// constant array of the specified element type.
+ QualType getConstantArrayWithExprType(QualType EltTy,
+ const llvm::APInt &ArySize,
+ Expr *ArySizeExpr,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals,
+ SourceRange Brackets);
+
+ /// getConstantArrayWithoutExprType - Return a reference to the type
+ /// for a constant array of the specified element type.
+ QualType getConstantArrayWithoutExprType(QualType EltTy,
+ const llvm::APInt &ArySize,
+ ArrayType::ArraySizeModifier ASM,
+ unsigned EltTypeQuals);
+
/// getVectorType - Return the unique reference to a vector type of
/// the specified element type and size. VectorType must be a built-in type.
QualType getVectorType(QualType VectorType, unsigned NumElts);
@@ -309,13 +459,13 @@ public:
/// the type for a dependently-sized vector of the specified element
/// type. FIXME: We will need these to be uniqued, or at least
/// comparable, at some point.
- QualType getDependentSizedExtVectorType(QualType VectorType,
+ QualType getDependentSizedExtVectorType(QualType VectorType,
Expr *SizeExpr,
SourceLocation AttrLoc);
/// getFunctionNoProtoType - Return a K&R style C function type like 'int()'.
///
- QualType getFunctionNoProtoType(QualType ResultTy);
+ QualType getFunctionNoProtoType(QualType ResultTy, bool NoReturn = false);
/// getFunctionType - Return a normal function type with a typed argument
/// list. isVariadic indicates whether the argument list includes '...'.
@@ -323,7 +473,8 @@ public:
unsigned NumArgs, bool isVariadic,
unsigned TypeQuals, bool hasExceptionSpec = false,
bool hasAnyExceptionSpec = false,
- unsigned NumExs = 0, const QualType *ExArray = 0);
+ unsigned NumExs = 0, const QualType *ExArray = 0,
+ bool NoReturn = false);
/// getTypeDeclType - Return the unique reference to the type for
/// the specified type declaration.
@@ -332,9 +483,8 @@ public:
/// getTypedefType - Return the unique reference to the type for the
/// specified typename decl.
QualType getTypedefType(TypedefDecl *Decl);
- QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl);
- QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
+ QualType getTemplateTypeParmType(unsigned Depth, unsigned Index,
bool ParameterPack,
IdentifierInfo *Name = 0);
@@ -345,37 +495,40 @@ public:
QualType getQualifiedNameType(NestedNameSpecifier *NNS,
QualType NamedType);
- QualType getTypenameType(NestedNameSpecifier *NNS,
+ QualType getTypenameType(NestedNameSpecifier *NNS,
const IdentifierInfo *Name,
QualType Canon = QualType());
- QualType getTypenameType(NestedNameSpecifier *NNS,
+ QualType getTypenameType(NestedNameSpecifier *NNS,
const TemplateSpecializationType *TemplateId,
QualType Canon = QualType());
+ QualType getElaboratedType(QualType UnderlyingType,
+ ElaboratedType::TagKind Tag);
+
+ QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl,
+ ObjCProtocolDecl **Protocols = 0,
+ unsigned NumProtocols = 0);
/// getObjCObjectPointerType - Return a ObjCObjectPointerType type for the
/// given interface decl and the conforming protocol list.
- QualType getObjCObjectPointerType(ObjCInterfaceDecl *Decl,
+ QualType getObjCObjectPointerType(QualType OIT,
ObjCProtocolDecl **ProtocolList = 0,
unsigned NumProtocols = 0);
-
- /// getObjCQualifiedInterfaceType - Return a
- /// ObjCQualifiedInterfaceType type for the given interface decl and
- /// the conforming protocol list.
- QualType getObjCQualifiedInterfaceType(ObjCInterfaceDecl *Decl,
- ObjCProtocolDecl **ProtocolList,
- unsigned NumProtocols);
-
+
+ QualType getObjCProtocolListType(QualType T,
+ ObjCProtocolDecl **Protocols,
+ unsigned NumProtocols);
+
/// getTypeOfType - GCC extension.
QualType getTypeOfExprType(Expr *e);
QualType getTypeOfType(QualType t);
-
+
/// getDecltypeType - C++0x decltype.
QualType getDecltypeType(Expr *e);
-
+
/// getTagDeclType - Return the unique reference to the type for the
/// specified TagDecl (struct/union/class/enum) decl.
- QualType getTagDeclType(TagDecl *Decl);
-
+ QualType getTagDeclType(const TagDecl *Decl);
+
/// getSizeType - Return the unique type for "size_t" (C99 7.17), defined
/// in . The sizeof operator requires this (C99 6.5.3.4p4).
QualType getSizeType() const;
@@ -392,15 +545,15 @@ public:
/// getUnsignedWCharType - Return the type of "unsigned wchar_t".
/// Used when in C++, as a GCC extension.
QualType getUnsignedWCharType() const;
-
+
/// getPointerDiffType - Return the unique type for "ptrdiff_t" (ref?)
/// defined in . Pointer - pointer requires this (C99 6.5.6p9).
QualType getPointerDiffType() const;
-
+
// getCFConstantStringType - Return the C structure type used to represent
// constant CFStrings.
- QualType getCFConstantStringType();
-
+ QualType getCFConstantStringType();
+
/// Get the structure type used to representation CFStrings, or NULL
/// if it hasn't yet been built.
QualType getRawCFConstantStringType() {
@@ -412,13 +565,13 @@ public:
// This setter/getter represents the ObjC type for an NSConstantString.
void setObjCConstantStringInterface(ObjCInterfaceDecl *Decl);
- QualType getObjCConstantStringInterface() const {
- return ObjCConstantStringType;
+ QualType getObjCConstantStringInterface() const {
+ return ObjCConstantStringType;
}
//// This gets the struct used to keep track of fast enumerations.
QualType getObjCFastEnumerationStateType();
-
+
/// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet
/// been built.
QualType getRawObjCFastEnumerationStateType() {
@@ -429,109 +582,166 @@ public:
void setObjCFastEnumerationStateType(QualType T);
+ /// \brief Set the type for the C FILE type.
+ void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; }
+
+ /// \brief Retrieve the C FILE type.
+ QualType getFILEType() {
+ if (FILEDecl)
+ return getTypeDeclType(FILEDecl);
+ return QualType();
+ }
+
+ /// \brief Set the type for the C jmp_buf type.
+ void setjmp_bufDecl(TypeDecl *jmp_bufDecl) {
+ this->jmp_bufDecl = jmp_bufDecl;
+ }
+
+ /// \brief Retrieve the C jmp_buf type.
+ QualType getjmp_bufType() {
+ if (jmp_bufDecl)
+ return getTypeDeclType(jmp_bufDecl);
+ return QualType();
+ }
+
+ /// \brief Set the type for the C sigjmp_buf type.
+ void setsigjmp_bufDecl(TypeDecl *sigjmp_bufDecl) {
+ this->sigjmp_bufDecl = sigjmp_bufDecl;
+ }
+
+ /// \brief Retrieve the C sigjmp_buf type.
+ QualType getsigjmp_bufType() {
+ if (sigjmp_bufDecl)
+ return getTypeDeclType(sigjmp_bufDecl);
+ return QualType();
+ }
+
/// getObjCEncodingForType - Emit the ObjC type encoding for the
/// given type into \arg S. If \arg NameFields is specified then
/// record field names are also encoded.
- void getObjCEncodingForType(QualType t, std::string &S,
+ void getObjCEncodingForType(QualType t, std::string &S,
const FieldDecl *Field=0);
void getLegacyIntegralTypeEncoding(QualType &t) const;
-
+
// Put the string version of type qualifiers into S.
- void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
+ void getObjCEncodingForTypeQualifier(Decl::ObjCDeclQualifier QT,
std::string &S) const;
-
+
/// getObjCEncodingForMethodDecl - Return the encoded type for this method
/// declaration.
void getObjCEncodingForMethodDecl(const ObjCMethodDecl *Decl, std::string &S);
-
+
/// getObjCEncodingForPropertyDecl - Return the encoded type for
/// this method declaration. If non-NULL, Container must be either
/// an ObjCCategoryImplDecl or ObjCImplementationDecl; it should
/// only be NULL when getting encodings for protocol properties.
- void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
+ void getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
const Decl *Container,
std::string &S);
-
+
+ bool ProtocolCompatibleWithProtocol(ObjCProtocolDecl *lProto,
+ ObjCProtocolDecl *rProto);
+
/// getObjCEncodingTypeSize returns size of type for objective-c encoding
/// purpose.
int getObjCEncodingTypeSize(QualType t);
/// This setter/getter represents the ObjC 'id' type. It is setup lazily, by
/// Sema. id is always a (typedef for a) pointer type, a pointer to a struct.
- QualType getObjCIdType() const { return ObjCIdType; }
+ QualType getObjCIdType() const { return ObjCIdTypedefType; }
void setObjCIdType(QualType T);
-
+
void setObjCSelType(QualType T);
QualType getObjCSelType() const { return ObjCSelType; }
-
+
void setObjCProtoType(QualType QT);
QualType getObjCProtoType() const { return ObjCProtoType; }
-
+
/// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
/// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a
/// struct.
- QualType getObjCClassType() const { return ObjCClassType; }
+ QualType getObjCClassType() const { return ObjCClassTypedefType; }
void setObjCClassType(QualType T);
-
+
void setBuiltinVaListType(QualType T);
QualType getBuiltinVaListType() const { return BuiltinVaListType; }
QualType getFixedWidthIntType(unsigned Width, bool Signed);
- TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
+ /// getCVRQualifiedType - Returns a type with additional const,
+ /// volatile, or restrict qualifiers.
+ QualType getCVRQualifiedType(QualType T, unsigned CVR) {
+ return getQualifiedType(T, Qualifiers::fromCVRMask(CVR));
+ }
+
+ /// getQualifiedType - Returns a type with additional qualifiers.
+ QualType getQualifiedType(QualType T, Qualifiers Qs) {
+ if (!Qs.hasNonFastQualifiers())
+ return T.withFastQualifiers(Qs.getFastQualifiers());
+ QualifierCollector Qc(Qs);
+ const Type *Ptr = Qc.strip(T);
+ return getExtQualType(Ptr, Qc);
+ }
+
+ /// getQualifiedType - Returns a type with additional qualifiers.
+ QualType getQualifiedType(const Type *T, Qualifiers Qs) {
+ if (!Qs.hasNonFastQualifiers())
+ return QualType(T, Qs.getFastQualifiers());
+ return getExtQualType(T, Qs);
+ }
+
+ TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
bool TemplateKeyword,
TemplateDecl *Template);
+ TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS,
+ bool TemplateKeyword,
+ OverloadedFunctionDecl *Template);
- TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
+ TemplateName getDependentTemplateName(NestedNameSpecifier *NNS,
const IdentifierInfo *Name);
enum GetBuiltinTypeError {
- GE_None, //< No error
- GE_Missing_FILE //< Missing the FILE type from
+ GE_None, //< No error
+ GE_Missing_stdio, //< Missing a type from
+ GE_Missing_setjmp //< Missing a type from
};
-
+
/// GetBuiltinType - Return the type for the specified builtin.
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error);
-
+
private:
QualType getFromTargetType(unsigned Type) const;
//===--------------------------------------------------------------------===//
// Type Predicates.
//===--------------------------------------------------------------------===//
-
-public:
- /// isObjCObjectPointerType - Returns true if type is an Objective-C pointer
- /// to an object type. This includes "id" and "Class" (two 'special' pointers
- /// to struct), Interface* (pointer to ObjCInterfaceType) and id
(qualified
- /// ID type).
- bool isObjCObjectPointerType(QualType Ty) const;
+public:
/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
/// garbage collection attribute.
///
- QualType::GCAttrTypes getObjCGCAttrKind(const QualType &Ty) const;
-
+ Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const;
+
/// isObjCNSObjectType - Return true if this is an NSObject object with
/// its NSObject attribute set.
bool isObjCNSObjectType(QualType Ty) const;
-
+
//===--------------------------------------------------------------------===//
// Type Sizing and Analysis
//===--------------------------------------------------------------------===//
-
+
/// getFloatTypeSemantics - Return the APFloat 'semantics' for the specified
/// scalar floating point type.
const llvm::fltSemantics &getFloatTypeSemantics(QualType T) const;
-
+
/// getTypeInfo - Get the size and alignment of the specified complete type in
/// bits.
std::pair getTypeInfo(const Type *T);
std::pair getTypeInfo(QualType T) {
return getTypeInfo(T.getTypePtr());
}
-
+
/// getTypeSize - Return the size of the specified type, in bits. This method
/// does not work on incomplete types.
uint64_t getTypeSize(QualType T) {
@@ -540,7 +750,7 @@ public:
uint64_t getTypeSize(const Type *T) {
return getTypeInfo(T).first;
}
-
+
/// getTypeAlign - Return the ABI-specified alignment of a type, in bits.
/// This method does not work on incomplete types.
unsigned getTypeAlign(QualType T) {
@@ -549,23 +759,23 @@ public:
unsigned getTypeAlign(const Type *T) {
return getTypeInfo(T).second;
}
-
+
/// getPreferredTypeAlign - Return the "preferred" alignment of the specified
/// type for the current target in bits. This can be different than the ABI
/// alignment in cases where it is beneficial for performance to overalign
/// a data type.
unsigned getPreferredTypeAlign(const Type *T);
-
+
/// getDeclAlignInBytes - Return the alignment of the specified decl
/// that should be returned by __alignof(). Note that bitfields do
/// not have a valid alignment, so this method will assert on them.
unsigned getDeclAlignInBytes(const Decl *D);
-
+
/// getASTRecordLayout - Get or compute information about the layout of the
/// specified record (struct/union/class), which indicates its size and field
/// position information.
const ASTRecordLayout &getASTRecordLayout(const RecordDecl *D);
-
+
/// getASTObjCInterfaceLayout - Get or compute information about the
/// layout of the specified Objective-C interface.
const ASTRecordLayout &getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D);
@@ -592,14 +802,14 @@ public:
//===--------------------------------------------------------------------===//
// Type Operators
//===--------------------------------------------------------------------===//
-
+
/// getCanonicalType - Return the canonical (structural) type corresponding to
/// the specified potentially non-canonical type. The non-canonical version
/// of a type may have many "decorated" versions of types. Decorators can
/// include typedefs, 'typeof' operators, etc. The returned type is guaranteed
/// to be free of any of these, allowing two canonical types to be compared
/// for exact equality with a simple pointer comparison.
- QualType getCanonicalType(QualType T);
+ CanQualType getCanonicalType(QualType T);
const Type *getCanonicalType(const Type *T) {
return T->getCanonicalTypeInternal().getTypePtr();
}
@@ -608,7 +818,7 @@ public:
bool hasSameType(QualType T1, QualType T2) {
return getCanonicalType(T1) == getCanonicalType(T2);
}
-
+
/// \brief Determine whether the given types are equivalent after
/// cvr-qualifiers have been removed.
bool hasSameUnqualifiedType(QualType T1, QualType T2) {
@@ -617,20 +827,7 @@ public:
return T1.getUnqualifiedType() == T2.getUnqualifiedType();
}
- /// \brief Retrieves the "canonical" declaration of the given declaration.
- Decl *getCanonicalDecl(Decl *D);
-
- /// \brief Retrieves the "canonical" declaration of the given tag
- /// declaration.
- ///
- /// The canonical declaration for the given tag declaration is
- /// either the definition of the tag (if it is a complete type) or
- /// the first declaration of that tag.
- TagDecl *getCanonicalDecl(TagDecl *Tag) {
- return cast(getCanonicalDecl((Decl *)Tag));
- }
-
- /// \brief Retrieves the "canonical" declaration of
+ /// \brief Retrieves the "canonical" declaration of
/// \brief Retrieves the "canonical" nested name specifier for a
/// given nested name specifier.
@@ -678,6 +875,13 @@ public:
/// types, values, and templates.
TemplateName getCanonicalTemplateName(TemplateName Name);
+ /// \brief Retrieve the "canonical" template argument.
+ ///
+ /// The canonical template argument is the simplest template argument
+ /// (which may be a type, value, expression, or declaration) that
+ /// expresses the value of the argument.
+ TemplateArgument getCanonicalTemplateArgument(const TemplateArgument &Arg);
+
/// Type Query functions. If the type is an instance of the specified class,
/// return the Type pointer for the underlying maximally pretty type. This
/// is a member of ASTContext because this may need to do some amount of
@@ -693,10 +897,17 @@ public:
return dyn_cast_or_null(getAsArrayType(T));
}
- /// getBaseElementType - Returns the innermost element type of a variable
- /// length array type. For example, will return "int" for int[m][n]
- QualType getBaseElementType(const VariableArrayType *VAT);
-
+ /// getBaseElementType - Returns the innermost element type of an array type.
+ /// For example, will return "int" for int[m][n]
+ QualType getBaseElementType(const ArrayType *VAT);
+
+ /// getBaseElementType - Returns the innermost element type of a type
+ /// (which needn't actually be an array type).
+ QualType getBaseElementType(QualType QT);
+
+ /// getConstantArrayElementCount - Returns number of constant array elements.
+ uint64_t getConstantArrayElementCount(const ConstantArrayType *CA) const;
+
/// getArrayDecayedType - Return the properly qualified result of decaying the
/// specified array type to a pointer. This operation is non-trivial when
/// handling typedefs etc. The canonical type of "T" must be an array type,
@@ -704,23 +915,35 @@ public:
///
/// See C99 6.7.5.3p7 and C99 6.3.2.1p3.
QualType getArrayDecayedType(QualType T);
-
- /// getIntegerTypeOrder - Returns the highest ranked integer type:
+
+ /// getPromotedIntegerType - Returns the type that Promotable will
+ /// promote to: C99 6.3.1.1p2, assuming that Promotable is a promotable
+ /// integer type.
+ QualType getPromotedIntegerType(QualType PromotableType);
+
+ /// \brief Whether this is a promotable bitfield reference according
+ /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
+ ///
+ /// \returns the type this bit-field will promote to, or NULL if no
+ /// promotion occurs.
+ QualType isPromotableBitField(Expr *E);
+
+ /// getIntegerTypeOrder - Returns the highest ranked integer type:
/// C99 6.3.1.8p1. If LHS > RHS, return 1. If LHS == RHS, return 0. If
- /// LHS < RHS, return -1.
+ /// LHS < RHS, return -1.
int getIntegerTypeOrder(QualType LHS, QualType RHS);
-
+
/// getFloatingTypeOrder - Compare the rank of the two specified floating
/// point types, ignoring the domain of the type (i.e. 'double' ==
/// '_Complex double'). If LHS > RHS, return 1. If LHS == RHS, return 0. If
- /// LHS < RHS, return -1.
+ /// LHS < RHS, return -1.
int getFloatingTypeOrder(QualType LHS, QualType RHS);
- /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
- /// point or a complex type (based on typeDomain/typeSize).
+ /// getFloatingTypeOfSizeWithinDomain - Returns a real floating
+ /// point or a complex type (based on typeDomain/typeSize).
/// 'typeDomain' is a real floating point or complex type.
/// 'typeSize' is a real floating point or complex type.
- QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
+ QualType getFloatingTypeOfSizeWithinDomain(QualType typeSize,
QualType typeDomain) const;
private:
@@ -732,33 +955,28 @@ public:
//===--------------------------------------------------------------------===//
// Type Compatibility Predicates
//===--------------------------------------------------------------------===//
-
+
/// Compatibility predicates used to check assignment expressions.
bool typesAreCompatible(QualType, QualType); // C99 6.2.7p1
-
+
bool isObjCIdType(QualType T) const {
- return T == ObjCIdType;
- }
- bool isObjCIdStructType(QualType T) const {
- if (!IdStructType) // ObjC isn't enabled
- return false;
- return T->getAsStructureType() == IdStructType;
+ return T == ObjCIdTypedefType;
}
bool isObjCClassType(QualType T) const {
- return T == ObjCClassType;
- }
- bool isObjCClassStructType(QualType T) const {
- if (!ClassStructType) // ObjC isn't enabled
- return false;
- return T->getAsStructureType() == ClassStructType;
+ return T == ObjCClassTypedefType;
}
bool isObjCSelType(QualType T) const {
assert(SelStructType && "isObjCSelType used before 'SEL' type is built");
return T->getAsStructureType() == SelStructType;
}
+ bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
+ bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
+ bool ForCompare);
// Check the safety of assignment from LHS to RHS
- bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
+ bool canAssignObjCInterfaces(const ObjCObjectPointerType *LHSOPT,
+ const ObjCObjectPointerType *RHSOPT);
+ bool canAssignObjCInterfaces(const ObjCInterfaceType *LHS,
const ObjCInterfaceType *RHS);
bool areComparableObjCPointerTypes(QualType LHS, QualType RHS);
@@ -766,6 +984,11 @@ public:
QualType mergeTypes(QualType, QualType);
QualType mergeFunctionTypes(QualType, QualType);
+ /// UsualArithmeticConversionsType - handles the various conversions
+ /// that are common to binary operators (C99 6.3.1.8, C++ [expr]p9)
+ /// and returns the result type of that conversion.
+ QualType UsualArithmeticConversionsType(QualType lhs, QualType rhs);
+
//===--------------------------------------------------------------------===//
// Integer Predicates
//===--------------------------------------------------------------------===//
@@ -782,15 +1005,15 @@ public:
//===--------------------------------------------------------------------===//
// Type Iterators.
//===--------------------------------------------------------------------===//
-
+
typedef std::vector::iterator type_iterator;
typedef std::vector::const_iterator const_type_iterator;
-
+
type_iterator types_begin() { return Types.begin(); }
type_iterator types_end() { return Types.end(); }
const_type_iterator types_begin() const { return Types.begin(); }
- const_type_iterator types_end() const { return Types.end(); }
-
+ const_type_iterator types_end() const { return Types.end(); }
+
//===--------------------------------------------------------------------===//
// Integer Values
//===--------------------------------------------------------------------===//
@@ -803,15 +1026,37 @@ public:
return Res;
}
+ /// \brief Get the implementation of ObjCInterfaceDecl,or NULL if none exists.
+ ObjCImplementationDecl *getObjCImplementation(ObjCInterfaceDecl *D);
+ /// \brief Get the implementation of ObjCCategoryDecl, or NULL if none exists.
+ ObjCCategoryImplDecl *getObjCImplementation(ObjCCategoryDecl *D);
+
+ /// \brief Set the implementation of ObjCInterfaceDecl.
+ void setObjCImplementation(ObjCInterfaceDecl *IFaceD,
+ ObjCImplementationDecl *ImplD);
+ /// \brief Set the implementation of ObjCCategoryDecl.
+ void setObjCImplementation(ObjCCategoryDecl *CatD,
+ ObjCCategoryImplDecl *ImplD);
+
+ /// \brief Allocate an uninitialized DeclaratorInfo.
+ ///
+ /// The caller should initialize the memory held by DeclaratorInfo using
+ /// the TypeLoc wrappers.
+ ///
+ /// \param T the type that will be the basis for type source info. This type
+ /// should refer to how the declarator was written in source code, not to
+ /// what type semantic analysis resolved the declarator to.
+ DeclaratorInfo *CreateDeclaratorInfo(QualType T);
+
private:
ASTContext(const ASTContext&); // DO NOT IMPLEMENT
void operator=(const ASTContext&); // DO NOT IMPLEMENT
-
+
void InitBuiltinTypes();
void InitBuiltinType(QualType &R, BuiltinType::Kind K);
-
+
// Return the ObjC type encoding for a given type.
- void getObjCEncodingForTypeImpl(QualType t, std::string &S,
+ void getObjCEncodingForTypeImpl(QualType t, std::string &S,
bool ExpandPointedToStructures,
bool ExpandStructures,
const FieldDecl *Field,
@@ -819,7 +1064,7 @@ private:
bool EncodingProperty = false);
const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D,
- const ObjCImplementationDecl *Impl);
+ const ObjCImplementationDecl *Impl);
};
} // end namespace clang
diff --git a/include/clang/AST/ASTDiagnostic.h b/include/clang/AST/ASTDiagnostic.h
index e9f150574b050..abd36f7e5f0fa 100644
--- a/include/clang/AST/ASTDiagnostic.h
+++ b/include/clang/AST/ASTDiagnostic.h
@@ -13,7 +13,7 @@
#include "clang/Basic/Diagnostic.h"
namespace clang {
- namespace diag {
+ namespace diag {
enum {
#define DIAG(ENUM,FLAGS,DEFAULT_MAPPING,DESC,GROUP,SFINAE) ENUM,
#define ASTSTART
diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h
index 7d3009b011293..6a5e3666a92c4 100644
--- a/include/clang/AST/Attr.h
+++ b/include/clang/AST/Attr.h
@@ -14,6 +14,9 @@
#ifndef LLVM_CLANG_AST_ATTR_H
#define LLVM_CLANG_AST_ATTR_H
+#include "llvm/Support/Casting.h"
+using llvm::dyn_cast;
+
#include
#include
#include
@@ -54,22 +57,24 @@ public:
DLLImport,
Deprecated,
Destructor,
- FastCall,
+ FastCall,
Format,
FormatArg,
GNUInline,
IBOutletKind, // Clang-specific. Use "Kind" suffix to not conflict with
+ Malloc,
+ NoDebug,
+ NoInline,
+ NonNull,
NoReturn,
NoThrow,
- Nodebug,
- Noinline,
- NonNull,
ObjCException,
ObjCNSObject,
CFReturnsRetained, // Clang/Checker-specific.
NSReturnsRetained, // Clang/Checker-specific.
Overloadable, // Clang-specific
Packed,
+ PragmaPack,
Pure,
Regparm,
ReqdWorkGroupSize, // OpenCL-specific
@@ -78,14 +83,14 @@ public:
StdCall,
TransparentUnion,
Unavailable,
- Unused,
+ Unused,
Used,
Visibility,
WarnUnusedResult,
Weak,
WeakImport
};
-
+
private:
Attr *Next;
Kind AttrKind;
@@ -99,16 +104,16 @@ protected:
void operator delete(void* data) throw() {
assert(0 && "Attrs cannot be released with regular 'delete'.");
}
-
+
protected:
Attr(Kind AK) : Next(0), AttrKind(AK), Inherited(false) {}
virtual ~Attr() {
assert(Next == 0 && "Destroy didn't work");
}
public:
-
+
void Destroy(ASTContext &C);
-
+
/// \brief Whether this attribute should be merged to new
/// declarations.
virtual bool isMerged() const { return true; }
@@ -119,17 +124,24 @@ public:
const Attr *getNext() const { return Next; }
void setNext(Attr *next) { Next = next; }
+ template const T *getNext() const {
+ for (const Attr *attr = getNext(); attr; attr = attr->getNext())
+ if (const T *V = dyn_cast(attr))
+ return V;
+ return 0;
+ }
+
bool isInherited() const { return Inherited; }
void setInherited(bool value) { Inherited = value; }
void addAttr(Attr *attr) {
assert((attr != 0) && "addAttr(): attr is null");
-
+
// FIXME: This doesn't preserve the order in any way.
attr->Next = Next;
Next = attr;
}
-
+
// Clone this attribute.
virtual Attr* clone(ASTContext &C) const = 0;
@@ -146,36 +158,39 @@ public: \
static bool classof(const ATTR##Attr *A) { return true; } \
}
-class PackedAttr : public Attr {
+DEF_SIMPLE_ATTR(Packed);
+
+class PragmaPackAttr : public Attr {
unsigned Alignment;
public:
- PackedAttr(unsigned alignment) : Attr(Packed), Alignment(alignment) {}
+ PragmaPackAttr(unsigned alignment) : Attr(PragmaPack), Alignment(alignment) {}
/// getAlignment - The specified alignment in bits.
unsigned getAlignment() const { return Alignment; }
- virtual Attr* clone(ASTContext &C) const {
- return ::new (C) PackedAttr(Alignment);
+ virtual Attr* clone(ASTContext &C) const {
+ return ::new (C) PragmaPackAttr(Alignment);
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
- return A->getKind() == Packed;
+ return A->getKind() == PragmaPack;
}
- static bool classof(const PackedAttr *A) { return true; }
+ static bool classof(const PragmaPackAttr *A) { return true; }
};
-
+
class AlignedAttr : public Attr {
unsigned Alignment;
public:
AlignedAttr(unsigned alignment) : Attr(Aligned), Alignment(alignment) {}
+ // FIXME: Should use addressable units, not bits, to match llvm
/// getAlignment - The specified alignment in bits.
unsigned getAlignment() const { return Alignment; }
virtual Attr* clone(ASTContext &C) const { return ::new (C) AlignedAttr(Alignment); }
-
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == Aligned;
@@ -187,11 +202,11 @@ class AnnotateAttr : public Attr {
std::string Annotation;
public:
AnnotateAttr(const std::string &ann) : Attr(Annotate), Annotation(ann) {}
-
+
const std::string& getAnnotation() const { return Annotation; }
virtual Attr* clone(ASTContext &C) const { return ::new (C) AnnotateAttr(Annotation); }
-
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == Annotate;
@@ -203,11 +218,11 @@ class AsmLabelAttr : public Attr {
std::string Label;
public:
AsmLabelAttr(const std::string &L) : Attr(AsmLabel), Label(L) {}
-
+
const std::string& getLabel() const { return Label; }
-
+
virtual Attr* clone(ASTContext &C) const { return ::new (C) AsmLabelAttr(Label); }
-
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == AsmLabel;
@@ -237,28 +252,28 @@ public:
ConstructorAttr(int p) : Attr(Constructor), priority(p) {}
int getPriority() const { return priority; }
-
+
virtual Attr *clone(ASTContext &C) const { return ::new (C) ConstructorAttr(priority); }
// Implement isa/cast/dyncast/etc.
- static bool classof(const Attr *A) { return A->getKind() == Constructor; }
+ static bool classof(const Attr *A) { return A->getKind() == Constructor; }
static bool classof(const ConstructorAttr *A) { return true; }
-};
-
+};
+
class DestructorAttr : public Attr {
int priority;
public:
DestructorAttr(int p) : Attr(Destructor), priority(p) {}
int getPriority() const { return priority; }
-
+
virtual Attr *clone(ASTContext &C) const { return ::new (C) DestructorAttr(priority); }
// Implement isa/cast/dyncast/etc.
- static bool classof(const Attr *A) { return A->getKind() == Destructor; }
+ static bool classof(const Attr *A) { return A->getKind() == Destructor; }
static bool classof(const DestructorAttr *A) { return true; }
-};
-
+};
+
class GNUInlineAttr : public Attr {
public:
GNUInlineAttr() : Attr(GNUInline) {}
@@ -285,15 +300,16 @@ public:
static bool classof(const IBOutletAttr *A) { return true; }
};
+DEF_SIMPLE_ATTR(Malloc);
DEF_SIMPLE_ATTR(NoReturn);
-DEF_SIMPLE_ATTR(AnalyzerNoReturn);
+DEF_SIMPLE_ATTR(AnalyzerNoReturn);
DEF_SIMPLE_ATTR(Deprecated);
class SectionAttr : public Attr {
std::string Name;
public:
SectionAttr(const std::string &N) : Attr(Section), Name(N) {}
-
+
const std::string& getName() const { return Name; }
virtual Attr *clone(ASTContext &C) const { return ::new (C) SectionAttr(Name); }
@@ -307,8 +323,8 @@ public:
DEF_SIMPLE_ATTR(Unavailable);
DEF_SIMPLE_ATTR(Unused);
-DEF_SIMPLE_ATTR(Used);
-DEF_SIMPLE_ATTR(Weak);
+DEF_SIMPLE_ATTR(Used);
+DEF_SIMPLE_ATTR(Weak);
DEF_SIMPLE_ATTR(WeakImport);
DEF_SIMPLE_ATTR(NoThrow);
DEF_SIMPLE_ATTR(Const);
@@ -320,14 +336,14 @@ class NonNullAttr : public Attr {
public:
NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull),
ArgNums(0), Size(0) {
-
+
if (size == 0) return;
assert(arg_nums);
ArgNums = new unsigned[size];
Size = size;
memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
}
-
+
virtual ~NonNullAttr() {
delete [] ArgNums;
}
@@ -339,7 +355,7 @@ public:
bool isNonNull(unsigned arg) const {
return ArgNums ? std::binary_search(ArgNums, ArgNums+Size, arg) : true;
- }
+ }
virtual Attr *clone(ASTContext &C) const { return ::new (C) NonNullAttr(ArgNums, Size); }
@@ -359,8 +375,8 @@ public:
int getFormatIdx() const { return formatIdx; }
int getFirstArg() const { return firstArg; }
- virtual Attr *clone(ASTContext &C) const {
- return ::new (C) FormatAttr(Type, formatIdx, firstArg);
+ virtual Attr *clone(ASTContext &C) const {
+ return ::new (C) FormatAttr(Type, formatIdx, firstArg);
}
// Implement isa/cast/dyncast/etc.
@@ -437,8 +453,8 @@ public:
virtual bool isMerged() const { return false; }
- virtual Attr *clone(ASTContext &C) const {
- return ::new (C) OverloadableAttr;
+ virtual Attr *clone(ASTContext &C) const {
+ return ::new (C) OverloadableAttr;
}
static bool classof(const Attr *A) { return A->getKind() == Overloadable; }
@@ -465,15 +481,15 @@ public:
};
class FunctionDecl;
-
+
class CleanupAttr : public Attr {
FunctionDecl *FD;
-
+
public:
CleanupAttr(FunctionDecl *fd) : Attr(Cleanup), FD(fd) {}
const FunctionDecl *getFunctionDecl() const { return FD; }
-
+
virtual Attr *clone(ASTContext &C) const { return ::new (C) CleanupAttr(FD); }
// Implement isa/cast/dyncast/etc.
@@ -481,9 +497,9 @@ public:
static bool classof(const CleanupAttr *A) { return true; }
};
-DEF_SIMPLE_ATTR(Nodebug);
-DEF_SIMPLE_ATTR(WarnUnusedResult);
-DEF_SIMPLE_ATTR(Noinline);
+DEF_SIMPLE_ATTR(NoDebug);
+DEF_SIMPLE_ATTR(WarnUnusedResult);
+DEF_SIMPLE_ATTR(NoInline);
class RegparmAttr : public Attr {
unsigned NumParams;
@@ -493,11 +509,11 @@ public:
unsigned getNumParams() const { return NumParams; }
- virtual Attr *clone(ASTContext &C) const {
- return ::new (C) RegparmAttr(NumParams);
+ virtual Attr *clone(ASTContext &C) const {
+ return ::new (C) RegparmAttr(NumParams);
}
- // Implement isa/cast/dyncast/etc.
+ // Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) { return A->getKind() == Regparm; }
static bool classof(const RegparmAttr *A) { return true; }
};
@@ -512,23 +528,23 @@ public:
unsigned getYDim() const { return Y; }
unsigned getZDim() const { return Z; }
- virtual Attr *clone(ASTContext &C) const {
- return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
+ virtual Attr *clone(ASTContext &C) const {
+ return ::new (C) ReqdWorkGroupSizeAttr(X, Y, Z);
}
-
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Attr *A) {
return A->getKind() == ReqdWorkGroupSize;
}
static bool classof(const ReqdWorkGroupSizeAttr *A) { return true; }
};
-
+
// Checker-specific attributes.
DEF_SIMPLE_ATTR(CFReturnsRetained);
DEF_SIMPLE_ATTR(NSReturnsRetained);
#undef DEF_SIMPLE_ATTR
-
+
} // end namespace clang
#endif
diff --git a/include/clang/AST/CXXInheritance.h b/include/clang/AST/CXXInheritance.h
new file mode 100644
index 0000000000000..a57bcc184a936
--- /dev/null
+++ b/include/clang/AST/CXXInheritance.h
@@ -0,0 +1,212 @@
+//===------ CXXInheritance.h - C++ Inheritance ------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides routines that help analyzing C++ inheritance hierarchies.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_CXXINHERITANCE_H
+#define LLVM_CLANG_AST_CXXINHERITANCE_H
+
+#include "clang/AST/DeclarationName.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeOrdering.h"
+#include "llvm/ADT/SmallVector.h"
+#include
+#include