Skip to content

Commit 134b907

Browse files
author
vlazzarini
committedNov 25, 2024
allowing wrong use of @global to be ignored (lhs) or raise a warning (rhs) instead of triggering a synterr
1 parent d2abf2e commit 134b907

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed
 

‎Engine/csound_orc.lex

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ int get_next_char(char *, int32_t, struct yyguts_t*);
7676
/* to avoid unused function errors */
7777
%option nounput
7878

79-
IDENT [a-zA-Z_][a-zA-Z0-9_]*
79+
IDENT [a-zA-Z_][a-zA-Z0-9_]*(@global)?
8080
IDENTB [a-zA-Z_][a-zA-Z0-9_]*\([ \t]*\n?
8181
TYPED_IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*(@global)?:[a-zA-Z_][a-zA-Z0-9_]*
8282
TYPED_IDENTIFIERB [a-zA-Z_][a-zA-Z0-9_]*:[a-zA-Z_][a-zA-Z0-9_]*\([ \t]*\n?

‎Engine/csound_orc_semantics.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
# define strtok_r strtok_s
4040
#endif
4141

42+
CS_VAR_POOL *find_global_annotation(char *varName, TYPE_TABLE* typeTable);
4243
extern char *csound_orcget_text ( void *scanner );
4344
static int32_t is_label(char* ident, CONS_CELL* labelList);
4445
extern uint64_t csound_orcget_locn(void *);
@@ -283,7 +284,7 @@ static int32_t isirate(/*CSOUND *csound,*/ TREE *t)
283284
CS_VARIABLE* find_var_from_pools(CSOUND* csound, char* varName,
284285
char* varBaseName, TYPE_TABLE* typeTable) {
285286
CS_VARIABLE* var = NULL;
286-
287+
287288
/* VL: 16/01/2014
288289
in a second compilation, the
289290
typeTable->globalPool is incorrect and will not
@@ -632,9 +633,13 @@ char* get_arg_type2(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable)
632633

633634
if (*s == '#')
634635
s++;
635-
636+
637+
// strip @global if it exists, it's a non-op here
638+
find_global_annotation(s, typeTable);
636639
// find the variable in one of the variable pools
637640
var = find_var_from_pools(csound, s, tree->value->lexeme, typeTable);
641+
642+
638643
if (UNLIKELY(var == NULL)) {
639644
synterr(csound, Str("get_arg_type2: Variable '%s' used before defined\n"
640645
"Line %d"),
@@ -1470,10 +1475,8 @@ int32_t check_args_exist(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable) {
14701475
return 1;
14711476
}
14721477

1473-
// For explicit types only (T_TYPED_IDENT)
1474-
// returns the correct pool and as side effect
1475-
// removes the global annotation
1476-
// from variable name.
1478+
// returns the correct pool (local or global) and as side effect
1479+
// removes the global annotation from variable name.
14771480
// Expected syntax: var@global
14781481
CS_VAR_POOL *find_global_annotation(char *varName, TYPE_TABLE* typeTable) {
14791482
CS_VAR_POOL* pool = typeTable->localPool;
@@ -1495,7 +1498,8 @@ CS_VAR_POOL *find_global_annotation(char *varName, TYPE_TABLE* typeTable) {
14951498
If the variable is found, a consistency check is made
14961499
to make sure the argument type matches the existing variable
14971500
*/
1498-
void add_arg(CSOUND* csound, char* varName, char* annotation, TYPE_TABLE* typeTable) {
1501+
void add_arg(CSOUND* csound, char* varName, char* annotation,
1502+
TYPE_TABLE* typeTable) {
14991503

15001504
const CS_TYPE* type;
15011505
CS_VARIABLE* var;
@@ -1509,11 +1513,16 @@ void add_arg(CSOUND* csound, char* varName, char* annotation, TYPE_TABLE* typeTa
15091513
var = find_var_from_pools(csound, varName, varName, typeTable);
15101514
if (var == NULL) {
15111515
if (annotation != NULL) {
1512-
// check for global annotation
1516+
// check for global annotation in explicit-type rhs vars
15131517
pool = find_global_annotation(varName, typeTable);
15141518
type = csoundGetTypeWithVarTypeName(csound->typePool, annotation);
15151519
typeArg = (void *) type;
15161520
} else {
1521+
// check for @global in implicit-type rhs vars
1522+
// and if found, strip it and print warning
1523+
if(find_global_annotation(varName, typeTable) == typeTable->globalPool)
1524+
csound->Warning(csound, "%s: @global annotation ignored", varName);
1525+
15171526
t = varName;
15181527
argLetter[1] = 0;
15191528

0 commit comments

Comments
 (0)
Please sign in to comment.