[cfe-dev] How to pull back data static array data in a code generator

chris nuernberger cnuernber at gmail.com
Thu May 12 13:06:13 PDT 2011


Hey guys,

Given a set of statements like this:

struct PropertyOverride
{
	const char* TypeName;
	const char* PropName;
	const char* OverridePropName;
	PropertyOverride( const char* tn, const char* pn, const char* opn )
		: TypeName( tn )
		, PropName( pn )
		, OverridePropName( opn )
	{
	}
};

static PropertyOverride gPropertyOverrides[] = {
	PropertyOverride( "PxShape", "Geometry", "PxShapeGeometryProperty" ),
	PropertyOverride( "PxShape", "Materials", "PxShapeMaterialsProperty" ),
	PropertyOverride( "PxRigidActor", "Shapes", "PxRigidActorShapeCollection" ),
	PropertyOverride( "PxArticulation", "Links",
"PxArticulationLinkCollectionProp" ),
};

I would like, by analyzing the clang AST, pull out the initializes for
gPropertyOverrides.  That is to say that I would like to pull out
"PxShape", "Geometry", "PxShapeGeometryProperty"

from the AST.

My first plan of attack is to visit all statements that declare global
or file-scope variables, and look for one named gPropertyOverrides.
Then dive down into that statement and attempt to pull out the static
array initializations.

I don't know which statements to visit to do this, and I am wondering
how to get back all those details from the array initialization.

I could setup the problem differently, so if digging through the class
constructor arguments is going to be tough I could go a different
route.  The important piece is linking gPropertyOverrides with a list
3 item string tuples.

I am also unclear on the difference between TraverseCxxRecordDecl and
VisitCxxRecordDecl.

Any thoughs?

Chris

-- 
A foolish consistency is the hobgoblin of little minds - Emerson



More information about the cfe-dev mailing list