mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Apply clang-format to code base
This commit is contained in:
parent
f37d0be806
commit
ddb0522bbf
2199 changed files with 118692 additions and 114392 deletions
|
@ -1,27 +1,27 @@
|
|||
#include "exprparser.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <stack>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <components/misc/strings/lower.hpp>
|
||||
|
||||
#include "generator.hpp"
|
||||
#include "scanner.hpp"
|
||||
#include "errorhandler.hpp"
|
||||
#include "locals.hpp"
|
||||
#include "stringparser.hpp"
|
||||
#include "extensions.hpp"
|
||||
#include "context.hpp"
|
||||
#include "discardparser.hpp"
|
||||
#include "errorhandler.hpp"
|
||||
#include "extensions.hpp"
|
||||
#include "generator.hpp"
|
||||
#include "junkparser.hpp"
|
||||
#include "locals.hpp"
|
||||
#include "scanner.hpp"
|
||||
#include "stringparser.hpp"
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
int ExprParser::getPriority (char op)
|
||||
int ExprParser::getPriority(char op)
|
||||
{
|
||||
switch (op)
|
||||
{
|
||||
|
@ -56,51 +56,51 @@ namespace Compiler
|
|||
return 0;
|
||||
}
|
||||
|
||||
char ExprParser::getOperandType (int Index) const
|
||||
char ExprParser::getOperandType(int Index) const
|
||||
{
|
||||
assert (!mOperands.empty());
|
||||
assert (Index>=0);
|
||||
assert (Index<static_cast<int> (mOperands.size()));
|
||||
return mOperands[mOperands.size()-1-Index];
|
||||
assert(!mOperands.empty());
|
||||
assert(Index >= 0);
|
||||
assert(Index < static_cast<int>(mOperands.size()));
|
||||
return mOperands[mOperands.size() - 1 - Index];
|
||||
}
|
||||
|
||||
char ExprParser::getOperator() const
|
||||
{
|
||||
assert (!mOperators.empty());
|
||||
return mOperators[mOperators.size()-1];
|
||||
assert(!mOperators.empty());
|
||||
return mOperators[mOperators.size() - 1];
|
||||
}
|
||||
|
||||
bool ExprParser::isOpen() const
|
||||
{
|
||||
return std::find (mOperators.begin(), mOperators.end(), '(')!=mOperators.end();
|
||||
return std::find(mOperators.begin(), mOperators.end(), '(') != mOperators.end();
|
||||
}
|
||||
|
||||
void ExprParser::popOperator()
|
||||
{
|
||||
assert (!mOperators.empty());
|
||||
mOperators.resize (mOperators.size()-1);
|
||||
assert(!mOperators.empty());
|
||||
mOperators.resize(mOperators.size() - 1);
|
||||
}
|
||||
|
||||
void ExprParser::popOperand()
|
||||
{
|
||||
assert (!mOperands.empty());
|
||||
mOperands.resize (mOperands.size()-1);
|
||||
assert(!mOperands.empty());
|
||||
mOperands.resize(mOperands.size() - 1);
|
||||
}
|
||||
|
||||
void ExprParser::replaceBinaryOperands()
|
||||
{
|
||||
char t1 = getOperandType (1);
|
||||
char t1 = getOperandType(1);
|
||||
char t2 = getOperandType();
|
||||
|
||||
popOperand();
|
||||
popOperand();
|
||||
|
||||
if (t1==t2)
|
||||
mOperands.push_back (t1);
|
||||
else if (t1=='f' || t2=='f')
|
||||
mOperands.push_back ('f');
|
||||
if (t1 == t2)
|
||||
mOperands.push_back(t1);
|
||||
else if (t1 == 'f' || t2 == 'f')
|
||||
mOperands.push_back('f');
|
||||
else
|
||||
throw std::logic_error ("Failed to determine result operand type");
|
||||
throw std::logic_error("Failed to determine result operand type");
|
||||
}
|
||||
|
||||
void ExprParser::pop()
|
||||
|
@ -111,34 +111,34 @@ namespace Compiler
|
|||
{
|
||||
case 'm':
|
||||
|
||||
Generator::negate (mCode, getOperandType());
|
||||
Generator::negate(mCode, getOperandType());
|
||||
popOperator();
|
||||
break;
|
||||
|
||||
case '+':
|
||||
|
||||
Generator::add (mCode, getOperandType (1), getOperandType());
|
||||
Generator::add(mCode, getOperandType(1), getOperandType());
|
||||
popOperator();
|
||||
replaceBinaryOperands();
|
||||
break;
|
||||
|
||||
case '-':
|
||||
|
||||
Generator::sub (mCode, getOperandType (1), getOperandType());
|
||||
Generator::sub(mCode, getOperandType(1), getOperandType());
|
||||
popOperator();
|
||||
replaceBinaryOperands();
|
||||
break;
|
||||
|
||||
case '*':
|
||||
|
||||
Generator::mul (mCode, getOperandType (1), getOperandType());
|
||||
Generator::mul(mCode, getOperandType(1), getOperandType());
|
||||
popOperator();
|
||||
replaceBinaryOperands();
|
||||
break;
|
||||
|
||||
case '/':
|
||||
|
||||
Generator::div (mCode, getOperandType (1), getOperandType());
|
||||
Generator::div(mCode, getOperandType(1), getOperandType());
|
||||
popOperator();
|
||||
replaceBinaryOperands();
|
||||
break;
|
||||
|
@ -150,87 +150,94 @@ namespace Compiler
|
|||
case 'g':
|
||||
case 'G':
|
||||
|
||||
Generator::compare (mCode, op, getOperandType (1), getOperandType());
|
||||
Generator::compare(mCode, op, getOperandType(1), getOperandType());
|
||||
popOperator();
|
||||
popOperand();
|
||||
popOperand();
|
||||
mOperands.push_back ('l');
|
||||
mOperands.push_back('l');
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
throw std::logic_error ("Unknown operator");
|
||||
throw std::logic_error("Unknown operator");
|
||||
}
|
||||
}
|
||||
|
||||
void ExprParser::pushIntegerLiteral (int value)
|
||||
void ExprParser::pushIntegerLiteral(int value)
|
||||
{
|
||||
mNextOperand = false;
|
||||
mOperands.push_back ('l');
|
||||
Generator::pushInt (mCode, mLiterals, value);
|
||||
mOperands.push_back('l');
|
||||
Generator::pushInt(mCode, mLiterals, value);
|
||||
}
|
||||
|
||||
void ExprParser::pushFloatLiteral (float value)
|
||||
void ExprParser::pushFloatLiteral(float value)
|
||||
{
|
||||
mNextOperand = false;
|
||||
mOperands.push_back ('f');
|
||||
Generator::pushFloat (mCode, mLiterals, value);
|
||||
mOperands.push_back('f');
|
||||
Generator::pushFloat(mCode, mLiterals, value);
|
||||
}
|
||||
|
||||
void ExprParser::pushBinaryOperator (char c)
|
||||
void ExprParser::pushBinaryOperator(char c)
|
||||
{
|
||||
while (!mOperators.empty() && getPriority (getOperator())>=getPriority (c))
|
||||
while (!mOperators.empty() && getPriority(getOperator()) >= getPriority(c))
|
||||
pop();
|
||||
|
||||
mOperators.push_back (c);
|
||||
mOperators.push_back(c);
|
||||
mNextOperand = true;
|
||||
}
|
||||
|
||||
void ExprParser::close()
|
||||
{
|
||||
while (getOperator()!='(')
|
||||
while (getOperator() != '(')
|
||||
pop();
|
||||
|
||||
popOperator();
|
||||
}
|
||||
|
||||
int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner)
|
||||
int ExprParser::parseArguments(const std::string& arguments, Scanner& scanner)
|
||||
{
|
||||
return parseArguments (arguments, scanner, mCode);
|
||||
return parseArguments(arguments, scanner, mCode);
|
||||
}
|
||||
|
||||
bool ExprParser::handleMemberAccess (const std::string& name)
|
||||
bool ExprParser::handleMemberAccess(const std::string& name)
|
||||
{
|
||||
mMemberOp = false;
|
||||
|
||||
std::string name2 = Misc::StringUtils::lowerCase (name);
|
||||
std::string id = Misc::StringUtils::lowerCase (mExplicit);
|
||||
std::string name2 = Misc::StringUtils::lowerCase(name);
|
||||
std::string id = Misc::StringUtils::lowerCase(mExplicit);
|
||||
|
||||
std::pair<char, bool> type = getContext().getMemberType (name2, id);
|
||||
std::pair<char, bool> type = getContext().getMemberType(name2, id);
|
||||
|
||||
if (type.first!=' ')
|
||||
if (type.first != ' ')
|
||||
{
|
||||
Generator::fetchMember (mCode, mLiterals, type.first, name2, id, !type.second);
|
||||
Generator::fetchMember(mCode, mLiterals, type.first, name2, id, !type.second);
|
||||
|
||||
mNextOperand = false;
|
||||
mExplicit.clear();
|
||||
mOperands.push_back (type.first=='f' ? 'f' : 'l');
|
||||
mOperands.push_back(type.first == 'f' ? 'f' : 'l');
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
ExprParser::ExprParser (ErrorHandler& errorHandler, const Context& context, Locals& locals,
|
||||
Literals& literals, bool argument)
|
||||
: Parser (errorHandler, context), mLocals (locals), mLiterals (literals),
|
||||
mNextOperand (true), mFirst (true), mArgument (argument), mRefOp (false), mMemberOp (false)
|
||||
{}
|
||||
ExprParser::ExprParser(
|
||||
ErrorHandler& errorHandler, const Context& context, Locals& locals, Literals& literals, bool argument)
|
||||
: Parser(errorHandler, context)
|
||||
, mLocals(locals)
|
||||
, mLiterals(literals)
|
||||
, mNextOperand(true)
|
||||
, mFirst(true)
|
||||
, mArgument(argument)
|
||||
, mRefOp(false)
|
||||
, mMemberOp(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool ExprParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
|
||||
bool ExprParser::parseInt(int value, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
if (!mExplicit.empty())
|
||||
return Parser::parseInt (value, loc, scanner);
|
||||
return Parser::parseInt(value, loc, scanner);
|
||||
|
||||
mFirst = false;
|
||||
|
||||
|
@ -238,21 +245,21 @@ namespace Compiler
|
|||
{
|
||||
start();
|
||||
|
||||
pushIntegerLiteral (value);
|
||||
pushIntegerLiteral(value);
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scanner.putbackInt (value, loc);
|
||||
scanner.putbackInt(value, loc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExprParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
|
||||
bool ExprParser::parseFloat(float value, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
if (!mExplicit.empty())
|
||||
return Parser::parseFloat (value, loc, scanner);
|
||||
return Parser::parseFloat(value, loc, scanner);
|
||||
|
||||
mFirst = false;
|
||||
|
||||
|
@ -260,33 +267,32 @@ namespace Compiler
|
|||
{
|
||||
start();
|
||||
|
||||
pushFloatLiteral (value);
|
||||
pushFloatLiteral(value);
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scanner.putbackFloat (value, loc);
|
||||
scanner.putbackFloat(value, loc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExprParser::parseName (const std::string& name, const TokenLoc& loc,
|
||||
Scanner& scanner)
|
||||
bool ExprParser::parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
if (!mExplicit.empty())
|
||||
{
|
||||
if (!mRefOp)
|
||||
{
|
||||
if (mMemberOp && handleMemberAccess (name))
|
||||
if (mMemberOp && handleMemberAccess(name))
|
||||
return true;
|
||||
|
||||
return Parser::parseName (name, loc, scanner);
|
||||
return Parser::parseName(name, loc, scanner);
|
||||
}
|
||||
else
|
||||
{
|
||||
mExplicit.clear();
|
||||
getErrorHandler().warning ("Stray explicit reference", loc);
|
||||
getErrorHandler().warning("Stray explicit reference", loc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,29 +302,29 @@ namespace Compiler
|
|||
{
|
||||
start();
|
||||
|
||||
std::string name2 = Misc::StringUtils::lowerCase (name);
|
||||
std::string name2 = Misc::StringUtils::lowerCase(name);
|
||||
|
||||
char type = mLocals.getType (name2);
|
||||
char type = mLocals.getType(name2);
|
||||
|
||||
if (type!=' ')
|
||||
if (type != ' ')
|
||||
{
|
||||
Generator::fetchLocal (mCode, type, mLocals.getIndex (name2));
|
||||
Generator::fetchLocal(mCode, type, mLocals.getIndex(name2));
|
||||
mNextOperand = false;
|
||||
mOperands.push_back (type=='f' ? 'f' : 'l');
|
||||
mOperands.push_back(type == 'f' ? 'f' : 'l');
|
||||
return true;
|
||||
}
|
||||
|
||||
type = getContext().getGlobalType (name2);
|
||||
type = getContext().getGlobalType(name2);
|
||||
|
||||
if (type!=' ')
|
||||
if (type != ' ')
|
||||
{
|
||||
Generator::fetchGlobal (mCode, mLiterals, type, name2);
|
||||
Generator::fetchGlobal(mCode, mLiterals, type, name2);
|
||||
mNextOperand = false;
|
||||
mOperands.push_back (type=='f' ? 'f' : 'l');
|
||||
mOperands.push_back(type == 'f' ? 'f' : 'l');
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mExplicit.empty() && getContext().isId (name2))
|
||||
if (mExplicit.empty() && getContext().isId(name2))
|
||||
{
|
||||
mExplicit = name2;
|
||||
return true;
|
||||
|
@ -336,48 +342,46 @@ namespace Compiler
|
|||
|
||||
pushFloatLiteral(number);
|
||||
mTokenLoc = loc;
|
||||
getErrorHandler().warning ("Parsing a non-variable string as a number: " + stream.str(), loc);
|
||||
getErrorHandler().warning("Parsing a non-variable string as a number: " + stream.str(), loc);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scanner.putbackName (name, loc);
|
||||
scanner.putbackName(name, loc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ExprParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
||||
bool ExprParser::parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
if (const Extensions *extensions = getContext().getExtensions())
|
||||
if (const Extensions* extensions = getContext().getExtensions())
|
||||
{
|
||||
char returnType; // ignored
|
||||
std::string argumentType; // ignored
|
||||
bool hasExplicit = false; // ignored
|
||||
bool isInstruction = extensions->isInstruction (keyword, argumentType, hasExplicit);
|
||||
bool isInstruction = extensions->isInstruction(keyword, argumentType, hasExplicit);
|
||||
|
||||
if(isInstruction || (mExplicit.empty() && extensions->isFunction(keyword, returnType, argumentType, hasExplicit)))
|
||||
if (isInstruction
|
||||
|| (mExplicit.empty() && extensions->isFunction(keyword, returnType, argumentType, hasExplicit)))
|
||||
{
|
||||
std::string name = loc.mLiteral;
|
||||
if (name.size()>=2 && name[0]=='"' && name[name.size()-1]=='"')
|
||||
name = name.substr (1, name.size()-2);
|
||||
if(isInstruction || mLocals.getType(Misc::StringUtils::lowerCase(name)) != ' ')
|
||||
if (name.size() >= 2 && name[0] == '"' && name[name.size() - 1] == '"')
|
||||
name = name.substr(1, name.size() - 2);
|
||||
if (isInstruction || mLocals.getType(Misc::StringUtils::lowerCase(name)) != ' ')
|
||||
{
|
||||
// pretend this is not a keyword
|
||||
return parseName (name, loc, scanner);
|
||||
return parseName(name, loc, scanner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (keyword==Scanner::K_end || keyword==Scanner::K_begin ||
|
||||
keyword==Scanner::K_short || keyword==Scanner::K_long ||
|
||||
keyword==Scanner::K_float || keyword==Scanner::K_if ||
|
||||
keyword==Scanner::K_endif || keyword==Scanner::K_else ||
|
||||
keyword==Scanner::K_elseif || keyword==Scanner::K_while ||
|
||||
keyword==Scanner::K_endwhile || keyword==Scanner::K_return ||
|
||||
keyword==Scanner::K_messagebox || keyword==Scanner::K_set ||
|
||||
keyword==Scanner::K_to)
|
||||
if (keyword == Scanner::K_end || keyword == Scanner::K_begin || keyword == Scanner::K_short
|
||||
|| keyword == Scanner::K_long || keyword == Scanner::K_float || keyword == Scanner::K_if
|
||||
|| keyword == Scanner::K_endif || keyword == Scanner::K_else || keyword == Scanner::K_elseif
|
||||
|| keyword == Scanner::K_while || keyword == Scanner::K_endwhile || keyword == Scanner::K_return
|
||||
|| keyword == Scanner::K_messagebox || keyword == Scanner::K_set || keyword == Scanner::K_to)
|
||||
{
|
||||
return parseName (loc.mLiteral, loc, scanner);
|
||||
return parseName(loc.mLiteral, loc, scanner);
|
||||
}
|
||||
|
||||
mFirst = false;
|
||||
|
@ -388,28 +392,27 @@ namespace Compiler
|
|||
{
|
||||
|
||||
// check for custom extensions
|
||||
if (const Extensions *extensions = getContext().getExtensions())
|
||||
if (const Extensions* extensions = getContext().getExtensions())
|
||||
{
|
||||
char returnType;
|
||||
std::string argumentType;
|
||||
|
||||
bool hasExplicit = true;
|
||||
if (extensions->isFunction (keyword, returnType, argumentType, hasExplicit))
|
||||
if (extensions->isFunction(keyword, returnType, argumentType, hasExplicit))
|
||||
{
|
||||
if (!hasExplicit)
|
||||
{
|
||||
getErrorHandler().warning ("Stray explicit reference", loc);
|
||||
getErrorHandler().warning("Stray explicit reference", loc);
|
||||
mExplicit.clear();
|
||||
}
|
||||
|
||||
start();
|
||||
|
||||
mTokenLoc = loc;
|
||||
int optionals = parseArguments (argumentType, scanner);
|
||||
int optionals = parseArguments(argumentType, scanner);
|
||||
|
||||
extensions->generateFunctionCode (keyword, mCode, mLiterals, mExplicit,
|
||||
optionals);
|
||||
mOperands.push_back (returnType);
|
||||
extensions->generateFunctionCode(keyword, mCode, mLiterals, mExplicit, optionals);
|
||||
mOperands.push_back(returnType);
|
||||
mExplicit.clear();
|
||||
mRefOp = false;
|
||||
|
||||
|
@ -419,13 +422,13 @@ namespace Compiler
|
|||
}
|
||||
}
|
||||
|
||||
return Parser::parseKeyword (keyword, loc, scanner);
|
||||
return Parser::parseKeyword(keyword, loc, scanner);
|
||||
}
|
||||
|
||||
if (mNextOperand)
|
||||
{
|
||||
// check for custom extensions
|
||||
if (const Extensions *extensions = getContext().getExtensions())
|
||||
if (const Extensions* extensions = getContext().getExtensions())
|
||||
{
|
||||
start();
|
||||
|
||||
|
@ -434,13 +437,13 @@ namespace Compiler
|
|||
|
||||
bool hasExplicit = false;
|
||||
|
||||
if (extensions->isFunction (keyword, returnType, argumentType, hasExplicit))
|
||||
if (extensions->isFunction(keyword, returnType, argumentType, hasExplicit))
|
||||
{
|
||||
mTokenLoc = loc;
|
||||
int optionals = parseArguments (argumentType, scanner);
|
||||
int optionals = parseArguments(argumentType, scanner);
|
||||
|
||||
extensions->generateFunctionCode (keyword, mCode, mLiterals, "", optionals);
|
||||
mOperands.push_back (returnType);
|
||||
extensions->generateFunctionCode(keyword, mCode, mLiterals, "", optionals);
|
||||
mOperands.push_back(returnType);
|
||||
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
|
@ -449,82 +452,82 @@ namespace Compiler
|
|||
}
|
||||
else
|
||||
{
|
||||
scanner.putbackKeyword (keyword, loc);
|
||||
scanner.putbackKeyword(keyword, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
return Parser::parseKeyword (keyword, loc, scanner);
|
||||
return Parser::parseKeyword(keyword, loc, scanner);
|
||||
}
|
||||
|
||||
bool ExprParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
||||
bool ExprParser::parseSpecial(int code, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
if (!mExplicit.empty())
|
||||
{
|
||||
if (mRefOp && code==Scanner::S_open)
|
||||
if (mRefOp && code == Scanner::S_open)
|
||||
{
|
||||
/// \todo add option to disable this workaround
|
||||
mOperators.push_back ('(');
|
||||
mOperators.push_back('(');
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mRefOp && code==Scanner::S_ref)
|
||||
if (!mRefOp && code == Scanner::S_ref)
|
||||
{
|
||||
mRefOp = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!mMemberOp && code==Scanner::S_member)
|
||||
if (!mMemberOp && code == Scanner::S_member)
|
||||
{
|
||||
mMemberOp = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return Parser::parseSpecial (code, loc, scanner);
|
||||
return Parser::parseSpecial(code, loc, scanner);
|
||||
}
|
||||
|
||||
mFirst = false;
|
||||
|
||||
if (code==Scanner::S_newline)
|
||||
if (code == Scanner::S_newline)
|
||||
{
|
||||
// end marker
|
||||
if (mTokenLoc.mLiteral.empty())
|
||||
mTokenLoc = loc;
|
||||
scanner.putbackSpecial (code, loc);
|
||||
scanner.putbackSpecial(code, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (code==Scanner::S_minus && mNextOperand)
|
||||
if (code == Scanner::S_minus && mNextOperand)
|
||||
{
|
||||
// unary
|
||||
mOperators.push_back ('m');
|
||||
mOperators.push_back('m');
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (code ==Scanner::S_plus && mNextOperand)
|
||||
if (code == Scanner::S_plus && mNextOperand)
|
||||
{
|
||||
// Also unary, but +, just ignore it
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (code==Scanner::S_open)
|
||||
if (code == Scanner::S_open)
|
||||
{
|
||||
if (mNextOperand)
|
||||
{
|
||||
mOperators.push_back ('(');
|
||||
mOperators.push_back('(');
|
||||
mTokenLoc = loc;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
scanner.putbackSpecial (code, loc);
|
||||
scanner.putbackSpecial(code, loc);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (code==Scanner::S_close && !mNextOperand)
|
||||
if (code == Scanner::S_close && !mNextOperand)
|
||||
{
|
||||
if (isOpen())
|
||||
{
|
||||
|
@ -533,7 +536,7 @@ namespace Compiler
|
|||
}
|
||||
|
||||
mTokenLoc = loc;
|
||||
scanner.putbackSpecial (code, loc);
|
||||
scanner.putbackSpecial(code, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -544,16 +547,36 @@ namespace Compiler
|
|||
|
||||
switch (code)
|
||||
{
|
||||
case Scanner::S_plus: c = '+'; break;
|
||||
case Scanner::S_minus: c = '-'; break;
|
||||
case Scanner::S_mult: pushBinaryOperator ('*'); return true;
|
||||
case Scanner::S_div: pushBinaryOperator ('/'); return true;
|
||||
case Scanner::S_cmpEQ: c = 'e'; break;
|
||||
case Scanner::S_cmpNE: c = 'n'; break;
|
||||
case Scanner::S_cmpLT: c = 'l'; break;
|
||||
case Scanner::S_cmpLE: c = 'L'; break;
|
||||
case Scanner::S_cmpGT: c = 'g'; break;
|
||||
case Scanner::S_cmpGE: c = 'G'; break;
|
||||
case Scanner::S_plus:
|
||||
c = '+';
|
||||
break;
|
||||
case Scanner::S_minus:
|
||||
c = '-';
|
||||
break;
|
||||
case Scanner::S_mult:
|
||||
pushBinaryOperator('*');
|
||||
return true;
|
||||
case Scanner::S_div:
|
||||
pushBinaryOperator('/');
|
||||
return true;
|
||||
case Scanner::S_cmpEQ:
|
||||
c = 'e';
|
||||
break;
|
||||
case Scanner::S_cmpNE:
|
||||
c = 'n';
|
||||
break;
|
||||
case Scanner::S_cmpLT:
|
||||
c = 'l';
|
||||
break;
|
||||
case Scanner::S_cmpLE:
|
||||
c = 'L';
|
||||
break;
|
||||
case Scanner::S_cmpGT:
|
||||
c = 'g';
|
||||
break;
|
||||
case Scanner::S_cmpGE:
|
||||
c = 'G';
|
||||
break;
|
||||
}
|
||||
|
||||
if (c)
|
||||
|
@ -562,16 +585,16 @@ namespace Compiler
|
|||
{
|
||||
// expression ends here
|
||||
// Thank you Morrowind for this rotten syntax :(
|
||||
scanner.putbackSpecial (code, loc);
|
||||
scanner.putbackSpecial(code, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
pushBinaryOperator (c);
|
||||
pushBinaryOperator(c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return Parser::parseSpecial (code, loc, scanner);
|
||||
return Parser::parseSpecial(code, loc, scanner);
|
||||
}
|
||||
|
||||
void ExprParser::reset()
|
||||
|
@ -587,131 +610,132 @@ namespace Compiler
|
|||
Parser::reset();
|
||||
}
|
||||
|
||||
char ExprParser::append (std::vector<Interpreter::Type_Code>& code)
|
||||
char ExprParser::append(std::vector<Interpreter::Type_Code>& code)
|
||||
{
|
||||
if (mOperands.empty() && mOperators.empty())
|
||||
{
|
||||
getErrorHandler().error ("Missing expression", mTokenLoc);
|
||||
getErrorHandler().error("Missing expression", mTokenLoc);
|
||||
return 'l';
|
||||
}
|
||||
|
||||
if (mNextOperand || mOperands.empty())
|
||||
{
|
||||
getErrorHandler().error ("Syntax error in expression", mTokenLoc);
|
||||
getErrorHandler().error("Syntax error in expression", mTokenLoc);
|
||||
return 'l';
|
||||
}
|
||||
|
||||
while (!mOperators.empty())
|
||||
pop();
|
||||
|
||||
std::copy (mCode.begin(), mCode.end(), std::back_inserter (code));
|
||||
std::copy(mCode.begin(), mCode.end(), std::back_inserter(code));
|
||||
|
||||
assert (mOperands.size()==1);
|
||||
assert(mOperands.size() == 1);
|
||||
return mOperands[0];
|
||||
}
|
||||
|
||||
int ExprParser::parseArguments (const std::string& arguments, Scanner& scanner,
|
||||
int ExprParser::parseArguments(const std::string& arguments, Scanner& scanner,
|
||||
std::vector<Interpreter::Type_Code>& code, int ignoreKeyword, bool expectNames)
|
||||
{
|
||||
bool optional = false;
|
||||
int optionalCount = 0;
|
||||
|
||||
ExprParser parser (getErrorHandler(), getContext(), mLocals, mLiterals, true);
|
||||
StringParser stringParser (getErrorHandler(), getContext(), mLiterals);
|
||||
DiscardParser discardParser (getErrorHandler(), getContext());
|
||||
JunkParser junkParser (getErrorHandler(), getContext(), ignoreKeyword);
|
||||
ExprParser parser(getErrorHandler(), getContext(), mLocals, mLiterals, true);
|
||||
StringParser stringParser(getErrorHandler(), getContext(), mLiterals);
|
||||
DiscardParser discardParser(getErrorHandler(), getContext());
|
||||
JunkParser junkParser(getErrorHandler(), getContext(), ignoreKeyword);
|
||||
|
||||
std::stack<std::vector<Interpreter::Type_Code> > stack;
|
||||
std::stack<std::vector<Interpreter::Type_Code>> stack;
|
||||
|
||||
for (char argument : arguments)
|
||||
{
|
||||
if (argument=='/')
|
||||
if (argument == '/')
|
||||
{
|
||||
optional = true;
|
||||
}
|
||||
else if (argument=='S' || argument=='c' || argument=='x')
|
||||
else if (argument == 'S' || argument == 'c' || argument == 'x')
|
||||
{
|
||||
stringParser.reset();
|
||||
|
||||
if (optional || argument=='x')
|
||||
stringParser.setOptional (true);
|
||||
if (optional || argument == 'x')
|
||||
stringParser.setOptional(true);
|
||||
|
||||
if (argument=='c') stringParser.smashCase();
|
||||
if (argument=='x') stringParser.discard();
|
||||
if (argument == 'c')
|
||||
stringParser.smashCase();
|
||||
if (argument == 'x')
|
||||
stringParser.discard();
|
||||
scanner.enableExpectName();
|
||||
scanner.scan (stringParser);
|
||||
scanner.scan(stringParser);
|
||||
|
||||
if ((optional || argument=='x') && stringParser.isEmpty())
|
||||
if ((optional || argument == 'x') && stringParser.isEmpty())
|
||||
break;
|
||||
|
||||
if (argument!='x')
|
||||
if (argument != 'x')
|
||||
{
|
||||
std::vector<Interpreter::Type_Code> tmp;
|
||||
stringParser.append (tmp);
|
||||
stringParser.append(tmp);
|
||||
|
||||
stack.push (tmp);
|
||||
stack.push(tmp);
|
||||
|
||||
if (optional)
|
||||
++optionalCount;
|
||||
}
|
||||
else
|
||||
getErrorHandler().warning ("Extra argument",
|
||||
stringParser.getTokenLoc());
|
||||
getErrorHandler().warning("Extra argument", stringParser.getTokenLoc());
|
||||
}
|
||||
else if (argument=='X')
|
||||
else if (argument == 'X')
|
||||
{
|
||||
parser.reset();
|
||||
|
||||
parser.setOptional (true);
|
||||
parser.setOptional(true);
|
||||
|
||||
scanner.scan (parser);
|
||||
scanner.scan(parser);
|
||||
|
||||
if (parser.isEmpty())
|
||||
break;
|
||||
else
|
||||
getErrorHandler().warning("Extra argument", parser.getTokenLoc());
|
||||
}
|
||||
else if (argument=='z')
|
||||
else if (argument == 'z')
|
||||
{
|
||||
discardParser.reset();
|
||||
discardParser.setOptional (true);
|
||||
discardParser.setOptional(true);
|
||||
|
||||
scanner.scan (discardParser);
|
||||
scanner.scan(discardParser);
|
||||
|
||||
if (discardParser.isEmpty())
|
||||
break;
|
||||
else
|
||||
getErrorHandler().warning("Extra argument", discardParser.getTokenLoc());
|
||||
}
|
||||
else if (argument=='j')
|
||||
else if (argument == 'j')
|
||||
{
|
||||
/// \todo disable this when operating in strict mode
|
||||
junkParser.reset();
|
||||
|
||||
scanner.scan (junkParser);
|
||||
scanner.scan(junkParser);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser.reset();
|
||||
|
||||
if (optional)
|
||||
parser.setOptional (true);
|
||||
if(expectNames)
|
||||
parser.setOptional(true);
|
||||
if (expectNames)
|
||||
scanner.enableExpectName();
|
||||
|
||||
scanner.scan (parser);
|
||||
scanner.scan(parser);
|
||||
|
||||
if (optional && parser.isEmpty())
|
||||
break;
|
||||
|
||||
std::vector<Interpreter::Type_Code> tmp;
|
||||
|
||||
char type = parser.append (tmp);
|
||||
char type = parser.append(tmp);
|
||||
|
||||
if (type!=argument)
|
||||
Generator::convert (tmp, type, argument);
|
||||
if (type != argument)
|
||||
Generator::convert(tmp, type, argument);
|
||||
|
||||
stack.push (tmp);
|
||||
stack.push(tmp);
|
||||
|
||||
if (optional)
|
||||
++optionalCount;
|
||||
|
@ -722,7 +746,7 @@ namespace Compiler
|
|||
{
|
||||
std::vector<Interpreter::Type_Code>& tmp = stack.top();
|
||||
|
||||
std::copy (tmp.begin(), tmp.end(), std::back_inserter (code));
|
||||
std::copy(tmp.begin(), tmp.end(), std::back_inserter(code));
|
||||
|
||||
stack.pop();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue