Files
francis.wang 4c86c082a2 Initial commit: OpenWrt-Yocto monorepo
Combine poky (Yocto scarthgap), meta-openembedded (scarthgap), and
meta-openwrt into a single repository.

Components:
- poky/             Yocto core framework (BitBake + OE-Core)
- meta-openembedded/ Community layers (meta-oe, meta-python, meta-networking)
- meta-openwrt/     OpenWrt customization layer
- setup-env.sh      One-click build environment setup
- README.md         Project documentation
2026-07-11 13:28:01 +08:00

413 lines
15 KiB
Diff

From b46c4c0c98dddd60cc017dc621fbbd596af1acdc Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Fri, 22 Jan 2016 09:02:19 +0000
Subject: [PATCH 1/2] sync lemon parser
Soured from
http://sourceforge.net/p/brlcad/code/HEAD/tree/brlcad/trunk/misc/tools/lemon/
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
Upstream-Status: Pending
contrib/lemon.c | 100 +++++++++++++++++++++++++++++--------------------------
contrib/lempar.c | 42 ++++++++++++++++++-----
2 files changed, 85 insertions(+), 57 deletions(-)
diff --git a/contrib/lemon.c b/contrib/lemon.c
index 85e94f7..89d992c 100644
--- a/contrib/lemon.c
+++ b/contrib/lemon.c
@@ -1114,7 +1114,6 @@ void FindActions(struct lemon *lemp)
/* Resolve conflicts */
for(i=0; i<lemp->nstate; i++){
struct action *ap, *nap;
- struct state *stp;
stp = lemp->sorted[i];
/* assert( stp->ap ); */
stp->ap = Action_sort(stp->ap);
@@ -1497,10 +1496,12 @@ int main(int argc, char **argv)
{OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
{OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
{OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
- {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
+ {OPT_FSTR, "f", 0, "Ignored. (Placeholder for -f compiler options.)"},
{OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
+ {OPT_FSTR, "I", 0, "Ignored. (Placeholder for '-I' compiler options.)"},
{OPT_FLAG, "m", (char*)&mhflag, "Output a makeheaders compatible file."},
{OPT_FLAG, "l", (char*)&nolinenosflag, "Do not print #line statements."},
+ {OPT_FSTR, "O", 0, "Ignored. (Placeholder for '-O' compiler options.)"},
{OPT_FLAG, "p", (char*)&showPrecedenceConflict,
"Show conflicts resolved by precedence rules"},
{OPT_FLAG, "q", (char*)&quiet, "(Quiet) Don't print the report file."},
@@ -1508,6 +1509,8 @@ int main(int argc, char **argv)
{OPT_FLAG, "s", (char*)&statistics,
"Print parser stats to standard output."},
{OPT_FLAG, "x", (char*)&version, "Print the version number."},
+ {OPT_FSTR, "T", (char*)handle_T_option, "Specify a template file."},
+ {OPT_FSTR, "W", 0, "Ignored. (Placeholder for '-W' compiler options.)"},
{OPT_FLAG,0,0,0}
};
int i;
@@ -1727,7 +1730,7 @@ static char *msort(
char *ep;
char *set[LISTSIZE];
int i;
- offset = (unsigned long)next - (unsigned long)list;
+ offset = (unsigned long)((char*)next - (char*)list);
for(i=0; i<LISTSIZE; i++) set[i] = 0;
while( list ){
ep = list;
@@ -1812,6 +1815,8 @@ static int handleflags(int i, FILE *err)
errline(i,1,err);
}
errcnt++;
+ }else if( op[j].arg==0 ){
+ /* Ignore this option */
}else if( op[j].type==OPT_FLAG ){
*((int*)op[j].arg) = v;
}else if( op[j].type==OPT_FFLAG ){
@@ -1869,7 +1874,7 @@ static int handleswitch(int i, FILE *err)
if( *end ){
if( err ){
fprintf(err,"%sillegal character in floating-point argument.\n",emsg);
- errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
+ errline(i,(int)((char*)end-(char*)argv[i]),err);
}
errcnt++;
}
@@ -1880,7 +1885,7 @@ static int handleswitch(int i, FILE *err)
if( *end ){
if( err ){
fprintf(err,"%sillegal character in integer argument.\n",emsg);
- errline(i,((unsigned long)end)-(unsigned long)argv[i],err);
+ errline(i,(int)((char*)end-(char*)argv[i]),err);
}
errcnt++;
}
@@ -2001,17 +2006,17 @@ void OptPrint(){
break;
case OPT_INT:
case OPT_FINT:
- fprintf(errstream," %s=<integer>%*s %s\n",op[i].label,
+ fprintf(errstream," -%s<integer>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-9),"",op[i].message);
break;
case OPT_DBL:
case OPT_FDBL:
- fprintf(errstream," %s=<real>%*s %s\n",op[i].label,
+ fprintf(errstream," -%s<real>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-6),"",op[i].message);
break;
case OPT_STR:
case OPT_FSTR:
- fprintf(errstream," %s=<string>%*s %s\n",op[i].label,
+ fprintf(errstream," -%s<string>%*s %s\n",op[i].label,
(int)(max-lemonStrlen(op[i].label)-8),"",op[i].message);
break;
}
@@ -2436,7 +2441,7 @@ to follow the previous rule.");
if( x[0]=='{' || x[0]=='\"' || isalnum(x[0]) ){
const char *zOld, *zNew;
char *zBuf, *z;
- int nOld, n, nLine, nNew, nBack;
+ int nOld, n, nLine = 0, nNew, nBack;
int addLineMacro;
char zLine[50];
zNew = x;
@@ -2635,7 +2640,7 @@ void Parse(struct lemon *gp)
struct pstate ps;
FILE *fp;
char *filebuf;
- int filesize;
+ unsigned int filesize;
int lineno;
int c;
char *cp, *nextcp;
@@ -2769,7 +2774,7 @@ void Parse(struct lemon *gp)
c = *cp;
*cp = 0; /* Null terminate the token */
parseonetoken(&ps); /* Parse the token */
- *cp = c; /* Restore the buffer */
+ *cp = (char)c; /* Restore the buffer */
cp = nextcp;
}
free(filebuf); /* Release the buffer after parsing */
@@ -3392,7 +3397,7 @@ PRIVATE char *append_str(const char *zText, int n, int p1, int p2){
zText++;
n--;
}else{
- z[used++] = c;
+ z[used++] = (char)c;
}
}
z[used] = 0;
@@ -3742,9 +3747,9 @@ void ReportTable(
/* Generate the include code, if any */
tplt_print(out,lemp,lemp->include,&lineno);
if( mhflag ){
- char *name = file_makename(lemp, ".h");
- fprintf(out,"#include \"%s\"\n", name); lineno++;
- free(name);
+ char *incName = file_makename(lemp, ".h");
+ fprintf(out,"#include \"%s\"\n", incName); lineno++;
+ free(incName);
}
tplt_xfer(lemp->name,in,out,&lineno);
@@ -3785,7 +3790,6 @@ void ReportTable(
}
name = lemp->name ? lemp->name : "Parse";
if( lemp->arg && lemp->arg[0] ){
- int i;
i = lemonStrlen(lemp->arg);
while( i>=1 && isspace(lemp->arg[i-1]) ) i--;
while( i>=1 && (isalnum(lemp->arg[i-1]) || lemp->arg[i-1]=='_') ) i--;
@@ -4473,18 +4477,18 @@ int Strsafe_insert(const char *data)
}
if( x1a->count>=x1a->size ){
/* Need to make the hash table bigger */
- int i,size;
+ int i,arrSize;
struct s_x1 array;
- array.size = size = x1a->size*2;
+ array.size = arrSize = x1a->size*2;
array.count = x1a->count;
- array.tbl = (x1node*)calloc(size, sizeof(x1node) + sizeof(x1node*));
+ array.tbl = (x1node*)calloc(arrSize, sizeof(x1node) + sizeof(x1node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
- array.ht = (x1node**)&(array.tbl[size]);
- for(i=0; i<size; i++) array.ht[i] = 0;
+ array.ht = (x1node**)&(array.tbl[arrSize]);
+ for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x1a->count; i++){
x1node *oldnp, *newnp;
oldnp = &(x1a->tbl[i]);
- h = strhash(oldnp->data) & (size-1);
+ h = strhash(oldnp->data) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
@@ -4640,18 +4644,18 @@ int Symbol_insert(struct symbol *data, const char *key)
}
if( x2a->count>=x2a->size ){
/* Need to make the hash table bigger */
- int i,size;
+ int i,arrSize;
struct s_x2 array;
- array.size = size = x2a->size*2;
+ array.size = arrSize = x2a->size*2;
array.count = x2a->count;
- array.tbl = (x2node*)calloc(size, sizeof(x2node) + sizeof(x2node*));
+ array.tbl = (x2node*)calloc(arrSize, sizeof(x2node) + sizeof(x2node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
- array.ht = (x2node**)&(array.tbl[size]);
- for(i=0; i<size; i++) array.ht[i] = 0;
+ array.ht = (x2node**)&(array.tbl[arrSize]);
+ for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x2a->count; i++){
x2node *oldnp, *newnp;
oldnp = &(x2a->tbl[i]);
- h = strhash(oldnp->key) & (size-1);
+ h = strhash(oldnp->key) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
@@ -4716,12 +4720,12 @@ int Symbol_count()
struct symbol **Symbol_arrayof()
{
struct symbol **array;
- int i,size;
+ int i,arrSize;
if( x2a==0 ) return 0;
- size = x2a->count;
- array = (struct symbol **)calloc(size, sizeof(struct symbol *));
+ arrSize = x2a->count;
+ array = (struct symbol **)calloc(arrSize, sizeof(struct symbol *));
if( array ){
- for(i=0; i<size; i++) array[i] = x2a->tbl[i].data;
+ for(i=0; i<arrSize; i++) array[i] = x2a->tbl[i].data;
}
return array;
}
@@ -4837,18 +4841,18 @@ int State_insert(struct state *data, struct config *key)
}
if( x3a->count>=x3a->size ){
/* Need to make the hash table bigger */
- int i,size;
+ int i,arrSize;
struct s_x3 array;
- array.size = size = x3a->size*2;
+ array.size = arrSize = x3a->size*2;
array.count = x3a->count;
- array.tbl = (x3node*)calloc(size, sizeof(x3node) + sizeof(x3node*));
+ array.tbl = (x3node*)calloc(arrSize, sizeof(x3node) + sizeof(x3node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
- array.ht = (x3node**)&(array.tbl[size]);
- for(i=0; i<size; i++) array.ht[i] = 0;
+ array.ht = (x3node**)&(array.tbl[arrSize]);
+ for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x3a->count; i++){
x3node *oldnp, *newnp;
oldnp = &(x3a->tbl[i]);
- h = statehash(oldnp->key) & (size-1);
+ h = statehash(oldnp->key) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
@@ -4895,12 +4899,12 @@ struct state *State_find(struct config *key)
struct state **State_arrayof()
{
struct state **array;
- int i,size;
+ int i,arrSize;
if( x3a==0 ) return 0;
- size = x3a->count;
- array = (struct state **)calloc(size, sizeof(struct state *));
+ arrSize = x3a->count;
+ array = (struct state **)calloc(arrSize, sizeof(struct state *));
if( array ){
- for(i=0; i<size; i++) array[i] = x3a->tbl[i].data;
+ for(i=0; i<arrSize; i++) array[i] = x3a->tbl[i].data;
}
return array;
}
@@ -4977,18 +4981,18 @@ int Configtable_insert(struct config *data)
}
if( x4a->count>=x4a->size ){
/* Need to make the hash table bigger */
- int i,size;
+ int i,arrSize;
struct s_x4 array;
- array.size = size = x4a->size*2;
+ array.size = arrSize = x4a->size*2;
array.count = x4a->count;
- array.tbl = (x4node*)calloc(size, sizeof(x4node) + sizeof(x4node*));
+ array.tbl = (x4node*)calloc(arrSize, sizeof(x4node) + sizeof(x4node*));
if( array.tbl==0 ) return 0; /* Fail due to malloc failure */
- array.ht = (x4node**)&(array.tbl[size]);
- for(i=0; i<size; i++) array.ht[i] = 0;
+ array.ht = (x4node**)&(array.tbl[arrSize]);
+ for(i=0; i<arrSize; i++) array.ht[i] = 0;
for(i=0; i<x4a->count; i++){
x4node *oldnp, *newnp;
oldnp = &(x4a->tbl[i]);
- h = confighash(oldnp->data) & (size-1);
+ h = confighash(oldnp->data) & (arrSize-1);
newnp = &(array.tbl[i]);
if( array.ht[h] ) array.ht[h]->from = &(newnp->next);
newnp->next = array.ht[h];
diff --git a/contrib/lempar.c b/contrib/lempar.c
index fe56d2d..21d4e50 100644
--- a/contrib/lempar.c
+++ b/contrib/lempar.c
@@ -4,6 +4,7 @@
/* First off, code is included that follows the "include" declaration
** in the input grammar file. */
#include <stdio.h>
+#include <assert.h>
%%
/* Next is all token values, in a form suitable for use by makeheaders.
** This section will be null unless lemon is run with the -m switch.
@@ -238,7 +239,7 @@ static void yyGrowStack(yyParser *p){
int newSize;
yyStackEntry *pNew;
- newSize = p->yystksz*2 + 100;
+ newSize = p->yystksz*2 + 256;
pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
if( pNew ){
p->yystack = pNew;
@@ -305,8 +306,12 @@ static void yy_destructor(
** inside the C code.
*/
%%
- default: break; /* If no destructor action specified: do nothing */
+ default:
+ if (!yypminor)
+ return;
+ break; /* If no destructor action specified: do nothing */
}
+ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
/*
@@ -319,9 +324,12 @@ static void yy_destructor(
*/
static int yy_pop_parser_stack(yyParser *pParser){
YYCODETYPE yymajor;
- yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
+ yyStackEntry *yytos;
if( pParser->yyidx<0 ) return 0;
+
+ yytos = &pParser->yystack[pParser->yyidx];
+
#ifndef NDEBUG
if( yyTraceFILE && pParser->yyidx>=0 ){
fprintf(yyTraceFILE,"%sPopping %s\n",
@@ -483,9 +491,11 @@ static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
#endif
while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
/* Here code is inserted which will execute if the parser
- ** stack every overflows */
+ ** stack ever overflows */
%%
ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
+ yypMinor = NULL; /* quellage */
+ assert(yypMinor == NULL);
}
/*
@@ -560,14 +570,23 @@ static void yy_reduce(
yyStackEntry *yymsp; /* The top of the parser's stack */
int yysize; /* Amount to pop the stack */
ParseARG_FETCH;
+
yymsp = &yypParser->yystack[yypParser->yyidx];
+
+ if( yyruleno>=0 ) {
#ifndef NDEBUG
- if( yyTraceFILE && yyruleno>=0
- && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
- fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
- yyRuleName[yyruleno]);
- }
+ if ( yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0]))) {
+ if (yyTraceFILE) {
+ fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
+ yyRuleName[yyruleno]);
+ }
+ }
#endif /* NDEBUG */
+ } else {
+ /* invalid rule number range */
+ return;
+ }
+
/* Silence complaints from purify about yygotominor being uninitialized
** in some cases when it is copied into the stack after the following
@@ -623,6 +642,8 @@ static void yy_reduce(
assert( yyact == YYNSTATE + YYNRULE + 1 );
yy_accept(yypParser);
}
+
+ ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
}
/*
@@ -658,6 +679,9 @@ static void yy_syntax_error(
#define TOKEN (yyminor.yy0)
%%
ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
+ yymajor = 0; /* quellage */
+ yyminor.yyinit = 0; /* quellage */
+ assert(yymajor == 0 && yyminor.yyinit == 0);
}
/*
--
2.7.0