Always pass the script string around by reference
This commit is contained in:
parent
10a2535c96
commit
601c4a3f89
|
@ -1,7 +1,3 @@
|
|||
#include <utility>
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
#ifndef PORYGONLANG_BOUNDEXPRESSION_HPP
|
||||
#define PORYGONLANG_BOUNDEXPRESSION_HPP
|
||||
|
@ -37,7 +33,7 @@ class BoundExpression{
|
|||
const unsigned int _length;
|
||||
const shared_ptr<ScriptType> _type;
|
||||
public:
|
||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
|
||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<ScriptType> type)
|
||||
: _start(start),
|
||||
_length(length),
|
||||
_type(std::move(type))
|
||||
|
@ -47,7 +43,7 @@ public:
|
|||
virtual ~BoundExpression() = default;
|
||||
|
||||
virtual const BoundExpressionKind GetKind() const = 0;
|
||||
virtual const std::shared_ptr<ScriptType> GetType() const{
|
||||
virtual const std::shared_ptr<ScriptType>& GetType() const{
|
||||
return _type;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#include <memory>
|
||||
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
|
|
|
@ -5,15 +5,9 @@
|
|||
|
||||
#include "Lexer.hpp"
|
||||
|
||||
Lexer::Lexer(string* scriptString, class Script* script) {
|
||||
this -> _scriptString = scriptString;
|
||||
this->_scriptSize = scriptString->size();
|
||||
this -> ScriptData = script;
|
||||
this -> _position = 0;
|
||||
}
|
||||
|
||||
Lexer::Lexer(const string& scriptString, class Script *script) {
|
||||
this -> _scriptString = new string(scriptString);
|
||||
Lexer::Lexer(const string& scriptString, class Script* script)
|
||||
: _scriptString(scriptString)
|
||||
{
|
||||
this->_scriptSize = scriptString.size();
|
||||
this -> ScriptData = script;
|
||||
this -> _position = 0;
|
||||
|
@ -38,7 +32,7 @@ vector<IToken*> Lexer::Lex() {
|
|||
char Lexer::Peek(){
|
||||
if (Lexer::_position >= this -> _scriptSize)
|
||||
return '\0';
|
||||
return this -> _scriptString->at(Lexer::_position);
|
||||
return this -> _scriptString.at(Lexer::_position);
|
||||
}
|
||||
|
||||
char Lexer::Next(){
|
||||
|
@ -200,7 +194,7 @@ IToken * Lexer::LexIdentifierOrKeyword() {
|
|||
}
|
||||
}
|
||||
|
||||
string s = this -> _scriptString->substr(start, end - start + 1);
|
||||
string s = this -> _scriptString.substr(start, end - start + 1);
|
||||
switch (HashedString::ConstHash(s.c_str())){
|
||||
case HashedString::ConstHash("and"): return new SimpleToken(TokenKind::AndKeyword, start, 3);
|
||||
case HashedString::ConstHash("break"): return new SimpleToken(TokenKind::BreakKeyword, start, 5);
|
||||
|
@ -258,7 +252,7 @@ IToken* Lexer::LexString(char c){
|
|||
return new SimpleToken(TokenKind::BadToken, start, end -start + 1);
|
||||
}
|
||||
|
||||
string s = this -> _scriptString->substr(start + 1, end - start);
|
||||
string s = this -> _scriptString.substr(start + 1, end - start);
|
||||
stringstream stream;
|
||||
for (int i = 0; i < s.size(); i++){
|
||||
c = s[i];
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
using namespace std;
|
||||
|
||||
class Lexer {
|
||||
string* _scriptString;
|
||||
const string& _scriptString;
|
||||
#ifdef TESTS_BUILD
|
||||
public:
|
||||
#endif
|
||||
|
@ -24,7 +24,6 @@ public:
|
|||
Script* ScriptData;
|
||||
|
||||
vector<IToken*> Lex();
|
||||
explicit Lexer(string* scriptString, class Script* script);
|
||||
explicit Lexer(const string& scriptString, class Script* script);
|
||||
|
||||
};
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include "Parser/Parser.hpp"
|
||||
#include "Binder/Binder.hpp"
|
||||
|
||||
Script* Script::Create(string script) {
|
||||
Script* Script::Create(const string& script) {
|
||||
auto s = new Script();
|
||||
s -> Parse(std::move(script));
|
||||
s -> Parse(script);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,8 @@ Script::~Script() {
|
|||
delete this->_scriptVariables;
|
||||
}
|
||||
|
||||
void Script::Parse(string script) {
|
||||
auto lexer = Lexer(&script, this);
|
||||
void Script::Parse(const string& script) {
|
||||
auto lexer = Lexer(script, this);
|
||||
auto lexResult = lexer.Lex();
|
||||
auto parser = Parser(lexResult, this);
|
||||
auto parseResult = parser.Parse();
|
||||
|
|
|
@ -23,9 +23,9 @@ class Script {
|
|||
shared_ptr<ScriptType> _returnType;
|
||||
|
||||
explicit Script();
|
||||
void Parse(string script);
|
||||
void Parse(const string& script);
|
||||
public:
|
||||
static Script* Create(string script);
|
||||
static Script* Create(const string& script);
|
||||
DiagnosticsHolder* Diagnostics;
|
||||
|
||||
~Script();
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
5381;
|
||||
}
|
||||
|
||||
const int GetHash(){
|
||||
const int GetHash() const{
|
||||
return _hash;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue