Skip to content

Commit 5e3ed3a

Browse files
committed
wip on adding some missing struct features
1 parent 6eafb4f commit 5e3ed3a

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

frontends/spin/spin.y

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,15 @@ conline:
11931193
AddSymbol(currentTypes, GetUserIdentifierName(ident), SYM_TYPEDEF, typ, NULL);
11941194
$$ = NULL;
11951195
}
1196+
| SP_STRUCT SP_IDENTIFIER '=' structname SP_EOLN
1197+
{
1198+
/* basically a type alias*/
1199+
AST *oldtype = $4;
1200+
AST *ident = $2;
1201+
const char *name = GetUserIdentifierName(ident);
1202+
AddSymbol(currentTypes, name, SYM_TYPEDEF, oldtype, NULL);
1203+
$$ = NULL;
1204+
}
11961205
| SP_EOLN
11971206
{ $$ = NULL; }
11981207
| error SP_EOLN
@@ -1234,7 +1243,7 @@ structitem:
12341243
{
12351244
$$ = NewAST(AST_DECLARE_VAR, MaybeArrayType(ast_type_long64, $3), $2);
12361245
}
1237-
| SP_TYPENAME SP_IDENTIFIER optarray
1246+
| structname SP_IDENTIFIER optarray
12381247
{
12391248
AST *name = $2;
12401249
AST *typname = $1;
@@ -1307,6 +1316,15 @@ datline:
13071316
idast = NewAST(AST_LISTHOLDER, linebreak, idast);
13081317
$$ = idast;
13091318
}
1319+
| identifier structname
1320+
{
1321+
AST *ident = $1;
1322+
AST *typ = $2;
1323+
AST *var;
1324+
1325+
var = NewAST(AST_DECLARE_VAR, typ, ident);
1326+
$$ = NewAST(AST_LISTHOLDER, var, NULL);
1327+
}
13101328
;
13111329

13121330
basedatline:
@@ -1536,7 +1554,7 @@ varline:
15361554
{ $$ = NewAST(AST_WORDLIST, $2, NULL); }
15371555
| SP_LONG identlist SP_EOLN
15381556
{ $$ = NewAST(AST_LONGLIST, $2, NULL); }
1539-
| SP_TYPENAME identlist SP_EOLN
1557+
| structname identlist SP_EOLN
15401558
{
15411559
AST *typ = $1;
15421560
AST *decllist = $2;
@@ -1586,7 +1604,7 @@ vardecl:
15861604
{ $$ = NewAST(AST_DECLARE_VAR, NULL, $2); }
15871605
| SP_QUAD identdecl
15881606
{ $$ = NewAST(AST_DECLARE_VAR, ast_type_long64, $2); }
1589-
| SP_TYPENAME identdecl
1607+
| structname identdecl
15901608
{ $$ = NewAST(AST_DECLARE_VAR, $1, $2); }
15911609
;
15921610

@@ -2727,6 +2745,13 @@ modifierlist:
27272745
{ $$ = AddToList($1, $3); }
27282746
;
27292747

2748+
structname:
2749+
SP_TYPENAME
2750+
{ $$ = $1; }
2751+
| structname '.' identifier
2752+
{
2753+
SYNTAX_ERROR("module types not supported yet");
2754+
}
27302755
%%
27312756

27322757
void

0 commit comments

Comments
 (0)