<div dir="ltr">How do I obtain the data that a macro points to, both expanded and unexpanded.<div><br></div><div>in example I have a file named "blah.c" with the following.</div><div>"""</div><div>
#define TESTA 1</div><div>#define TESTB 2 + TESTA</div><div>"""</div><div><br></div><div>I modified util.py's get_cursor to look at the displayname also, as spelling won't match the macroname.</div>
<div>"""<br> <font face="courier new, monospace"> <span class="">for</span> cursor <span class="">in</span> children:<br></font><span style="font-family:'courier new',monospace"> </span><span class="" style="font-family:'courier new',monospace">if</span><span style="font-family:'courier new',monospace"> cursor.spelling == spelling:<br>
</span><span style="font-family:'courier new',monospace"> </span><span class="" style="font-family:'courier new',monospace">return</span><span style="font-family:'courier new',monospace"> cursor<br>
</span><span style="font-family:'courier new',monospace"> </span><span class="" style="font-family:'courier new',monospace">if</span><span style="font-family:'courier new',monospace"> cursor.displayname == spelling:<br>
</span><span style="font-family:'courier new',monospace"> </span><span class="" style="font-family:'courier new',monospace">return</span><font face="courier new, monospace"> cursor<br></font>"""</div>
<div><br><div><div>import scripts.clang.cindex as cindex</div><div>from scripts.util import get_cursor</div><div><br></div><div>index = cindex.Index.create()</div><div><br></div><div>t = cindex.TranslationUnit</div><div>
tu = index.parse('blah.c',[ ] ,options=t.PARSE_DETAILED_PROCESSING_RECORD | t.PARSE_PRECOMPILED_PREAMBLE)</div>
<div><br></div><div>cursor = tu.cursor</div><div>z = get_cursor(cursor,'TESTB')</div><div><br></div><div>fid = open('blah.c')</div><div>raw = fid.read()</div><div>fid.close()</div><div>print raw[z.extent.start.offset:z.extent.end.offset]</div>
</div><div><br></div><div>this outputs</div><div><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.59375px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
TESTB 2 + TESTA</pre><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.59375px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<br></pre><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.59375px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
How should I go about obtaining the expanded macro of 3.</pre><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.59375px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<br></pre><pre style="padding:0px;font-size:14px;color:rgb(0,0,0);border-top-left-radius:0px;border-top-right-radius:0px;border-bottom-right-radius:0px;border-bottom-left-radius:0px;margin-top:0px;margin-bottom:0px;line-height:17.59375px;word-break:break-all;word-wrap:break-word;white-space:pre-wrap;border:0px;vertical-align:baseline">
<br></pre><div><br></div>-- <br>Thank you,<br><br>Sam Price<br></div></div></div>