Add support for function pointers.

Both uniform and varying function pointers are supported; when a function
is called through a varying function pointer, each unique function pointer
value across the running program instances is called once for the set of
active program instances that want to call it.
This commit is contained in:
Matt Pharr
2011-11-03 16:13:27 -07:00
parent f1d8ff96ce
commit afcd42028f
15 changed files with 1137 additions and 269 deletions

View File

@@ -91,6 +91,7 @@ Declarator::Declarator(Symbol *s, SourcePos p)
functionArgs = NULL;
isFunction = false;
initExpr = NULL;
pointerCount = 0;
}
@@ -104,6 +105,14 @@ Declarator::AddArrayDimension(int size) {
void
Declarator::InitFromDeclSpecs(DeclSpecs *ds) {
sym->type = GetType(ds);
for (int i = 0; i < pointerCount; ++i) {
// Only function pointers for now...
if (dynamic_cast<const FunctionType *>(sym->type) == NULL)
Error(pos, "Only pointers to functions are currently allowed, "
"not pointers to \"%s\".", sym->type->GetString().c_str());
else
sym->type = new PointerType(sym->type, true, false);
}
sym->storageClass = ds->storageClass;
}