summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclCXX.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Unify the code for defining tags in C and C++, so that we alwaysDouglas Gregor2009-01-081-32/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | introduce a Scope for the body of a tag. This reduces the number of semantic differences between C and C++ structs and unions, and will help with other features (e.g., anonymous unions) in C. Some important points: - Fields are now in the "member" namespace (IDNS_Member), to keep them separate from tags and ordinary names in C. See the new test in Sema/member-reference.c for an example of why this matters. In C++, ordinary and member name lookup will find members in both the ordinary and member namespace, so the difference between IDNS_Member and IDNS_Ordinary is erased by Sema::LookupDecl (but only in C++!). - We always introduce a Scope and push a DeclContext when we're defining a tag, in both C and C++. Previously, we had different actions and different Scope/CurContext behavior for enums, C structs/unions, and C++ structs/unions/classes. Now, it's one pair of actions. (Yay!) There's still some fuzziness in the handling of struct/union/enum definitions within other struct/union/enum definitions in C. We'll need to do some more cleanup to eliminate some reliance on CurContext before we can solve this issue for real. What we want is for something like this: struct X { struct T { int x; } t; }; to introduce T into translation unit scope (placing it at the appropriate point in the IdentifierResolver chain, too), but it should still have struct X as its lexical declaration context. PushOnScopeChains isn't smart enough to do that yet, though, so there's a FIXME test in nested-redef.c llvm-svn: 61940
* This is a large/messy diff that unifies the ObjC AST's with DeclContext.Steve Naroff2009-01-081-2/+2
| | | | | | | | | | | | | | | - ObjCContainerDecl's (ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl), ObjCCategoryImpl, & ObjCImplementation are all DeclContexts. - ObjCMethodDecl is now a ScopedDecl (so it can play nicely with DeclContext). - ObjCContainerDecl now does iteration/lookup using DeclContext infrastructure (no more linear search:-) - Removed ASTContext argument to DeclContext::lookup(). It wasn't being used and complicated it's use from an ObjC AST perspective. - Added Sema::ProcessPropertyDecl() and removed Sema::diagnosePropertySetterGetterMismatch(). - Simplified Sema::ActOnAtEnd() considerably. Still more work to do. - Fixed an incorrect casting assumption in Sema::getCurFunctionOrMethodDecl(), now that ObjCMethodDecl is a ScopedDecl. - Removed addPropertyMethods from ObjCInterfaceDecl/ObjCCategoryDecl/ObjCProtocolDecl. This passes all the tests on my machine. Since many of the changes are central to the way ObjC finds it's methods, I expect some fallout (and there are still a handful of FIXME's). Nevertheless, this should be a step in the right direction. llvm-svn: 61929
* Finished semantic analysis of anonymous unions in C++.Douglas Gregor2009-01-071-3/+10
| | | | | | | | | Duplicate-member checking within classes is still a little messy, and anonymous unions are still completely broken in C. We'll need to unify the handling of fields in C and C++ to make this code applicable in both languages. llvm-svn: 61878
* it is ok to insert empty source ranges into diagnostics, declare variable in ↵Chris Lattner2009-01-061-5/+2
| | | | | | an if. llvm-svn: 61800
* PODness and Type TraitsSebastian Redl2009-01-051-12/+106
| | | | | | | | | | | | | | | Make C++ classes track the POD property (C++ [class]p4) Track the existence of a copy assignment operator. Implicitly declare the copy assignment operator if none is provided. Implement most of the parsing job for the G++ type traits extension. Fully implement the low-hanging fruit of the type traits: __is_pod: Whether a type is a POD. __is_class: Whether a type is a (non-union) class. __is_union: Whether a type is a union. __is_enum: Whether a type is an enum. __is_polymorphic: Whether a type is polymorphic (C++ [class.virtual]p1). llvm-svn: 61746
* Introduce support for "transparent" DeclContexts, which areDouglas Gregor2009-01-051-29/+30
| | | | | | | | | | | | | | | | | | | | | | DeclContexts whose members are visible from enclosing DeclContexts up to (and including) the innermost enclosing non-transparent DeclContexts. Transparent DeclContexts unify the mechanism to be used for various language features, including C enumerations, anonymous unions, C++0x inline namespaces, and C++ linkage specifications. Please refer to the documentation in the Clang internals manual for more information. Only enumerations and linkage specifications currently use transparent DeclContexts. Still to do: use transparent DeclContexts to implement anonymous unions and GCC's anonymous structs extension, and, later, the C++0x features. We also need to tighten up the DeclContext/ScopedDecl link to ensure that every ScopedDecl is in a single DeclContext, which will ensure that we can then enforce ownership and reduce the memory footprint of DeclContext. llvm-svn: 61735
* Parser support for C++ using directives, from Piotr RakDouglas Gregor2008-12-301-0/+28
| | | | llvm-svn: 61486
* Add support for out-of-line definitions of conversion functions and member ↵Douglas Gregor2008-12-261-16/+14
| | | | | | operators llvm-svn: 61442
* Correct the order in which we cope with end-of-class-definitionDouglas Gregor2008-12-241-11/+34
| | | | | | | | | | | | | | | | | | | | | | semantics and improve our handling of default arguments. Specifically, we follow this order: - As soon as the see the '}' in the class definition, the class is complete and we add any implicit declarations (default constructor, copy constructor, etc.) to the class. - If there are any default function arguments, parse them - If there were any inline member function definitions, parse them As part of this change, we now keep track of the the fact that we've seen unparsed default function arguments within the AST. See the new ParmVarDecl::hasUnparsedDefaultArg member. This allows us to properly cope with calls inside default function arguments to other functions where we're making use of the default arguments. Made some C++ error messages regarding failed initializations more specific. llvm-svn: 61406
* Don't explicitly represent OverloadedFunctionDecls withinDouglas Gregor2008-12-231-34/+6
| | | | | | | | | | | | | | | | | | | | | | | | DeclContext. Instead, just keep the list of currently-active declarations and only build the OverloadedFunctionDecl when we absolutely need it. This is a half-step toward eliminating the need to explicitly build OverloadedFunctionDecls that store sets of overloaded functions. This was suggested by Argiris a while back, and it's a good thing for several reasons: first, it eliminates the messy logic that currently tries to keep the OverloadedFunctionDecl in sync with the declarations that are being added. Second, it will (eventually) eliminate the need to allocate memory for overload sets, which could help performance. Finally, it helps set us up for when name lookup can return multiple (possibly ambiguous) results, as can happen with lookup of class members in C++. Next steps: make the IdentifierResolver store overloads as separate entries in its list rather than replacing them with an OverloadedFunctionDecl now, then see how far we can go toward eliminating OverloadedFunctionDecl entirely. llvm-svn: 61357
* Full AST support and better Sema support for C++ try-catch.Sebastian Redl2008-12-221-0/+4
| | | | llvm-svn: 61346
* Partial AST and Sema support for C++ try-catch.Sebastian Redl2008-12-221-0/+63
| | | | llvm-svn: 61337
* Allow downcasts of pointers to Objective-C interfaces, with aDouglas Gregor2008-12-191-1/+1
| | | | | | | warning. This matches GCC's behavior and addresses <rdar://problem/6458293>. llvm-svn: 61246
* Make the injected-class-name of a C++ class a separate RecordDecl from the ↵Douglas Gregor2008-12-171-1/+3
| | | | | | class itself, with a different scope. This eliminates some ownership issues, so that the RecordDecl only lives in a single context llvm-svn: 61140
* Move the other Sema::ActOnLinkageSpec to SemaDeclCXX.Chris Lattner2008-12-171-0/+26
| | | | | | Move Sema::ActOnDefs to SemaDeclObjC llvm-svn: 61126
* Move Sema::ActOnLinkageSpec to SemaDeclCXX.Chris Lattner2008-12-171-0/+19
| | | | llvm-svn: 61125
* Delay parsing of default arguments of member functions until the classDouglas Gregor2008-12-161-3/+106
| | | | | | | | | | is completely defined (C++ [class.mem]p2). Reverse the order in which we process the definitions of member functions specified inline. This way, we'll get diagnostics in the order in which the member functions were declared in the class. llvm-svn: 61103
* Place constructors and destructors into the DeclContext of the class,Douglas Gregor2008-12-151-105/+47
| | | | | | | | | | | | just like all other members, and remove the special variables in CXXRecordDecl to store them. This eliminates a lot of special-case code for constructors and destructors, including ActOnConstructor/ActOnDeclarator and special lookup rules in LookupDecl. The result is far more uniform and manageable. Diagnose the redeclaration of member functions. llvm-svn: 61048
* Don't double-destroy constructors defined out-of-line. This is aDouglas Gregor2008-12-151-8/+12
| | | | | | | half-solution; the real solution is coming when constructors and destructors are treated like all other functions by ActOnDeclarator. llvm-svn: 61037
* Some utilities for using the smart pointers in Actions, especially Sema. ↵Sebastian Redl2008-12-131-1/+1
| | | | | | Convert a few functions. llvm-svn: 60983
* Enable out-of-line definitions of C++ constructors and destructorsDouglas Gregor2008-12-121-15/+24
| | | | llvm-svn: 60947
* Address some comments on the name lookup/DeclContext patch from ChrisDouglas Gregor2008-12-111-2/+2
| | | | llvm-svn: 60897
* Unifies the name-lookup mechanisms used in various parts of the ASTDouglas Gregor2008-12-111-35/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and separates lexical name lookup from qualified name lookup. In particular: * Make DeclContext the central data structure for storing and looking up declarations within existing declarations, e.g., members of structs/unions/classes, enumerators in C++0x enums, members of C++ namespaces, and (later) members of Objective-C interfaces/implementations. DeclContext uses a lazily-constructed data structure optimized for fast lookup (array for small contexts, hash table for larger contexts). * Implement C++ qualified name lookup in terms of lookup into DeclContext. * Implement C++ unqualified name lookup in terms of qualified+unqualified name lookup (since unqualified lookup is not purely lexical in C++!) * Limit the use of the chains of declarations stored in IdentifierInfo to those names declared lexically. * Eliminate CXXFieldDecl, collapsing its behavior into FieldDecl. (FieldDecl is now a ScopedDecl). * Make RecordDecl into a DeclContext and eliminates its Members/NumMembers fields (since one can just iterate through the DeclContext to get the fields). llvm-svn: 60878
* Simplify some diagnostics.Anders Carlsson2008-12-061-7/+7
| | | | llvm-svn: 60626
* Change a whole lot of diagnostics to take QualType's directly Chris Lattner2008-11-241-11/+9
| | | | | | | | instead of converting them to strings first. This also fixes a bunch of minor inconsistencies in the diagnostics emitted by clang and adds a bunch of FIXME's to DiagnosticKinds.def. llvm-svn: 59948
* Rename NamedDecl::getName() to getNameAsString(). Replace a bunch of Chris Lattner2008-11-241-10/+9
| | | | | | | | | | | uses of getName() with uses of getDeclName(). This upgrades a bunch of diags to take DeclNames instead of std::strings. This also tweaks a couple of diagnostics to be cleaner and changes CheckInitializerTypes/PerformInitializationByConstructor to pass around DeclarationNames instead of std::strings. llvm-svn: 59947
* Make all the 'redefinition' diagnostics more consistent, and make the Chris Lattner2008-11-231-8/+8
| | | | | | "previously defined here" diagnostics all notes. llvm-svn: 59920
* Convert IdentifierInfo's to be printed the same as DeclarationNames Chris Lattner2008-11-231-4/+4
| | | | | | | | | | | | | | | | | | | | | with implicit quotes around them. This has a bunch of follow-on effects and requires tweaking to a whole lot of code. This causes a regression in two tests (xfailed) by causing it to emit things like: Line 10: duplicate interface declaration for category 'MyClass1' ('Category1') instead of: Line 10: duplicate interface declaration for category 'MyClass1(Category1)' I will fix this in a follow-up commit. As part of this, I had to start switching stuff to use ->getDeclName() instead of Decl::getName() for consistency. This is good, but I was planning to do this as an independent patch. There will be several follow-on patches to clean up some of the mess, but this patch is already too big. llvm-svn: 59917
* Implement a %plural modifier for complex plural forms in diagnostics. Use it ↵Sebastian Redl2008-11-221-7/+3
| | | | | | in the overload diagnostics. llvm-svn: 59871
* merge 3 more diagnostics into 1.Chris Lattner2008-11-211-5/+6
| | | | llvm-svn: 59805
* Add the concept of "modifiers" to the clang diagnostic format Chris Lattner2008-11-211-23/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | strings. This allows us to have considerable flexibility in how these things are displayed and provides extra information that allows us to merge away diagnostics that are very similar. Diagnostic modifiers are a string of characters with the regex [-a-z]+ that occur between the % and digit. They may optionally have an argument that can parameterize them. For now, I've added two example modifiers. One is a very useful tool that allows you to factor commonality across diagnostics that need single words or phrases combined. Basically you can use %select{a|b|c}4 with with an integer argument that selects either a/b/c based on an integer value in the range [0..3). The second modifier is also an integer modifier, aimed to help English diagnostics handle plurality. "%s3" prints to 's' if integer argument #3 is not 1, otherwise it prints to nothing. I'm fully aware that 's' is an English concept and doesn't apply to all situations (mouse vs mice). However, this is very useful and we can add other crazy modifiers once we add support for polish! ;-) I converted a couple C++ diagnostics over to use this as an example, I'd appreciate it if others could merge the other likely candiates. If you have other modifiers that you want, lets talk on cfe-dev. llvm-svn: 59803
* Don't print canonical types in overloading-related diagnosticsDouglas Gregor2008-11-211-2/+2
| | | | llvm-svn: 59789
* remove the last old-fashioned Diag method. Transition complete!Chris Lattner2008-11-201-11/+10
| | | | llvm-svn: 59714
* remove another old Diag method.Chris Lattner2008-11-201-10/+9
| | | | llvm-svn: 59713
* remove another old-school Diag method.Chris Lattner2008-11-201-12/+10
| | | | llvm-svn: 59712
* stop calling II::getName() unnecesarily in semaChris Lattner2008-11-191-6/+6
| | | | llvm-svn: 59609
* Allow sending IdentifierInfo*'s into Diagnostics without turning them into ↵Chris Lattner2008-11-191-1/+1
| | | | | | | | strings first. This should allow removal of a bunch of II->getName() calls. llvm-svn: 59601
* convert some diags to use numbers instead of strings.Chris Lattner2008-11-191-6/+1
| | | | llvm-svn: 59600
* remove one more old-style Diag method.Chris Lattner2008-11-191-2/+2
| | | | llvm-svn: 59589
* Switch several more Sema Diag methods over. This simplifies theChris Lattner2008-11-191-118/+81
| | | | | | | | __builtin_prefetch code to only emit one diagnostic per builtin_prefetch. While this has nothing to do with the rest of the patch, the code seemed like overkill when I was updating it. llvm-svn: 59588
* start converting Sema over to using its canonical Diag method.Chris Lattner2008-11-181-8/+8
| | | | llvm-svn: 59561
* Implement effects of 'mutable', and a few comments from Chris on its parsing.Sebastian Redl2008-11-171-0/+4
| | | | llvm-svn: 59470
* Eliminate all of the placeholder identifiers used for constructors,Douglas Gregor2008-11-171-9/+9
| | | | | | | | | destructors, and conversion functions. The placeholders were used to work around the fact that the parser and some of Sema really wanted declarators to have simple identifiers; now, the code that deals with declarators will use DeclarationNames. llvm-svn: 59469
* Some cleanups for C++ operator overloadingDouglas Gregor2008-11-171-57/+37
| | | | llvm-svn: 59443
* Simplify error messages for two-parameter overloaded increment/decrement ↵Douglas Gregor2008-11-171-11/+4
| | | | | | operators llvm-svn: 59442
* Introduction the DeclarationName class, as a single, general method ofDouglas Gregor2008-11-171-6/+12
| | | | | | | | representing the names of declarations in the C family of languages. DeclarationName is used in NamedDecl to store the name of the declaration (naturally), and ObjCMethodDecl is now a NamedDecl. llvm-svn: 59441
* Implement parsing and semantic checking of the 'mutable' keyword.Sebastian Redl2008-11-141-2/+32
| | | | | | Thanks to Doug for the review. Actual effects of mutable to follow. llvm-svn: 59331
* Don't build identifiers for C++ constructors, destructors, orDouglas Gregor2008-11-121-5/+3
| | | | | | | | | | | | | | conversion functions. Instead, we just use a placeholder identifier for these (e.g., "<constructor>") and override NamedDecl::getName() to provide a human-readable name. This is one potential solution to the problem; another solution would be to replace the use of IdentifierInfo* in NamedDecl with a different class that deals with identifiers better. I'm also prototyping that to see how it compares, but this commit is better than what we had previously. llvm-svn: 59193
* Implement support for operator overloading using candidate operatorDouglas Gregor2008-11-121-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functions for built-in operators, e.g., the builtin bool operator==(int const*, int const*) can be used for the expression "x1 == x2" given: struct X { operator int const*(); } x1, x2; The scheme for handling these built-in operators is relatively simple: for each candidate required by the standard, create a special kind of candidate function for the built-in. If overload resolution picks the built-in operator, we perform the appropriate conversions on the arguments and then let the normal built-in operator take care of it. There may be some optimization opportunity left: if we can reduce the number of built-in operator overloads we generate, overload resolution for these cases will go faster. However, one must be careful when doing this: GCC generates too few operator overloads in our little test program, and fails to compile it because none of the overloads it generates match. Note that we only support operator overload for non-member binary operators at the moment. The other operators will follow. As part of this change, ImplicitCastExpr can now be an lvalue. llvm-svn: 59148
* Basic support for taking the address of an overloaded functionDouglas Gregor2008-11-101-0/+16
| | | | llvm-svn: 59000
OpenPOWER on IntegriCloud