]> granicus.if.org Git - clang/commitdiff
Fill in Index.h header file and add stubs to implementation file.
authorSteve Naroff <snaroff@apple.com>
Thu, 27 Aug 2009 19:51:58 +0000 (19:51 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 27 Aug 2009 19:51:58 +0000 (19:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80279 91177308-0d34-0410-b5e6-96231b3b80d8

clang.xcodeproj/project.pbxproj
include/clang-c/Index.h
tools/CIndex/CIndex.cpp

index 2f81bc20b39423b80d231f8f6a180bf6c593cb8c..89fb901d3869b19006c5c2d44fd2697c06280621 100644 (file)
                84D9A8870C1A57E100AC7ABC /* AttributeList.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = AttributeList.cpp; path = lib/Parse/AttributeList.cpp; sourceTree = "<group>"; tabWidth = 2; };
                84D9A88B0C1A581300AC7ABC /* AttributeList.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = AttributeList.h; path = clang/Parse/AttributeList.h; sourceTree = "<group>"; tabWidth = 2; };
                8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+               9012911510470FCE0083456D /* Index.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Index.h; path = "clang-c/Index.h"; sourceTree = "<group>"; };
                9063F2210F9E8BDF002F7251 /* ExternalSemaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExternalSemaSource.h; path = clang/Sema/ExternalSemaSource.h; sourceTree = "<group>"; };
                9063F2220F9E8BDF002F7251 /* SemaConsumer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SemaConsumer.h; path = clang/Sema/SemaConsumer.h; sourceTree = "<group>"; };
                9063F2280F9E911F002F7251 /* OnDiskHashTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OnDiskHashTable.h; sourceTree = "<group>"; };
                        name = Analyses;
                        sourceTree = "<group>";
                };
+               9012911210470FAF0083456D /* clang-c */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9012911510470FCE0083456D /* Index.h */,
+                       );
+                       name = "clang-c";
+                       sourceTree = "<group>";
+               };
                90FD6D5E103C3D03005F5B73 /* Index */ = {
                        isa = PBXGroup;
                        children = (
                DED7D72E0A524295003AD0FB /* include */ = {
                        isa = PBXGroup;
                        children = (
+                               9012911210470FAF0083456D /* clang-c */,
                                90FD6D5E103C3D03005F5B73 /* Index */,
                                DED7D7300A524295003AD0FB /* Basic */,
                                DED7D7390A524295003AD0FB /* Lex */,
index eb1cbd156d6411db4ab406efd35792f29443244d..426223fb1afdb53f69188afdb295937c5808fadf 100644 (file)
 extern "C" {
 #endif
 
-/**
- * Dummy function that serves as an entrance to the library.
- * To be replaced with specific functions.
- */
-void clang_index_dummy(void);
+/*
+   Clang indeX abstractions. The backing store for the following API's will be 
+   clangs PCH file (which contains AST's, or Abstract Syntax Trees). PCH files
+   are created by the following command:
+   
+   "clang -emit-pch <sourcefile.langsuffix> -o <sourcefile.ast>". 
+   
+   If the ast file format ends up diverging from the pch file format, we will 
+   need to add a new switch (-emit-ast). For now, the contents are identical.
+
+   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 *CXCursor;  // An opaque cursor into the CXTranslationUnit.
+
+// Cursors represent declarations and references (provides line/column info).
+enum CXCursorKind {  
+ Cursor_Declaration,
+ Cursor_Reference,
+ Cursor_ObjC_ClassRef,
+ Cursor_ObjC_ProtocolRef,
+ Cursor_ObjC_MessageRef,
+ Cursor_ObjC_SelectorRef
+};
+
+typedef void *CXDecl;    // A specific declaration within a translation unit.
+
+enum CXDeclKind {  // The various kinds of declarations.
+ CXDecl_any,
+ CXDecl_typedef,
+ CXDecl_enum,
+ CXDecl_enum_constant,
+ CXDecl_record,
+ CXDecl_field,
+ CXDecl_function,
+ CXDecl_variable,
+ CXDecl_parameter,
+ CXDecl_ObjC_interface,
+ CXDecl_ObjC_category,
+ CXDecl_ObjC_protocol,
+ CXDecl_ObjC_property,
+ CXDecl_ObjC_instance_variable,
+ CXDecl_ObjC_instance_method,
+ CXDecl_ObjC_class_method,
+ CXDecl_ObjC_category_implementation,
+ CXDecl_ObjC_class_implementation,
+ CXDecl_ObjC_property_implementation
+};
+
+// A unique token for looking up "visible" CXDecls from a CXTranslationUnit.
+typedef void *CXEntity;     
+
+CXIndex clang_createIndex();
+
+CXTranslationUnit clang_loadTranslationUnitFromASTFile(
+  CXIndex, const char *ast_filename
+);
+
+/*
+   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);
+   }
+*/
+void clang_loadTranslationUnit(
+  CXTranslationUnit, void (*callback)(CXTranslationUnit, CXCursor)
+);
+
+/*
+   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);
+     }
+   }
+*/
+void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor));
+
+//
+// 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);
+enum CXDeclKind clang_getDeclKind(CXDecl);
+const char *clang_getDeclSpelling(CXDecl);
+//
+// CXCursor Operations.
+//
+CXCursor clang_getCursor(CXTranslationUnit, const char *source_name, 
+                         unsigned line, unsigned column);
+
+CXCursorKind clang_getCursorKind(CXCursor);
+
+unsigned clang_getCursorLine(CXCursor);
+unsigned clang_getCursorColumn(CXCursor);
+const char *clang_getCursorSource(CXCursor);
+
+// 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
 }
index 8eb45452c9709c17c8e38ab886ab1e81bfa770b6..86e63607b473cc99af675f967bc873d321622d6f 100644 (file)
 
 #include "clang-c/Index.h"
 
-void clang_index_dummy(void) {}
+extern "C" {
 
+// Some notes on CXEntity:
+//
+// - Since the 'ordinary' namespace includes functions, data, typedefs, ObjC interfaces, the
+// current algorithm is a bit naive (resulting in one entity for 2 different types). For example:
+//
+// module1.m: @interface Foo @end Foo *x;
+// module2.m: void Foo(int);
+//
+// - Since the unique name spans translation units, static data/functions within a CXTranslationUnit
+// are *not* currently represented by entities. As a result, there will be no entity for the following:
+//
+// module.m: static void Foo() { }
+//
+
+CXIndex clang_createIndex() 
+{ 
+  return 0; 
+}
+
+CXTranslationUnit clang_loadTranslationUnitFromASTFile(
+  CXIndex, const char *ast_filename) 
+{
+  return 0;
+}
+
+void clang_loadTranslationUnit(
+  CXTranslationUnit, void (*callback)(CXTranslationUnit, CXCursor)
+)
+{
+}
+
+void clang_loadDeclaration(CXDecl, void (*callback)(CXDecl, CXCursor))
+{
+}
+
+const char *clang_getDeclarationName(CXEntity)
+{
+  return "";
+}
+const char *clang_getURI(CXEntity)
+{
+  return "";
+}
+
+CXEntity clang_getEntity(const char *URI)
+{
+  return 0;
+}
+
+//
+// CXDecl Operations.
+//
+CXCursor clang_getCursorFromDecl(CXDecl)
+{
+  return 0;
+}
+CXEntity clang_getEntityFromDecl(CXDecl)
+{
+  return 0;
+}
+enum CXDeclKind clang_getDeclKind(CXDecl)
+{
+  return CXDecl_any;
+}
+const char *clang_getDeclSpelling(CXDecl)
+{
+  return "";
+}
+//
+// CXCursor Operations.
+//
+CXCursor clang_getCursor(CXTranslationUnit, const char *source_name, 
+                         unsigned line, unsigned column)
+{
+  return 0;
+}
+
+CXCursorKind clang_getCursorKind(CXCursor)
+{
+  return Cursor_Declaration;
+}
+
+unsigned clang_getCursorLine(CXCursor)
+{
+  return 0;
+}
+unsigned clang_getCursorColumn(CXCursor)
+{
+  return 0;
+}
+const char *clang_getCursorSource(CXCursor) 
+{
+  return "";
+}
+
+// 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) 
+{
+  return 0;
+}
+
+} // end extern "C"