<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"> for cursor in children:<br></font><span style="font-family:'courier new',monospace">        </span><span 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 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 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 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="white-space:pre-wrap;border-top-left-radius:0px;margin-bottom:0px;padding:0px;vertical-align:baseline;line-height:17.59375px;word-break:break-all;border-top-right-radius:0px;font-size:14px;border-bottom-right-radius:0px;margin-top:0px;word-wrap:break-word;border:0px;border-bottom-left-radius:0px">

TESTB 2 + TESTA</pre><pre style="white-space:pre-wrap;border-top-left-radius:0px;margin-bottom:0px;padding:0px;vertical-align:baseline;line-height:17.59375px;word-break:break-all;border-top-right-radius:0px;font-size:14px;border-bottom-right-radius:0px;margin-top:0px;word-wrap:break-word;border:0px;border-bottom-left-radius:0px">

<br></pre><pre style="white-space:pre-wrap;border-top-left-radius:0px;margin-bottom:0px;padding:0px;vertical-align:baseline;line-height:17.59375px;word-break:break-all;border-top-right-radius:0px;font-size:14px;border-bottom-right-radius:0px;margin-top:0px;word-wrap:break-word;border:0px;border-bottom-left-radius:0px">

How should I go about obtaining the expanded macro of 3.</pre><div class="" style="font-family:arial,sans-serif;font-size:12.727272033691406px"></div></div></div><div class="gmail_extra">preferably without reading in the file and accessing the raw binary data. <br>

<br></div></div>