MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / parse_enum

Method parse_enum

modules/gdscript/gdscript_parser.cpp:1487–1583  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1485}
1486
1487GDScriptParser::EnumNode *GDScriptParser::parse_enum(bool p_is_static) {
1488 EnumNode *enum_node = alloc_node<EnumNode>();
1489 bool named = false;
1490
1491 if (match(GDScriptTokenizer::Token::IDENTIFIER)) {
1492 enum_node->identifier = parse_identifier();
1493 named = true;
1494 }
1495
1496 push_multiline(true);
1497 consume(GDScriptTokenizer::Token::BRACE_OPEN, vformat(R"(Expected "{" after %s.)", named ? "enum name" : R"("enum")"));
1498#ifdef TOOLS_ENABLED
1499 int min_enum_value_doc_line = previous.end_line + 1;
1500#endif
1501
1502 HashMap<StringName, int> elements;
1503
1504#ifdef DEBUG_ENABLED
1505 List<MethodInfo> gdscript_funcs;
1506 GDScriptLanguage::get_singleton()->get_public_functions(&gdscript_funcs);
1507#endif
1508
1509 do {
1510 if (check(GDScriptTokenizer::Token::BRACE_CLOSE)) {
1511 break; // Allow trailing comma.
1512 }
1513 if (consume(GDScriptTokenizer::Token::IDENTIFIER, R"(Expected identifier for enum key.)")) {
1514 GDScriptParser::IdentifierNode *identifier = parse_identifier();
1515
1516 EnumNode::Value item;
1517 item.identifier = identifier;
1518 item.parent_enum = enum_node;
1519 item.line = previous.start_line;
1520 item.start_column = previous.start_column;
1521 item.end_column = previous.end_column;
1522
1523 if (elements.has(item.identifier->name)) {
1524 push_error(vformat(R"(Name "%s" was already in this enum (at line %d).)", item.identifier->name, elements[item.identifier->name]), item.identifier);
1525 } else if (!named) {
1526 if (current_class->members_indices.has(item.identifier->name)) {
1527 push_error(vformat(R"(Name "%s" is already used as a class %s.)", item.identifier->name, current_class->get_member(item.identifier->name).get_type_name()));
1528 }
1529 }
1530
1531 elements[item.identifier->name] = item.line;
1532
1533 if (match(GDScriptTokenizer::Token::EQUAL)) {
1534 ExpressionNode *value = parse_expression(false);
1535 if (value == nullptr) {
1536 push_error(R"(Expected expression value after "=".)");
1537 }
1538 item.custom_value = value;
1539 }
1540
1541 item.index = enum_node->values.size();
1542 enum_node->values.push_back(item);
1543 if (!named) {
1544 // Add as member of current class.

Callers

nothing calls this directly

Calls 9

vformatFunction · 0.85
get_memberMethod · 0.80
sizeMethod · 0.65
get_public_functionsMethod · 0.45
hasMethod · 0.45
get_type_nameMethod · 0.45
push_backMethod · 0.45
add_memberMethod · 0.45

Tested by

no test coverage detected