mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Complain if a function or an integer is used as a local variable name
This commit is contained in:
parent
176e6490c5
commit
89eccffbf6
1 changed files with 12 additions and 0 deletions
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
#include <components/misc/strings/lower.hpp>
|
#include <components/misc/strings/lower.hpp>
|
||||||
|
|
||||||
|
#include "context.hpp"
|
||||||
#include "errorhandler.hpp"
|
#include "errorhandler.hpp"
|
||||||
|
#include "extensions.hpp"
|
||||||
#include "locals.hpp"
|
#include "locals.hpp"
|
||||||
#include "scanner.hpp"
|
#include "scanner.hpp"
|
||||||
#include "skipparser.hpp"
|
#include "skipparser.hpp"
|
||||||
|
@ -70,6 +72,15 @@ bool Compiler::DeclarationParser::parseKeyword(int keyword, const TokenLoc& loc,
|
||||||
else if (mState == State_Name)
|
else if (mState == State_Name)
|
||||||
{
|
{
|
||||||
// allow keywords to be used as local variable names. MW script compiler, you suck!
|
// allow keywords to be used as local variable names. MW script compiler, you suck!
|
||||||
|
if (const Extensions* extensions = getContext().getExtensions())
|
||||||
|
{
|
||||||
|
std::string argumentType;
|
||||||
|
bool hasExplicit = false;
|
||||||
|
char returnType;
|
||||||
|
if (extensions->isFunction(keyword, returnType, argumentType, hasExplicit))
|
||||||
|
getErrorHandler().warning("Local variable declaration shadows a function", loc);
|
||||||
|
}
|
||||||
|
|
||||||
return parseName(loc.mLiteral, loc, scanner);
|
return parseName(loc.mLiteral, loc, scanner);
|
||||||
}
|
}
|
||||||
else if (mState == State_End)
|
else if (mState == State_End)
|
||||||
|
@ -104,6 +115,7 @@ bool Compiler::DeclarationParser::parseInt(int value, const TokenLoc& loc, Scann
|
||||||
if (mState == State_Name)
|
if (mState == State_Name)
|
||||||
{
|
{
|
||||||
// Allow integers to be used as variable names
|
// Allow integers to be used as variable names
|
||||||
|
getErrorHandler().warning("Integer is used as a local variable name", loc);
|
||||||
return parseName(loc.mLiteral, loc, scanner);
|
return parseName(loc.mLiteral, loc, scanner);
|
||||||
}
|
}
|
||||||
return Parser::parseInt(value, loc, scanner);
|
return Parser::parseInt(value, loc, scanner);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue