Skip to content

Commit

Permalink
Merge pull request #3717 from masatake/gdscript--fix-marking-xtag
Browse files Browse the repository at this point in the history
GDScript : mark xtag bit for implicitClass xtags
  • Loading branch information
masatake committed May 12, 2023
2 parents 30320ed + af3b00d commit cc36e4f
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--sort=no
--fields=+irK
--fields=+irKE
--extras=+r
--extras-GDScript=-{implicitClass}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended extras:reference
MyNode input.gd /^class_name MyNode extends Node$/;" class inherits:Node roles:def
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/class_name-extends.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--sort=no
--fields=+irK
--fields=+irKE
--extras=+r
--extras-GDScript=+{implicitClass}
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/class_name-extends.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MyNode input.gd /^class_name MyNode extends Node$/;" class inherits:Node roles:def
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended
Node input.gd /^class_name MyNode extends Node$/;" class roles:extended extras:reference
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/inner-class.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--sort=no
--fields=+{inherits}{signature}
--fields=+{inherits}{signature}{extras}
--kinds-GDScript=-{local}
--kinds-GDScript=-{parameter}
--extras-GDScript=+{implicitClass}
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/inner-class.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anon_class_186e00360100 input.gd /^# Taken from godot-demo-projects\/networking\/webrtc_signaling\/server\/ws_webrtc_server.gd$/;" c inherits:Node
anon_class_186e00360100 input.gd /^# Taken from godot-demo-projects\/networking\/webrtc_signaling\/server\/ws_webrtc_server.gd$/;" c inherits:Node extras:anonymous,implicitClass
TIMEOUT input.gd /^const TIMEOUT = 1000 # Unresponsive clients times out after 1 sec$/;" C class:anon_class_186e00360100
SEAL_TIME input.gd /^const SEAL_TIME = 10000 # A sealed room will be closed after this time$/;" C class:anon_class_186e00360100
ALFNUM input.gd /^const ALFNUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"$/;" C class:anon_class_186e00360100
Expand Down
1 change: 1 addition & 0 deletions Units/parser-gdscript.r/modifiers.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
--sort=no
--kinds-GDScript=+zl
--fields=+E
--fields-GDScript={annotations}
--extras-GDScript=+{implicitClass}
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/modifiers.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anon_class_025551790100 input.gd /^# Taken from godot-demo-projects\/3d\/voxel\/world\/chunk.gd$/;" c
anon_class_025551790100 input.gd /^# Taken from godot-demo-projects\/3d\/voxel\/world\/chunk.gd$/;" c extras:anonymous,implicitClass
_create_block_collider input.gd /^func _create_block_collider(block_sub_position):$/;" m class:anon_class_025551790100
block_sub_position input.gd /^func _create_block_collider(block_sub_position):$/;" z method:anon_class_025551790100._create_block_collider file:
collider input.gd /^ var collider = CollisionShape.new()$/;" l method:anon_class_025551790100._create_block_collider file:
Expand Down
2 changes: 1 addition & 1 deletion Units/parser-gdscript.r/signal.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--sort=no
--fields=+SKi
--fields=+SKiE
--kinds-GDScript=+z
--extras-GDScript=+{implicitClass}
4 changes: 2 additions & 2 deletions Units/parser-gdscript.r/signal.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
anon_class_e8da5fd50100 input.gd /^extends Node$/;" class inherits:Node
anon_class_e8da5fd50100 input.gd /^extends Node$/;" class inherits:Node extras:anonymous,implicitClass
finished input.gd /^signal finished(next_state_name)$/;" signal class:anon_class_e8da5fd50100 signature:(next_state_name)
next_state_name input.gd /^signal finished(next_state_name)$/;" parameter signal:anon_class_e8da5fd50100.finished file:
enter input.gd /^func enter():$/;" method class:anon_class_e8da5fd50100 signature:()
Expand All @@ -9,7 +9,7 @@ update input.gd /^func update(_delta):$/;" method class:anon_class_e8da5fd50100
_delta input.gd /^func update(_delta):$/;" parameter method:anon_class_e8da5fd50100.update file:
_on_animation_finished input.gd /^func _on_animation_finished(_anim_name):$/;" method class:anon_class_e8da5fd50100 signature:(_anim_name)
_anim_name input.gd /^func _on_animation_finished(_anim_name):$/;" parameter method:anon_class_e8da5fd50100._on_animation_finished file:
anon_class_88c08fb20100 input-0.gd /^signal start_game$/;" class
anon_class_88c08fb20100 input-0.gd /^signal start_game$/;" class extras:anonymous,implicitClass
start_game input-0.gd /^signal start_game$/;" signal class:anon_class_88c08fb20100
C input-1.gd /^class_name C, "res:\/\/path\/to\/optional\/icon.svg"$/;" class inherits:B
sdf input-1.gd /^signal sdf$/;" signal class:C
Expand Down
10 changes: 1 addition & 9 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,7 @@ static bool isSignatureFieldAvailable (const tagEntryInfo *const tag)

static bool isExtrasFieldAvailable (const tagEntryInfo *const tag)
{
unsigned int i;

if (tag->extraDynamic)
return true;
for (i = 0; i < sizeof (tag->extra); i++)
if (tag->extra [i])
return true;

return false;
return isTagExtra (tag);
}

static bool isXpathFieldAvailable (const tagEntryInfo *const tag)
Expand Down
52 changes: 29 additions & 23 deletions parsers/gdscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ static void copyToken (tokenInfo *const dest, const tokenInfo *const src)
dest->type = src->type;
dest->keyword = src->keyword;
dest->indent = src->indent;
vStringCopy(dest->string, src->string);
vStringCopy (dest->string, src->string);
}

/* Skip a single or double quoted string. */
Expand Down Expand Up @@ -827,7 +827,7 @@ static bool parseClassOrDef (tokenInfo *const token,
vString *arglist = NULL;
tokenInfo *name = NULL;
tokenInfo *parameterTokens[16] = { NULL };
vString *parameterTypes [ARRAY_SIZE(parameterTokens)] = { NULL };
vString *parameterTypes [ARRAY_SIZE (parameterTokens)] = { NULL };
unsigned int parameterCount = 0;
NestingLevel *lv;
int corkIndex;
Expand Down Expand Up @@ -967,7 +967,7 @@ static bool parseEnum (tokenInfo *const token)
}
else if (token->type == TOKEN_IDENTIFIER)
{
corkIndex = makeSimpleGDScriptTag(token, K_ENUM);
corkIndex = makeSimpleGDScriptTag (token, K_ENUM);
readToken (token);
}
else
Expand All @@ -982,7 +982,7 @@ static bool parseEnum (tokenInfo *const token)
while (token->type != '}' && token->type != TOKEN_EOF)
{
if (token->type == TOKEN_IDENTIFIER)
makeSimpleGDScriptTag(token, K_ENUMERATOR);
makeSimpleGDScriptTag (token, K_ENUMERATOR);
else if (token->type == '=')
{
/* Skip the right value. */
Expand Down Expand Up @@ -1030,7 +1030,8 @@ static bool parseClassName (tokenInfo *const token)
eFree ((void *)klass->name);
klass->name = name;
name = NULL;
unmarkTagExtraBit(klass, XTAG_ANONYMOUS);
unmarkTagExtraBit (klass, XTAG_ANONYMOUS);
unmarkTagExtraBit (klass, GDScriptXtagTable[X_IMPLICIT_CLASS].xtype);

/* Adjust the position. */
setTagPositionFromTag (klass, &e);
Expand All @@ -1054,7 +1055,7 @@ static bool parseClassName (tokenInfo *const token)
klass->extensionFields.inheritance = vStringStrdup (token->string);
}
else
e.extensionFields.inheritance = vStringValue(token->string);
e.extensionFields.inheritance = vStringValue (token->string);
}
}

Expand Down Expand Up @@ -1089,7 +1090,7 @@ static bool parseExtends (tokenInfo *const token)
{
if (klass->extensionFields.inheritance)
eFree ((void *)klass->extensionFields.inheritance);
klass->extensionFields.inheritance = vStringStrdup(token->string);
klass->extensionFields.inheritance = vStringStrdup (token->string);
}
}
}
Expand Down Expand Up @@ -1148,8 +1149,8 @@ static bool parseVariable (tokenInfo *const token, const gdscriptKind kind,
const stringList *const decorators,
const int keyword)
{
readToken(token);
vString *type = vStringNew();
readToken (token);
vString *type = vStringNew ();
tokenInfo *name = newToken ();
copyToken (name, token);
if (!name)
Expand All @@ -1166,7 +1167,7 @@ static bool parseVariable (tokenInfo *const token, const gdscriptKind kind,
readToken (token);

int index = makeSimpleGDScriptTag (name, kind);
deleteToken(name);
deleteToken (name);
tagEntryInfo *e = getEntryInCorkQueue (index);

if (e && decorators && stringListCount (decorators) > 0)
Expand All @@ -1177,22 +1178,22 @@ static bool parseVariable (tokenInfo *const token, const gdscriptKind kind,
vStringDelete (vstr);
}

vString *vtype = vStringNew();
vString *vtype = vStringNew ();
char * stype = vStringValue (type);
if (strcmp(stype, "=") && strcmp(stype, ""))
if (strcmp (stype, "=") && strcmp (stype, ""))
{
vStringCatS(vtype, stype);
vStringCatS (vtype, stype);
}
vStringDelete(type);
vStringDelete (type);

if (e && vStringLength(vtype) > 0) /// TODO: Fix types away
if (e && vStringLength (vtype) > 0) /// TODO: Fix types away
{
e->extensionFields.typeRef [0] = eStrdup ("typename");
e->extensionFields.typeRef [1] = vStringDeleteUnwrap (vtype);
}
else
{
vStringDelete(vtype);
vStringDelete (vtype);
}


Expand Down Expand Up @@ -1255,15 +1256,20 @@ static int prepareUnnamedClass (struct NestingLevels *nls)
static void findGDScriptTags (void)
{
tokenInfo *const token = newToken ();
stringList *decorators = stringListNew();
stringList *decorators = stringListNew ();
bool atStatementStart = true;

TokenContinuationDepth = 0;
NextToken = NULL;
GDScriptNestingLevels = nestingLevelsNew (sizeof (struct gdscriptNestingLevelUserData));

if (isXtagEnabled (GDScriptXtagTable[X_IMPLICIT_CLASS].xtype))
prepareUnnamedClass (GDScriptNestingLevels);
{
int index = prepareUnnamedClass (GDScriptNestingLevels);
tagEntryInfo *e = getEntryInCorkQueue (index);
if (e)
markTagExtraBit (e, GDScriptXtagTable[X_IMPLICIT_CLASS].xtype);
}

readToken (token);
while (token->type != TOKEN_EOF)
Expand All @@ -1285,7 +1291,7 @@ static void findGDScriptTags (void)
case KEYWORD_func: kind = K_METHOD; break;
case KEYWORD_signal: kind = K_SIGNAL; break;
default:
AssertNotReached();
AssertNotReached ();
}
readNext = parseClassOrDef (token, decorators, kind);
}
Expand Down Expand Up @@ -1325,7 +1331,7 @@ static void findGDScriptTags (void)
else if (token->type == TOKEN_KEYWORD
&& token->keyword == KEYWORD_modifier)
{
stringListAdd (decorators, vStringNewCopy(token->string));
stringListAdd (decorators, vStringNewCopy (token->string));
}
else if (token->type == '@' && atStatementStart &&
GDScriptFields[F_ANNOTATIONS].enabled)
Expand All @@ -1337,7 +1343,7 @@ static void findGDScriptTags (void)
readNext = false;
else
{
stringListAdd (decorators, vStringNewCopy(token->string));
stringListAdd (decorators, vStringNewCopy (token->string));
readToken (token);

vString *d = vStringNew ();
Expand Down Expand Up @@ -1402,8 +1408,8 @@ extern parserDefinition* GDScriptParser (void)
def->keywordCount = ARRAY_SIZE (GDScriptKeywordTable);
def->fieldTable = GDScriptFields;
def->fieldCount = ARRAY_SIZE (GDScriptFields);
def->xtagTable = GDScriptXtagTable;
def->xtagCount = ARRAY_SIZE(GDScriptXtagTable);
def->xtagTable = GDScriptXtagTable;
def->xtagCount = ARRAY_SIZE (GDScriptXtagTable);
def->useCork = CORK_QUEUE;
def->requestAutomaticFQTag = true;
return def;
Expand Down

0 comments on commit cc36e4f

Please sign in to comment.