Handle seeing the function prototype in front of a function definition in the grammar. The body is handled after this function returns.
| 1282 | // The body is handled after this function returns. |
| 1283 | // |
| 1284 | TIntermAggregate* 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 | // |
no test coverage detected