2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* shader_language.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "shader_language.h"
|
|
|
|
#include "os/os.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "print_string.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
static bool _is_text_char(CharType c) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_number(CharType c) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (c >= '0' && c <= '9');
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool _is_hex(CharType c) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
String ShaderLanguage::get_operator_text(Operator p_op) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static const char *op_names[OP_MAX] = { "==",
|
|
|
|
"!=",
|
|
|
|
"<",
|
|
|
|
"<=",
|
|
|
|
">",
|
|
|
|
">=",
|
|
|
|
"&&",
|
|
|
|
"||",
|
|
|
|
"!",
|
|
|
|
"-",
|
|
|
|
"+",
|
|
|
|
"-",
|
|
|
|
"*",
|
|
|
|
"/",
|
|
|
|
"%",
|
|
|
|
"<<",
|
|
|
|
">>",
|
|
|
|
"=",
|
|
|
|
"+=",
|
|
|
|
"-=",
|
|
|
|
"*=",
|
|
|
|
"/=",
|
|
|
|
"%=",
|
|
|
|
"<<=",
|
|
|
|
">>=",
|
|
|
|
"&=",
|
|
|
|
"|=",
|
|
|
|
"^=",
|
|
|
|
"&",
|
|
|
|
"|",
|
|
|
|
"^",
|
|
|
|
"~",
|
2017-09-05 20:22:33 +02:00
|
|
|
"++",
|
|
|
|
"--",
|
|
|
|
"?",
|
|
|
|
":",
|
|
|
|
"++",
|
2017-03-05 16:44:50 +01:00
|
|
|
"--",
|
|
|
|
"()",
|
2017-04-07 04:36:37 +02:00
|
|
|
"construct",
|
|
|
|
"index" };
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
return op_names[p_op];
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *ShaderLanguage::token_names[TK_MAX] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
"EMPTY",
|
2016-10-03 21:33:42 +02:00
|
|
|
"IDENTIFIER",
|
2014-02-10 02:10:30 +01:00
|
|
|
"TRUE",
|
|
|
|
"FALSE",
|
|
|
|
"REAL_CONSTANT",
|
2016-10-07 16:31:18 +02:00
|
|
|
"INT_CONSTANT",
|
2014-02-10 02:10:30 +01:00
|
|
|
"TYPE_VOID",
|
|
|
|
"TYPE_BOOL",
|
2016-10-07 16:31:18 +02:00
|
|
|
"TYPE_BVEC2",
|
|
|
|
"TYPE_BVEC3",
|
|
|
|
"TYPE_BVEC4",
|
|
|
|
"TYPE_INT",
|
|
|
|
"TYPE_IVEC2",
|
|
|
|
"TYPE_IVEC3",
|
|
|
|
"TYPE_IVEC4",
|
|
|
|
"TYPE_UINT",
|
|
|
|
"TYPE_UVEC2",
|
|
|
|
"TYPE_UVEC3",
|
|
|
|
"TYPE_UVEC4",
|
2014-02-10 02:10:30 +01:00
|
|
|
"TYPE_FLOAT",
|
|
|
|
"TYPE_VEC2",
|
|
|
|
"TYPE_VEC3",
|
|
|
|
"TYPE_VEC4",
|
2015-03-10 04:53:09 +01:00
|
|
|
"TYPE_MAT2",
|
2014-02-10 02:10:30 +01:00
|
|
|
"TYPE_MAT3",
|
|
|
|
"TYPE_MAT4",
|
2016-10-07 16:31:18 +02:00
|
|
|
"TYPE_SAMPLER2D",
|
|
|
|
"TYPE_ISAMPLER2D",
|
|
|
|
"TYPE_USAMPLER2D",
|
|
|
|
"TYPE_SAMPLERCUBE",
|
|
|
|
"PRECISION_LOW",
|
|
|
|
"PRECISION_MID",
|
|
|
|
"PRECISION_HIGH",
|
2014-02-10 02:10:30 +01:00
|
|
|
"OP_EQUAL",
|
|
|
|
"OP_NOT_EQUAL",
|
|
|
|
"OP_LESS",
|
|
|
|
"OP_LESS_EQUAL",
|
|
|
|
"OP_GREATER",
|
|
|
|
"OP_GREATER_EQUAL",
|
|
|
|
"OP_AND",
|
|
|
|
"OP_OR",
|
|
|
|
"OP_NOT",
|
|
|
|
"OP_ADD",
|
|
|
|
"OP_SUB",
|
|
|
|
"OP_MUL",
|
|
|
|
"OP_DIV",
|
2016-10-07 16:31:18 +02:00
|
|
|
"OP_MOD",
|
|
|
|
"OP_SHIFT_LEFT",
|
|
|
|
"OP_SHIFT_RIGHT",
|
2014-02-10 02:10:30 +01:00
|
|
|
"OP_ASSIGN",
|
|
|
|
"OP_ASSIGN_ADD",
|
|
|
|
"OP_ASSIGN_SUB",
|
|
|
|
"OP_ASSIGN_MUL",
|
|
|
|
"OP_ASSIGN_DIV",
|
2016-10-07 16:31:18 +02:00
|
|
|
"OP_ASSIGN_MOD",
|
|
|
|
"OP_ASSIGN_SHIFT_LEFT",
|
|
|
|
"OP_ASSIGN_SHIFT_RIGHT",
|
|
|
|
"OP_ASSIGN_BIT_AND",
|
|
|
|
"OP_ASSIGN_BIT_OR",
|
|
|
|
"OP_ASSIGN_BIT_XOR",
|
|
|
|
"OP_BIT_AND",
|
|
|
|
"OP_BIT_OR",
|
|
|
|
"OP_BIT_XOR",
|
|
|
|
"OP_BIT_INVERT",
|
|
|
|
"OP_INCREMENT",
|
|
|
|
"OP_DECREMENT",
|
2014-02-10 02:10:30 +01:00
|
|
|
"CF_IF",
|
|
|
|
"CF_ELSE",
|
2016-10-07 16:31:18 +02:00
|
|
|
"CF_FOR",
|
|
|
|
"CF_WHILE",
|
|
|
|
"CF_DO",
|
|
|
|
"CF_SWITCH",
|
|
|
|
"CF_CASE",
|
|
|
|
"CF_BREAK",
|
|
|
|
"CF_CONTINUE",
|
2014-02-10 02:10:30 +01:00
|
|
|
"CF_RETURN",
|
2017-08-29 15:14:07 +02:00
|
|
|
"CF_DISCARD",
|
2014-02-10 02:10:30 +01:00
|
|
|
"BRACKET_OPEN",
|
|
|
|
"BRACKET_CLOSE",
|
|
|
|
"CURLY_BRACKET_OPEN",
|
|
|
|
"CURLY_BRACKET_CLOSE",
|
|
|
|
"PARENTHESIS_OPEN",
|
|
|
|
"PARENTHESIS_CLOSE",
|
2016-10-07 16:31:18 +02:00
|
|
|
"QUESTION",
|
2014-02-10 02:10:30 +01:00
|
|
|
"COMMA",
|
2016-10-07 16:31:18 +02:00
|
|
|
"COLON",
|
2014-02-10 02:10:30 +01:00
|
|
|
"SEMICOLON",
|
|
|
|
"PERIOD",
|
|
|
|
"UNIFORM",
|
2016-10-07 16:31:18 +02:00
|
|
|
"VARYING",
|
2017-04-07 04:36:37 +02:00
|
|
|
"IN",
|
|
|
|
"OUT",
|
|
|
|
"INOUT",
|
2016-10-07 16:31:18 +02:00
|
|
|
"RENDER_MODE",
|
|
|
|
"HINT_WHITE_TEXTURE",
|
|
|
|
"HINT_BLACK_TEXTURE",
|
|
|
|
"HINT_NORMAL_TEXTURE",
|
2016-11-21 02:49:53 +01:00
|
|
|
"HINT_ANISO_TEXTURE",
|
2016-10-07 16:31:18 +02:00
|
|
|
"HINT_ALBEDO_TEXTURE",
|
2016-11-21 02:49:53 +01:00
|
|
|
"HINT_BLACK_ALBEDO_TEXTURE",
|
2016-10-07 16:31:18 +02:00
|
|
|
"HINT_COLOR",
|
|
|
|
"HINT_RANGE",
|
2017-04-07 04:36:37 +02:00
|
|
|
"SHADER_TYPE",
|
2016-10-07 16:31:18 +02:00
|
|
|
"CURSOR",
|
2014-02-10 02:10:30 +01:00
|
|
|
"ERROR",
|
2016-10-07 16:31:18 +02:00
|
|
|
"EOF",
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
String ShaderLanguage::get_token_text(Token p_token) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = token_names[p_token.type];
|
|
|
|
if (p_token.type == TK_INT_CONSTANT || p_token.type == TK_REAL_CONSTANT) {
|
|
|
|
name += "(" + rtos(p_token.constant) + ")";
|
|
|
|
} else if (p_token.type == TK_IDENTIFIER) {
|
|
|
|
name += "(" + String(p_token.text) + ")";
|
|
|
|
} else if (p_token.type == TK_ERROR) {
|
|
|
|
name += "(" + String(p_token.text) + ")";
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return name;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ShaderLanguage::Token ShaderLanguage::_make_token(TokenType p_type, const StringName &p_text) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk;
|
2017-03-05 16:44:50 +01:00
|
|
|
tk.type = p_type;
|
|
|
|
tk.text = p_text;
|
|
|
|
tk.line = tk_line;
|
|
|
|
if (tk.type == TK_ERROR) {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_error(p_text);
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
return tk;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = {
|
|
|
|
{ TK_TRUE, "true" },
|
|
|
|
{ TK_FALSE, "false" },
|
|
|
|
{ TK_TYPE_VOID, "void" },
|
|
|
|
{ TK_TYPE_BOOL, "bool" },
|
|
|
|
{ TK_TYPE_BVEC2, "bvec2" },
|
|
|
|
{ TK_TYPE_BVEC3, "bvec3" },
|
|
|
|
{ TK_TYPE_BVEC4, "bvec4" },
|
|
|
|
{ TK_TYPE_INT, "int" },
|
|
|
|
{ TK_TYPE_IVEC2, "ivec2" },
|
|
|
|
{ TK_TYPE_IVEC3, "ivec3" },
|
|
|
|
{ TK_TYPE_IVEC4, "ivec4" },
|
|
|
|
{ TK_TYPE_UINT, "uint" },
|
|
|
|
{ TK_TYPE_UVEC2, "uvec2" },
|
|
|
|
{ TK_TYPE_UVEC3, "uvec3" },
|
|
|
|
{ TK_TYPE_UVEC4, "uvec4" },
|
|
|
|
{ TK_TYPE_FLOAT, "float" },
|
|
|
|
{ TK_TYPE_VEC2, "vec2" },
|
|
|
|
{ TK_TYPE_VEC3, "vec3" },
|
|
|
|
{ TK_TYPE_VEC4, "vec4" },
|
|
|
|
{ TK_TYPE_MAT2, "mat2" },
|
|
|
|
{ TK_TYPE_MAT3, "mat3" },
|
|
|
|
{ TK_TYPE_MAT4, "mat4" },
|
|
|
|
{ TK_TYPE_SAMPLER2D, "sampler2D" },
|
|
|
|
{ TK_TYPE_ISAMPLER2D, "isampler2D" },
|
|
|
|
{ TK_TYPE_USAMPLER2D, "usampler2D" },
|
|
|
|
{ TK_TYPE_SAMPLERCUBE, "samplerCube" },
|
2017-11-27 16:47:46 +01:00
|
|
|
{ TK_INTERPOLATION_FLAT, "flat" },
|
|
|
|
{ TK_INTERPOLATION_NO_PERSPECTIVE, "noperspective" },
|
|
|
|
{ TK_INTERPOLATION_SMOOTH, "smooth" },
|
2017-03-05 16:44:50 +01:00
|
|
|
{ TK_PRECISION_LOW, "lowp" },
|
|
|
|
{ TK_PRECISION_MID, "mediump" },
|
|
|
|
{ TK_PRECISION_HIGH, "highp" },
|
|
|
|
{ TK_CF_IF, "if" },
|
|
|
|
{ TK_CF_ELSE, "else" },
|
|
|
|
{ TK_CF_FOR, "for" },
|
|
|
|
{ TK_CF_WHILE, "while" },
|
|
|
|
{ TK_CF_DO, "do" },
|
|
|
|
{ TK_CF_SWITCH, "switch" },
|
|
|
|
{ TK_CF_CASE, "case" },
|
|
|
|
{ TK_CF_BREAK, "break" },
|
|
|
|
{ TK_CF_CONTINUE, "continue" },
|
|
|
|
{ TK_CF_RETURN, "return" },
|
2017-09-24 09:27:12 +02:00
|
|
|
{ TK_CF_DISCARD, "discard" },
|
2017-03-05 16:44:50 +01:00
|
|
|
{ TK_UNIFORM, "uniform" },
|
|
|
|
{ TK_VARYING, "varying" },
|
2017-04-07 04:36:37 +02:00
|
|
|
{ TK_ARG_IN, "in" },
|
|
|
|
{ TK_ARG_OUT, "out" },
|
|
|
|
{ TK_ARG_INOUT, "inout" },
|
2017-03-05 16:44:50 +01:00
|
|
|
{ TK_RENDER_MODE, "render_mode" },
|
|
|
|
{ TK_HINT_WHITE_TEXTURE, "hint_white" },
|
|
|
|
{ TK_HINT_BLACK_TEXTURE, "hint_black" },
|
|
|
|
{ TK_HINT_NORMAL_TEXTURE, "hint_normal" },
|
|
|
|
{ TK_HINT_ANISO_TEXTURE, "hint_aniso" },
|
|
|
|
{ TK_HINT_ALBEDO_TEXTURE, "hint_albedo" },
|
|
|
|
{ TK_HINT_BLACK_ALBEDO_TEXTURE, "hint_black_albedo" },
|
|
|
|
{ TK_HINT_COLOR, "hint_color" },
|
|
|
|
{ TK_HINT_RANGE, "hint_range" },
|
2017-04-07 04:36:37 +02:00
|
|
|
{ TK_SHADER_TYPE, "shader_type" },
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
{ TK_ERROR, NULL }
|
2016-10-07 16:31:18 +02:00
|
|
|
};
|
2015-04-26 17:34:42 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderLanguage::Token ShaderLanguage::_get_token() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#define GETCHAR(m_idx) (((char_idx + m_idx) < code.length()) ? code[char_idx + m_idx] : CharType(0))
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (GETCHAR(-1)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
case 0:
|
|
|
|
return _make_token(TK_EOF);
|
|
|
|
case 0xFFFF:
|
|
|
|
return _make_token(TK_CURSOR); //for completion
|
2016-10-03 21:33:42 +02:00
|
|
|
case '\t':
|
|
|
|
case '\r':
|
|
|
|
case ' ':
|
|
|
|
continue;
|
|
|
|
case '\n':
|
|
|
|
tk_line++;
|
|
|
|
continue;
|
|
|
|
case '/': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (GETCHAR(0)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case '*': { // block comment
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
|
|
|
if (GETCHAR(0) == 0) {
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_EOF);
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
|
|
|
if (GETCHAR(0) == '*' && GETCHAR(1) == '/') {
|
|
|
|
char_idx += 2;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '\n') {
|
2016-10-03 21:33:42 +02:00
|
|
|
tk_line++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case '/': { // line comment skip
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
|
|
|
if (GETCHAR(0) == '\n') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
break;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == 0) {
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_EOF);
|
|
|
|
}
|
|
|
|
char_idx++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case '=': { // diveq
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_DIV);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
return _make_token(TK_OP_DIV);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
continue; //a comment, continue to next token
|
|
|
|
} break;
|
|
|
|
case '=': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_EQUAL);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_ASSIGN);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case '<': {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_LESS_EQUAL);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '<') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_SHIFT_LEFT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_SHIFT_LEFT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_LESS);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case '>': {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_GREATER_EQUAL);
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (GETCHAR(0) == '>') {
|
2017-01-14 18:03:38 +01:00
|
|
|
char_idx++;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_SHIFT_RIGHT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_SHIFT_RIGHT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_GREATER);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case '!': {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_NOT_EQUAL);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_NOT);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
//case '"' //string - no strings in shader
|
|
|
|
//case '\'' //string - no strings in shader
|
|
|
|
case '{':
|
|
|
|
return _make_token(TK_CURLY_BRACKET_OPEN);
|
|
|
|
case '}':
|
|
|
|
return _make_token(TK_CURLY_BRACKET_CLOSE);
|
|
|
|
case '[':
|
|
|
|
return _make_token(TK_BRACKET_OPEN);
|
|
|
|
case ']':
|
|
|
|
return _make_token(TK_BRACKET_CLOSE);
|
|
|
|
case '(':
|
|
|
|
return _make_token(TK_PARENTHESIS_OPEN);
|
|
|
|
case ')':
|
|
|
|
return _make_token(TK_PARENTHESIS_CLOSE);
|
|
|
|
case ',':
|
|
|
|
return _make_token(TK_COMMA);
|
|
|
|
case ';':
|
|
|
|
return _make_token(TK_SEMICOLON);
|
|
|
|
case '?':
|
|
|
|
return _make_token(TK_QUESTION);
|
|
|
|
case ':':
|
|
|
|
return _make_token(TK_COLON);
|
|
|
|
case '^':
|
|
|
|
return _make_token(TK_OP_BIT_XOR);
|
|
|
|
case '~':
|
|
|
|
return _make_token(TK_OP_BIT_INVERT);
|
|
|
|
case '&': {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_BIT_AND);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '&') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_AND);
|
|
|
|
}
|
|
|
|
return _make_token(TK_OP_BIT_AND);
|
|
|
|
} break;
|
|
|
|
case '|': {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_BIT_OR);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '|') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_OR);
|
|
|
|
}
|
|
|
|
return _make_token(TK_OP_BIT_OR);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case '*': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_MUL);
|
|
|
|
}
|
|
|
|
return _make_token(TK_OP_MUL);
|
|
|
|
} break;
|
|
|
|
case '+': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_ADD);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '+') {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_INCREMENT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_ADD);
|
|
|
|
} break;
|
|
|
|
case '-': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_SUB);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (GETCHAR(0) == '-') {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_DECREMENT);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_SUB);
|
|
|
|
} break;
|
|
|
|
case '%': {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '=') {
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
return _make_token(TK_OP_ASSIGN_MOD);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_OP_MOD);
|
|
|
|
} break;
|
|
|
|
default: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx--; //go back one, since we have no idea what this is
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_is_number(GETCHAR(0)) || (GETCHAR(0) == '.' && _is_number(GETCHAR(1)))) {
|
2016-10-03 21:33:42 +02:00
|
|
|
// parse number
|
2017-03-05 16:44:50 +01:00
|
|
|
bool period_found = false;
|
|
|
|
bool exponent_found = false;
|
|
|
|
bool hexa_found = false;
|
|
|
|
bool sign_found = false;
|
|
|
|
bool minus_exponent_found = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
String str;
|
2017-03-05 16:44:50 +01:00
|
|
|
int i = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
|
|
|
if (GETCHAR(i) == '.') {
|
2016-10-03 21:33:42 +02:00
|
|
|
if (period_found || exponent_found)
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
|
|
|
period_found = true;
|
|
|
|
} else if (GETCHAR(i) == 'x') {
|
|
|
|
if (hexa_found || str.length() != 1 || str[0] != '0')
|
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
|
|
|
hexa_found = true;
|
|
|
|
} else if (GETCHAR(i) == 'e') {
|
2016-10-03 21:33:42 +02:00
|
|
|
if (hexa_found || exponent_found)
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
|
|
|
exponent_found = true;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else if (_is_number(GETCHAR(i))) {
|
|
|
|
//all ok
|
|
|
|
} else if (hexa_found && _is_hex(GETCHAR(i))) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) {
|
2016-10-03 21:33:42 +02:00
|
|
|
if (sign_found)
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
|
|
|
sign_found = true;
|
|
|
|
if (GETCHAR(i) == '-')
|
|
|
|
minus_exponent_found = true;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else
|
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
str += CharType(GETCHAR(i));
|
2016-10-03 21:33:42 +02:00
|
|
|
i++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_is_number(str[str.length() - 1]))
|
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
char_idx += str.length();
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk;
|
|
|
|
if (period_found || minus_exponent_found)
|
2017-03-05 16:44:50 +01:00
|
|
|
tk.type = TK_REAL_CONSTANT;
|
2016-10-03 21:33:42 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
tk.type = TK_INT_CONSTANT;
|
2015-03-10 04:53:09 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!str.is_valid_float()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_ERROR, "Invalid numeric constant");
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tk.constant = str.to_double();
|
|
|
|
tk.line = tk_line;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return tk;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) == '.') {
|
2016-10-03 21:33:42 +02:00
|
|
|
//parse period
|
2016-10-07 16:31:18 +02:00
|
|
|
char_idx++;
|
2016-10-03 21:33:42 +02:00
|
|
|
return _make_token(TK_PERIOD);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (_is_text_char(GETCHAR(0))) {
|
|
|
|
// parse identifier
|
|
|
|
String str;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (_is_text_char(GETCHAR(0))) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
str += CharType(GETCHAR(0));
|
2016-10-03 21:33:42 +02:00
|
|
|
char_idx++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//see if keyword
|
|
|
|
//should be converted to a static map
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (keyword_list[idx].text) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (str == keyword_list[idx].text) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
return _make_token(keyword_list[idx].token);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
idx++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_IDENTIFIER, str);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (GETCHAR(0) > 32)
|
|
|
|
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)) + ": '" + String::chr(GETCHAR(0)) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
return _make_token(TK_ERROR, "Tokenizer: Unknown character #" + itos(GETCHAR(0)));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
ERR_PRINT("BUG");
|
|
|
|
return Token();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String ShaderLanguage::token_debug(const String &p_code) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
code = p_code;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
String output;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
Token tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
while (tk.type != TK_EOF && tk.type != TK_ERROR) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
output += itos(tk_line) + ": " + get_token_text(tk) + "\n";
|
2016-10-07 16:31:18 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
return output;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderLanguage::is_token_datatype(TokenType p_type) {
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return (
|
2017-03-05 16:44:50 +01:00
|
|
|
p_type == TK_TYPE_VOID ||
|
|
|
|
p_type == TK_TYPE_BOOL ||
|
|
|
|
p_type == TK_TYPE_BVEC2 ||
|
|
|
|
p_type == TK_TYPE_BVEC3 ||
|
|
|
|
p_type == TK_TYPE_BVEC4 ||
|
|
|
|
p_type == TK_TYPE_INT ||
|
|
|
|
p_type == TK_TYPE_IVEC2 ||
|
|
|
|
p_type == TK_TYPE_IVEC3 ||
|
|
|
|
p_type == TK_TYPE_IVEC4 ||
|
|
|
|
p_type == TK_TYPE_UINT ||
|
|
|
|
p_type == TK_TYPE_UVEC2 ||
|
|
|
|
p_type == TK_TYPE_UVEC3 ||
|
|
|
|
p_type == TK_TYPE_UVEC4 ||
|
|
|
|
p_type == TK_TYPE_FLOAT ||
|
|
|
|
p_type == TK_TYPE_VEC2 ||
|
|
|
|
p_type == TK_TYPE_VEC3 ||
|
|
|
|
p_type == TK_TYPE_VEC4 ||
|
|
|
|
p_type == TK_TYPE_MAT2 ||
|
|
|
|
p_type == TK_TYPE_MAT3 ||
|
|
|
|
p_type == TK_TYPE_MAT4 ||
|
|
|
|
p_type == TK_TYPE_SAMPLER2D ||
|
|
|
|
p_type == TK_TYPE_ISAMPLER2D ||
|
|
|
|
p_type == TK_TYPE_USAMPLER2D ||
|
|
|
|
p_type == TK_TYPE_SAMPLERCUBE);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return DataType(p_type - TK_TYPE_VOID);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-27 16:47:46 +01:00
|
|
|
bool ShaderLanguage::is_token_interpolation(TokenType p_type) {
|
|
|
|
|
|
|
|
return (
|
|
|
|
p_type == TK_INTERPOLATION_FLAT ||
|
|
|
|
p_type == TK_INTERPOLATION_NO_PERSPECTIVE ||
|
|
|
|
p_type == TK_INTERPOLATION_SMOOTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) {
|
|
|
|
|
|
|
|
if (p_type == TK_INTERPOLATION_FLAT)
|
|
|
|
return INTERPOLATION_FLAT;
|
|
|
|
else if (p_type == TK_INTERPOLATION_NO_PERSPECTIVE)
|
|
|
|
return INTERPOLATION_NO_PERSPECTIVE;
|
|
|
|
else
|
|
|
|
return INTERPOLATION_SMOOTH;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
bool ShaderLanguage::is_token_precision(TokenType p_type) {
|
|
|
|
|
|
|
|
return (
|
2017-03-05 16:44:50 +01:00
|
|
|
p_type == TK_PRECISION_LOW ||
|
|
|
|
p_type == TK_PRECISION_MID ||
|
|
|
|
p_type == TK_PRECISION_HIGH);
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderLanguage::DataPrecision ShaderLanguage::get_token_precision(TokenType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_type == TK_PRECISION_LOW)
|
2016-10-03 21:33:42 +02:00
|
|
|
return PRECISION_LOWP;
|
2017-03-05 16:44:50 +01:00
|
|
|
else if (p_type == TK_PRECISION_HIGH)
|
2016-10-03 21:33:42 +02:00
|
|
|
return PRECISION_HIGHP;
|
|
|
|
else
|
|
|
|
return PRECISION_MEDIUMP;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String ShaderLanguage::get_datatype_name(DataType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_type) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
case TYPE_VOID: return "void";
|
|
|
|
case TYPE_BOOL: return "bool";
|
2016-10-03 21:33:42 +02:00
|
|
|
case TYPE_BVEC2: return "bvec2";
|
|
|
|
case TYPE_BVEC3: return "bvec3";
|
|
|
|
case TYPE_BVEC4: return "bvec4";
|
|
|
|
case TYPE_INT: return "int";
|
|
|
|
case TYPE_IVEC2: return "ivec2";
|
|
|
|
case TYPE_IVEC3: return "ivec3";
|
|
|
|
case TYPE_IVEC4: return "ivec4";
|
|
|
|
case TYPE_UINT: return "uint";
|
|
|
|
case TYPE_UVEC2: return "uvec2";
|
|
|
|
case TYPE_UVEC3: return "uvec3";
|
|
|
|
case TYPE_UVEC4: return "uvec4";
|
2014-02-10 02:10:30 +01:00
|
|
|
case TYPE_FLOAT: return "float";
|
|
|
|
case TYPE_VEC2: return "vec2";
|
|
|
|
case TYPE_VEC3: return "vec3";
|
|
|
|
case TYPE_VEC4: return "vec4";
|
2015-03-10 04:53:09 +01:00
|
|
|
case TYPE_MAT2: return "mat2";
|
2014-02-10 02:10:30 +01:00
|
|
|
case TYPE_MAT3: return "mat3";
|
|
|
|
case TYPE_MAT4: return "mat4";
|
2016-10-03 21:33:42 +02:00
|
|
|
case TYPE_SAMPLER2D: return "sampler2D";
|
|
|
|
case TYPE_ISAMPLER2D: return "isampler2D";
|
|
|
|
case TYPE_USAMPLER2D: return "usampler2D";
|
|
|
|
case TYPE_SAMPLERCUBE: return "samplerCube";
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderLanguage::is_token_nonvoid_datatype(TokenType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return is_token_datatype(p_type) && p_type != TK_TYPE_VOID;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
void ShaderLanguage::clear() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
current_function = StringName();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_type = COMPLETION_NONE;
|
|
|
|
completion_block = NULL;
|
|
|
|
completion_function = StringName();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
error_line = 0;
|
|
|
|
tk_line = 1;
|
|
|
|
char_idx = 0;
|
|
|
|
error_set = false;
|
|
|
|
error_str = "";
|
|
|
|
while (nodes) {
|
2016-10-03 21:33:42 +02:00
|
|
|
Node *n = nodes;
|
2017-03-05 16:44:50 +01:00
|
|
|
nodes = nodes->next;
|
2016-10-03 21:33:42 +02:00
|
|
|
memdelete(n);
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
bool ShaderLanguage::_find_identifier(const BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, const StringName &p_identifier, DataType *r_data_type, IdentifierType *r_type) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_builtin_types.has(p_identifier)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_data_type) {
|
2017-12-15 22:23:16 +01:00
|
|
|
*r_data_type = p_builtin_types[p_identifier].type;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_BUILTIN_VAR;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
FunctionNode *function = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (p_block) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_block->variables.has(p_identifier)) {
|
|
|
|
if (r_data_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_data_type = p_block->variables[p_identifier].type;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_LOCAL_VAR;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_block->parent_function) {
|
2017-03-05 16:44:50 +01:00
|
|
|
function = p_block->parent_function;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!p_block->parent_block, false);
|
|
|
|
p_block = p_block->parent_block;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (function) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < function->arguments.size(); i++) {
|
|
|
|
if (function->arguments[i].name == p_identifier) {
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_data_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_data_type = function->arguments[i].type;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_FUNCTION_ARGUMENT;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (shader->varyings.has(p_identifier)) {
|
|
|
|
if (r_data_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_data_type = shader->varyings[p_identifier].type;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_VARYING;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (shader->uniforms.has(p_identifier)) {
|
|
|
|
if (r_data_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_data_type = shader->uniforms[p_identifier].type;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_UNIFORM;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader->functions.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!shader->functions[i].callable)
|
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (shader->functions[i].name == p_identifier) {
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_data_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_data_type = shader->functions[i].function->return_type;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
if (r_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_type = IDENTIFIER_FUNCTION;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ShaderLanguage::_validate_operator(OperatorNode *p_op, DataType *r_ret_type) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool valid = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType ret_type;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_op->op) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case OP_EQUAL:
|
|
|
|
case OP_NOT_EQUAL: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == nb;
|
|
|
|
ret_type = TYPE_BOOL;
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_LESS:
|
|
|
|
case OP_LESS_EQUAL:
|
|
|
|
case OP_GREATER:
|
|
|
|
case OP_GREATER_EQUAL: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == nb && (na == TYPE_UINT || na == TYPE_INT || na == TYPE_FLOAT);
|
|
|
|
ret_type = TYPE_BOOL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_AND:
|
|
|
|
case OP_OR: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == nb && na == TYPE_BOOL;
|
|
|
|
ret_type = TYPE_BOOL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_NOT: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == TYPE_BOOL;
|
|
|
|
ret_type = TYPE_BOOL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_INCREMENT:
|
|
|
|
case OP_DECREMENT:
|
|
|
|
case OP_POST_INCREMENT:
|
|
|
|
case OP_POST_DECREMENT:
|
|
|
|
case OP_NEGATE: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na > TYPE_BOOL && na < TYPE_MAT2;
|
|
|
|
ret_type = na;
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_ADD:
|
|
|
|
case OP_SUB:
|
|
|
|
case OP_MUL:
|
|
|
|
case OP_DIV: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (na > nb) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//make things easier;
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(na, nb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (na == nb) {
|
2017-04-07 04:36:37 +02:00
|
|
|
valid = (na > TYPE_BOOL && na <= TYPE_MAT4);
|
2017-03-05 16:44:50 +01:00
|
|
|
ret_type = na;
|
|
|
|
} else if (na == TYPE_INT && nb == TYPE_IVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_INT && nb == TYPE_IVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_INT && nb == TYPE_IVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
|
|
|
} else if (na == TYPE_FLOAT && nb == TYPE_VEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC2;
|
|
|
|
} else if (na == TYPE_FLOAT && nb == TYPE_VEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC3;
|
|
|
|
} else if (na == TYPE_FLOAT && nb == TYPE_VEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC4;
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT2) {
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT2;
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT3) {
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT3;
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_FLOAT && nb == TYPE_MAT4) {
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT4;
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_VEC2 && nb == TYPE_MAT2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC2;
|
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_VEC3 && nb == TYPE_MAT3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC3;
|
|
|
|
} else if (p_op->op == OP_MUL && na == TYPE_VEC4 && nb == TYPE_MAT4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_ASSIGN_MOD:
|
|
|
|
case OP_MOD: {
|
|
|
|
/*
|
|
|
|
* The operator modulus (%) operates on signed or unsigned integers or integer vectors. The operand
|
|
|
|
* types must both be signed or both be unsigned. The operands cannot be vectors of differing size. If
|
|
|
|
* one operand is a scalar and the other vector, then the scalar is applied component-wise to the vector,
|
|
|
|
* resulting in the same type as the vector. If both are vectors of the same size, the result is computed
|
|
|
|
* component-wise.
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (na == TYPE_INT && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_INT;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
/////
|
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UINT;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_ASSIGN_SHIFT_LEFT:
|
|
|
|
case OP_ASSIGN_SHIFT_RIGHT:
|
|
|
|
case OP_SHIFT_LEFT:
|
|
|
|
case OP_SHIFT_RIGHT: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (na == TYPE_INT && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_INT;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UINT;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OP_ASSIGN: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == nb;
|
|
|
|
ret_type = na;
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_ASSIGN_ADD:
|
|
|
|
case OP_ASSIGN_SUB:
|
|
|
|
case OP_ASSIGN_MUL:
|
|
|
|
case OP_ASSIGN_DIV: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (na == nb) {
|
|
|
|
valid = (na > TYPE_BOOL && na < TYPE_MAT2) || (p_op->op == OP_ASSIGN_MUL && na >= TYPE_MAT2 && na <= TYPE_MAT4);
|
|
|
|
ret_type = na;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
|
|
|
} else if (na == TYPE_VEC2 && nb == TYPE_FLOAT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC2;
|
|
|
|
} else if (na == TYPE_VEC3 && nb == TYPE_FLOAT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC3;
|
|
|
|
} else if (na == TYPE_VEC4 && nb == TYPE_FLOAT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_VEC4;
|
|
|
|
} else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT2 && nb == TYPE_VEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT2;
|
|
|
|
} else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT3 && nb == TYPE_VEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT3;
|
|
|
|
} else if (p_op->op == OP_ASSIGN_MUL && na == TYPE_MAT4 && nb == TYPE_VEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_MAT4;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OP_ASSIGN_BIT_AND:
|
|
|
|
case OP_ASSIGN_BIT_OR:
|
|
|
|
case OP_ASSIGN_BIT_XOR:
|
|
|
|
case OP_BIT_AND:
|
|
|
|
case OP_BIT_OR:
|
|
|
|
case OP_BIT_XOR: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
/*
|
|
|
|
* The bitwise operators and (&), exclusive-or (^), and inclusive-or (|). The operands must be of type
|
|
|
|
* signed or unsigned integers or integer vectors. The operands cannot be vectors of differing size. If
|
|
|
|
* one operand is a scalar and the other a vector, the scalar is applied component-wise to the vector,
|
|
|
|
* resulting in the same type as the vector. The fundamental types of the operands (signed or unsigned)
|
|
|
|
* must match.
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (na > nb && p_op->op >= OP_BIT_AND) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//can swap for non assign
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(na, nb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (na == TYPE_INT && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_INT;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_INT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
} else if (na == TYPE_IVEC2 && nb == TYPE_IVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC2;
|
|
|
|
} else if (na == TYPE_IVEC3 && nb == TYPE_IVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC3;
|
|
|
|
} else if (na == TYPE_IVEC4 && nb == TYPE_IVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_IVEC4;
|
|
|
|
/////
|
|
|
|
} else if (na == TYPE_UINT && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UINT;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UINT) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
|
|
|
} else if (na == TYPE_UVEC2 && nb == TYPE_UVEC2) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC2;
|
|
|
|
} else if (na == TYPE_UVEC3 && nb == TYPE_UVEC3) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC3;
|
|
|
|
} else if (na == TYPE_UVEC4 && nb == TYPE_UVEC4) {
|
|
|
|
valid = true;
|
|
|
|
ret_type = TYPE_UVEC4;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_BIT_INVERT: { //unaries
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na >= TYPE_INT && na < TYPE_FLOAT;
|
|
|
|
ret_type = na;
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case OP_SELECT_IF: {
|
|
|
|
DataType na = p_op->arguments[0]->get_datatype();
|
|
|
|
DataType nb = p_op->arguments[1]->get_datatype();
|
|
|
|
DataType nc = p_op->arguments[2]->get_datatype();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = na == TYPE_BOOL && (nb == nc);
|
|
|
|
ret_type = nb;
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
ERR_FAIL_V(false);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_ret_type)
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_ret_type = ret_type;
|
2016-10-03 21:33:42 +02:00
|
|
|
return valid;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = {
|
2014-02-10 02:10:30 +01:00
|
|
|
//constructors
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "bool", TYPE_BOOL, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_BOOL, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_BVEC2, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_BOOL, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BVEC2, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BVEC2, TYPE_BOOL, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BOOL, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BOOL, TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BVEC3, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "float", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_VEC2, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "int", TYPE_INT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_INT, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_IVEC2, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_INT, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_INT, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_IVEC3, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "uint", TYPE_UINT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_UVEC2, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_UINT, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UVEC2, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UVEC2, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UINT, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UINT, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UVEC3, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "mat2", TYPE_MAT2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "mat3", TYPE_MAT3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "mat4", TYPE_MAT4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "mat2", TYPE_MAT2, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mat3", TYPE_MAT3, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mat4", TYPE_MAT4, { TYPE_FLOAT, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
//conversion scalars
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "int", TYPE_INT, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "int", TYPE_INT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "int", TYPE_INT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "int", TYPE_INT, { TYPE_FLOAT, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "float", TYPE_FLOAT, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "float", TYPE_FLOAT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "float", TYPE_FLOAT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "float", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "uint", TYPE_UINT, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "uint", TYPE_UINT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "uint", TYPE_UINT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uint", TYPE_UINT, { TYPE_FLOAT, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "bool", TYPE_BOOL, { TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "bool", TYPE_BOOL, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "bool", TYPE_BOOL, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "bool", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
//conversion vectors
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "ivec2", TYPE_IVEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "vec2", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "uvec2", TYPE_UVEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "bvec2", TYPE_BVEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "ivec3", TYPE_IVEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "vec3", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "uvec3", TYPE_UVEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "bvec3", TYPE_BVEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_BVEC4, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
{ "ivec4", TYPE_IVEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_BVEC4, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
{ "vec4", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_BVEC4, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
{ "uvec4", TYPE_UVEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_BVEC4, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
{ "bvec4", TYPE_BVEC4, { TYPE_VEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
//builtins - trigonometry
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "sin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "sin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "sin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "sin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "cos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "cos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "cos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "cos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "tan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "tan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "tan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "tan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "asin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "asin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "asin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "asin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "acos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "acos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "acos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "acos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
2017-11-24 03:19:11 +01:00
|
|
|
{ "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "sinh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "sinh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "sinh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "sinh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "cosh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "cosh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "cosh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "cosh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "tanh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
2017-11-25 23:19:16 +01:00
|
|
|
{ "tanh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "tanh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "tanh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
//builtins - exponential
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "pow", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "pow", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "pow", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "pow", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "exp", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "exp", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "exp", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "exp", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "log", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "log", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "log", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "log", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "sqrt", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "sqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "sqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "sqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
2017-09-22 03:02:08 +02:00
|
|
|
{ "inversesqrt", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "inversesqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "inversesqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "inversesqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
2016-10-07 16:31:18 +02:00
|
|
|
//builtins - common
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "abs", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "abs", TYPE_INT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "abs", TYPE_UINT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_UVEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_UVEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "abs", TYPE_UVEC4, { TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "sign", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "sign", TYPE_INT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_IVEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_IVEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "sign", TYPE_IVEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "floor", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "floor", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "floor", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "floor", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "trunc", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "trunc", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "trunc", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "trunc", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "round", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "round", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "round", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "round", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "ceil", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "ceil", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "ceil", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "ceil", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "fract", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "fract", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "fract", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "fract", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "mod", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "mod", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "modf", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "modf", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "modf", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "modf", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "min", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "min", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "min", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "min", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "max", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "max", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "max", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "max", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "clamp", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC2, { TYPE_VEC2, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC3, { TYPE_VEC3, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_VEC4, { TYPE_VEC4, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "clamp", TYPE_INT, { TYPE_INT, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC2, { TYPE_IVEC2, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC3, { TYPE_IVEC3, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_IVEC4, { TYPE_IVEC4, TYPE_INT, TYPE_INT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "clamp", TYPE_UINT, { TYPE_UINT, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC2, { TYPE_UVEC2, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC3, { TYPE_UVEC3, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "clamp", TYPE_UVEC4, { TYPE_UVEC4, TYPE_UINT, TYPE_UINT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "mix", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_BOOL, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "mix", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "step", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC2, { TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC3, { TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "step", TYPE_VEC4, { TYPE_FLOAT, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC2, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC3, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "smoothstep", TYPE_VEC4, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "isnan", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "isnan", TYPE_BOOL, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "isnan", TYPE_BOOL, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "isnan", TYPE_BOOL, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "isinf", TYPE_BOOL, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "isinf", TYPE_BOOL, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "isinf", TYPE_BOOL, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "isinf", TYPE_BOOL, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "floatBitsToInt", TYPE_INT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "floatBitsToInt", TYPE_IVEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "floatBitsToInt", TYPE_IVEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "floatBitsToInt", TYPE_IVEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "floatBitsToUInt", TYPE_UINT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "floatBitsToUInt", TYPE_UVEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "floatBitsToUInt", TYPE_UVEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "floatBitsToUInt", TYPE_UVEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "intBitsToFloat", TYPE_FLOAT, { TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "intBitsToFloat", TYPE_VEC2, { TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "intBitsToFloat", TYPE_VEC3, { TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "intBitsToFloat", TYPE_VEC4, { TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "uintBitsToFloat", TYPE_FLOAT, { TYPE_UINT, TYPE_VOID } },
|
|
|
|
{ "uintBitsToFloat", TYPE_VEC2, { TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "uintBitsToFloat", TYPE_VEC3, { TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "uintBitsToFloat", TYPE_VEC4, { TYPE_UVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
//builtins - geometric
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "length", TYPE_FLOAT, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "length", TYPE_FLOAT, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "length", TYPE_FLOAT, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "distance", TYPE_FLOAT, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "distance", TYPE_FLOAT, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "distance", TYPE_FLOAT, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "dot", TYPE_FLOAT, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "dot", TYPE_FLOAT, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "dot", TYPE_FLOAT, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "cross", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "normalize", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "normalize", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "normalize", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "reflect", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "refract", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
2017-08-17 18:15:16 +02:00
|
|
|
{ "faceforward", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "faceforward", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "faceforward", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
{ "matrixCompMult", TYPE_MAT2, { TYPE_MAT2, TYPE_MAT2, TYPE_VOID } },
|
|
|
|
{ "matrixCompMult", TYPE_MAT3, { TYPE_MAT3, TYPE_MAT3, TYPE_VOID } },
|
|
|
|
{ "matrixCompMult", TYPE_MAT4, { TYPE_MAT4, TYPE_MAT4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "outerProduct", TYPE_MAT2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "outerProduct", TYPE_MAT3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "outerProduct", TYPE_MAT4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "transpose", TYPE_MAT2, { TYPE_MAT2, TYPE_VOID } },
|
|
|
|
{ "transpose", TYPE_MAT3, { TYPE_MAT3, TYPE_VOID } },
|
|
|
|
{ "transpose", TYPE_MAT4, { TYPE_MAT4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "determinant", TYPE_FLOAT, { TYPE_MAT2, TYPE_VOID } },
|
|
|
|
{ "determinant", TYPE_FLOAT, { TYPE_MAT3, TYPE_VOID } },
|
|
|
|
{ "determinant", TYPE_FLOAT, { TYPE_MAT4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "inverse", TYPE_MAT2, { TYPE_MAT2, TYPE_VOID } },
|
|
|
|
{ "inverse", TYPE_MAT3, { TYPE_MAT3, TYPE_VOID } },
|
|
|
|
{ "inverse", TYPE_MAT4, { TYPE_MAT4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThan", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThan", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThan", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "lessThan", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThan", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThan", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThan", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThan", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThanEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThanEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "lessThanEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "lessThanEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "greaterThanEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "equal", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "equal", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "equal", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "equal", TYPE_BVEC2, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC3, { TYPE_BVEC3, TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "equal", TYPE_BVEC4, { TYPE_BVEC4, TYPE_BVEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "notEqual", TYPE_BVEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "notEqual", TYPE_BVEC2, { TYPE_IVEC2, TYPE_IVEC2, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC3, { TYPE_IVEC3, TYPE_IVEC3, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC4, { TYPE_IVEC4, TYPE_IVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "notEqual", TYPE_BVEC2, { TYPE_UVEC2, TYPE_UVEC2, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC3, { TYPE_UVEC3, TYPE_UVEC3, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC4, { TYPE_UVEC4, TYPE_UVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "notEqual", TYPE_BVEC2, { TYPE_BVEC2, TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC3, { TYPE_BVEC3, TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "notEqual", TYPE_BVEC4, { TYPE_BVEC4, TYPE_BVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "any", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "any", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "any", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "all", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "all", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "all", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "not", TYPE_BOOL, { TYPE_BVEC2, TYPE_VOID } },
|
|
|
|
{ "not", TYPE_BOOL, { TYPE_BVEC3, TYPE_VOID } },
|
|
|
|
{ "not", TYPE_BOOL, { TYPE_BVEC4, TYPE_VOID } },
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
//builtins - texture
|
2017-04-07 04:36:37 +02:00
|
|
|
{ "textureSize", TYPE_IVEC2, { TYPE_SAMPLER2D, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "textureSize", TYPE_IVEC2, { TYPE_ISAMPLER2D, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "textureSize", TYPE_IVEC2, { TYPE_USAMPLER2D, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "textureSize", TYPE_IVEC2, { TYPE_SAMPLERCUBE, TYPE_INT, TYPE_VOID } },
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
{ "texture", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "texture", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "texture", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "texture", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "texture", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "texture", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "texture", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "texture", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProj", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
{ "textureLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_FLOAT, TYPE_VOID } },
|
2017-03-05 16:44:50 +01:00
|
|
|
{ "textureLod", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "texelFetch", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "texelFetch", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
|
|
|
|
{ "texelFetch", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_IVEC2, TYPE_INT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProjLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProjLod", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProjLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProjLod", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureProjLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC3, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "textureProjLod", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC4, TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "textureGrad", TYPE_VEC4, { TYPE_SAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "textureGrad", TYPE_IVEC4, { TYPE_ISAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "textureGrad", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "textureGrad", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "dFdx", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "dFdx", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "dFdx", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "dFdx", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "dFdy", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "dFdy", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "dFdy", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "dFdy", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ "fwidth", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
|
|
|
|
{ "fwidth", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
|
|
|
|
{ "fwidth", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
|
|
|
|
{ "fwidth", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
|
|
|
|
|
|
|
|
{ NULL, TYPE_VOID, { TYPE_VOID } }
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ShaderLanguage::_validate_function_call(BlockNode *p_block, OperatorNode *p_func, DataType *r_ret_type) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_func->op != OP_CALL && p_func->op != OP_CONSTRUCT, NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Vector<DataType> args;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(p_func->arguments[0]->type != Node::TYPE_VARIABLE, NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
StringName name = static_cast<VariableNode *>(p_func->arguments[0])->name.operator String();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool all_const = true;
|
|
|
|
for (int i = 1; i < p_func->arguments.size(); i++) {
|
|
|
|
if (p_func->arguments[i]->type != Node::TYPE_CONSTANT)
|
|
|
|
all_const = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
args.push_back(p_func->arguments[i]->get_datatype());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int argcount = args.size();
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool failed_builtin = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (argcount <= 4) {
|
2016-10-07 16:31:18 +02:00
|
|
|
// test builtins
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
while (builtin_func_defs[idx].name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (name == builtin_func_defs[idx].name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
failed_builtin = true;
|
|
|
|
bool fail = false;
|
|
|
|
for (int i = 0; i < argcount; i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (get_scalar_type(args[i]) == args[i] && p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[i + 1]), builtin_func_defs[idx].args[i])) {
|
2016-10-07 16:31:18 +02:00
|
|
|
//all good
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (args[i] != builtin_func_defs[idx].args[i]) {
|
|
|
|
fail = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!fail && argcount < 4 && builtin_func_defs[idx].args[argcount] != TYPE_VOID)
|
|
|
|
fail = true; //make sure the number of arguments matches
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!fail) {
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (r_ret_type)
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_ret_type = builtin_func_defs[idx].rettype;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
if (failed_builtin) {
|
2017-03-05 16:44:50 +01:00
|
|
|
String err = "Invalid arguments for built-in function: " + String(name) + "(";
|
|
|
|
for (int i = 0; i < argcount; i++) {
|
|
|
|
if (i > 0)
|
|
|
|
err += ",";
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && p_func->arguments[i + 1]->get_datatype() == TYPE_INT && static_cast<ConstantNode *>(p_func->arguments[i + 1])->values[0].sint < 0) {
|
|
|
|
err += "-";
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
err += get_datatype_name(args[i]);
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
err += ")";
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_error(err);
|
|
|
|
return false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
// try existing functions..
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
StringName exclude_function;
|
|
|
|
BlockNode *block = p_block;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (block) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (block->parent_function) {
|
2017-03-05 16:44:50 +01:00
|
|
|
exclude_function = block->parent_function->name;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
block = block->parent_block;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (name == exclude_function) {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_error("Recursion is not allowed");
|
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader->functions.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
if (name != shader->functions[i].name)
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!shader->functions[i].callable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Function '" + String(name) + " can't be called from source code.");
|
2016-10-03 21:33:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
FunctionNode *pfunc = shader->functions[i].function;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pfunc->arguments.size() != args.size())
|
2014-02-10 02:10:30 +01:00
|
|
|
continue;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool fail = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < args.size(); i++) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (get_scalar_type(args[i]) == args[i] && p_func->arguments[i + 1]->type == Node::TYPE_CONSTANT && convert_constant(static_cast<ConstantNode *>(p_func->arguments[i + 1]), pfunc->arguments[i].type)) {
|
2016-10-07 16:31:18 +02:00
|
|
|
//all good
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (args[i] != pfunc->arguments[i].type) {
|
|
|
|
fail = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!fail) {
|
2017-08-20 21:15:08 +02:00
|
|
|
if (r_ret_type)
|
|
|
|
*r_ret_type = pfunc->return_type;
|
2016-10-03 21:33:42 +02:00
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
bool ShaderLanguage::_parse_function_arguments(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, OperatorNode *p_func, int *r_complete_arg) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
TkPos pos = _get_tkpos();
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_PARENTHESIS_CLOSE) {
|
2016-10-07 16:31:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
_set_tkpos(pos);
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (r_complete_arg) {
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_CURSOR) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
*r_complete_arg = p_func->arguments.size() - 1;
|
2016-10-07 16:31:18 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
_set_tkpos(pos);
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *arg = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (!arg) {
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return false;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
p_func->arguments.push_back(arg);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_PARENTHESIS_CLOSE) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type != TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
// something is broken
|
|
|
|
_set_error("Expected ',' or ')' after argument");
|
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderLanguage::is_token_operator(TokenType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return (p_type == TK_OP_EQUAL ||
|
|
|
|
p_type == TK_OP_NOT_EQUAL ||
|
|
|
|
p_type == TK_OP_LESS ||
|
|
|
|
p_type == TK_OP_LESS_EQUAL ||
|
|
|
|
p_type == TK_OP_GREATER ||
|
|
|
|
p_type == TK_OP_GREATER_EQUAL ||
|
|
|
|
p_type == TK_OP_AND ||
|
|
|
|
p_type == TK_OP_OR ||
|
|
|
|
p_type == TK_OP_NOT ||
|
|
|
|
p_type == TK_OP_ADD ||
|
|
|
|
p_type == TK_OP_SUB ||
|
|
|
|
p_type == TK_OP_MUL ||
|
|
|
|
p_type == TK_OP_DIV ||
|
|
|
|
p_type == TK_OP_MOD ||
|
|
|
|
p_type == TK_OP_SHIFT_LEFT ||
|
|
|
|
p_type == TK_OP_SHIFT_RIGHT ||
|
|
|
|
p_type == TK_OP_ASSIGN ||
|
|
|
|
p_type == TK_OP_ASSIGN_ADD ||
|
|
|
|
p_type == TK_OP_ASSIGN_SUB ||
|
|
|
|
p_type == TK_OP_ASSIGN_MUL ||
|
|
|
|
p_type == TK_OP_ASSIGN_DIV ||
|
|
|
|
p_type == TK_OP_ASSIGN_MOD ||
|
|
|
|
p_type == TK_OP_ASSIGN_SHIFT_LEFT ||
|
|
|
|
p_type == TK_OP_ASSIGN_SHIFT_RIGHT ||
|
|
|
|
p_type == TK_OP_ASSIGN_BIT_AND ||
|
|
|
|
p_type == TK_OP_ASSIGN_BIT_OR ||
|
|
|
|
p_type == TK_OP_ASSIGN_BIT_XOR ||
|
|
|
|
p_type == TK_OP_BIT_AND ||
|
|
|
|
p_type == TK_OP_BIT_OR ||
|
|
|
|
p_type == TK_OP_BIT_XOR ||
|
|
|
|
p_type == TK_OP_BIT_INVERT ||
|
|
|
|
p_type == TK_OP_INCREMENT ||
|
|
|
|
p_type == TK_OP_DECREMENT ||
|
|
|
|
p_type == TK_QUESTION ||
|
|
|
|
p_type == TK_COLON);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ShaderLanguage::convert_constant(ConstantNode *p_constant, DataType p_to_type, ConstantNode::Value *p_value) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_constant->datatype == p_to_type) {
|
2016-10-07 16:31:18 +02:00
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_constant->values.size(); i++) {
|
|
|
|
p_value[i] = p_constant->values[i];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_constant->datatype == TYPE_INT && p_to_type == TYPE_FLOAT) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_value->real = p_constant->values[0].sint;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_constant->datatype == TYPE_UINT && p_to_type == TYPE_FLOAT) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_value->real = p_constant->values[0].uint;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_constant->datatype == TYPE_INT && p_to_type == TYPE_UINT) {
|
|
|
|
if (p_constant->values[0].sint < 0) {
|
2016-10-07 16:31:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_value->uint = p_constant->values[0].sint;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_constant->datatype == TYPE_UINT && p_to_type == TYPE_INT) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_constant->values[0].uint > 0x7FFFFFFF) {
|
2016-10-07 16:31:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p_value) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_value->sint = p_constant->values[0].uint;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderLanguage::is_scalar_type(DataType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return p_type == TYPE_BOOL || p_type == TYPE_INT || p_type == TYPE_UINT || p_type == TYPE_FLOAT;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
bool ShaderLanguage::is_sampler_type(DataType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
return p_type == TYPE_SAMPLER2D || p_type == TYPE_ISAMPLER2D || p_type == TYPE_USAMPLER2D || p_type == TYPE_SAMPLERCUBE;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
void ShaderLanguage::get_keyword_list(List<String> *r_keywords) {
|
|
|
|
|
|
|
|
Set<String> kws;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (keyword_list[idx].text) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
kws.insert(keyword_list[idx].text);
|
2014-02-10 02:10:30 +01:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
while (builtin_func_defs[idx].name) {
|
|
|
|
|
|
|
|
kws.insert(builtin_func_defs[idx].name);
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<String>::Element *E = kws.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
r_keywords->push_back(E->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
void ShaderLanguage::get_builtin_funcs(List<String> *r_keywords) {
|
|
|
|
|
|
|
|
Set<String> kws;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
while (builtin_func_defs[idx].name) {
|
|
|
|
|
|
|
|
kws.insert(builtin_func_defs[idx].name);
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<String>::Element *E = kws.front(); E; E = E->next()) {
|
2016-10-10 23:31:01 +02:00
|
|
|
r_keywords->push_back(E->get());
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
ShaderLanguage::DataType ShaderLanguage::get_scalar_type(DataType p_type) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static const DataType scalar_types[] = {
|
2016-10-07 16:31:18 +02:00
|
|
|
TYPE_VOID,
|
|
|
|
TYPE_BOOL,
|
|
|
|
TYPE_BOOL,
|
|
|
|
TYPE_BOOL,
|
|
|
|
TYPE_BOOL,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
TYPE_INT,
|
|
|
|
TYPE_UINT,
|
|
|
|
TYPE_FLOAT,
|
|
|
|
};
|
|
|
|
|
|
|
|
return scalar_types[p_type];
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ShaderLanguage::_get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName &identifier) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
identifier = StringName();
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
TkPos pos;
|
|
|
|
|
|
|
|
Token tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_IDENTIFIER) {
|
|
|
|
identifier = tk.text;
|
|
|
|
pos = _get_tkpos();
|
2016-10-07 16:31:18 +02:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_CURSOR) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
completion_type = p_type;
|
|
|
|
completion_line = tk_line;
|
|
|
|
completion_block = p_block;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_IDENTIFIER) {
|
|
|
|
identifier = identifier.operator String() + tk.text.operator String();
|
2016-10-07 16:31:18 +02:00
|
|
|
} else {
|
|
|
|
_set_tkpos(pos);
|
|
|
|
}
|
|
|
|
return true;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (identifier != StringName()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
bool ShaderLanguage::_is_operator_assign(Operator p_op) const {
|
|
|
|
switch (p_op) {
|
|
|
|
case OP_ASSIGN:
|
|
|
|
case OP_ASSIGN_ADD:
|
|
|
|
case OP_ASSIGN_SUB:
|
|
|
|
case OP_ASSIGN_MUL:
|
|
|
|
case OP_ASSIGN_DIV:
|
|
|
|
case OP_ASSIGN_MOD:
|
|
|
|
case OP_ASSIGN_SHIFT_LEFT:
|
|
|
|
case OP_ASSIGN_SHIFT_RIGHT:
|
|
|
|
case OP_ASSIGN_BIT_AND:
|
|
|
|
case OP_ASSIGN_BIT_OR:
|
|
|
|
case OP_ASSIGN_BIT_XOR:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderLanguage::_validate_assign(Node *p_node, const Map<StringName, BuiltInInfo> &p_builtin_types) {
|
|
|
|
|
|
|
|
if (p_node->type == Node::TYPE_OPERATOR) {
|
|
|
|
|
|
|
|
OperatorNode *op = static_cast<OperatorNode *>(p_node);
|
|
|
|
if (op->type == OP_INDEX) {
|
|
|
|
return _validate_assign(op->arguments[0], p_builtin_types);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_node->type == Node::TYPE_VARIABLE) {
|
|
|
|
|
|
|
|
VariableNode *var = static_cast<VariableNode *>(p_node);
|
|
|
|
if (p_builtin_types.has(var->name) && p_builtin_types[var->name].constant) {
|
|
|
|
return false; //ops not valid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
Vector<Expression> expression;
|
|
|
|
//Vector<TokenType> operators;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *expr = NULL;
|
2016-10-07 16:31:18 +02:00
|
|
|
TkPos prepos = _get_tkpos();
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
TkPos pos = _get_tkpos();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_PARENTHESIS_OPEN) {
|
2014-02-10 02:10:30 +01:00
|
|
|
//handle subexpression
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!expr)
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ')' in expression");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_REAL_CONSTANT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
2016-10-07 16:31:18 +02:00
|
|
|
ConstantNode::Value v;
|
2017-03-05 16:44:50 +01:00
|
|
|
v.real = tk.constant;
|
2016-10-07 16:31:18 +02:00
|
|
|
constant->values.push_back(v);
|
2017-03-05 16:44:50 +01:00
|
|
|
constant->datatype = TYPE_FLOAT;
|
|
|
|
expr = constant;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_INT_CONSTANT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
2016-10-07 16:31:18 +02:00
|
|
|
ConstantNode::Value v;
|
2017-03-05 16:44:50 +01:00
|
|
|
v.sint = tk.constant;
|
2016-10-07 16:31:18 +02:00
|
|
|
constant->values.push_back(v);
|
2017-03-05 16:44:50 +01:00
|
|
|
constant->datatype = TYPE_INT;
|
|
|
|
expr = constant;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_TRUE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
//print_line("found true");
|
|
|
|
|
|
|
|
//handle true constant
|
2016-10-03 21:33:42 +02:00
|
|
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
2016-10-07 16:31:18 +02:00
|
|
|
ConstantNode::Value v;
|
2017-03-05 16:44:50 +01:00
|
|
|
v.boolean = true;
|
2016-10-07 16:31:18 +02:00
|
|
|
constant->values.push_back(v);
|
2017-03-05 16:44:50 +01:00
|
|
|
constant->datatype = TYPE_BOOL;
|
|
|
|
expr = constant;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_FALSE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//handle false constant
|
2016-10-03 21:33:42 +02:00
|
|
|
ConstantNode *constant = alloc_node<ConstantNode>();
|
2016-10-07 16:31:18 +02:00
|
|
|
ConstantNode::Value v;
|
2017-03-05 16:44:50 +01:00
|
|
|
v.boolean = false;
|
2016-10-07 16:31:18 +02:00
|
|
|
constant->values.push_back(v);
|
2017-03-05 16:44:50 +01:00
|
|
|
constant->datatype = TYPE_BOOL;
|
|
|
|
expr = constant;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_TYPE_VOID) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//make sure void is not used in expression
|
|
|
|
_set_error("Void value not allowed in Expression");
|
|
|
|
return NULL;
|
2016-10-07 16:31:18 +02:00
|
|
|
} else if (is_token_nonvoid_datatype(tk.type)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//basic type constructor
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *func = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
func->op = OP_CONSTRUCT;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_precision(tk.type)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
func->return_precision_cache = get_token_precision(tk.type);
|
|
|
|
tk = _get_token();
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
VariableNode *funcname = alloc_node<VariableNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
funcname->name = get_datatype_name(get_token_datatype(tk.type));
|
2014-02-10 02:10:30 +01:00
|
|
|
func->arguments.push_back(funcname);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected '(' after type name");
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int carg = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (carg >= 0) {
|
|
|
|
completion_type = COMPLETION_CALL_ARGUMENTS;
|
|
|
|
completion_line = tk_line;
|
|
|
|
completion_block = p_block;
|
|
|
|
completion_function = funcname->name;
|
|
|
|
completion_argument = carg;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
if (!ok)
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_validate_function_call(p_block, func, &func->return_cache)) {
|
|
|
|
_set_error("No matching constructor found for: '" + String(funcname->name) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
//validate_Function_call()
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expr = _reduce_expression(p_block, func);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_IDENTIFIER) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(prepos);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
StringName identifier;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_get_completable_identifier(p_block, COMPLETION_IDENTIFIER, identifier);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type == TK_PARENTHESIS_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//a function
|
2016-10-07 16:31:18 +02:00
|
|
|
StringName name = identifier;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *func = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
func->op = OP_CALL;
|
2016-10-03 21:33:42 +02:00
|
|
|
VariableNode *funcname = alloc_node<VariableNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
funcname->name = name;
|
2016-10-03 21:33:42 +02:00
|
|
|
func->arguments.push_back(funcname);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int carg = -1;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
//test if function was parsed first
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader->functions.size(); i++) {
|
|
|
|
if (shader->functions[i].name == name) {
|
2017-04-07 04:36:37 +02:00
|
|
|
//add to current function as dependency
|
|
|
|
for (int j = 0; j < shader->functions.size(); j++) {
|
|
|
|
if (shader->functions[j].name == current_function) {
|
|
|
|
shader->functions[j].uses_function.insert(name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (carg >= 0) {
|
|
|
|
completion_type = COMPLETION_CALL_ARGUMENTS;
|
|
|
|
completion_line = tk_line;
|
|
|
|
completion_block = p_block;
|
|
|
|
completion_function = funcname->name;
|
|
|
|
completion_argument = carg;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
if (!ok)
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_validate_function_call(p_block, func, &func->return_cache)) {
|
|
|
|
_set_error("No matching function found for: '" + String(funcname->name) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expr = func;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
|
|
|
//an identifier
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType data_type;
|
|
|
|
IdentifierType ident_type;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_find_identifier(p_block, p_builtin_types, identifier, &data_type, &ident_type)) {
|
|
|
|
_set_error("Unknown identifier in expression: " + String(identifier));
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ident_type == IDENTIFIER_FUNCTION) {
|
|
|
|
_set_error("Can't use function as identifier: " + String(identifier));
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
VariableNode *varname = alloc_node<VariableNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
varname->name = identifier;
|
|
|
|
varname->datatype_cache = data_type;
|
|
|
|
expr = varname;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_OP_ADD) {
|
2016-10-03 21:33:42 +02:00
|
|
|
continue; //this one does nothing
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_OP_SUB || tk.type == TK_OP_NOT || tk.type == TK_OP_BIT_INVERT || tk.type == TK_OP_INCREMENT || tk.type == TK_OP_DECREMENT) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
|
|
|
Expression e;
|
2017-03-05 16:44:50 +01:00
|
|
|
e.is_op = true;
|
|
|
|
|
|
|
|
switch (tk.type) {
|
|
|
|
case TK_OP_SUB: e.op = OP_NEGATE; break;
|
|
|
|
case TK_OP_NOT: e.op = OP_NOT; break;
|
|
|
|
case TK_OP_BIT_INVERT: e.op = OP_BIT_INVERT; break;
|
|
|
|
case TK_OP_INCREMENT: e.op = OP_INCREMENT; break;
|
|
|
|
case TK_OP_DECREMENT: e.op = OP_DECREMENT; break;
|
2016-10-03 21:33:42 +02:00
|
|
|
default: ERR_FAIL_V(NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
expression.push_back(e);
|
|
|
|
continue;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Expected expression, found: " + get_token_text(tk));
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
//nothing
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!expr, NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* OK now see what's NEXT to the operator.. */
|
|
|
|
/* OK now see what's NEXT to the operator.. */
|
|
|
|
/* OK now see what's NEXT to the operator.. */
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2016-10-07 16:31:18 +02:00
|
|
|
TkPos pos = _get_tkpos();
|
2017-03-05 16:44:50 +01:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_PERIOD) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
StringName identifier;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_get_completable_identifier(p_block, COMPLETION_INDEX, identifier)) {
|
|
|
|
completion_base = expr->get_datatype();
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (identifier == StringName()) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected identifier as member");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType dt = expr->get_datatype();
|
2016-10-07 16:31:18 +02:00
|
|
|
String ident = identifier;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ok = true;
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType member_type;
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (dt) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case TYPE_BVEC2:
|
|
|
|
case TYPE_IVEC2:
|
|
|
|
case TYPE_UVEC2:
|
|
|
|
case TYPE_VEC2: {
|
|
|
|
|
|
|
|
int l = ident.length();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (l == 1) {
|
|
|
|
member_type = DataType(dt - 1);
|
|
|
|
} else if (l == 2) {
|
|
|
|
member_type = dt;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const CharType *c = ident.ptr();
|
|
|
|
for (int i = 0; i < l; i++) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (c[i]) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case 'r':
|
|
|
|
case 'g':
|
|
|
|
case 'x':
|
|
|
|
case 'y':
|
|
|
|
break;
|
|
|
|
default:
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case TYPE_BVEC3:
|
|
|
|
case TYPE_IVEC3:
|
|
|
|
case TYPE_UVEC3:
|
|
|
|
case TYPE_VEC3: {
|
|
|
|
|
|
|
|
int l = ident.length();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (l == 1) {
|
|
|
|
member_type = DataType(dt - 2);
|
|
|
|
} else if (l == 2) {
|
|
|
|
member_type = DataType(dt - 1);
|
|
|
|
} else if (l == 3) {
|
|
|
|
member_type = dt;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const CharType *c = ident.ptr();
|
|
|
|
for (int i = 0; i < l; i++) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (c[i]) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case 'r':
|
|
|
|
case 'g':
|
|
|
|
case 'b':
|
|
|
|
case 'x':
|
|
|
|
case 'y':
|
|
|
|
case 'z':
|
|
|
|
break;
|
|
|
|
default:
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
case TYPE_BVEC4:
|
|
|
|
case TYPE_IVEC4:
|
|
|
|
case TYPE_UVEC4:
|
|
|
|
case TYPE_VEC4: {
|
|
|
|
|
|
|
|
int l = ident.length();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (l == 1) {
|
|
|
|
member_type = DataType(dt - 3);
|
|
|
|
} else if (l == 2) {
|
|
|
|
member_type = DataType(dt - 2);
|
|
|
|
} else if (l == 3) {
|
|
|
|
member_type = DataType(dt - 1);
|
|
|
|
} else if (l == 4) {
|
|
|
|
member_type = dt;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const CharType *c = ident.ptr();
|
|
|
|
for (int i = 0; i < l; i++) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (c[i]) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case 'r':
|
|
|
|
case 'g':
|
|
|
|
case 'b':
|
|
|
|
case 'a':
|
|
|
|
case 'x':
|
|
|
|
case 'y':
|
|
|
|
case 'z':
|
|
|
|
case 'w':
|
|
|
|
break;
|
|
|
|
default:
|
2017-03-05 16:44:50 +01:00
|
|
|
ok = false;
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
2017-06-17 16:03:48 +02:00
|
|
|
default: {
|
|
|
|
ok = false;
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!ok) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-17 16:03:48 +02:00
|
|
|
_set_error("Invalid member for " + get_datatype_name(dt) + " expression: ." + ident);
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
MemberNode *mn = alloc_node<MemberNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
mn->basetype = dt;
|
|
|
|
mn->datatype = member_type;
|
|
|
|
mn->name = ident;
|
|
|
|
mn->owner = expr;
|
|
|
|
expr = mn;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//todo
|
|
|
|
//member (period) has priority over any operator
|
|
|
|
//creates a subindexing expression in place
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
/*} else if (tk.type==TK_BRACKET_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//todo
|
|
|
|
//subindexing has priority over any operator
|
|
|
|
//creates a subindexing expression in place
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
*/
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (tk.type == TK_BRACKET_OPEN) {
|
|
|
|
|
|
|
|
Node *index = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2017-10-16 21:55:42 +02:00
|
|
|
if (!index)
|
|
|
|
return NULL;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
if (index->get_datatype() != TYPE_INT && index->get_datatype() != TYPE_UINT) {
|
|
|
|
_set_error("Only integer datatypes are allowed for indexing");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool index_valid = false;
|
2017-09-01 22:33:39 +02:00
|
|
|
DataType member_type = TYPE_VOID;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
switch (expr->get_datatype()) {
|
|
|
|
case TYPE_BVEC2:
|
|
|
|
case TYPE_VEC2:
|
|
|
|
case TYPE_IVEC2:
|
|
|
|
case TYPE_UVEC2:
|
|
|
|
case TYPE_MAT2:
|
|
|
|
if (index->type == Node::TYPE_CONSTANT) {
|
|
|
|
uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint;
|
|
|
|
if (index_constant >= 2) {
|
|
|
|
_set_error("Index out of range (0-1)");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_set_error("Only integer constants are allowed as index at the moment");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
index_valid = true;
|
|
|
|
switch (expr->get_datatype()) {
|
|
|
|
case TYPE_BVEC2: member_type = TYPE_BOOL; break;
|
|
|
|
case TYPE_VEC2: member_type = TYPE_FLOAT; break;
|
|
|
|
case TYPE_IVEC2: member_type = TYPE_INT; break;
|
|
|
|
case TYPE_UVEC2: member_type = TYPE_UINT; break;
|
|
|
|
case TYPE_MAT2: member_type = TYPE_VEC2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case TYPE_BVEC3:
|
|
|
|
case TYPE_VEC3:
|
|
|
|
case TYPE_IVEC3:
|
|
|
|
case TYPE_UVEC3:
|
|
|
|
case TYPE_MAT3:
|
|
|
|
if (index->type == Node::TYPE_CONSTANT) {
|
|
|
|
uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint;
|
|
|
|
if (index_constant >= 3) {
|
|
|
|
_set_error("Index out of range (0-2)");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_set_error("Only integer constants are allowed as index at the moment");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
index_valid = true;
|
|
|
|
switch (expr->get_datatype()) {
|
|
|
|
case TYPE_BVEC3: member_type = TYPE_BOOL; break;
|
|
|
|
case TYPE_VEC3: member_type = TYPE_FLOAT; break;
|
|
|
|
case TYPE_IVEC3: member_type = TYPE_INT; break;
|
|
|
|
case TYPE_UVEC3: member_type = TYPE_UINT; break;
|
|
|
|
case TYPE_MAT3: member_type = TYPE_VEC3; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TYPE_BVEC4:
|
|
|
|
case TYPE_VEC4:
|
|
|
|
case TYPE_IVEC4:
|
|
|
|
case TYPE_UVEC4:
|
|
|
|
case TYPE_MAT4:
|
|
|
|
if (index->type == Node::TYPE_CONSTANT) {
|
|
|
|
uint32_t index_constant = static_cast<ConstantNode *>(index)->values[0].uint;
|
|
|
|
if (index_constant >= 4) {
|
|
|
|
_set_error("Index out of range (0-3)");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_set_error("Only integer constants are allowed as index at the moment");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
index_valid = true;
|
|
|
|
switch (expr->get_datatype()) {
|
|
|
|
case TYPE_BVEC4: member_type = TYPE_BOOL; break;
|
|
|
|
case TYPE_VEC4: member_type = TYPE_FLOAT; break;
|
|
|
|
case TYPE_IVEC4: member_type = TYPE_INT; break;
|
|
|
|
case TYPE_UVEC4: member_type = TYPE_UINT; break;
|
|
|
|
case TYPE_MAT4: member_type = TYPE_VEC4; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: {
|
|
|
|
_set_error("Object of type '" + get_datatype_name(expr->get_datatype()) + "' can't be indexed");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!index_valid) {
|
|
|
|
_set_error("Invalid index");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
OperatorNode *op = alloc_node<OperatorNode>();
|
|
|
|
op->op = OP_INDEX;
|
|
|
|
op->return_cache = member_type;
|
|
|
|
op->arguments.push_back(expr);
|
|
|
|
op->arguments.push_back(index);
|
|
|
|
expr = op;
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_BRACKET_CLOSE) {
|
|
|
|
_set_error("Expected ']' after indexing expression");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_OP_INCREMENT || tk.type == TK_OP_DECREMENT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *op = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
op->op = tk.type == TK_OP_DECREMENT ? OP_POST_DECREMENT : OP_POST_INCREMENT;
|
2016-10-03 21:33:42 +02:00
|
|
|
op->arguments.push_back(expr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_validate_operator(op, &op->return_cache)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Invalid base type for increment/decrement operator");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-12-15 22:23:16 +01:00
|
|
|
|
|
|
|
if (!_validate_assign(expr, p_builtin_types)) {
|
|
|
|
_set_error("Invalid use of increment/decrement operator in constant expression.");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
expr = op;
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos);
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
Expression e;
|
2017-03-05 16:44:50 +01:00
|
|
|
e.is_op = false;
|
|
|
|
e.node = expr;
|
2014-09-18 04:23:42 +02:00
|
|
|
expression.push_back(e);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
pos = _get_tkpos();
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_operator(tk.type)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
Expression o;
|
2017-03-05 16:44:50 +01:00
|
|
|
o.is_op = true;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (tk.type) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
case TK_OP_EQUAL: o.op = OP_EQUAL; break;
|
|
|
|
case TK_OP_NOT_EQUAL: o.op = OP_NOT_EQUAL; break;
|
|
|
|
case TK_OP_LESS: o.op = OP_LESS; break;
|
|
|
|
case TK_OP_LESS_EQUAL: o.op = OP_LESS_EQUAL; break;
|
|
|
|
case TK_OP_GREATER: o.op = OP_GREATER; break;
|
|
|
|
case TK_OP_GREATER_EQUAL: o.op = OP_GREATER_EQUAL; break;
|
|
|
|
case TK_OP_AND: o.op = OP_AND; break;
|
|
|
|
case TK_OP_OR: o.op = OP_OR; break;
|
|
|
|
case TK_OP_ADD: o.op = OP_ADD; break;
|
|
|
|
case TK_OP_SUB: o.op = OP_SUB; break;
|
|
|
|
case TK_OP_MUL: o.op = OP_MUL; break;
|
|
|
|
case TK_OP_DIV: o.op = OP_DIV; break;
|
|
|
|
case TK_OP_MOD: o.op = OP_MOD; break;
|
|
|
|
case TK_OP_SHIFT_LEFT: o.op = OP_SHIFT_LEFT; break;
|
|
|
|
case TK_OP_SHIFT_RIGHT: o.op = OP_SHIFT_RIGHT; break;
|
|
|
|
case TK_OP_ASSIGN: o.op = OP_ASSIGN; break;
|
|
|
|
case TK_OP_ASSIGN_ADD: o.op = OP_ASSIGN_ADD; break;
|
|
|
|
case TK_OP_ASSIGN_SUB: o.op = OP_ASSIGN_SUB; break;
|
|
|
|
case TK_OP_ASSIGN_MUL: o.op = OP_ASSIGN_MUL; break;
|
|
|
|
case TK_OP_ASSIGN_DIV: o.op = OP_ASSIGN_DIV; break;
|
|
|
|
case TK_OP_ASSIGN_MOD: o.op = OP_ASSIGN_MOD; break;
|
|
|
|
case TK_OP_ASSIGN_SHIFT_LEFT: o.op = OP_ASSIGN_SHIFT_LEFT; break;
|
|
|
|
case TK_OP_ASSIGN_SHIFT_RIGHT: o.op = OP_ASSIGN_SHIFT_RIGHT; break;
|
|
|
|
case TK_OP_ASSIGN_BIT_AND: o.op = OP_ASSIGN_BIT_AND; break;
|
|
|
|
case TK_OP_ASSIGN_BIT_OR: o.op = OP_ASSIGN_BIT_OR; break;
|
|
|
|
case TK_OP_ASSIGN_BIT_XOR: o.op = OP_ASSIGN_BIT_XOR; break;
|
|
|
|
case TK_OP_BIT_AND: o.op = OP_BIT_AND; break;
|
2017-03-05 16:44:50 +01:00
|
|
|
case TK_OP_BIT_OR: o.op = OP_BIT_OR; break;
|
2016-10-03 21:33:42 +02:00
|
|
|
case TK_OP_BIT_XOR: o.op = OP_BIT_XOR; break;
|
|
|
|
case TK_QUESTION: o.op = OP_SELECT_IF; break;
|
|
|
|
case TK_COLON: o.op = OP_SELECT_ELSE; break;
|
|
|
|
default: {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Invalid token for operator: " + get_token_text(tk));
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
expression.push_back(o);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos); //something else, so rollback and end
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reduce the set set of expressions and place them in an operator tree, respecting precedence */
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (expression.size() > 1) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int next_op = -1;
|
|
|
|
int min_priority = 0xFFFFF;
|
|
|
|
bool is_unary = false;
|
|
|
|
bool is_ternary = false;
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < expression.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
if (!expression[i].is_op) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool unary = false;
|
|
|
|
bool ternary = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int priority;
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (expression[i].op) {
|
|
|
|
case OP_EQUAL: priority = 8; break;
|
|
|
|
case OP_NOT_EQUAL: priority = 8; break;
|
|
|
|
case OP_LESS: priority = 7; break;
|
|
|
|
case OP_LESS_EQUAL: priority = 7; break;
|
|
|
|
case OP_GREATER: priority = 7; break;
|
|
|
|
case OP_GREATER_EQUAL: priority = 7; break;
|
|
|
|
case OP_AND: priority = 12; break;
|
|
|
|
case OP_OR: priority = 14; break;
|
|
|
|
case OP_NOT:
|
|
|
|
priority = 3;
|
|
|
|
unary = true;
|
|
|
|
break;
|
|
|
|
case OP_NEGATE:
|
|
|
|
priority = 3;
|
|
|
|
unary = true;
|
|
|
|
break;
|
|
|
|
case OP_ADD: priority = 5; break;
|
|
|
|
case OP_SUB: priority = 5; break;
|
|
|
|
case OP_MUL: priority = 4; break;
|
|
|
|
case OP_DIV: priority = 4; break;
|
|
|
|
case OP_MOD: priority = 4; break;
|
|
|
|
case OP_SHIFT_LEFT: priority = 6; break;
|
|
|
|
case OP_SHIFT_RIGHT: priority = 6; break;
|
|
|
|
case OP_ASSIGN: priority = 16; break;
|
|
|
|
case OP_ASSIGN_ADD: priority = 16; break;
|
|
|
|
case OP_ASSIGN_SUB: priority = 16; break;
|
|
|
|
case OP_ASSIGN_MUL: priority = 16; break;
|
|
|
|
case OP_ASSIGN_DIV: priority = 16; break;
|
|
|
|
case OP_ASSIGN_MOD: priority = 16; break;
|
|
|
|
case OP_ASSIGN_SHIFT_LEFT: priority = 16; break;
|
|
|
|
case OP_ASSIGN_SHIFT_RIGHT: priority = 16; break;
|
|
|
|
case OP_ASSIGN_BIT_AND: priority = 16; break;
|
|
|
|
case OP_ASSIGN_BIT_OR: priority = 16; break;
|
|
|
|
case OP_ASSIGN_BIT_XOR: priority = 16; break;
|
|
|
|
case OP_BIT_AND: priority = 9; break;
|
|
|
|
case OP_BIT_OR: priority = 11; break;
|
|
|
|
case OP_BIT_XOR: priority = 10; break;
|
|
|
|
case OP_BIT_INVERT:
|
|
|
|
priority = 3;
|
|
|
|
unary = true;
|
|
|
|
break;
|
|
|
|
case OP_INCREMENT:
|
|
|
|
priority = 3;
|
|
|
|
unary = true;
|
|
|
|
break;
|
|
|
|
case OP_DECREMENT:
|
|
|
|
priority = 3;
|
|
|
|
unary = true;
|
|
|
|
break;
|
|
|
|
case OP_SELECT_IF:
|
|
|
|
priority = 15;
|
|
|
|
ternary = true;
|
|
|
|
break;
|
|
|
|
case OP_SELECT_ELSE:
|
|
|
|
priority = 15;
|
|
|
|
ternary = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR_FAIL_V(NULL); //unexpected operator
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priority < min_priority) {
|
2014-02-10 02:10:30 +01:00
|
|
|
// < is used for left to right (default)
|
|
|
|
// <= is used for right to left
|
2017-03-05 16:44:50 +01:00
|
|
|
next_op = i;
|
|
|
|
min_priority = priority;
|
|
|
|
is_unary = unary;
|
|
|
|
is_ternary = ternary;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(next_op == -1, NULL);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
// OK! create operator..
|
2014-09-18 04:23:42 +02:00
|
|
|
// OK! create operator..
|
|
|
|
if (is_unary) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int expr_pos = next_op;
|
|
|
|
while (expression[expr_pos].is_op) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
|
|
|
expr_pos++;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (expr_pos == expression.size()) {
|
2014-09-18 04:23:42 +02:00
|
|
|
//can happen..
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Unexpected end of expression..");
|
|
|
|
return NULL;
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//consecutively do unary opeators
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = expr_pos - 1; i >= next_op; i--) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *op = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
op->op = expression[i].op;
|
2017-12-15 22:23:16 +01:00
|
|
|
if ((op->op == OP_INCREMENT || op->op == OP_DECREMENT) && !_validate_assign(expression[i + 1].node, p_builtin_types)) {
|
|
|
|
|
|
|
|
_set_error("Can't use increment/decrement operator in constant expression.");
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
op->arguments.push_back(expression[i + 1].node);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expression[i].is_op = false;
|
|
|
|
expression[i].node = op;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_validate_operator(op, &op->return_cache)) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
|
|
|
String at;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < op->arguments.size(); i++) {
|
|
|
|
if (i > 0)
|
|
|
|
at += " and ";
|
|
|
|
at += get_datatype_name(op->arguments[i]->get_datatype());
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Invalid arguments to unary operator '" + get_operator_text(op->op) + "' :" + at);
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
expression.remove(i + 1);
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
} else if (is_ternary) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (next_op < 1 || next_op >= (expression.size() - 1)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Parser bug..");
|
|
|
|
ERR_FAIL_V(NULL);
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (next_op + 2 >= expression.size() || !expression[next_op + 2].is_op || expression[next_op + 2].op != OP_SELECT_ELSE) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Mising matching ':' for select operator");
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *op = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
op->op = expression[next_op].op;
|
|
|
|
op->arguments.push_back(expression[next_op - 1].node);
|
|
|
|
op->arguments.push_back(expression[next_op + 1].node);
|
|
|
|
op->arguments.push_back(expression[next_op + 3].node);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expression[next_op - 1].is_op = false;
|
|
|
|
expression[next_op - 1].node = op;
|
|
|
|
if (!_validate_operator(op, &op->return_cache)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
String at;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < op->arguments.size(); i++) {
|
|
|
|
if (i > 0)
|
|
|
|
at += " and ";
|
|
|
|
at += get_datatype_name(op->arguments[i]->get_datatype());
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Invalid argument to ternary ?: operator: " + at);
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2016-10-03 21:33:42 +02:00
|
|
|
expression.remove(next_op);
|
|
|
|
}
|
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
} else {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (next_op < 1 || next_op >= (expression.size() - 1)) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Parser bug..");
|
|
|
|
ERR_FAIL_V(NULL);
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
OperatorNode *op = alloc_node<OperatorNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
op->op = expression[next_op].op;
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (expression[next_op - 1].is_op) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Parser bug..");
|
|
|
|
ERR_FAIL_V(NULL);
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
if (_is_operator_assign(op->op) && !_validate_assign(expression[next_op - 1].node, p_builtin_types)) {
|
|
|
|
|
|
|
|
_set_error("Assignment to constant expression.");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (expression[next_op + 1].is_op) {
|
2014-09-18 04:23:42 +02:00
|
|
|
// this is not invalid and can really appear
|
|
|
|
// but it becomes invalid anyway because no binary op
|
2017-09-02 16:19:06 +02:00
|
|
|
// can be followed by a unary op in a valid combination,
|
2017-03-24 21:45:31 +01:00
|
|
|
// due to how precedence works, unaries will always disappear first
|
2014-09-18 04:23:42 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Parser bug..");
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
op->arguments.push_back(expression[next_op - 1].node); //expression goes as left
|
|
|
|
op->arguments.push_back(expression[next_op + 1].node); //next expression goes as right
|
|
|
|
expression[next_op - 1].node = op;
|
2014-09-18 04:23:42 +02:00
|
|
|
|
|
|
|
//replace all 3 nodes by this operator and make it an expression
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!_validate_operator(op, &op->return_cache)) {
|
2014-09-18 04:23:42 +02:00
|
|
|
|
|
|
|
String at;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < op->arguments.size(); i++) {
|
|
|
|
if (i > 0)
|
|
|
|
at += " and ";
|
|
|
|
at += get_datatype_name(op->arguments[i]->get_datatype());
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Invalid arguments to operator '" + get_operator_text(op->op) + "' :" + at);
|
2016-10-03 21:33:42 +02:00
|
|
|
return NULL;
|
2014-09-18 04:23:42 +02:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-09-18 04:23:42 +02:00
|
|
|
expression.remove(next_op);
|
|
|
|
expression.remove(next_op);
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return expression[0].node;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ShaderLanguage::Node *ShaderLanguage::_reduce_expression(BlockNode *p_block, ShaderLanguage::Node *p_node) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_node->type != Node::TYPE_OPERATOR)
|
2016-10-03 21:33:42 +02:00
|
|
|
return p_node;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//for now only reduce simple constructors
|
2017-03-05 16:44:50 +01:00
|
|
|
OperatorNode *op = static_cast<OperatorNode *>(p_node);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (op->op == OP_CONSTRUCT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(op->arguments[0]->type != Node::TYPE_VARIABLE, p_node);
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
DataType base = get_scalar_type(op->get_datatype());
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
Vector<ConstantNode::Value> values;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 1; i < op->arguments.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
op->arguments[i] = _reduce_expression(p_block, op->arguments[i]);
|
|
|
|
if (op->arguments[i]->type == Node::TYPE_CONSTANT) {
|
|
|
|
ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (get_scalar_type(cn->datatype) == base) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < cn->values.size(); j++) {
|
2016-10-07 16:31:18 +02:00
|
|
|
values.push_back(cn->values[j]);
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (get_scalar_type(cn->datatype) == cn->datatype) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
ConstantNode::Value v;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!convert_constant(cn, base, &v)) {
|
2016-10-07 16:31:18 +02:00
|
|
|
return p_node;
|
|
|
|
}
|
|
|
|
values.push_back(v);
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2016-10-07 16:31:18 +02:00
|
|
|
return p_node;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return p_node;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConstantNode *cn = alloc_node<ConstantNode>();
|
|
|
|
cn->datatype = op->get_datatype();
|
|
|
|
cn->values = values;
|
2016-10-07 16:31:18 +02:00
|
|
|
return cn;
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (op->op == OP_NEGATE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
op->arguments[0] = _reduce_expression(p_block, op->arguments[0]);
|
|
|
|
if (op->arguments[0]->type == Node::TYPE_CONSTANT) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[0]);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
DataType base = get_scalar_type(cn->datatype);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
Vector<ConstantNode::Value> values;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < cn->values.size(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
ConstantNode::Value nv;
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (base) {
|
2016-10-07 16:31:18 +02:00
|
|
|
case TYPE_BOOL: {
|
2017-03-05 16:44:50 +01:00
|
|
|
nv.boolean = !cn->values[i].boolean;
|
2016-10-07 16:31:18 +02:00
|
|
|
} break;
|
|
|
|
case TYPE_INT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
nv.sint = -cn->values[i].sint;
|
2016-10-07 16:31:18 +02:00
|
|
|
} break;
|
|
|
|
case TYPE_UINT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
nv.uint = -cn->values[i].uint;
|
2016-10-07 16:31:18 +02:00
|
|
|
} break;
|
|
|
|
case TYPE_FLOAT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
nv.real = -cn->values[i].real;
|
2016-10-07 16:31:18 +02:00
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
values.push_back(nv);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
cn->values = values;
|
2016-10-03 21:33:42 +02:00
|
|
|
return cn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return p_node;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
ShaderLanguage::Node *ShaderLanguage::_parse_and_reduce_expression(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ShaderLanguage::Node *expr = _parse_expression(p_block, p_builtin_types);
|
2016-10-07 16:31:18 +02:00
|
|
|
if (!expr) //errored
|
|
|
|
return NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
expr = _reduce_expression(p_block, expr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return expr;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, BuiltInInfo> &p_builtin_types, bool p_just_one, bool p_can_break, bool p_can_continue) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
TkPos pos = _get_tkpos();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_CURLY_BRACKET_CLOSE) { //end of block
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_just_one) {
|
|
|
|
_set_error("Unexpected '}'");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} else if (is_token_precision(tk.type) || is_token_nonvoid_datatype(tk.type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_precision(tk.type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
precision = get_token_precision(tk.type);
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
if (!is_token_nonvoid_datatype(tk.type)) {
|
|
|
|
_set_error("Expected datatype after precission");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType type = get_token_datatype(tk.type);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
VariableDeclarationNode *vardecl = alloc_node<VariableDeclarationNode>();
|
2017-09-02 22:32:31 +02:00
|
|
|
vardecl->datatype = type;
|
|
|
|
vardecl->precision = precision;
|
2017-09-05 20:22:33 +02:00
|
|
|
|
|
|
|
p_block->statements.push_back(vardecl);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_IDENTIFIER) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected identifier after type");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
StringName name = tk.text;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_find_identifier(p_block, p_builtin_types, name)) {
|
|
|
|
_set_error("Redefinition of '" + String(name) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
BlockNode::Variable var;
|
2017-03-05 16:44:50 +01:00
|
|
|
var.type = type;
|
|
|
|
var.precision = precision;
|
|
|
|
var.line = tk_line;
|
2017-09-05 20:22:33 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
p_block->variables[name] = var;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
VariableDeclarationNode::Declaration decl;
|
|
|
|
|
2017-09-02 22:32:31 +02:00
|
|
|
decl.name = name;
|
|
|
|
decl.initializer = NULL;
|
2017-09-05 20:22:33 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_OP_ASSIGN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//variable creted with assignment! must parse an expression
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!n)
|
|
|
|
return ERR_PARSE_ERROR;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
decl.initializer = n;
|
2017-08-20 21:15:08 +02:00
|
|
|
|
2017-09-02 22:32:31 +02:00
|
|
|
if (var.type != n->get_datatype()) {
|
2017-09-05 20:22:33 +02:00
|
|
|
_set_error("Invalid assignment of '" + get_datatype_name(n->get_datatype()) + "' to '" + get_datatype_name(var.type) + "'");
|
2017-08-20 21:15:08 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-09-05 20:22:33 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
vardecl->declarations.push_back(decl);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
//another variable
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_SEMICOLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
_set_error("Expected ',' or ';' after variable");
|
2014-02-10 02:10:30 +01:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_CURLY_BRACKET_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//a sub block, just because..
|
2017-03-05 16:44:50 +01:00
|
|
|
BlockNode *block = alloc_node<BlockNode>();
|
|
|
|
block->parent_block = p_block;
|
|
|
|
_parse_block(block, p_builtin_types, false, p_can_break, p_can_continue);
|
2016-10-07 16:31:18 +02:00
|
|
|
p_block->statements.push_back(block);
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_CF_IF) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//if () {}
|
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected '(' after if");
|
|
|
|
return ERR_PARSE_ERROR;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
cf->flow_op = FLOW_OP_IF;
|
|
|
|
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!n)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
|
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
2017-06-04 23:08:06 +02:00
|
|
|
_set_error("Expected ')' after expression");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BlockNode *block = alloc_node<BlockNode>();
|
|
|
|
block->parent_block = p_block;
|
2016-10-07 16:31:18 +02:00
|
|
|
cf->expressions.push_back(n);
|
2016-10-03 21:33:42 +02:00
|
|
|
cf->blocks.push_back(block);
|
2016-10-07 16:31:18 +02:00
|
|
|
p_block->statements.push_back(cf);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue);
|
2017-06-04 23:08:06 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
pos = _get_tkpos();
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_CF_ELSE) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
block = alloc_node<BlockNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
block->parent_block = p_block;
|
2016-10-03 21:33:42 +02:00
|
|
|
cf->blocks.push_back(block);
|
2017-03-05 16:44:50 +01:00
|
|
|
err = _parse_block(block, p_builtin_types, true, p_can_break, p_can_continue);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} else {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos); //rollback
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-06-04 23:08:06 +02:00
|
|
|
} else if (tk.type == TK_CF_WHILE) {
|
|
|
|
//if () {}
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
2017-09-05 20:22:33 +02:00
|
|
|
_set_error("Expected '(' after while");
|
2017-06-04 23:08:06 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
|
|
|
|
cf->flow_op = FLOW_OP_WHILE;
|
|
|
|
Node *n = _parse_and_reduce_expression(p_block, p_builtin_types);
|
|
|
|
if (!n)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
|
|
|
_set_error("Expected ')' after expression");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockNode *block = alloc_node<BlockNode>();
|
|
|
|
block->parent_block = p_block;
|
|
|
|
cf->expressions.push_back(n);
|
|
|
|
cf->blocks.push_back(block);
|
|
|
|
p_block->statements.push_back(cf);
|
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
Error err = _parse_block(block, p_builtin_types, true, true, true);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
} else if (tk.type == TK_CF_FOR) {
|
|
|
|
//if () {}
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
|
|
|
_set_error("Expected '(' after for");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *cf = alloc_node<ControlFlowNode>();
|
|
|
|
cf->flow_op = FLOW_OP_FOR;
|
|
|
|
|
|
|
|
BlockNode *init_block = alloc_node<BlockNode>();
|
|
|
|
init_block->parent_block = p_block;
|
2017-09-02 22:32:31 +02:00
|
|
|
init_block->single_statement = true;
|
2017-09-05 20:22:33 +02:00
|
|
|
cf->blocks.push_back(init_block);
|
2017-09-02 22:32:31 +02:00
|
|
|
if (_parse_block(init_block, p_builtin_types, true, false, false) != OK) {
|
2017-09-05 20:22:33 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *n = _parse_and_reduce_expression(init_block, p_builtin_types);
|
|
|
|
if (!n)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
|
2017-09-02 22:32:31 +02:00
|
|
|
if (n->get_datatype() != TYPE_BOOL) {
|
2017-09-05 20:22:33 +02:00
|
|
|
_set_error("Middle expression is expected to be boolean.");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
_set_error("Expected ';' after middle expression");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cf->expressions.push_back(n);
|
|
|
|
|
|
|
|
n = _parse_and_reduce_expression(init_block, p_builtin_types);
|
|
|
|
if (!n)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
|
|
|
|
cf->expressions.push_back(n);
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
|
|
|
_set_error("Expected ')' after third expression");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlockNode *block = alloc_node<BlockNode>();
|
2017-12-17 01:43:59 +01:00
|
|
|
block->parent_block = init_block;
|
2017-09-05 20:22:33 +02:00
|
|
|
cf->blocks.push_back(block);
|
|
|
|
p_block->statements.push_back(cf);
|
|
|
|
|
|
|
|
Error err = _parse_block(block, p_builtin_types, true, true, true);
|
2017-06-04 23:08:06 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
} else if (tk.type == TK_CF_RETURN) {
|
|
|
|
|
|
|
|
//check return type
|
|
|
|
BlockNode *b = p_block;
|
|
|
|
while (b && !b->parent_function) {
|
|
|
|
b = b->parent_block;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!b) {
|
|
|
|
_set_error("Bug");
|
|
|
|
return ERR_BUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *flow = alloc_node<ControlFlowNode>();
|
|
|
|
flow->flow_op = FLOW_OP_RETURN;
|
|
|
|
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type == TK_SEMICOLON) {
|
|
|
|
//all is good
|
|
|
|
if (b->parent_function->return_type != TYPE_VOID) {
|
|
|
|
_set_error("Expected return with expression of type '" + get_datatype_name(b->parent_function->return_type) + "'");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_set_tkpos(pos); //rollback, wants expression
|
|
|
|
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
|
|
|
if (!expr)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
|
|
|
|
if (b->parent_function->return_type != expr->get_datatype()) {
|
|
|
|
_set_error("Expected return expression of type '" + get_datatype_name(b->parent_function->return_type) + "'");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
_set_error("Expected ';' after return expression");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
flow->expressions.push_back(expr);
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
p_block->statements.push_back(flow);
|
|
|
|
} else if (tk.type == TK_CF_DISCARD) {
|
|
|
|
|
|
|
|
//check return type
|
|
|
|
BlockNode *b = p_block;
|
|
|
|
while (b && !b->parent_function) {
|
|
|
|
b = b->parent_block;
|
|
|
|
}
|
|
|
|
if (!b) {
|
|
|
|
_set_error("Bug");
|
|
|
|
return ERR_BUG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!b->parent_function->can_discard) {
|
|
|
|
_set_error("Use of 'discard' is not allowed here.");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *flow = alloc_node<ControlFlowNode>();
|
|
|
|
flow->flow_op = FLOW_OP_DISCARD;
|
|
|
|
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
//all is good
|
|
|
|
_set_error("Expected ';' after discard");
|
|
|
|
}
|
|
|
|
|
2017-09-05 20:22:33 +02:00
|
|
|
p_block->statements.push_back(flow);
|
|
|
|
} else if (tk.type == TK_CF_BREAK) {
|
|
|
|
|
|
|
|
if (!p_can_break) {
|
|
|
|
//all is good
|
|
|
|
_set_error("Breaking is not allowed here");
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *flow = alloc_node<ControlFlowNode>();
|
|
|
|
flow->flow_op = FLOW_OP_BREAK;
|
|
|
|
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
//all is good
|
|
|
|
_set_error("Expected ';' after break");
|
|
|
|
}
|
|
|
|
|
|
|
|
p_block->statements.push_back(flow);
|
|
|
|
} else if (tk.type == TK_CF_CONTINUE) {
|
|
|
|
|
|
|
|
if (!p_can_break) {
|
|
|
|
//all is good
|
|
|
|
_set_error("Contiuning is not allowed here");
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlFlowNode *flow = alloc_node<ControlFlowNode>();
|
|
|
|
flow->flow_op = FLOW_OP_CONTINUE;
|
|
|
|
|
|
|
|
pos = _get_tkpos();
|
|
|
|
tk = _get_token();
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
//all is good
|
|
|
|
_set_error("Expected ';' after continue");
|
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
p_block->statements.push_back(flow);
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//nothng else, so expression
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_tkpos(pos); //rollback
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *expr = _parse_and_reduce_expression(p_block, p_builtin_types);
|
2016-10-07 16:31:18 +02:00
|
|
|
if (!expr)
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
p_block->statements.push_back(expr);
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_SEMICOLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ';' after statement");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_just_one)
|
|
|
|
break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
Token tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
if (tk.type != TK_SHADER_TYPE) {
|
2017-09-01 17:54:57 +02:00
|
|
|
_set_error("Expected 'shader_type' at the beginning of shader.");
|
2017-04-07 04:36:37 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
|
|
|
|
if (tk.type != TK_IDENTIFIER) {
|
|
|
|
_set_error("Expected identifier after 'shader_type', indicating type of shader.");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
String shader_type_identifier;
|
|
|
|
|
|
|
|
shader_type_identifier = tk.text;
|
|
|
|
|
|
|
|
if (!p_shader_types.has(shader_type_identifier)) {
|
|
|
|
|
|
|
|
String valid;
|
|
|
|
for (Set<String>::Element *E = p_shader_types.front(); E; E = E->next()) {
|
|
|
|
if (valid != String()) {
|
|
|
|
valid += ", ";
|
|
|
|
}
|
|
|
|
valid += "'" + E->get() + "'";
|
|
|
|
}
|
|
|
|
_set_error("Invalid shader type, valid types are: " + valid);
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
|
|
|
|
if (tk.type != TK_SEMICOLON) {
|
|
|
|
_set_error("Expected ';' after 'shader_type <type>'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
int texture_uniforms = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
int uniforms = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (tk.type != TK_EOF) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (tk.type) {
|
2016-10-03 21:33:42 +02:00
|
|
|
case TK_RENDER_MODE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
StringName mode;
|
2017-03-05 16:44:50 +01:00
|
|
|
_get_completable_identifier(NULL, COMPLETION_RENDER_MODE, mode);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (mode == StringName()) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected identifier for render mode");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-27 16:50:26 +02:00
|
|
|
if (!p_render_modes.has(mode)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Invalid render mode: '" + String(mode) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (shader->render_modes.find(mode) != -1) {
|
|
|
|
_set_error("Duplicate render mode: '" + String(mode) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2015-11-22 06:49:58 +01:00
|
|
|
|
2016-10-27 16:50:26 +02:00
|
|
|
shader->render_modes.push_back(mode);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//all good, do nothing
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type == TK_SEMICOLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
break; //done
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Unexpected token: " + get_token_text(tk));
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case TK_UNIFORM:
|
|
|
|
case TK_VARYING: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool uniform = tk.type == TK_UNIFORM;
|
2016-10-03 21:33:42 +02:00
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
2017-11-27 16:47:46 +01:00
|
|
|
DataInterpolation interpolation = INTERPOLATION_SMOOTH;
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType type;
|
|
|
|
StringName name;
|
|
|
|
|
|
|
|
tk = _get_token();
|
2017-11-27 16:47:46 +01:00
|
|
|
if (is_token_interpolation(tk.type)) {
|
|
|
|
interpolation = get_token_interpolation(tk.type);
|
|
|
|
tk = _get_token();
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_precision(tk.type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
precision = get_token_precision(tk.type);
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!is_token_datatype(tk.type)) {
|
|
|
|
_set_error("Expected datatype. ");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
type = get_token_datatype(tk.type);
|
2015-11-22 06:49:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (type == TYPE_VOID) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("void datatype not allowed here");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (!uniform && type < TYPE_FLOAT && type > TYPE_VEC4) { // FIXME: always false! should it be || instead?
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Invalid type for varying, only float,vec2,vec3,vec4 allowed.");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2015-11-22 06:49:58 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_IDENTIFIER) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected identifier!");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
name = tk.text;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
if (_find_identifier(NULL, Map<StringName, BuiltInInfo>(), name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Redefinition of '" + String(name) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (uniform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderNode::Uniform uniform;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
if (is_sampler_type(type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.texture_order = texture_uniforms++;
|
|
|
|
uniform.order = -1;
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.texture_order = -1;
|
|
|
|
uniform.order = uniforms++;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.type = type;
|
|
|
|
uniform.precission = precision;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
//todo parse default value
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_OP_ASSIGN) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
Node *expr = _parse_and_reduce_expression(NULL, Map<StringName, BuiltInInfo>());
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!expr)
|
|
|
|
return ERR_PARSE_ERROR;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (expr->type != Node::TYPE_CONSTANT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected constant expression after '='");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ConstantNode *cn = static_cast<ConstantNode *>(expr);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
uniform.default_value.resize(cn->values.size());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-25 04:07:54 +01:00
|
|
|
if (!convert_constant(cn, uniform.type, uniform.default_value.ptrw())) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Can't convert constant to " + get_datatype_name(uniform.type));
|
2016-10-07 16:31:18 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_COLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
//hint
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_HINT_WHITE_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_WHITE;
|
|
|
|
} else if (tk.type == TK_HINT_BLACK_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_BLACK;
|
|
|
|
} else if (tk.type == TK_HINT_NORMAL_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_NORMAL;
|
|
|
|
} else if (tk.type == TK_HINT_ANISO_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_ANISO;
|
|
|
|
} else if (tk.type == TK_HINT_ALBEDO_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_ALBEDO;
|
|
|
|
} else if (tk.type == TK_HINT_BLACK_ALBEDO_TEXTURE) {
|
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_BLACK_ALBEDO;
|
|
|
|
} else if (tk.type == TK_HINT_COLOR) {
|
|
|
|
if (type != TYPE_VEC4) {
|
2016-10-07 16:31:18 +02:00
|
|
|
_set_error("Color hint is for vec4 only");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_COLOR;
|
|
|
|
} else if (tk.type == TK_HINT_RANGE) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint = ShaderNode::Uniform::HINT_RANGE;
|
|
|
|
if (type != TYPE_FLOAT && type != TYPE_INT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Range hint is for float and int only");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected '(' after hint_range");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float sign = 1.0;
|
2016-11-21 02:49:53 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_OP_SUB) {
|
|
|
|
sign = -1.0;
|
2016-11-21 02:49:53 +01:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected integer constant");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint_range[0] = tk.constant;
|
|
|
|
uniform.hint_range[0] *= sign;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ',' after integer constant");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
sign = 1.0;
|
2016-11-21 02:49:53 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_OP_SUB) {
|
|
|
|
sign = -1.0;
|
2016-11-21 02:49:53 +01:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected integer constant after ','");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint_range[1] = tk.constant;
|
|
|
|
uniform.hint_range[1] *= sign;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_REAL_CONSTANT && tk.type != TK_INT_CONSTANT) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected integer constant after ','");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint_range[2] = tk.constant;
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (type == TYPE_INT) {
|
|
|
|
uniform.hint_range[2] = 1;
|
2016-10-03 21:33:42 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
uniform.hint_range[2] = 0.001;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_CLOSE) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ','");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
} else {
|
|
|
|
_set_error("Expected valid type hint after ':'.");
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (uniform.hint != ShaderNode::Uniform::HINT_RANGE && uniform.hint != ShaderNode::Uniform::HINT_NONE && uniform.hint != ShaderNode::Uniform::HINT_COLOR && type <= TYPE_MAT4) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("This hint is only for sampler types");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
tk = _get_token();
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
shader->uniforms[name] = uniform;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_SEMICOLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ';'");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderNode::Varying varying;
|
2017-03-05 16:44:50 +01:00
|
|
|
varying.type = type;
|
|
|
|
varying.precission = precision;
|
2017-11-27 16:47:46 +01:00
|
|
|
varying.interpolation = interpolation;
|
2017-03-05 16:44:50 +01:00
|
|
|
shader->varyings[name] = varying;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_SEMICOLON) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ';'");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
//function
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataPrecision precision = PRECISION_DEFAULT;
|
|
|
|
DataType type;
|
|
|
|
StringName name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_precision(tk.type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
precision = get_token_precision(tk.type);
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!is_token_datatype(tk.type)) {
|
2017-03-24 21:45:31 +01:00
|
|
|
_set_error("Expected function, uniform or varying ");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
type = get_token_datatype(tk.type);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_get_completable_identifier(NULL, COMPLETION_MAIN_FUNCTION, name);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (name == StringName()) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected function name after datatype");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
if (_find_identifier(NULL, Map<StringName, BuiltInInfo>(), name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Redefinition of '" + String(name) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_PARENTHESIS_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected '(' after identifier");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
Map<StringName, BuiltInInfo> builtin_types;
|
2016-10-03 21:33:42 +02:00
|
|
|
if (p_functions.has(name)) {
|
2017-08-29 15:14:07 +02:00
|
|
|
builtin_types = p_functions[name].built_ins;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderNode::Function function;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
function.callable = !p_functions.has(name);
|
|
|
|
function.name = name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
FunctionNode *func_node = alloc_node<FunctionNode>();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
function.function = func_node;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
shader->functions.push_back(function);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
func_node->name = name;
|
|
|
|
func_node->return_type = type;
|
|
|
|
func_node->return_precision = precision;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-09-24 09:27:12 +02:00
|
|
|
if (p_functions.has(name)) {
|
|
|
|
func_node->can_discard = p_functions[name].can_discard;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
func_node->body = alloc_node<BlockNode>();
|
2017-03-05 16:44:50 +01:00
|
|
|
func_node->body->parent_function = func_node;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (true) {
|
|
|
|
if (tk.type == TK_PARENTHESIS_CLOSE) {
|
2016-10-03 21:33:42 +02:00
|
|
|
break;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
ArgumentQualifier qualifier = ARGUMENT_QUALIFIER_IN;
|
|
|
|
|
|
|
|
if (tk.type == TK_ARG_IN) {
|
|
|
|
qualifier = ARGUMENT_QUALIFIER_IN;
|
|
|
|
tk = _get_token();
|
|
|
|
} else if (tk.type == TK_ARG_OUT) {
|
|
|
|
qualifier = ARGUMENT_QUALIFIER_OUT;
|
|
|
|
tk = _get_token();
|
|
|
|
} else if (tk.type == TK_ARG_INOUT) {
|
|
|
|
qualifier = ARGUMENT_QUALIFIER_INOUT;
|
|
|
|
tk = _get_token();
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
DataType ptype;
|
|
|
|
StringName pname;
|
|
|
|
DataPrecision pprecision = PRECISION_DEFAULT;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (is_token_precision(tk.type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pprecision = get_token_precision(tk.type);
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
if (!is_token_datatype(tk.type)) {
|
|
|
|
_set_error("Expected a valid datatype for argument");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ptype = get_token_datatype(tk.type);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ptype == TYPE_VOID) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("void not allowed in argument");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_IDENTIFIER) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected identifier for argument name");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
pname = tk.text;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (_find_identifier(func_node->body, builtin_types, pname)) {
|
|
|
|
_set_error("Redefinition of '" + String(pname) + "'");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
FunctionNode::Argument arg;
|
2017-03-05 16:44:50 +01:00
|
|
|
arg.type = ptype;
|
|
|
|
arg.name = pname;
|
|
|
|
arg.precision = pprecision;
|
2017-04-07 04:36:37 +02:00
|
|
|
arg.qualifier = qualifier;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
func_node->arguments.push_back(arg);
|
|
|
|
|
|
|
|
tk = _get_token();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type == TK_COMMA) {
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
|
|
|
//do none and go on
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (tk.type != TK_PARENTHESIS_CLOSE) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected ',' or ')' after identifier");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_functions.has(name)) {
|
|
|
|
//if one of the core functions, make sure they are of the correct form
|
|
|
|
if (func_node->arguments.size() > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_set_error("Function '" + String(name) + "' expects no arguments.");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (func_node->return_type != TYPE_VOID) {
|
|
|
|
_set_error("Function '" + String(name) + "' must be of void return type.");
|
2016-10-03 21:33:42 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-24 21:45:31 +01:00
|
|
|
//all good let's parse inside the function!
|
2016-10-03 21:33:42 +02:00
|
|
|
tk = _get_token();
|
2017-03-05 16:44:50 +01:00
|
|
|
if (tk.type != TK_CURLY_BRACKET_OPEN) {
|
2016-10-03 21:33:42 +02:00
|
|
|
_set_error("Expected '{' to begin function");
|
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
current_function = name;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = _parse_block(func_node->body, builtin_types);
|
2016-10-03 21:33:42 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
current_function = StringName();
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
tk = _get_token();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
String ShaderLanguage::get_shader_type(const String &p_code) {
|
|
|
|
|
|
|
|
bool reading_type = false;
|
|
|
|
|
|
|
|
String cur_identifier;
|
|
|
|
|
2017-05-02 08:36:24 +02:00
|
|
|
for (int i = 0; i < p_code.length(); i++) {
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
if (p_code[i] == ';') {
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if (p_code[i] <= 32) {
|
|
|
|
if (cur_identifier != String()) {
|
|
|
|
if (!reading_type) {
|
|
|
|
if (cur_identifier != "shader_type") {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
|
|
|
reading_type = true;
|
|
|
|
cur_identifier = String();
|
|
|
|
} else {
|
|
|
|
return cur_identifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cur_identifier += String::chr(p_code[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reading_type)
|
|
|
|
return cur_identifier;
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
Error ShaderLanguage::compile(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types) {
|
2016-10-03 21:33:42 +02:00
|
|
|
|
|
|
|
clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
code = p_code;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
nodes = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
shader = alloc_node<ShaderNode>();
|
2017-04-07 04:36:37 +02:00
|
|
|
Error err = _parse_shader(p_functions, p_render_modes, p_shader_types);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (err != OK) {
|
2016-10-03 21:33:42 +02:00
|
|
|
return err;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-03 21:33:42 +02:00
|
|
|
return OK;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
Error ShaderLanguage::complete(const String &p_code, const Map<StringName, FunctionInfo> &p_functions, const Set<String> &p_render_modes, const Set<String> &p_shader_types, List<String> *r_options, String &r_call_hint) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
clear();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
code = p_code;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
nodes = NULL;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
shader = alloc_node<ShaderNode>();
|
2017-04-07 04:36:37 +02:00
|
|
|
Error err = _parse_shader(p_functions, p_render_modes, p_shader_types);
|
2017-09-02 22:32:31 +02:00
|
|
|
if (err != OK)
|
|
|
|
ERR_PRINT("Failed to parse shader");
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (completion_type) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
case COMPLETION_NONE: {
|
|
|
|
//do none
|
|
|
|
return ERR_PARSE_ERROR;
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2016-10-07 16:31:18 +02:00
|
|
|
case COMPLETION_RENDER_MODE: {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Set<String>::Element *E = p_render_modes.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
r_options->push_back(E->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
return OK;
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2016-10-07 16:31:18 +02:00
|
|
|
case COMPLETION_MAIN_FUNCTION: {
|
2016-10-27 16:50:26 +02:00
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
for (const Map<StringName, FunctionInfo>::Element *E = p_functions.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
r_options->push_back(E->key());
|
2014-06-28 04:21:45 +02:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
return OK;
|
2014-06-28 04:21:45 +02:00
|
|
|
} break;
|
2016-10-07 16:31:18 +02:00
|
|
|
case COMPLETION_IDENTIFIER:
|
|
|
|
case COMPLETION_FUNCTION_CALL: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool comp_ident = completion_type == COMPLETION_IDENTIFIER;
|
2016-10-07 16:31:18 +02:00
|
|
|
Set<String> matches;
|
|
|
|
|
|
|
|
StringName skip_function;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BlockNode *block = completion_block;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (block) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (comp_ident) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Map<StringName, BlockNode::Variable>::Element *E = block->variables.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (E->get().line < completion_line) {
|
2016-10-07 16:31:18 +02:00
|
|
|
matches.insert(E->key());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (block->parent_function) {
|
|
|
|
if (comp_ident) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < block->parent_function->arguments.size(); i++) {
|
2016-10-07 16:31:18 +02:00
|
|
|
matches.insert(block->parent_function->arguments[i].name);
|
|
|
|
}
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
skip_function = block->parent_function->name;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
block = block->parent_block;
|
2015-01-11 15:43:31 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (comp_ident && skip_function != StringName() && p_functions.has(skip_function)) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-12-15 22:23:16 +01:00
|
|
|
for (Map<StringName, BuiltInInfo>::Element *E = p_functions[skip_function].built_ins.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
matches.insert(E->key());
|
|
|
|
}
|
2015-01-11 15:43:31 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (comp_ident) {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Map<StringName, ShaderNode::Varying>::Element *E = shader->varyings.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
matches.insert(E->key());
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
for (const Map<StringName, ShaderNode::Uniform>::Element *E = shader->uniforms.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
matches.insert(E->key());
|
|
|
|
}
|
2015-01-11 15:43:31 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader->functions.size(); i++) {
|
|
|
|
if (!shader->functions[i].callable || shader->functions[i].name == skip_function)
|
2016-10-07 16:31:18 +02:00
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
matches.insert(String(shader->functions[i].name) + "(");
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
while (builtin_func_defs[idx].name) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
matches.insert(String(builtin_func_defs[idx].name) + "(");
|
2014-02-10 02:10:30 +01:00
|
|
|
idx++;
|
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<String>::Element *E = matches.front(); E; E = E->next()) {
|
2016-10-07 16:31:18 +02:00
|
|
|
r_options->push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2016-10-07 16:31:18 +02:00
|
|
|
case COMPLETION_CALL_ARGUMENTS: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader->functions.size(); i++) {
|
2016-10-07 16:31:18 +02:00
|
|
|
if (!shader->functions[i].callable)
|
|
|
|
continue;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (shader->functions[i].name == completion_function) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
String calltip;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += get_datatype_name(shader->functions[i].function->return_type);
|
|
|
|
calltip += " ";
|
|
|
|
calltip += shader->functions[i].name;
|
|
|
|
calltip += "(";
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < shader->functions[i].function->arguments.size(); j++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j > 0)
|
|
|
|
calltip += ", ";
|
2016-10-07 16:31:18 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += " ";
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j == completion_argument) {
|
|
|
|
calltip += CharType(0xFFFF);
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += get_datatype_name(shader->functions[i].function->arguments[j].type);
|
|
|
|
calltip += " ";
|
|
|
|
calltip += shader->functions[i].function->arguments[j].name;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (j == completion_argument) {
|
|
|
|
calltip += CharType(0xFFFF);
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
if (shader->functions[i].function->arguments.size())
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += " ";
|
|
|
|
calltip += ")";
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_call_hint = calltip;
|
2016-10-07 16:31:18 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 04:53:09 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int idx = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
String calltip;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
while (builtin_func_defs[idx].name) {
|
2015-03-10 04:53:09 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (completion_function == builtin_func_defs[idx].name) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
if (calltip.length())
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += "\n";
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += get_datatype_name(builtin_func_defs[idx].rettype);
|
|
|
|
calltip += " ";
|
|
|
|
calltip += builtin_func_defs[idx].name;
|
|
|
|
calltip += "(";
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool found_arg = false;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (builtin_func_defs[idx].args[i] == TYPE_VOID)
|
2016-10-07 16:31:18 +02:00
|
|
|
break;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i > 0)
|
|
|
|
calltip += ", ";
|
2016-10-07 16:31:18 +02:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += " ";
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == completion_argument) {
|
|
|
|
calltip += CharType(0xFFFF);
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += get_datatype_name(builtin_func_defs[idx].args[i]);
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == completion_argument) {
|
|
|
|
calltip += CharType(0xFFFF);
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
found_arg = true;
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (found_arg)
|
2017-03-05 16:44:50 +01:00
|
|
|
calltip += " ";
|
|
|
|
calltip += ")";
|
2016-10-07 16:31:18 +02:00
|
|
|
}
|
2015-01-12 00:52:42 +01:00
|
|
|
idx++;
|
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_call_hint = calltip;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
2015-01-12 00:52:42 +01:00
|
|
|
} break;
|
2016-10-07 16:31:18 +02:00
|
|
|
case COMPLETION_INDEX: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char colv[4] = { 'r', 'g', 'b', 'a' };
|
|
|
|
const char coordv[4] = { 'x', 'y', 'z', 'w' };
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int limit = 0;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (completion_base) {
|
2016-10-07 16:31:18 +02:00
|
|
|
case TYPE_BVEC2:
|
|
|
|
case TYPE_IVEC2:
|
|
|
|
case TYPE_UVEC2:
|
|
|
|
case TYPE_VEC2: {
|
2017-03-05 16:44:50 +01:00
|
|
|
limit = 2;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TYPE_BVEC3:
|
|
|
|
case TYPE_IVEC3:
|
|
|
|
case TYPE_UVEC3:
|
|
|
|
case TYPE_VEC3: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
limit = 3;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TYPE_BVEC4:
|
|
|
|
case TYPE_IVEC4:
|
|
|
|
case TYPE_UVEC4:
|
|
|
|
case TYPE_VEC4: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
limit = 4;
|
2016-10-07 16:31:18 +02:00
|
|
|
|
|
|
|
} break;
|
2017-03-05 16:44:50 +01:00
|
|
|
case TYPE_MAT2: limit = 2; break;
|
|
|
|
case TYPE_MAT3: limit = 3; break;
|
|
|
|
case TYPE_MAT4: limit = 4; break;
|
2016-10-07 16:31:18 +02:00
|
|
|
default: {}
|
2015-01-12 00:52:42 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < limit; i++) {
|
2016-10-07 16:31:18 +02:00
|
|
|
r_options->push_back(String::chr(colv[i]));
|
|
|
|
r_options->push_back(String::chr(coordv[i]));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-10-07 16:31:18 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
return ERR_PARSE_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
String ShaderLanguage::get_error_text() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return error_str;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2015-03-10 04:53:09 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
int ShaderLanguage::get_error_line() {
|
2015-01-12 00:52:42 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
return error_line;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-07 16:31:18 +02:00
|
|
|
ShaderLanguage::ShaderNode *ShaderLanguage::get_shader() {
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
ShaderLanguage::ShaderLanguage() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
nodes = NULL;
|
2016-10-03 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ShaderLanguage::~ShaderLanguage() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-10-03 21:33:42 +02:00
|
|
|
clear();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|