made local variable names case-insensitive

actorid
Marc Zinnschlag 15 years ago
parent c6a37b2e18
commit 10cb9d3dab

@ -49,8 +49,10 @@ namespace Compiler
scanner.scan (skip); scanner.scan (skip);
return false; return false;
} }
std::string name2 = toLower (name);
char type = mLocals.getType (name); char type = mLocals.getType (name2);
if (type!=' ') if (type!=' ')
{ {
@ -61,7 +63,7 @@ namespace Compiler
} }
mLocals.declare (mState==ShortState ? 's' : (mState==LongState ? 'l' : 'f'), mLocals.declare (mState==ShortState ? 's' : (mState==LongState ? 'l' : 'f'),
name); name2);
mState = EndState; mState = EndState;
return true; return true;
@ -70,10 +72,11 @@ namespace Compiler
if (mState==SetState) if (mState==SetState)
{ {
// local variable? // local variable?
char type = mLocals.getType (name); std::string name2 = toLower (name);
char type = mLocals.getType (name2);
if (type!=' ') if (type!=' ')
{ {
mName = name; mName = name2;
mState = SetLocalVarState; mState = SetLocalVarState;
return true; return true;
} }

@ -1,6 +1,9 @@
#include "parser.hpp" #include "parser.hpp"
#include <cctype>
#include <algorithm>
#include "errorhandler.hpp" #include "errorhandler.hpp"
#include "exception.hpp" #include "exception.hpp"
@ -50,6 +53,16 @@ namespace Compiler
return mContext; return mContext;
} }
std::string Parser::toLower (const std::string& name)
{
std::string lowerCase;
std::transform (name.begin(), name.end(), std::back_inserter (lowerCase),
(int(*)(int)) std::tolower);
return lowerCase;
}
Parser::Parser (ErrorHandler& errorHandler, Context& context) Parser::Parser (ErrorHandler& errorHandler, Context& context)
: mErrorHandler (errorHandler), mContext (context) : mErrorHandler (errorHandler), mContext (context)
{} {}

@ -21,8 +21,6 @@ namespace Compiler
protected: protected:
// mutators
void reportSeriousError (const std::string& message, const TokenLoc& loc); void reportSeriousError (const std::string& message, const TokenLoc& loc);
///< Report the error and throw a exception. ///< Report the error and throw a exception.
@ -41,6 +39,8 @@ namespace Compiler
Context& getContext(); Context& getContext();
///< Return context ///< Return context
static std::string toLower (const std::string& name);
public: public:
Parser (ErrorHandler& errorHandler, Context& context); Parser (ErrorHandler& errorHandler, Context& context);

Loading…
Cancel
Save