Commit Graph

167 Commits

Author SHA1 Message Date
Douglas Gregor 7de5966d76 Create a new PrintingPolicy class, which we pass down through the AST
printing logic to help customize the output. For now, we use this
rather than a special flag to suppress the "struct" when printing
"struct X" and to print the Boolean type as "bool" in C++ but "_Bool"
in C.

llvm-svn: 72590
2009-05-29 20:38:28 +00:00
Sebastian Redl eed0ec5fdb Fix usage of placement new. Placement new is not actually declared implicitly.
llvm-svn: 72576
2009-05-29 16:43:59 +00:00
Douglas Gregor 0558094464 Follow-on test case for template instantiation of interesting DeclGroups
llvm-svn: 72569
2009-05-29 14:26:40 +00:00
Douglas Gregor 8157b07caf Now that we have declared/defined tag types within DeclGroups,
instantiation of tags local to member functions of class templates
(and, eventually, function templates) works when the tag is defined as
part of the decl-specifier-seq, e.g.,

  struct S { T x, y; } s1;

Also, make sure that we don't try to default-initialize a dependent
type.

llvm-svn: 72568
2009-05-29 14:25:00 +00:00
Douglas Gregor 019d3750cb Add the missing public: thanks, Fariborz
llvm-svn: 72528
2009-05-28 16:41:44 +00:00
Douglas Gregor 9e927abc41 Introduced DeclContext::isDependentContext, which determines whether a
given DeclContext is dependent on type parameters. Use this to
properly determine whether a TagDecl is dependent; previously, we were
missing the case where the TagDecl is a local class of a member
function of a class template (phew!).

Also, make sure that, when we instantiate declarations within a member
function of a class template (or a function template, eventually),
that we add those declarations to the "instantiated locals" map so
that they can be found when instantiating declaration references.

Unfortunately, I was not able to write a useful test for this change,
although the assert() that fires when uncommenting the FIXME'd line in
test/SemaTemplate/instantiate-declref.cpp tells the "experienced user"
that we're now doing the right thing.

llvm-svn: 72526
2009-05-28 16:34:51 +00:00
Douglas Gregor e44a2adf41 Reimplement much of the way that we track nested classes in the
parser. Rather than placing all of the delayed member function
declarations and inline definitions into a single bucket corresponding
to the top-level class, we instead mirror the nesting structure of the
nested classes and place the delayed member functions into their
appropriate place. Then, when we actually parse the delayed member
function declarations, set up the scope stack the same way as it was
when we originally saw the declaration, so that we can find, e.g.,
template parameters that are in scope.

llvm-svn: 72502
2009-05-27 23:11:45 +00:00
Sebastian Redl eed3d4c73e Fix the type of a enum non-type template argument within the instantiation.
llvm-svn: 72489
2009-05-27 19:21:29 +00:00
Douglas Gregor cd3a097925 Simplify, and improve the performance of, template instantiation for
declaration references. The key realization is that dependent Decls,
which actually require instantiation, can only refer to the current
instantiation or members thereof. And, since the current context
during instantiation contains all of those members of the current
instantiation, we can simply find the real instantiate that matches up
with the "current instantiation" template.

llvm-svn: 72486
2009-05-27 17:54:46 +00:00
Douglas Gregor b8006fafe8 Add some more tests for instantiation of declaration references. Also,
improve some error recovery with explicit template instantiation.

llvm-svn: 72484
2009-05-27 17:30:49 +00:00
Douglas Gregor 7a74938fca Enumeration declarations that were instantiated from an enumeration
within a template now have a link back to the enumeration from which
they were instantiated. This means that we can now find the
instantiation of an anonymous enumeration.

llvm-svn: 72482
2009-05-27 17:20:35 +00:00
Douglas Gregor f98d9b60db Improve name lookup for and template instantiation of declaration
references. There are several smallish fixes here:

  - Make sure we look through template parameter scope when
    determining whether we're parsing a nested class (or nested class
    *template*). This makes sure that we delay parsing the bodies of
    inline member functions until after we're out of the outermost
    class (template) scope.
  - Since the bodies of member functions are always parsed
    "out-of-line", even when they were declared in-line, teach
    unqualified name lookup to look into the (semantic) parents.
  - Use the new InstantiateDeclRef to handle the instantiation of a
    reference to a declaration (in DeclRefExpr), which drastically
    simplifies template instantiation for DeclRefExprs.
  - When we're instantiating a ParmVarDecl, it must be in the current
    instantiation scope, so only look there.

Also, remove the #if 0's and FIXME's from the dynarray example, which
now compiles and executes thanks to Anders and Eli.

llvm-svn: 72481
2009-05-27 17:07:49 +00:00
Douglas Gregor 5178331379 Initial stab at a generalized operation for determining the
instantiation of a declaration from the template version (or version
that lives in a template) and a given set of template arguments. This
needs much, much more testing, but it suffices for simple examples
like

  typedef T* iterator;
  iterator begin();

llvm-svn: 72461
2009-05-27 05:35:12 +00:00
Douglas Gregor 408c619afc Template instantiation for "typeof" for both types and expressions.
llvm-svn: 72440
2009-05-26 22:09:24 +00:00
Douglas Gregor c44ba89397 A simple dynamic array class template, to be used as a test-bed for template instantiation
llvm-svn: 72437
2009-05-26 21:27:04 +00:00
Douglas Gregor 4a9f481db9 Template instantiation for qualified declaration reference
expressions. We are now missing template instantiation logic for only
three classes of expressions:
  - Blocks-related expressions (BlockExpr, BlockDeclRefExpr)
  - C++ default argument expressions
  - Objective-C expressions

Additionally, our handling of DeclRefExpr is still quite poor, since
it cannot handle references to many kinds of declarations.

As part of this change, converted the TemplateExprInstantiator to use
iteration through all of the expressions via clang/AST/StmtNodes.def,
ensuring that we don't forget to add template instantiation logic for
any new expression node kinds.

llvm-svn: 72303
2009-05-22 23:47:06 +00:00
Douglas Gregor 93fcf93bc6 Template instantiation for the GNU address-of-label extension.
llvm-svn: 72301
2009-05-22 23:25:52 +00:00
Douglas Gregor 36fe6901d4 Template instantiation for ExtVectorElementExpr.
llvm-svn: 72299
2009-05-22 23:07:44 +00:00
Douglas Gregor efe7c393e1 Add a few tests to ensure that member functions of class templates can
call other member functions of class templates, including after
template instantiation. No functionality change.

llvm-svn: 72282
2009-05-22 21:26:58 +00:00
Douglas Gregor a8db954f24 Representation of and template instantiation for member
expressions. This change introduces another AST node,
CXXUnresolvedMemberExpr, that captures member references (x->m, x.m)
when the base of the expression (the "x") is type-dependent, and we
therefore cannot resolve the member reference yet.

Note that our parsing of member references for C++ is still quite
poor, e.g., we don't handle x->Base::m or x->operator int.

llvm-svn: 72281
2009-05-22 21:13:27 +00:00
Douglas Gregor 1c37d9eed5 Template instantiation for C99 compound literals
llvm-svn: 72236
2009-05-21 23:48:18 +00:00
Douglas Gregor 0f9d4003df Template instantiation for GNU array-range designators.
llvm-svn: 72234
2009-05-21 23:30:39 +00:00
Douglas Gregor ca1aeecd37 Template instantiation for C99 designated initializers, because we
can. Also, delay semantic analysis of initialization for
value-dependent as well as type-dependent expressions, since we can't
always properly type-check a value-dependent expression.

llvm-svn: 72233
2009-05-21 23:17:49 +00:00
Douglas Gregor c2607b9a08 Template instantiation for initializer lists
llvm-svn: 72229
2009-05-21 21:38:12 +00:00
Douglas Gregor 31c7e99401 Template instantiation for unary type traits, e.g., __is_pod
llvm-svn: 72220
2009-05-21 18:55:48 +00:00
Douglas Gregor aa85d8221c Template instantiation for C++ "typeid" expressions.
llvm-svn: 72218
2009-05-21 18:34:44 +00:00
Douglas Gregor 728d41bbb9 Template instantiation for C++ throw expressions
llvm-svn: 72217
2009-05-21 17:37:52 +00:00
Douglas Gregor 29fe6aeef3 Template instantiation for C++ delete expression
llvm-svn: 72216
2009-05-21 17:21:12 +00:00
Sebastian Redl 027de2adcd Avoid using the built-in type checker for assignment in C++ when classes are involved. Patch by Vyacheslav Kononenko.
llvm-svn: 72212
2009-05-21 11:50:50 +00:00
Douglas Gregor d0fefbafd1 Template instantiation for C++ "new" expressions.
llvm-svn: 72199
2009-05-21 00:00:09 +00:00
Douglas Gregor 920e3af495 Fix template instantiation for compound statements so that it properly
passes the "isStmtExpr" flag, to suppress warnings about unused
expressions.

llvm-svn: 72190
2009-05-20 22:57:03 +00:00
Douglas Gregor 1301fdd6c4 Introduce a new kind of RAII class, ASTOwningVector, which is an
llvm::SmallVector that owns all of the AST nodes inside of it. This
RAII class is used to ensure proper destruction of AST nodes when
template instantiation fails.

llvm-svn: 72186
2009-05-20 22:33:37 +00:00
Douglas Gregor 06555f134a Template instantiation for CXXExprWithTemporaries, which occurs when
temporaries are generated for some object-constructing expressions in
templates that are not type-dependent. 

Also, be sure to introduce the variable from a CXXConditionDeclExpr
into the set of instantiated local variables.

llvm-svn: 72185
2009-05-20 21:51:01 +00:00
Douglas Gregor e70f108158 Template instantiation for the various kinds of AST nodes that occur
due to C++ type construction of the form T(a1, a2, ..., aN).

llvm-svn: 72183
2009-05-20 21:38:11 +00:00
Douglas Gregor c902c85b6c Tweak test case so that the expected-error text matches on both i686 and x86-64.
llvm-svn: 72181
2009-05-20 20:30:46 +00:00
Douglas Gregor 895ef6e6f9 Add a va_list/template instantiation test suggested by Eli
llvm-svn: 72178
2009-05-20 18:50:16 +00:00
Douglas Gregor 68f1096212 Add FIXMEs for the remaining C and C++ expression types that still
need template instantiation logic. Remove one FIXME by instantiating
the callee in a non-type-dependent CXXOperatorCallExpr.

llvm-svn: 72145
2009-05-19 23:29:16 +00:00
Douglas Gregor ad3150cd38 Template instantiation for __builtin_va_arg.
llvm-svn: 72144
2009-05-19 23:10:31 +00:00
Douglas Gregor 0df91121ba Template instantiation for __builtin_choose_expr.
llvm-svn: 72143
2009-05-19 22:43:30 +00:00
Douglas Gregor f907cbf634 Ban the use of __builtin_types_compatible_p in C++; g++ doesn't support it,
and it isn't clear exactly what it's supposed to mean. Thanks Eli!

llvm-svn: 72142
2009-05-19 22:28:02 +00:00
Douglas Gregor c25f766065 Template instantiation for __builtin_shufflevector.
llvm-svn: 72139
2009-05-19 22:10:17 +00:00
Douglas Gregor 4b58ca02c5 Template instantiation for __builtin_types_compatible_p.
llvm-svn: 72134
2009-05-19 20:55:31 +00:00
Douglas Gregor 8d7fef3cf2 Template instantiation for GNU statement expressions
llvm-svn: 72129
2009-05-19 20:31:21 +00:00
Douglas Gregor 115652db4a Fix handling of the GNU "t ? : f" extension to the conditional
operator in C++, and verify that template instantiation for the
condition operator does the right thing.

llvm-svn: 72127
2009-05-19 20:13:50 +00:00
Douglas Gregor 3234db1e13 Template instantiation for compound assignment operators.
llvm-svn: 72126
2009-05-19 20:02:01 +00:00
Douglas Gregor 71b6a37bc4 Template instantiation for cast expressions.
llvm-svn: 72119
2009-05-19 19:05:47 +00:00
Douglas Gregor be81045db7 Template instantiation for call expressions.
llvm-svn: 72081
2009-05-19 00:38:01 +00:00
Douglas Gregor 7a77a6bcf9 Template instantiation for array subscript expressions. This was far
easier than expected because of the limitation that subscript
operators must be member functions.

llvm-svn: 72076
2009-05-19 00:01:19 +00:00
Douglas Gregor 38e7f8bd6d Template instantiation for imaginary literals, because they were next in Expr.h
llvm-svn: 72058
2009-05-18 22:38:38 +00:00
Douglas Gregor 655fc35fcd Deal with an icky corner case where we were complaining that a catch
statement was using an rvalue reference during the template
definition. However, template instantiations based on an lvalue
reference type are well-formed, so we delay checking of these property
until template instantiation time.

llvm-svn: 72041
2009-05-18 21:08:14 +00:00