| Index: src/sksl/SkSLIRGenerator.cpp
|
| diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
|
| index c30cac17d76db3626ab059d6ecb6c1ff249ad56a..d64684e62dc3312ed3c885c46f9d064026799664 100644
|
| --- a/src/sksl/SkSLIRGenerator.cpp
|
| +++ b/src/sksl/SkSLIRGenerator.cpp
|
| @@ -189,7 +189,11 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
|
| }
|
| value = this->coerce(std::move(value), *type);
|
| }
|
| - if ("gl_FragCoord" == varDecl.fName && (*fSymbolTable)[varDecl.fName]) {
|
| + if ("sk_FragColor" == varDecl.fName && (*fSymbolTable)[varDecl.fName]) {
|
| + // already defined, ignore
|
| + } else if ((*fSymbolTable)[varDecl.fName] &&
|
| + (*fSymbolTable)[varDecl.fName]->fKind == Symbol::kVariable_Kind &&
|
| + ((Variable*) (*fSymbolTable)[varDecl.fName])->fModifiers.fLayout.fBuiltin >= 0) {
|
| // already defined, just update the modifiers
|
| Variable* old = (Variable*) (*fSymbolTable)[varDecl.fName];
|
| old->fModifiers = var->fModifiers;
|
| @@ -203,6 +207,12 @@ std::unique_ptr<VarDeclarations> IRGenerator::convertVarDeclarations(const ASTVa
|
| std::move(variables)));
|
| }
|
|
|
| +std::unique_ptr<ModifiersDeclaration> IRGenerator::convertModifiersDeclaration(
|
| + const ASTModifiersDeclaration& m) {
|
| + Modifiers modifiers = this->convertModifiers(m.fModifiers);
|
| + return std::unique_ptr<ModifiersDeclaration>(new ModifiersDeclaration(modifiers));
|
| +}
|
| +
|
| std::unique_ptr<Statement> IRGenerator::convertIf(const ASTIfStatement& s) {
|
| std::unique_ptr<Expression> test = this->coerce(this->convertExpression(*s.fTest),
|
| *fContext.fBool_Type);
|
| @@ -419,8 +429,9 @@ std::unique_ptr<FunctionDefinition> IRGenerator::convertFunction(const ASTFuncti
|
| for (size_t i = 0; i < parameters.size(); i++) {
|
| if (parameters[i]->fModifiers != other->fParameters[i]->fModifiers) {
|
| fErrors.error(f.fPosition, "modifiers on parameter " +
|
| - to_string(i + 1) + " differ between " +
|
| - "declaration and definition");
|
| + to_string((uint64_t) i + 1) +
|
| + " differ between declaration and "
|
| + "definition");
|
| return nullptr;
|
| }
|
| }
|
| @@ -616,8 +627,9 @@ std::unique_ptr<Expression> IRGenerator::coerce(std::unique_ptr<Expression> expr
|
| ASSERT(ctor);
|
| return this->call(Position(), std::move(ctor), std::move(args));
|
| }
|
| - ABORT("cannot coerce %s to %s", expr->fType.description().c_str(),
|
| - type.description().c_str());
|
| + std::vector<std::unique_ptr<Expression>> args;
|
| + args.push_back(std::move(expr));
|
| + return std::unique_ptr<Expression>(new Constructor(Position(), type, std::move(args)));
|
| }
|
|
|
| static bool is_matrix_multiply(const Type& left, const Type& right) {
|
| @@ -832,12 +844,12 @@ std::unique_ptr<Expression> IRGenerator::call(Position position,
|
| std::vector<std::unique_ptr<Expression>> arguments) {
|
| if (function.fParameters.size() != arguments.size()) {
|
| std::string msg = "call to '" + function.fName + "' expected " +
|
| - to_string(function.fParameters.size()) +
|
| + to_string((uint64_t) function.fParameters.size()) +
|
| " argument";
|
| if (function.fParameters.size() != 1) {
|
| msg += "s";
|
| }
|
| - msg += ", but found " + to_string(arguments.size());
|
| + msg += ", but found " + to_string((uint64_t) arguments.size());
|
| fErrors.error(position, msg);
|
| return nullptr;
|
| }
|
| @@ -921,7 +933,8 @@ std::unique_ptr<Expression> IRGenerator::convertConstructor(
|
| std::vector<std::unique_ptr<Expression>> args) {
|
| // FIXME: add support for structs and arrays
|
| Type::Kind kind = type.kind();
|
| - if (!type.isNumber() && kind != Type::kVector_Kind && kind != Type::kMatrix_Kind) {
|
| + if (!type.isNumber() && kind != Type::kVector_Kind && kind != Type::kMatrix_Kind &&
|
| + kind != Type::kArray_Kind) {
|
| fErrors.error(position, "cannot construct '" + type.description() + "'");
|
| return nullptr;
|
| }
|
| @@ -938,7 +951,7 @@ std::unique_ptr<Expression> IRGenerator::convertConstructor(
|
| if (args.size() != 1) {
|
| fErrors.error(position, "invalid arguments to '" + type.description() +
|
| "' constructor, (expected exactly 1 argument, but found " +
|
| - to_string(args.size()) + ")");
|
| + to_string((uint64_t) args.size()) + ")");
|
| }
|
| if (args[0]->fType == *fContext.fBool_Type) {
|
| std::unique_ptr<IntLiteral> zero(new IntLiteral(fContext, position, 0));
|
| @@ -953,6 +966,18 @@ std::unique_ptr<Expression> IRGenerator::convertConstructor(
|
| "' constructor (expected a number or bool, but found '" +
|
| args[0]->fType.description() + "')");
|
| }
|
| + if (args[0]->fKind == Expression::kIntLiteral_Kind && (type == *fContext.fInt_Type ||
|
| + type == *fContext.fUInt_Type)) {
|
| + return std::unique_ptr<Expression>(new IntLiteral(fContext,
|
| + position,
|
| + ((IntLiteral&) *args[0]).fValue,
|
| + &type));
|
| + }
|
| + } else if (kind == Type::kArray_Kind) {
|
| + const Type& base = type.componentType();
|
| + for (size_t i = 0; i < args.size(); i++) {
|
| + args[i] = this->coerce(std::move(args[i]), base);
|
| + }
|
| } else {
|
| ASSERT(kind == Type::kVector_Kind || kind == Type::kMatrix_Kind);
|
| int actual = 0;
|
| @@ -1037,7 +1062,7 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(
|
| }
|
| this->markWrittenTo(*base);
|
| break;
|
| - case Token::NOT:
|
| + case Token::LOGICALNOT:
|
| if (base->fType != *fContext.fBool_Type) {
|
| fErrors.error(expression.fPosition,
|
| "'" + Token::OperatorName(expression.fOperator) +
|
| @@ -1045,6 +1070,14 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(
|
| return nullptr;
|
| }
|
| break;
|
| + case Token::BITWISENOT:
|
| + if (base->fType != *fContext.fInt_Type) {
|
| + fErrors.error(expression.fPosition,
|
| + "'" + Token::OperatorName(expression.fOperator) +
|
| + "' cannot operate on '" + base->fType.description() + "'");
|
| + return nullptr;
|
| + }
|
| + break;
|
| default:
|
| ABORT("unsupported prefix operator\n");
|
| }
|
| @@ -1054,7 +1087,8 @@ std::unique_ptr<Expression> IRGenerator::convertPrefixExpression(
|
|
|
| std::unique_ptr<Expression> IRGenerator::convertIndex(std::unique_ptr<Expression> base,
|
| const ASTExpression& index) {
|
| - if (base->fType.kind() != Type::kArray_Kind && base->fType.kind() != Type::kMatrix_Kind) {
|
| + if (base->fType.kind() != Type::kArray_Kind && base->fType.kind() != Type::kMatrix_Kind &&
|
| + base->fType.kind() != Type::kVector_Kind) {
|
| fErrors.error(base->fPosition, "expected array, but found '" + base->fType.description() +
|
| "'");
|
| return nullptr;
|
| @@ -1063,9 +1097,11 @@ std::unique_ptr<Expression> IRGenerator::convertIndex(std::unique_ptr<Expression
|
| if (!converted) {
|
| return nullptr;
|
| }
|
| - converted = this->coerce(std::move(converted), *fContext.fInt_Type);
|
| - if (!converted) {
|
| - return nullptr;
|
| + if (converted->fType != *fContext.fUInt_Type) {
|
| + converted = this->coerce(std::move(converted), *fContext.fInt_Type);
|
| + if (!converted) {
|
| + return nullptr;
|
| + }
|
| }
|
| return std::unique_ptr<Expression>(new IndexExpression(fContext, std::move(base),
|
| std::move(converted)));
|
| @@ -1143,9 +1179,21 @@ std::unique_ptr<Expression> IRGenerator::convertSuffixExpression(
|
| return nullptr;
|
| }
|
| switch (expression.fSuffix->fKind) {
|
| - case ASTSuffix::kIndex_Kind:
|
| - return this->convertIndex(std::move(base),
|
| - *((ASTIndexSuffix&) *expression.fSuffix).fExpression);
|
| + case ASTSuffix::kIndex_Kind: {
|
| + const ASTExpression* expr = ((ASTIndexSuffix&) *expression.fSuffix).fExpression.get();
|
| + if (expr) {
|
| + return this->convertIndex(std::move(base), *expr);
|
| + } else if (base->fKind == Expression::kTypeReference_Kind) {
|
| + const Type& oldType = ((TypeReference&) *base).fValue;
|
| + Type* newType = new Type(oldType.name() + "[]", Type::kArray_Kind, oldType,
|
| + -1);
|
| + fSymbolTable->takeOwnership(newType);
|
| + return std::unique_ptr<Expression>(new TypeReference(fContext, base->fPosition,
|
| + *newType));
|
| + } else {
|
| + fErrors.error(expression.fPosition, "'[]' must follow a type name");
|
| + }
|
| + }
|
| case ASTSuffix::kCall_Kind: {
|
| auto rawArguments = &((ASTCallSuffix&) *expression.fSuffix).fArguments;
|
| std::vector<std::unique_ptr<Expression>> arguments;
|
|
|