mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 08:47:28 +01:00
[apps/code] Use ScriptNode::Type in VariableBoxController
This commit is contained in:
@@ -92,114 +92,114 @@ void VariableBoxController::loadFunctionsAndVariables(int scriptIndex, const cha
|
||||
m_importedNodesCount = 0;
|
||||
|
||||
// Add buitin nodes
|
||||
static const struct { const char * name; NodeType type; } builtinNames[] = {
|
||||
{qstr_str(MP_QSTR_abs), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_all), NodeType::Function},
|
||||
{"and", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_any), NodeType::Function},
|
||||
{"as", NodeType::Variable},
|
||||
//{qstr_str(MP_QSTR_ascii), NodeType::Function},
|
||||
{"assert", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_bin), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_bool), NodeType::Function},
|
||||
{"break", NodeType::Variable},
|
||||
//{qstr_str(MP_QSTR_breakpoint), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_bytearray), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_bytes), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_callable), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_chr), NodeType::Function},
|
||||
{"class", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_classmethod), NodeType::Function},
|
||||
//{qstr_str(MP_QSTR_compile), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_complex), NodeType::Function},
|
||||
{"continue", NodeType::Variable},
|
||||
{"def", NodeType::Variable},
|
||||
{"__del__", NodeType::Variable},
|
||||
//{qstr_str(MP_QSTR_delattr), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_dict), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_dir), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_divmod), NodeType::Function},
|
||||
{"elif", NodeType::Variable},
|
||||
{"else", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_enumerate), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_eval), NodeType::Function},
|
||||
{"except", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_exec), NodeType::Function},
|
||||
{"False", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_filter), NodeType::Function},
|
||||
{"finally", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_float), NodeType::Function},
|
||||
{"for", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_format), NodeType::Function},
|
||||
{"from", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_frozenset), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_getattr), NodeType::Function},
|
||||
{"global", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_globals), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_hasattr), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_hash), NodeType::Function},
|
||||
//{qstr_str(MP_QSTR_help), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_hex), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_id), NodeType::Function},
|
||||
{"if", NodeType::Variable},
|
||||
{"import", NodeType::Variable},
|
||||
{"in", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_input), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_int), NodeType::Function},
|
||||
{"is", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_isinstance), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_issubclass), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_iter), NodeType::Function},
|
||||
{"lambda", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_len), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_list), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_locals), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_map), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_max), NodeType::Function},
|
||||
//{qstr_str(MP_QSTR_memoryview), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_min), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_next), NodeType::Function},
|
||||
{"None", NodeType::Variable},
|
||||
{"nonlocal", NodeType::Variable},
|
||||
{"not", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_object), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_oct), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_open), NodeType::Function},
|
||||
{"or", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_ord), NodeType::Function},
|
||||
{"pass", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_pow), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_print), NodeType::Function},
|
||||
//{qstr_str(MP_QSTR_property), NodeType::Function},
|
||||
{"raise", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_range), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_repr), NodeType::Function},
|
||||
{"return", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_reversed), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_round), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_set), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_setattr), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_slice), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_sorted), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_staticmethod), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_str), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_sum), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_super), NodeType::Function},
|
||||
{"True", NodeType::Variable},
|
||||
{"try", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_tuple), NodeType::Function},
|
||||
{qstr_str(MP_QSTR_type), NodeType::Function},
|
||||
//{qstr_str(MP_QSTR_vars), NodeType::Function},
|
||||
{"while", NodeType::Variable},
|
||||
{"with", NodeType::Variable},
|
||||
{"yield", NodeType::Variable},
|
||||
{qstr_str(MP_QSTR_zip), NodeType::Function},
|
||||
{qstr_str(MP_QSTR___import__), NodeType::Function} //TODO LEA alphabetical order?
|
||||
static const struct { const char * name; ScriptNode::Type type; } builtinNames[] = {
|
||||
{qstr_str(MP_QSTR_abs), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_all), ScriptNode::Type::Function},
|
||||
{"and", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_any), ScriptNode::Type::Function},
|
||||
{"as", ScriptNode::Type::Variable},
|
||||
//{qstr_str(MP_QSTR_ascii), ScriptNode::Type::Function},
|
||||
{"assert", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_bin), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_bool), ScriptNode::Type::Function},
|
||||
{"break", ScriptNode::Type::Variable},
|
||||
//{qstr_str(MP_QSTR_breakpoint), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_bytearray), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_bytes), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_callable), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_chr), ScriptNode::Type::Function},
|
||||
{"class", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_classmethod), ScriptNode::Type::Function},
|
||||
//{qstr_str(MP_QSTR_compile), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_complex), ScriptNode::Type::Function},
|
||||
{"continue", ScriptNode::Type::Variable},
|
||||
{"def", ScriptNode::Type::Variable},
|
||||
{"__del__", ScriptNode::Type::Variable},
|
||||
//{qstr_str(MP_QSTR_delattr), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_dict), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_dir), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_divmod), ScriptNode::Type::Function},
|
||||
{"elif", ScriptNode::Type::Variable},
|
||||
{"else", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_enumerate), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_eval), ScriptNode::Type::Function},
|
||||
{"except", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_exec), ScriptNode::Type::Function},
|
||||
{"False", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_filter), ScriptNode::Type::Function},
|
||||
{"finally", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_float), ScriptNode::Type::Function},
|
||||
{"for", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_format), ScriptNode::Type::Function},
|
||||
{"from", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_frozenset), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_getattr), ScriptNode::Type::Function},
|
||||
{"global", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_globals), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_hasattr), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_hash), ScriptNode::Type::Function},
|
||||
//{qstr_str(MP_QSTR_help), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_hex), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_id), ScriptNode::Type::Function},
|
||||
{"if", ScriptNode::Type::Variable},
|
||||
{"import", ScriptNode::Type::Variable},
|
||||
{"in", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_input), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_int), ScriptNode::Type::Function},
|
||||
{"is", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_isinstance), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_issubclass), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_iter), ScriptNode::Type::Function},
|
||||
{"lambda", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_len), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_list), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_locals), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_map), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_max), ScriptNode::Type::Function},
|
||||
//{qstr_str(MP_QSTR_memoryview), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_min), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_next), ScriptNode::Type::Function},
|
||||
{"None", ScriptNode::Type::Variable},
|
||||
{"nonlocal", ScriptNode::Type::Variable},
|
||||
{"not", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_object), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_oct), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_open), ScriptNode::Type::Function},
|
||||
{"or", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_ord), ScriptNode::Type::Function},
|
||||
{"pass", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_pow), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_print), ScriptNode::Type::Function},
|
||||
//{qstr_str(MP_QSTR_property), ScriptNode::Type::Function},
|
||||
{"raise", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_range), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_repr), ScriptNode::Type::Function},
|
||||
{"return", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_reversed), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_round), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_set), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_setattr), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_slice), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_sorted), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_staticmethod), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_str), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_sum), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_super), ScriptNode::Type::Function},
|
||||
{"True", ScriptNode::Type::Variable},
|
||||
{"try", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_tuple), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR_type), ScriptNode::Type::Function},
|
||||
//{qstr_str(MP_QSTR_vars), ScriptNode::Type::Function},
|
||||
{"while", ScriptNode::Type::Variable},
|
||||
{"with", ScriptNode::Type::Variable},
|
||||
{"yield", ScriptNode::Type::Variable},
|
||||
{qstr_str(MP_QSTR_zip), ScriptNode::Type::Function},
|
||||
{qstr_str(MP_QSTR___import__), ScriptNode::Type::Function} //TODO LEA alphabetical order?
|
||||
};
|
||||
assert(sizeof(builtinNames) / sizeof(builtinNames[0]) == k_totalBuiltinNodesCount);
|
||||
for (int i = 0; i < k_totalBuiltinNodesCount; i++) {
|
||||
// TODO remove those two constructors
|
||||
ScriptNode node = builtinNames[i].type == NodeType::Function ? ScriptNode::FunctionNode( builtinNames[i].name, -1, 0) : ScriptNode::VariableNode(builtinNames[i].name, -1, 0);
|
||||
ScriptNode node = builtinNames[i].type == ScriptNode::Type::Function ? ScriptNode::FunctionNode( builtinNames[i].name, -1, 0) : ScriptNode::VariableNode(builtinNames[i].name, -1, 0);
|
||||
int startsWith = textToAutocomplete == nullptr ? 0 : NodeNameStartsWith(&node, textToAutocomplete, textToAutocompleteLength);
|
||||
if (startsWith == 0) {
|
||||
m_builtinNodes[m_builtinNodesCount++] = node;
|
||||
@@ -273,7 +273,7 @@ void VariableBoxController::loadFunctionsAndVariables(int scriptIndex, const cha
|
||||
tokenInText--;
|
||||
}
|
||||
assert(strncmp(tokenInText, name, nameLength) == 0);
|
||||
addNode(defToken ? NodeType::Function : NodeType::Variable, NodeOrigin::CurrentScript, tokenInText, nameLength, scriptIndex);
|
||||
addNode(defToken ? ScriptNode::Type::Function : ScriptNode::Type::Variable, NodeOrigin::CurrentScript, tokenInText, nameLength, scriptIndex);
|
||||
}
|
||||
}
|
||||
defToken = lex->tok_kind == MP_TOKEN_KW_DEF;
|
||||
@@ -428,7 +428,7 @@ void VariableBoxController::insertTextInCaller(const char * text, int textLength
|
||||
sender()->handleEventWithText(commandBuffer);
|
||||
}
|
||||
|
||||
void VariableBoxController::addNode(NodeType type, NodeOrigin origin, const char * name, int nameLength, int scriptIndex) {
|
||||
void VariableBoxController::addNode(ScriptNode::Type type, NodeOrigin origin, const char * name, int nameLength, int scriptIndex) {
|
||||
assert(origin == NodeOrigin::CurrentScript || origin == NodeOrigin::Importation);
|
||||
int * currentNodeCount = nodesCountPointerForOrigin(origin);
|
||||
if (*currentNodeCount >= MaxNodesCountForOrigin(origin)) {
|
||||
@@ -454,7 +454,7 @@ void VariableBoxController::addNode(NodeType type, NodeOrigin origin, const char
|
||||
nodes[i+1] = nodes[i];
|
||||
}
|
||||
// Add the node
|
||||
nodes[insertionIndex] = type == NodeType::Variable ?
|
||||
nodes[insertionIndex] = type == ScriptNode::Type::Variable ?
|
||||
ScriptNode::VariableNode(name, nameLength, scriptIndex) :
|
||||
ScriptNode::FunctionNode(name, nameLength, scriptIndex);
|
||||
// Increase the node count
|
||||
|
||||
Reference in New Issue
Block a user