llvm-project/clang/lib/Index
Douglas Gregor 9a12919421 Overhaul the AST representation of Objective-C message send
expressions, to improve source-location information, clarify the
actual receiver of the message, and pave the way for proper C++
support. The ObjCMessageExpr node represents four different kinds of
message sends in a single AST node:

  1) Send to a object instance described by an expression (e.g., [x method:5])
  2) Send to a class described by the class name (e.g., [NSString method:5])
  3) Send to a superclass class (e.g, [super method:5] in class method)
  4) Send to a superclass instance (e.g., [super method:5] in instance method)

Previously these four cases where tangled together. Now, they have
more distinct representations. Specific changes:

  1) Unchanged; the object instance is represented by an Expr*.

  2) Previously stored the ObjCInterfaceDecl* referring to the class
  receiving the message. Now stores a TypeSourceInfo* so that we know
  how the class was spelled. This both maintains typedef information
  and opens the door for more complicated C++ types (e.g., dependent
  types). There was an alternative, unused representation of these
  sends by naming the class via an IdentifierInfo *. In practice, we
  either had an ObjCInterfaceDecl *, from which we would get the
  IdentifierInfo *, or we fell into the case below...

  3) Previously represented by a class message whose IdentifierInfo *
  referred to "super". Sema and CodeGen would use isStr("super") to
  determine if they had a send to super. Now represented as a
  "class super" send, where we have both the location of the "super"
  keyword and the ObjCInterfaceDecl* of the superclass we're
  targetting (statically).

  4) Previously represented by an instance message whose receiver is a
  an ObjCSuperExpr, which Sema and CodeGen would check for via
  isa<ObjCSuperExpr>(). Now represented as an "instance super" send,
  where we have both the location of the "super" keyword and the
  ObjCInterfaceDecl* of the superclass we're targetting
  (statically). Note that ObjCSuperExpr only has one remaining use in
  the AST, which is for "super.prop" references.

The new representation of ObjCMessageExpr is 2 pointers smaller than
the old one, since it combines more storage. It also eliminates a leak
when we loaded message-send expressions from a precompiled header. The
representation also feels much cleaner to me; comments welcome!

This patch attempts to maintain the same semantics we previously had
with Objective-C message sends. In several places, there are massive
changes that boil down to simply replacing a nested-if structure such
as:

  if (message has a receiver expression) {
    // instance message
    if (isa<ObjCSuperExpr>(...)) {
     // send to super
    } else {
     // send to an object
   }
  } else {
    // class message
    if (name->isStr("super")) {
      // class send to super
    } else {
      // send to class
    }
  }

with a switch

  switch (E->getReceiverKind()) {
  case ObjCMessageExpr::SuperInstance: ...
  case ObjCMessageExpr::Instance: ...
  case ObjCMessageExpr::SuperClass: ...
  case ObjCMessageExpr::Class:...
  }

There are quite a few places (particularly in the checkers) where
send-to-super is effectively ignored. I've placed FIXMEs in most of
them, and attempted to address send-to-super in a reasonable way. This
could use some review.

llvm-svn: 101972
2010-04-21 00:45:42 +00:00
..
ASTLocation.cpp Add raw_ostream operators to NamedDecl for convenience. Switch over all users of getNameAsString on a stream. 2010-04-17 09:33:03 +00:00
ASTVisitor.h Add the BlockDecl to the DeclContext. 2009-12-07 22:01:30 +00:00
Analyzer.cpp Overhaul the AST representation of Objective-C message send 2010-04-21 00:45:42 +00:00
CMakeLists.txt Update CMake for CallGraph.cpp move. 2009-12-03 09:14:19 +00:00
CallGraph.cpp Fix layering violation by moving Analysis/CallGraph to Index 2009-12-03 07:20:04 +00:00
DeclReferenceMap.cpp Remove remaining VISIBILITY_HIDDEN from anonymous namespaces. 2009-11-28 19:45:26 +00:00
Entity.cpp Cleanup using StringRef 2010-03-12 09:33:31 +00:00
EntityImpl.h Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
GlobalSelector.cpp Cleanup using StringRef 2010-03-12 09:33:31 +00:00
Handlers.cpp Introduce TULocation and TULocationHandler classes. 2009-07-29 23:40:02 +00:00
IndexProvider.cpp -Make IndexProvider an abstract interface for getting indexing information. 2009-07-29 23:38:21 +00:00
Indexer.cpp Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
Makefile Allow users to set CPPFLAGS and CXXFLAGS on the make command line. 2010-03-12 22:55:16 +00:00
Program.cpp Accept Handler objects in parameters as references. 2009-07-29 23:38:45 +00:00
ProgramImpl.h Remove tabs, and whitespace cleanups. 2009-09-09 15:08:12 +00:00
ResolveLocation.cpp Add -cursor-at=file:line:column command line option to c-index-test, 2010-01-15 19:40:17 +00:00
SelectorMap.cpp Remove remaining VISIBILITY_HIDDEN from anonymous namespaces. 2009-11-28 19:45:26 +00:00