<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Thanks for your explanation.<br><br>But I can't get the result you said, when i run my test programe on the input, i get totally different result list below, could you kindly check my code please? <br>//run( cursor is on previous)<br>./clang_test /home/lucency/Study/source/lua/src/lcode.c 45 21 -I/home/lucency/Study/source/lua/src<br><br>//Result begin<br>Display: []<br>Kind [200] - [UnexposedStmt].<br>LK [0].<br>USR: [].<br>Can't find Cursor's reference.<br>//Result end<br><br>//code begin<br>#include "clang-c/Index.h"<br>#include <stdio.h><br>#include <stdlib.h><br>#include <string.h><br><br>static int displayCursorInfo(CXCursor Cursor)<br>{ <br> CXString String = clang_getCursorDisplayName(Cursor);<br> printf("Display: [%s]\n", clang_getCString(String));<br>
clang_disposeString(String);<br><br> CXCursorKind Kind = clang_getCursorKind(Cursor);<br> String = clang_getCursorKindSpelling(Kind);<br> printf("Kind [%d] - [%s].\n", Kind, clang_getCString(String));<br> clang_disposeString(String);<br><br> CXLinkageKind LK = clang_getCursorLinkage(Cursor);<br> printf("LK [%d].\n", LK);<br><br> CXString str2 = clang_getCursorUSR(Cursor);<br> printf("USR: [%s].\n", clang_getCString(str2));<br> clang_disposeString(str2);<br><br> return 0;<br>}<br>int main(int argc, char** argv)<br>{<br> CXTranslationUnit TU;<br> CXIndex Index = clang_createIndex(0,0);<br><br> //clang_test file line column -I..<br> int idx = 1;<br> char* szFileName =
argv[idx++];<br> int nLine = atoi(argv[idx++]);<br> int nColumn = atoi(argv[idx++]);<br> int nArgs = argc - idx;<br> char** szArgs = &argv[idx];<br><br> TU = clang_parseTranslationUnit(Index, szFileName, szArgs, nArgs, 0, 0, CXTranslationUnit_DetailedPreprocessingRecord);<br><br> if( !TU )<br> {<br> printf("File has some errors.\n");<br><br> clang_disposeIndex(Index);<br><br> return -1;<br> }<br><br> CXFile File = clang_getFile(TU, szFileName );<br> if( File == NULL )<br> {<br> printf("Can't get CXFile.\n");<br><br>
clang_disposeTranslationUnit(TU);<br> clang_disposeIndex(Index);<br><br> return -1;<br> }<br> CXSourceLocation Location = clang_getLocation(TU, File, nLine, nColumn);<br><br> CXCursor Cursor = clang_getCursor(TU, Location);<br><br> displayCursorInfo(Cursor);<br><br> CXCursor iDefCursor;<br> if( clang_getCursorKind(Cursor) == CXCursor_MacroDefinition )<br> iDefCursor = Cursor;<br> else<br> iDefCursor = clang_getCursorReferenced(Cursor);<br> if( clang_equalCursors(iDefCursor, clang_getNullCursor() ) )<br> {<br> printf("Can't find Cursor's
reference.\n");<br><br> clang_disposeTranslationUnit(TU);<br> clang_disposeIndex(Index);<br><br> return -1;<br> }<br><br> displayCursorInfo(iDefCursor);<br><br> clang_disposeTranslationUnit(TU);<br> clang_disposeIndex(Index);<br><br> return 0;<br>}<br>//code ends<br><br>// /Input file(only important piece, the most left column in lcode.c is line number)<br>//lopcodes.h<br>... ...<br>#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \<br> ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B))))<br>... ...<br><br>//lcode.c <br>... ...<br>35 void luaK_nil (FuncState *fs, int from, int n) {<br>36 Instruction *previous;<br>37 if (fs->pc >
fs->lasttarget) { /* no jumps to current position? */<br>38 if (fs->pc == 0) /* function start? */<br>39 return; /* positions are already clean */<br>40 if (GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {<br>41 int pfrom = GETARG_A(*previous);<br>42 int pto = GETARG_B(*previous);<br>43 if (pfrom <= from && from <= pto+1) { /* can connect both? */<br>44 if (from+n-1 > pto)<br>45 SETARG_B(*previous, from+n-1);<br>46 return;<br>47 }<br>48 }<br>49 }<br>50 luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0); /* else no optimization */<br>51}<br>... ...<br><br>--- <b>11年1月25日,周二,
Douglas Gregor <i><dgregor@apple.com></i></b> 写道:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>发件人: Douglas Gregor <dgregor@apple.com><br>主题: Re: [cfe-dev] How to get symbol's info. when the symbol is in macro instantiation<br>收件人: "jiyang zhao" <zjyzhaojiyang@yahoo.com.cn><br>抄送: cfe-dev@cs.uiuc.edu<br>日期: 2011年1月25日,周二,下午11:53<br><br><div id="yiv1157008527"><br>On Jan 25, 2011, at 12:30 AM, jiyang zhao wrote:<br><br><blockquote type="cite">Hi list<br>I meet a problem about macro when using libclang, when i want to get a viriable's infomation which is in a macro instantiation, for example, its linkage kind, i get 200(UnexposedStmt), is this the expected result? If so, how can i get the exact information of the symbol(e.g. previous in following code, SETARG_B is macro)?<br><br>//example<br>SETARG_B(*previous,
from+n-1);<br><br>Thanks<br></blockquote><br>This reference to previous will show up as a CXCursor_DeclRefExpr cursor. You can then use clang_getCursorReferenced() to find the declaration that the cursor points to.<div><br></div><div><span class="yiv1157008527Apple-tab-span" style="white-space: pre;"> </span>- Doug<br><br></div></div></blockquote></td></tr></table><br>