[cfe-dev] Changing the size of ConstantArrayType

John McCall rjmccall at apple.com
Mon Jan 31 14:08:28 PST 2011

On Jan 31, 2011, at 1:39 PM, Dimitrij Kotrev wrote:
> i need a way to change the size of the ConstantArrayType after the AST
> is created.

Types are immutable, and for good reason.

I assume that what you're actually trying to do is change the allocated
size of an array-typed variable or field.

> I thought about two ways to do it:
> 1. I'll add a setSize method to ConstantArrayType class.

This would play havoc with the entire type system;  don't do this.

> or
> 2. I replace 'somehow' the node in the AST with a new one, which has
> the size i need.

If my guess above is correct, then what you want to do is to set the type
of your VarDecl/FieldDecl to be the new type.  It's not necessarily quite that
simple, though — you'll also need to modify the types of all the references
to that variable, and you'll need to pretend that all the ways in which the
length of a declared array is reflectively discoverable in code can't actually
happen (†).


† The most obvious way to detect the length of an array is with template
argument deduction in C++; even in C, though, you have to worry about
code doing clever things with sizeof.

More information about the cfe-dev mailing list