summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/gd_editor.cpp11
-rw-r--r--modules/gdscript/gd_function.cpp2
-rw-r--r--modules/gdscript/gd_parser.cpp45
-rw-r--r--modules/gdscript/gd_script.cpp4
-rw-r--r--modules/gdscript/gd_tokenizer.cpp4
-rw-r--r--modules/gdscript/gd_tokenizer.h2
6 files changed, 63 insertions, 5 deletions
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index f325aec072..9dd41847d7 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -323,6 +323,16 @@ void GDScriptLanguage::get_public_constants(List<Pair<String,Variant> > *p_const
pi.first="PI";
pi.second=Math_PI;
p_constants->push_back(pi);
+
+ Pair<String, Variant> infinity;
+ infinity.first = "INF";
+ infinity.second = Math_INF;
+ p_constants->push_back(infinity);
+
+ Pair<String, Variant> nan;
+ nan.first = "NAN";
+ nan.second = Math_NAN;
+ p_constants->push_back(nan);
}
String GDScriptLanguage::make_function(const String& p_class,const String& p_name,const PoolStringArray& p_args) const {
@@ -2645,6 +2655,7 @@ Error GDScriptLanguage::lookup_code(const String& p_code, const String& p_symbol
switch(p.get_completion_type()) {
+ case GDParser::COMPLETION_GET_NODE:
case GDParser::COMPLETION_NONE: {
} break;
case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: {
diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gd_function.cpp
index 31bac2748a..0c72f6d187 100644
--- a/modules/gdscript/gd_function.cpp
+++ b/modules/gdscript/gd_function.cpp
@@ -725,7 +725,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
err.argument-=1;
}
}
- } if (methodstr=="free") {
+ } else if (methodstr=="free") {
if (err.error==Variant::CallError::CALL_ERROR_INVALID_METHOD) {
diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gd_parser.cpp
index 1bda8f0cd3..5147ccd63f 100644
--- a/modules/gdscript/gd_parser.cpp
+++ b/modules/gdscript/gd_parser.cpp
@@ -375,6 +375,22 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
constant->value=Math_PI;
tokenizer->advance();
expr=constant;
+ }
+ else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) {
+
+ //constant defined by tokenizer
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value = Math_INF;
+ tokenizer->advance();
+ expr = constant;
+ }
+ else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) {
+
+ //constant defined by tokenizer
+ ConstantNode *constant = alloc_node<ConstantNode>();
+ constant->value = Math_NAN;
+ tokenizer->advance();
+ expr = constant;
} else if (tokenizer->get_token()==GDTokenizer::TK_PR_PRELOAD) {
//constant defined by tokenizer
@@ -386,21 +402,42 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
tokenizer->advance();
String path;
+ bool found_constant = false;
bool valid = false;
+ ConstantNode *cn;
+
Node *subexpr = _parse_and_reduce_expression(p_parent, p_static);
if (subexpr) {
if (subexpr->type == Node::TYPE_CONSTANT) {
- ConstantNode *cn = static_cast<ConstantNode*>(subexpr);
- if (cn->value.get_type() == Variant::STRING) {
- valid = true;
- path = (String) cn->value;
+ cn = static_cast<ConstantNode*>(subexpr);
+ found_constant = true;
+ }
+ if (subexpr->type == Node::TYPE_IDENTIFIER) {
+ IdentifierNode *in = static_cast<IdentifierNode*>(subexpr);
+ Vector<ClassNode::Constant> ce = current_class->constant_expressions;
+
+ // Try to find the constant expression by the identifier
+ for(int i=0; i < ce.size(); ++i){
+ if(ce[i].identifier == in->name) {
+ if(ce[i].expression->type == Node::TYPE_CONSTANT) {
+ cn = static_cast<ConstantNode*>(ce[i].expression);
+ found_constant = true;
+ }
+ }
}
}
+
+ if (found_constant && cn->value.get_type() == Variant::STRING) {
+ valid = true;
+ path = (String) cn->value;
+ }
}
+
if (!valid) {
_set_error("expected string constant as 'preload' argument.");
return NULL;
}
+
if (!path.is_abs_path() && base_path!="")
path=base_path+"/"+path;
path = path.replace("///","//").simplify_path();
diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gd_script.cpp
index d4646aa36d..4e72bc39a4 100644
--- a/modules/gdscript/gd_script.cpp
+++ b/modules/gdscript/gd_script.cpp
@@ -1517,6 +1517,8 @@ void GDScriptLanguage::init() {
}
_add_global(StaticCString::create("PI"),Math_PI);
+ _add_global(StaticCString::create("INF"),Math_INF);
+ _add_global(StaticCString::create("NAN"),Math_NAN);
//populate native classes
@@ -1909,6 +1911,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
"bool",
"null",
"PI",
+ "INF",
+ "NAN",
"self",
"true",
// functions
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index 477a1f1ac8..54b9624e8e 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -120,6 +120,8 @@ const char* GDTokenizer::token_names[TK_MAX]={
"'\\n'",
"PI",
"_",
+"INF",
+"NAN",
"Error",
"EOF",
"Cursor"};
@@ -901,6 +903,8 @@ void GDTokenizerText::_advance() {
{TK_SELF,"self"},
{TK_CONST_PI,"PI"},
{TK_WILDCARD,"_"},
+ {TK_CONST_INF,"INF"},
+ {TK_CONST_NAN,"NAN"},
{TK_ERROR,NULL}
};
diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gd_tokenizer.h
index 5d955ff1ae..1e9eda7947 100644
--- a/modules/gdscript/gd_tokenizer.h
+++ b/modules/gdscript/gd_tokenizer.h
@@ -128,6 +128,8 @@ public:
TK_NEWLINE,
TK_CONST_PI,
TK_WILDCARD,
+ TK_CONST_INF,
+ TK_CONST_NAN,
TK_ERROR,
TK_EOF,
TK_CURSOR, //used for code completion