MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / handleFunctionDefinition

Method handleFunctionDefinition

glslang/MachineIndependent/ParseHelper.cpp:1284–1371  ·  view source on GitHub ↗

Handle seeing the function prototype in front of a function definition in the grammar. The body is handled after this function returns.

Source from the content-addressed store, hash-verified

1282// The body is handled after this function returns.
1283//
1284TIntermAggregate* TParseContext::handleFunctionDefinition(const TSourceLoc& loc, TFunction& function)
1285{
1286 currentCaller = function.getMangledName();
1287 TSymbol* symbol = symbolTable.find(function.getMangledName());
1288 TFunction* prevDec = symbol ? symbol->getAsFunction() : nullptr;
1289
1290 if (! prevDec)
1291 error(loc, "can't find function", function.getName().c_str(), "");
1292 // Note: 'prevDec' could be 'function' if this is the first time we've seen function
1293 // as it would have just been put in the symbol table. Otherwise, we're looking up
1294 // an earlier occurrence.
1295
1296 if (prevDec && prevDec->isDefined()) {
1297 // Then this function already has a body.
1298 error(loc, "function already has a body", function.getName().c_str(), "");
1299 }
1300 if (prevDec && ! prevDec->isDefined()) {
1301 prevDec->setDefined();
1302
1303 // Remember the return type for later checking for RETURN statements.
1304 currentFunctionType = &(prevDec->getType());
1305 } else
1306 currentFunctionType = new TType(EbtVoid);
1307 functionReturnsValue = false;
1308
1309 // Check for entry point
1310 if (function.getName().compare(intermediate.getEntryPointName().c_str()) == 0) {
1311 intermediate.setEntryPointMangledName(function.getMangledName().c_str());
1312 intermediate.incrementEntryPointCount();
1313 inMain = true;
1314 } else
1315 inMain = false;
1316
1317 //
1318 // Raise error message if main function takes any parameters or returns anything other than void
1319 //
1320 if (inMain) {
1321 if (function.getParamCount() > 0)
1322 error(loc, "function cannot take any parameter(s)", function.getName().c_str(), "");
1323 if (function.getType().getBasicType() != EbtVoid)
1324 error(loc, "", function.getType().getBasicTypeString().c_str(), "entry point cannot return a value");
1325 if (function.getLinkType() != ELinkNone)
1326 error(loc, "main function cannot be exported", "", "");
1327 }
1328
1329 //
1330 // New symbol table scope for body of function plus its arguments
1331 //
1332 symbolTable.push();
1333
1334 //
1335 // Insert parameters into the symbol table.
1336 // If the parameter has no name, it's not an error, just don't insert it
1337 // (could be used for unused args).
1338 //
1339 // Also, accumulate the list of parameters into the HIL, so lower level code
1340 // knows where to find parameters.
1341 //

Callers 1

yyparseFunction · 0.45

Calls 15

errorFunction · 0.85
c_strMethod · 0.80
isDefinedMethod · 0.80
setDefinedMethod · 0.80
getTypeMethod · 0.80
getParamCountMethod · 0.80
getBasicTypeStringMethod · 0.80
growAggregateMethod · 0.80
addSymbolMethod · 0.80
setLinkTypeMethod · 0.80

Tested by

no test coverage detected