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
d4ceab12
Commit
d4ceab12
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
5d1cffdc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
18 deletions
+60
-18
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_lex.cpp
src/compiler/glslang_lex.cpp
+1
-1
glslang_tab.cpp
src/compiler/glslang_tab.cpp
+32
-14
No files found.
src/compiler/ParseHelper.cpp
View file @
d4ceab12
...
...
@@ -907,8 +907,9 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
{
// First find by unmangled name to check whether the function name has been
// 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
(),
builtIn
);
if
(
symbol
==
0
)
{
if
(
symbol
==
0
||
symbol
->
isFunction
()
)
{
symbol
=
symbolTable
.
find
(
call
->
getMangledName
(),
builtIn
);
}
...
...
src/compiler/SymbolTable.h
View file @
d4ceab12
...
...
@@ -190,17 +190,22 @@ public:
TSymbolTableLevel
()
{
}
~
TSymbolTableLevel
();
bool
insert
(
TSymbol
&
symbol
)
bool
insert
(
const
TString
&
name
,
TSymbol
&
symbol
)
{
//
// returning true means symbol was added to the table
//
tInsertResult
result
;
result
=
level
.
insert
(
tLevelPair
(
symbol
.
getMangledName
()
,
&
symbol
));
result
=
level
.
insert
(
tLevelPair
(
name
,
&
symbol
));
return
result
.
second
;
}
bool
insert
(
TSymbol
&
symbol
)
{
return
insert
(
symbol
.
getMangledName
(),
symbol
);
}
TSymbol
*
find
(
const
TString
&
name
)
const
{
tLevel
::
const_iterator
it
=
level
.
find
(
name
);
...
...
src/compiler/glslang.y
View file @
d4ceab12
...
...
@@ -1030,6 +1030,24 @@ function_prototype
}
//
// Check for previously declared variables using the same name.
//
TSymbol *prevSym = context->symbolTable.find($1->getName());
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,
// 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.
...
...
src/compiler/glslang_lex.cpp
View file @
d4ceab12
...
...
@@ -2097,7 +2097,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner)
case
EOB_ACT_END_OF_FILE
:
{
if
(
yywrap
(
yyscanner
)
)
return
0
;
return
EOF
;
if
(
!
yyg
->
yy_did_buffer_switch_on_eof
)
YY_NEW_FILE
;
...
...
src/compiler/glslang_tab.cpp
View file @
d4ceab12
...
...
@@ -720,20 +720,20 @@ static const yytype_uint16 yyrline[] =
756
,
764
,
775
,
779
,
780
,
790
,
800
,
810
,
823
,
824
,
834
,
847
,
851
,
855
,
859
,
860
,
873
,
874
,
887
,
888
,
901
,
902
,
919
,
920
,
933
,
934
,
935
,
936
,
937
,
941
,
944
,
955
,
963
,
990
,
995
,
1009
,
10
46
,
1049
,
1056
,
1064
,
1
085
,
1106
,
1116
,
1144
,
1149
,
1159
,
1164
,
1174
,
1177
,
1180
,
1
183
,
1189
,
1196
,
1199
,
1221
,
1239
,
1263
,
1286
,
1290
,
1308
,
13
16
,
1348
,
1368
,
1389
,
1398
,
1421
,
1424
,
1430
,
1438
,
1446
,
14
54
,
1464
,
1471
,
1474
,
1477
,
1483
,
1486
,
1501
,
1505
,
1509
,
15
13
,
1517
,
1522
,
1527
,
1532
,
1537
,
1542
,
1547
,
1552
,
1557
,
15
62
,
1567
,
1572
,
1577
,
1581
,
1585
,
1593
,
1601
,
1605
,
1618
,
16
18
,
1632
,
1632
,
1641
,
1644
,
1660
,
1693
,
1697
,
1703
,
1710
,
17
25
,
1729
,
1733
,
1734
,
1740
,
1741
,
1742
,
1743
,
1744
,
1748
,
17
49
,
1749
,
1749
,
1759
,
1760
,
1764
,
1764
,
1765
,
1765
,
1770
,
17
73
,
1783
,
1786
,
1792
,
1793
,
1797
,
1805
,
1809
,
1819
,
1824
,
18
41
,
1841
,
1846
,
1846
,
1853
,
1853
,
1861
,
1864
,
1870
,
1873
,
18
79
,
1883
,
1890
,
1897
,
1904
,
1911
,
1922
,
1931
,
1935
,
1942
,
19
45
,
1951
,
1951
944
,
955
,
963
,
990
,
995
,
1009
,
10
64
,
1067
,
1074
,
1082
,
1
103
,
1124
,
1134
,
1162
,
1167
,
1177
,
1182
,
1192
,
1195
,
1198
,
1
201
,
1207
,
1214
,
1217
,
1239
,
1257
,
1281
,
1304
,
1308
,
1326
,
13
34
,
1366
,
1386
,
1407
,
1416
,
1439
,
1442
,
1448
,
1456
,
1464
,
14
72
,
1482
,
1489
,
1492
,
1495
,
1501
,
1504
,
1519
,
1523
,
1527
,
15
31
,
1535
,
1540
,
1545
,
1550
,
1555
,
1560
,
1565
,
1570
,
1575
,
15
80
,
1585
,
1590
,
1595
,
1599
,
1603
,
1611
,
1619
,
1623
,
1636
,
16
36
,
1650
,
1650
,
1659
,
1662
,
1678
,
1711
,
1715
,
1721
,
1728
,
17
43
,
1747
,
1751
,
1752
,
1758
,
1759
,
1760
,
1761
,
1762
,
1766
,
17
67
,
1767
,
1767
,
1777
,
1778
,
1782
,
1782
,
1783
,
1783
,
1788
,
17
91
,
1801
,
1804
,
1810
,
1811
,
1815
,
1823
,
1827
,
1837
,
1842
,
18
59
,
1859
,
1864
,
1864
,
1871
,
1871
,
1879
,
1882
,
1888
,
1891
,
18
97
,
1901
,
1908
,
1915
,
1922
,
1929
,
1940
,
1949
,
1953
,
1960
,
19
63
,
1969
,
1969
};
#endif
...
...
@@ -3285,6 +3285,24 @@ yyreduce:
}
//
// Check for previously declared variables using the same name.
//
TSymbol
*
prevSym
=
context
->
symbolTable
.
find
((
yyvsp
[(
1
)
-
(
2
)].
interm
.
function
)
->
getName
());
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,
// 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.
...
...
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