re-land of switched skslc from std::string to SkString
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5084
Change-Id: Ib21c30afc0d8483392b417e660b7fecfcc30e617
Reviewed-on: https://skia-review.googlesource.com/5084
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLParser.cpp b/src/sksl/SkSLParser.cpp
index 2be664d..03d0d33 100644
--- a/src/sksl/SkSLParser.cpp
+++ b/src/sksl/SkSLParser.cpp
@@ -88,7 +88,7 @@
bool checkValid() {
if (fParser->fDepth > MAX_PARSE_DEPTH) {
- fParser->error(fParser->peek().fPosition, "exceeded max parse depth");
+ fParser->error(fParser->peek().fPosition, SkString("exceeded max parse depth"));
return false;
}
return true;
@@ -98,8 +98,8 @@
Parser* fParser;
};
-Parser::Parser(std::string text, SymbolTable& types, ErrorReporter& errors)
-: fPushback(Position(-1, -1), Token::INVALID_TOKEN, "")
+Parser::Parser(SkString text, SymbolTable& types, ErrorReporter& errors)
+: fPushback(Position(-1, -1), Token::INVALID_TOKEN, SkString())
, fTypes(types)
, fErrors(errors) {
sksllex_init(&fScanner);
@@ -157,13 +157,13 @@
return result;
}
int token = sksllex(fScanner);
- std::string text;
+ SkString text;
switch ((Token::Kind) token) {
case Token::IDENTIFIER: // fall through
case Token::INT_LITERAL: // fall through
case Token::FLOAT_LITERAL: // fall through
case Token::DIRECTIVE:
- text = std::string(skslget_text(fScanner));
+ text = SkString(skslget_text(fScanner));
break;
default:
break;
@@ -181,7 +181,12 @@
return fPushback;
}
-bool Parser::expect(Token::Kind kind, std::string expected, Token* result) {
+
+bool Parser::expect(Token::Kind kind, const char* expected, Token* result) {
+ return this->expect(kind, SkString(expected), result);
+}
+
+bool Parser::expect(Token::Kind kind, SkString expected, Token* result) {
Token next = this->nextToken();
if (next.fKind == kind) {
if (result) {
@@ -194,11 +199,15 @@
}
}
-void Parser::error(Position p, std::string msg) {
+void Parser::error(Position p, const char* msg) {
+ this->error(p, SkString(msg));
+}
+
+void Parser::error(Position p, SkString msg) {
fErrors.error(p, msg);
}
-bool Parser::isType(std::string name) {
+bool Parser::isType(SkString name) {
return nullptr != fTypes[name];
}
@@ -370,7 +379,7 @@
return nullptr;
}
uint64_t columns = ((ASTIntLiteral&) *var.fSizes[i]).fValue;
- std::string name = type->name() + "[" + to_string(columns) + "]";
+ SkString name = type->name() + "[" + to_string(columns) + "]";
type = new Type(name, Type::kArray_Kind, *type, (int) columns);
fTypes.takeOwnership((Type*) type);
}
@@ -417,7 +426,7 @@
(LBRACKET expression? RBRACKET)* (EQ expression)?)* SEMICOLON */
std::unique_ptr<ASTVarDeclarations> Parser::varDeclarationEnd(ASTModifiers mods,
std::unique_ptr<ASTType> type,
- std::string name) {
+ SkString name) {
std::vector<ASTVarDeclaration> vars;
std::vector<std::unique_ptr<ASTExpression>> currentVarSizes;
while (this->peek().fKind == Token::LBRACKET) {
@@ -731,7 +740,7 @@
decls.push_back(std::move(decl));
}
this->nextToken();
- std::string valueName;
+ SkString valueName;
if (this->peek().fKind == Token::IDENTIFIER) {
valueName = this->nextToken().fText;
}
@@ -1361,7 +1370,7 @@
}
case Token::DOT: {
Position pos = this->peek().fPosition;
- std::string text;
+ SkString text;
if (this->identifier(&text)) {
return std::unique_ptr<ASTSuffix>(new ASTFieldSuffix(pos, std::move(text)));
}
@@ -1406,7 +1415,7 @@
Token t = this->peek();
switch (t.fKind) {
case Token::IDENTIFIER: {
- std::string text;
+ SkString text;
if (this->identifier(&text)) {
result.reset(new ASTIdentifier(t.fPosition, std::move(text)));
}
@@ -1487,7 +1496,7 @@
}
/* IDENTIFIER */
-bool Parser::identifier(std::string* dest) {
+bool Parser::identifier(SkString* dest) {
Token t;
if (this->expect(Token::IDENTIFIER, "identifier", &t)) {
*dest = t.fText;