<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 10/19/2018 2:04 AM, illiop via
cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:65ffc76a.f3f8.1668b91c714.Coremail.huansprout@163.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div
style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial">
<div>Hello, </div>
<div> </div>
<div>if the program is :</div>
<div> </div>
<div>void foo()</div>
<div>{</div>
<div> int a[3] = {0,1,2};</div>
<div>}</div>
<div> </div>
<div>If I get the ast nodes by the ast matcher:
varDecl(hasType(arrayType()))</div>
<div>I will get int a[3] matched, the matched node is a VarDecl
type.</div>
<div>How can I get the array size (in this example is 3) from
the VarDecl node ? </div>
</div>
</blockquote>
<br>
getType() on the VarDecl returns a QualType. Call
ASTContext::getAsConstantArrayType to convert that to a
ConstantArrayType*. Call ConstantArrayType::getSize() to return the
size.<br>
<br>
If you need access to the original Expr*, as opposed to the computed
size, you might need to dig through the TypeSourceInfo instead.<br>
<br>
-Eli
<pre class="moz-signature" cols="72">--
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</pre>
</body>
</html>