Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
angle
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
angle
Commits
d4a9b8dd
Commit
d4a9b8dd
authored
Jul 18, 2013
by
Nicolas Capens
Committed by
Shannon Woods
Jul 19, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Detect redefinition of functions and variables.
TRAC #21840 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens
parent
1b45214a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
78 additions
and
36 deletions
+78
-36
ParseHelper.cpp
src/compiler/ParseHelper.cpp
+2
-1
SymbolTable.h
src/compiler/SymbolTable.h
+7
-2
glslang.y
src/compiler/glslang.y
+18
-0
glslang_tab.cpp
src/compiler/glslang_tab.cpp
+49
-31
glslang_tab.h
src/compiler/glslang_tab.h
+2
-2
No files found.
src/compiler/ParseHelper.cpp
View file @
d4a9b8dd
...
@@ -1008,8 +1008,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
...
@@ -1008,8 +1008,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
{
{
// First find by unmangled name to check whether the function name has been
// First find by unmangled name to check whether the function name has been
// hidden by a variable name or struct typename.
// hidden by a variable name or struct typename.
// If a function is found, check for one with a matching argument list.
const
TSymbol
*
symbol
=
symbolTable
.
find
(
call
->
getName
(),
shaderVersion
,
builtIn
);
const
TSymbol
*
symbol
=
symbolTable
.
find
(
call
->
getName
(),
shaderVersion
,
builtIn
);
if
(
symbol
==
0
)
{
if
(
symbol
==
0
||
symbol
->
isFunction
()
)
{
symbol
=
symbolTable
.
find
(
call
->
getMangledName
(),
shaderVersion
,
builtIn
);
symbol
=
symbolTable
.
find
(
call
->
getMangledName
(),
shaderVersion
,
builtIn
);
}
}
...
...
src/compiler/SymbolTable.h
View file @
d4a9b8dd
...
@@ -197,7 +197,7 @@ public:
...
@@ -197,7 +197,7 @@ public:
TSymbolTableLevel
()
{
}
TSymbolTableLevel
()
{
}
~
TSymbolTableLevel
();
~
TSymbolTableLevel
();
bool
insert
(
TSymbol
&
symbol
)
bool
insert
(
const
TString
&
name
,
TSymbol
&
symbol
)
{
{
symbol
.
setUniqueId
(
++
uniqueId
);
symbol
.
setUniqueId
(
++
uniqueId
);
...
@@ -205,11 +205,16 @@ public:
...
@@ -205,11 +205,16 @@ public:
// returning true means symbol was added to the table
// returning true means symbol was added to the table
//
//
tInsertResult
result
;
tInsertResult
result
;
result
=
level
.
insert
(
tLevelPair
(
symbol
.
getMangledName
()
,
&
symbol
));
result
=
level
.
insert
(
tLevelPair
(
name
,
&
symbol
));
return
result
.
second
;
return
result
.
second
;
}
}
bool
insert
(
TSymbol
&
symbol
)
{
return
insert
(
symbol
.
getMangledName
(),
symbol
);
}
TSymbol
*
find
(
const
TString
&
name
)
const
TSymbol
*
find
(
const
TString
&
name
)
const
{
{
tLevel
::
const_iterator
it
=
level
.
find
(
name
);
tLevel
::
const_iterator
it
=
level
.
find
(
name
);
...
...
src/compiler/glslang.y
View file @
d4a9b8dd
...
@@ -859,6 +859,24 @@ function_prototype
...
@@ -859,6 +859,24 @@ function_prototype
}
}
//
//
// Check for previously declared variables using the same name.
//
TSymbol *prevSym = context->symbolTable.find($1->getName(), context->shaderVersion);
if (prevSym)
{
if (!prevSym->isFunction())
{
context->error(@2, "redefinition", $1->getName().c_str(), "function");
context->recover();
}
}
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
context->symbolTable.getOuterLevel()->insert($1->getName(), *$1);
}
//
// If this is a redeclaration, it could also be a definition,
// If this is a redeclaration, it could also be a definition,
// in which case, we want to use the variable names from this one, and not the one that's
// in which case, we want to use the variable names from this one, and not the one that's
// being redeclared. So, pass back up this declaration, not the one in the symbol table.
// being redeclared. So, pass back up this declaration, not the one in the symbol table.
...
...
src/compiler/glslang_tab.cpp
View file @
d4a9b8dd
/* A Bison parser, made by GNU Bison 2.7.
12-4996.
*/
/* A Bison parser, made by GNU Bison 2.7. */
/* Bison implementation for Yacc-like parsers in C
/* Bison implementation for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-201
3
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-201
2
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
#define YYBISON 1
#define YYBISON 1
/* Bison version. */
/* Bison version. */
#define YYBISON_VERSION "2.7
.12-4996
"
#define YYBISON_VERSION "2.7"
/* Skeleton name. */
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
#define YYSKELETON_NAME "yacc.c"
...
@@ -448,14 +448,6 @@ typedef short int yytype_int16;
...
@@ -448,14 +448,6 @@ typedef short int yytype_int16;
# endif
# endif
#endif
#endif
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if (! defined __GNUC__ || __GNUC__ < 2 \
|| (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
# define __attribute__(Spec)
/* empty */
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
#if ! defined lint || defined __GNUC__
# define YYUSE(E) ((void) (E))
# define YYUSE(E) ((void) (E))
...
@@ -463,7 +455,6 @@ typedef short int yytype_int16;
...
@@ -463,7 +455,6 @@ typedef short int yytype_int16;
# define YYUSE(E)
/* empty */
# define YYUSE(E)
/* empty */
#endif
#endif
/* Identity function, used to suppress warnings about constant conditions. */
/* Identity function, used to suppress warnings about constant conditions. */
#ifndef lint
#ifndef lint
# define YYID(N) (N)
# define YYID(N) (N)
...
@@ -798,23 +789,23 @@ static const yytype_uint16 yyrline[] =
...
@@ -798,23 +789,23 @@ static const yytype_uint16 yyrline[] =
629
,
639
,
652
,
656
,
660
,
664
,
665
,
678
,
679
,
692
,
629
,
639
,
652
,
656
,
660
,
664
,
665
,
678
,
679
,
692
,
693
,
706
,
707
,
724
,
725
,
738
,
739
,
740
,
741
,
742
,
693
,
706
,
707
,
724
,
725
,
738
,
739
,
740
,
741
,
742
,
746
,
749
,
760
,
768
,
776
,
803
,
808
,
819
,
823
,
827
,
746
,
749
,
760
,
768
,
776
,
803
,
808
,
819
,
823
,
827
,
831
,
838
,
8
75
,
878
,
885
,
893
,
914
,
935
,
945
,
973
,
831
,
838
,
8
93
,
896
,
903
,
911
,
932
,
953
,
963
,
991
,
9
78
,
988
,
993
,
1003
,
1006
,
1009
,
1012
,
1018
,
1025
,
1028
,
9
96
,
1006
,
1011
,
1021
,
1024
,
1027
,
1030
,
1036
,
1043
,
1046
,
10
32
,
1036
,
1040
,
1047
,
1051
,
1055
,
1062
,
1066
,
1070
,
1091
,
10
50
,
1054
,
1058
,
1065
,
1069
,
1073
,
1080
,
1084
,
1088
,
1109
,
11
00
,
1106
,
1109
,
1115
,
1121
,
1128
,
1137
,
1146
,
1149
,
1185
,
11
18
,
1124
,
1127
,
1133
,
1139
,
1146
,
1155
,
1164
,
1167
,
1203
,
1
192
,
1196
,
1203
,
1206
,
1210
,
1214
,
1223
,
1232
,
1240
,
1250
,
1
210
,
1214
,
1221
,
1224
,
1228
,
1232
,
1241
,
1250
,
1258
,
1268
,
12
57
,
1260
,
1263
,
1269
,
1276
,
1279
,
1285
,
1288
,
1291
,
1297
,
12
75
,
1278
,
1281
,
1287
,
1294
,
1297
,
1303
,
1306
,
1309
,
1315
,
13
00
,
1315
,
1319
,
1323
,
1327
,
1331
,
1335
,
1340
,
1345
,
1350
,
13
18
,
1333
,
1337
,
1341
,
1345
,
1349
,
1353
,
1358
,
1363
,
1368
,
13
55
,
1360
,
1365
,
1370
,
1375
,
1380
,
1385
,
1390
,
1395
,
1400
,
13
73
,
1378
,
1383
,
1388
,
1393
,
1398
,
1403
,
1408
,
1413
,
1418
,
14
05
,
1410
,
1415
,
1420
,
1425
,
1430
,
1435
,
1440
,
1444
,
1448
,
14
23
,
1428
,
1433
,
1438
,
1443
,
1448
,
1453
,
1458
,
1462
,
1466
,
14
52
,
1456
,
1460
,
1464
,
1468
,
1472
,
1476
,
1480
,
1484
,
1488
,
14
70
,
1474
,
1478
,
1482
,
1486
,
1490
,
1494
,
1498
,
1502
,
1506
,
1
496
,
1504
,
1508
,
1521
,
1521
,
1524
,
1524
,
1530
,
1533
,
1549
,
1
514
,
1522
,
1526
,
1539
,
1539
,
1542
,
1542
,
1548
,
1551
,
1567
,
15
52
,
1561
,
1565
,
1571
,
1578
,
1593
,
1597
,
1601
,
1602
,
1608
,
15
70
,
1579
,
1583
,
1589
,
1596
,
1611
,
1615
,
1619
,
1620
,
1626
,
16
09
,
1610
,
1611
,
1612
,
1616
,
1617
,
1617
,
1617
,
1627
,
1628
,
16
27
,
1628
,
1629
,
1630
,
1634
,
1635
,
1635
,
1635
,
1645
,
1646
,
16
32
,
1632
,
1633
,
1633
,
1638
,
1641
,
1651
,
1654
,
1660
,
1661
,
16
50
,
1650
,
1651
,
1651
,
1656
,
1659
,
1669
,
1672
,
1678
,
1679
,
16
65
,
1673
,
1677
,
1687
,
1692
,
1709
,
1709
,
1714
,
1714
,
1721
,
16
83
,
1691
,
1695
,
1705
,
1710
,
1727
,
1727
,
1732
,
1732
,
1739
,
17
21
,
1729
,
1732
,
1738
,
1741
,
1747
,
1751
,
1758
,
1765
,
1772
,
17
39
,
1747
,
1750
,
1756
,
1759
,
1765
,
1769
,
1776
,
1783
,
1790
,
17
79
,
1790
,
1799
,
1803
,
1810
,
1813
,
1819
,
1819
17
97
,
1808
,
1817
,
1821
,
1828
,
1831
,
1837
,
1837
};
};
#endif
#endif
...
@@ -1798,7 +1789,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context)
...
@@ -1798,7 +1789,11 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, context)
# else
# else
YYUSE
(
yyoutput
);
YYUSE
(
yyoutput
);
# endif
# endif
YYUSE
(
yytype
);
switch
(
yytype
)
{
default
:
break
;
}
}
}
...
@@ -2198,7 +2193,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context)
...
@@ -2198,7 +2193,12 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, context)
yymsg
=
"Deleting"
;
yymsg
=
"Deleting"
;
YY_SYMBOL_PRINT
(
yymsg
,
yytype
,
yyvaluep
,
yylocationp
);
YY_SYMBOL_PRINT
(
yymsg
,
yytype
,
yyvaluep
,
yylocationp
);
YYUSE
(
yytype
);
switch
(
yytype
)
{
default
:
break
;
}
}
}
...
@@ -3387,6 +3387,24 @@ yyreduce:
...
@@ -3387,6 +3387,24 @@ yyreduce:
}
}
//
//
// Check for previously declared variables using the same name.
//
TSymbol
*
prevSym
=
context
->
symbolTable
.
find
((
yyvsp
[(
1
)
-
(
2
)].
interm
.
function
)
->
getName
(),
context
->
shaderVersion
);
if
(
prevSym
)
{
if
(
!
prevSym
->
isFunction
())
{
context
->
error
((
yylsp
[(
2
)
-
(
2
)]),
"redefinition"
,
(
yyvsp
[(
1
)
-
(
2
)].
interm
.
function
)
->
getName
().
c_str
(),
"function"
);
context
->
recover
();
}
}
else
{
// Insert the unmangled name to detect potential future redefinition as a variable.
context
->
symbolTable
.
getOuterLevel
()
->
insert
((
yyvsp
[(
1
)
-
(
2
)].
interm
.
function
)
->
getName
(),
*
(
yyvsp
[(
1
)
-
(
2
)].
interm
.
function
));
}
//
// If this is a redeclaration, it could also be a definition,
// If this is a redeclaration, it could also be a definition,
// in which case, we want to use the variable names from this one, and not the one that's
// in which case, we want to use the variable names from this one, and not the one that's
// being redeclared. So, pass back up this declaration, not the one in the symbol table.
// being redeclared. So, pass back up this declaration, not the one in the symbol table.
...
...
src/compiler/glslang_tab.h
View file @
d4a9b8dd
/* A Bison parser, made by GNU Bison 2.7.
12-4996.
*/
/* A Bison parser, made by GNU Bison 2.7. */
/* Bison interface for Yacc-like parsers in C
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-201
3
Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-201
2
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment