mirror of
https://github.com/linux-msm/qmic.git
synced 2024-11-23 09:44:06 +08:00
parser: introduce symbol_find()
Create a new helper function symbol_find() that determines whether there exists a defined symbol having the given name. It returns a pointer to the symbol structure is returned if one exists, or a null pointer otherwise. Signed-off-by: Alex Elder <elder@linaro.org> Message-Id: <20211001232338.769309-31-elder@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
parent
734ecff5a5
commit
b793b576ff
30
parser.c
30
parser.c
@ -119,10 +119,19 @@ struct symbol {
|
||||
|
||||
static struct list_head symbols = LIST_INIT(symbols);
|
||||
|
||||
static struct symbol *symbol_find(const char *name)
|
||||
{
|
||||
struct symbol *sym;
|
||||
|
||||
list_for_each_entry(sym, &symbols, node)
|
||||
if (!strcmp(name, sym->name))
|
||||
return sym;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool symbol_valid(const char *name)
|
||||
{
|
||||
const char *p = name;
|
||||
struct symbol *sym;
|
||||
char ch;
|
||||
|
||||
/* Symbol name must start with an alphabetic character */
|
||||
@ -139,9 +148,8 @@ static bool symbol_valid(const char *name)
|
||||
return 0;
|
||||
|
||||
/* Finally, symbol names must be unique */
|
||||
list_for_each_entry(sym, &symbols, node)
|
||||
if (!strcmp(name, sym->name))
|
||||
return false;
|
||||
if (symbol_find(name))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -233,10 +241,8 @@ static struct token yylex()
|
||||
if (!token.str)
|
||||
yyerror("strdup() failed in %s(), line %d\n",
|
||||
__func__, __LINE__);
|
||||
list_for_each_entry(sym, &symbols, node) {
|
||||
if (strcmp(buf, sym->name))
|
||||
continue;
|
||||
|
||||
sym = symbol_find(token.str);
|
||||
if (sym) {
|
||||
token.id = sym->token_id;
|
||||
switch (token.id) {
|
||||
case TOK_MESSAGE:
|
||||
@ -247,14 +253,12 @@ static struct token yylex()
|
||||
token.qmi_struct = sym->qmi_struct;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break; /* Others just have id and string */
|
||||
}
|
||||
|
||||
return token;
|
||||
} else {
|
||||
token.id = TOK_ID; /* Just an identifier */
|
||||
}
|
||||
|
||||
token.id = TOK_ID;
|
||||
|
||||
return token;
|
||||
} else if (isdigit(ch)) {
|
||||
/* Determine base and valid character set */
|
||||
|
Loading…
Reference in New Issue
Block a user