aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl
diff options
context:
space:
mode:
Diffstat (limited to 'src/sksl')
-rw-r--r--src/sksl/SkSLParser.cpp63
-rw-r--r--src/sksl/SkSLParser.h3
-rw-r--r--src/sksl/SkSLString.cpp6
-rw-r--r--src/sksl/SkSLString.h6
4 files changed, 42 insertions, 36 deletions
diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp
index d3e1d5712c..f712b34e1a 100644
--- a/src/sksl/SkSLParser.cpp
+++ b/src/sksl/SkSLParser.cpp
@@ -150,9 +150,9 @@ std::vector<std::unique_ptr<ASTDeclaration>> Parser::file() {
Token Parser::nextRawToken(bool needText) {
if (fPushback.fKind != Token::INVALID_TOKEN) {
- Token result = fPushback;
+ Token result(std::move(fPushback));
fPushback.fKind = Token::INVALID_TOKEN;
- fPushback.fText = "";
+ fPushback.fText.clear();
return result;
}
Token::Kind kind = (Token::Kind) sksllex(fScanner);
@@ -187,11 +187,16 @@ void Parser::pushback(Token t) {
}
Token Parser::peek() {
- fPushback = this->nextToken();
+ if (fPushback.fKind == Token::INVALID_TOKEN) {
+ fPushback = this->nextToken();
+ }
return fPushback;
}
bool Parser::checkNext(Token::Kind kind, Token* result) {
+ if (fPushback.fKind != Token::INVALID_TOKEN && fPushback.fKind != kind) {
+ return false;
+ }
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
@@ -204,20 +209,16 @@ bool Parser::checkNext(Token::Kind kind, Token* result) {
}
bool Parser::expect(Token::Kind kind, const char* expected, Token* result) {
- return this->expect(kind, String(expected), result);
-}
-
-bool Parser::expect(Token::Kind kind, String expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
- *result = next;
+ *result = std::move(next);
}
return true;
} else {
if (next.fText.size()) {
- this->error(next.fPosition, "expected " + expected + ", but found '" + next.fText +
- "'");
+ this->error(next.fPosition, "expected " + String(expected) + ", but found '" +
+ next.fText + "'");
} else {
this->error(next.fPosition, "parse error, recompile in debug mode for details");
}
@@ -233,7 +234,7 @@ void Parser::error(Position p, String msg) {
fErrors.error(p, msg);
}
-bool Parser::isType(String name) {
+bool Parser::isType(const String& name) {
return nullptr != fTypes[name];
}
@@ -409,7 +410,7 @@ std::unique_ptr<ASTDeclaration> Parser::declaration() {
std::move(parameters),
std::move(body)));
} else {
- return this->varDeclarationEnd(modifiers, std::move(type), name.fText);
+ return this->varDeclarationEnd(modifiers, std::move(type), std::move(name.fText));
}
}
@@ -994,7 +995,8 @@ std::unique_ptr<ASTDeclaration> Parser::interfaceBlock(Modifiers mods) {
}
this->expect(Token::SEMICOLON, "';'");
return std::unique_ptr<ASTDeclaration>(new ASTInterfaceBlock(name.fPosition, mods,
- name.fText, std::move(decls),
+ std::move(name.fText),
+ std::move(decls),
std::move(instanceName.fText),
std::move(sizes)));
}
@@ -1361,7 +1363,7 @@ std::unique_ptr<ASTExpression> Parser::commaExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1397,7 +1399,7 @@ std::unique_ptr<ASTExpression> Parser::assignmentExpression() {
return nullptr;
}
result = std::unique_ptr<ASTExpression>(new ASTBinaryExpression(std::move(result),
- t,
+ std::move(t),
std::move(right)));
}
default:
@@ -1440,7 +1442,7 @@ std::unique_ptr<ASTExpression> Parser::logicalOrExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1457,7 +1459,7 @@ std::unique_ptr<ASTExpression> Parser::logicalXorExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1474,7 +1476,7 @@ std::unique_ptr<ASTExpression> Parser::logicalAndExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1491,7 +1493,7 @@ std::unique_ptr<ASTExpression> Parser::bitwiseOrExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1508,7 +1510,7 @@ std::unique_ptr<ASTExpression> Parser::bitwiseXorExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1525,7 +1527,7 @@ std::unique_ptr<ASTExpression> Parser::bitwiseAndExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
}
return result;
}
@@ -1545,7 +1547,7 @@ std::unique_ptr<ASTExpression> Parser::equalityExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t), std::move(right)));
break;
}
default:
@@ -1571,7 +1573,8 @@ std::unique_ptr<ASTExpression> Parser::relationalExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t),
+ std::move(right)));
break;
}
default:
@@ -1595,7 +1598,8 @@ std::unique_ptr<ASTExpression> Parser::shiftExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t),
+ std::move(right)));
break;
}
default:
@@ -1619,7 +1623,8 @@ std::unique_ptr<ASTExpression> Parser::additiveExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t),
+ std::move(right)));
break;
}
default:
@@ -1644,7 +1649,8 @@ std::unique_ptr<ASTExpression> Parser::multiplicativeExpression() {
if (!right) {
return nullptr;
}
- result.reset(new ASTBinaryExpression(std::move(result), t, std::move(right)));
+ result.reset(new ASTBinaryExpression(std::move(result), std::move(t),
+ std::move(right)));
break;
}
default:
@@ -1667,7 +1673,8 @@ std::unique_ptr<ASTExpression> Parser::unaryExpression() {
if (!expr) {
return nullptr;
}
- return std::unique_ptr<ASTExpression>(new ASTPrefixExpression(t, std::move(expr)));
+ return std::unique_ptr<ASTExpression>(new ASTPrefixExpression(std::move(t),
+ std::move(expr)));
}
default:
return this->postfixExpression();
@@ -1846,7 +1853,7 @@ bool Parser::boolLiteral(bool* dest) {
bool Parser::identifier(String* dest) {
Token t;
if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
- *dest = t.fText;
+ *dest = std::move(t.fText);
return true;
}
return false;
diff --git a/src/sksl/SkSLParser.h b/src/sksl/SkSLParser.h
index 22ef7bc1e9..4edd8e4e02 100644
--- a/src/sksl/SkSLParser.h
+++ b/src/sksl/SkSLParser.h
@@ -103,7 +103,6 @@ private:
* Returns true if the read token was as expected, false otherwise.
*/
bool expect(Token::Kind kind, const char* expected, Token* result = nullptr);
- bool expect(Token::Kind kind, String expected, Token* result = nullptr);
void error(Position p, const char* msg);
void error(Position p, String msg);
@@ -112,7 +111,7 @@ private:
* Returns true if the 'name' identifier refers to a type name. For instance, isType("int") will
* always return true.
*/
- bool isType(String name);
+ bool isType(const String& name);
// these functions parse individual grammar rules from the current parse position; you probably
// don't need to call any of these outside of the parser. The function declarations in the .cpp
diff --git a/src/sksl/SkSLString.cpp b/src/sksl/SkSLString.cpp
index 722d61fbd0..ac6d7f85c1 100644
--- a/src/sksl/SkSLString.cpp
+++ b/src/sksl/SkSLString.cpp
@@ -146,7 +146,7 @@ String to_string(double value) {
#undef MAX_DOUBLE_CHARS
}
-int stoi(String s) {
+int stoi(const String& s) {
char* p;
SKSL_DEBUGCODE(errno = 0;)
long result = strtoul(s.c_str(), &p, 0);
@@ -155,7 +155,7 @@ int stoi(String s) {
return (int) result;
}
-double stod(String s) {
+double stod(const String& s) {
double result;
std::string str(s.c_str(), s.size());
std::stringstream buffer(str);
@@ -165,7 +165,7 @@ double stod(String s) {
return result;
}
-long stol(String s) {
+long stol(const String& s) {
char* p;
SKSL_DEBUGCODE(errno = 0;)
long result = strtoul(s.c_str(), &p, 0);
diff --git a/src/sksl/SkSLString.h b/src/sksl/SkSLString.h
index 2478c56bbf..76bcbe4d70 100644
--- a/src/sksl/SkSLString.h
+++ b/src/sksl/SkSLString.h
@@ -76,11 +76,11 @@ String to_string(int64_t value);
String to_string(uint64_t value);
-int stoi(String s);
+int stoi(const String& s);
-double stod(String s);
+double stod(const String& s);
-long stol(String s);
+long stol(const String& s);
} // namespace