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
ba2cfe7c
Commit
ba2cfe7c
authored
Aug 14, 2013
by
Alok Priyadarshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved the definition of max-token length from preprocessor to compiler.
R=kbr@chromium.org Review URL:
https://codereview.appspot.com/12957043
parent
76985f3c
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
49 additions
and
36 deletions
+49
-36
glslang.l
src/compiler/glslang.l
+1
-0
glslang.y
src/compiler/glslang.y
+1
-0
glslang_lex.cpp
src/compiler/glslang_lex.cpp
+1
-0
glslang_tab.cpp
src/compiler/glslang_tab.cpp
+22
-21
glslang_tab.h
src/compiler/glslang_tab.h
+1
-0
Preprocessor.cpp
src/compiler/preprocessor/Preprocessor.cpp
+5
-0
Preprocessor.h
src/compiler/preprocessor/Preprocessor.h
+6
-0
Tokenizer.cpp
src/compiler/preprocessor/Tokenizer.cpp
+5
-7
Tokenizer.h
src/compiler/preprocessor/Tokenizer.h
+2
-1
Tokenizer.l
src/compiler/preprocessor/Tokenizer.l
+5
-7
No files found.
src/compiler/glslang.l
View file @
ba2cfe7c
...
@@ -321,6 +321,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
...
@@ -321,6 +321,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
// Initialize preprocessor.
// Initialize preprocessor.
if (!context->preprocessor.init(count, string, length))
if (!context->preprocessor.init(count, string, length))
return 1;
return 1;
context->preprocessor.setMaxTokenLength(SH_MAX_TOKEN_LENGTH);
// Define extension macros.
// Define extension macros.
const TExtensionBehavior& extBehavior = context->extensionBehavior();
const TExtensionBehavior& extBehavior = context->extensionBehavior();
...
...
src/compiler/glslang.y
View file @
ba2cfe7c
...
@@ -51,6 +51,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
...
@@ -51,6 +51,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
%code requires {
%code requires {
#define YYLTYPE TSourceLoc
#define YYLTYPE TSourceLoc
#define YYLTYPE_IS_DECLARED 1
#define YYLTYPE_IS_DECLARED 1
#define SH_MAX_TOKEN_LENGTH 256 // WebGL spec.
}
}
%union {
%union {
...
...
src/compiler/glslang_lex.cpp
View file @
ba2cfe7c
...
@@ -2930,6 +2930,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
...
@@ -2930,6 +2930,7 @@ int glslang_scan(size_t count, const char* const string[], const int length[],
// Initialize preprocessor.
// Initialize preprocessor.
if
(
!
context
->
preprocessor
.
init
(
count
,
string
,
length
))
if
(
!
context
->
preprocessor
.
init
(
count
,
string
,
length
))
return
1
;
return
1
;
context
->
preprocessor
.
setMaxTokenLength
(
SH_MAX_TOKEN_LENGTH
);
// Define extension macros.
// Define extension macros.
const
TExtensionBehavior
&
extBehavior
=
context
->
extensionBehavior
();
const
TExtensionBehavior
&
extBehavior
=
context
->
extensionBehavior
();
...
...
src/compiler/glslang_tab.cpp
View file @
ba2cfe7c
...
@@ -126,6 +126,7 @@ extern int yydebug;
...
@@ -126,6 +126,7 @@ extern int yydebug;
#define YYLTYPE TSourceLoc
#define YYLTYPE TSourceLoc
#define YYLTYPE_IS_DECLARED 1
#define YYLTYPE_IS_DECLARED 1
#define SH_MAX_TOKEN_LENGTH 256 // WebGL spec.
...
@@ -713,27 +714,27 @@ static const yytype_int16 yyrhs[] =
...
@@ -713,27 +714,27 @@ static const yytype_int16 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static
const
yytype_uint16
yyrline
[]
=
static
const
yytype_uint16
yyrline
[]
=
{
{
0
,
1
79
,
179
,
180
,
183
,
226
,
229
,
242
,
247
,
252
,
0
,
1
80
,
180
,
181
,
184
,
227
,
230
,
243
,
248
,
253
,
25
8
,
261
,
264
,
267
,
362
,
372
,
385
,
393
,
493
,
496
,
25
9
,
262
,
265
,
268
,
363
,
373
,
386
,
394
,
494
,
497
,
50
4
,
507
,
513
,
517
,
524
,
530
,
539
,
547
,
602
,
612
,
50
5
,
508
,
514
,
518
,
525
,
531
,
540
,
548
,
603
,
613
,
61
5
,
625
,
635
,
656
,
657
,
658
,
663
,
664
,
672
,
683
,
61
6
,
626
,
636
,
657
,
658
,
659
,
664
,
665
,
673
,
684
,
68
4
,
692
,
703
,
707
,
708
,
718
,
728
,
738
,
751
,
752
,
68
5
,
693
,
704
,
708
,
709
,
719
,
729
,
739
,
752
,
753
,
76
2
,
775
,
779
,
783
,
787
,
788
,
801
,
802
,
815
,
816
,
76
3
,
776
,
780
,
784
,
788
,
789
,
802
,
803
,
816
,
817
,
8
29
,
830
,
847
,
848
,
861
,
862
,
863
,
864
,
865
,
869
,
8
30
,
831
,
848
,
849
,
862
,
863
,
864
,
865
,
866
,
870
,
87
2
,
883
,
891
,
918
,
923
,
937
,
992
,
995
,
1002
,
1010
,
87
3
,
884
,
892
,
919
,
924
,
938
,
993
,
996
,
1003
,
1011
,
103
1
,
1052
,
1062
,
1090
,
1095
,
1105
,
1110
,
1120
,
1123
,
1126
,
103
2
,
1053
,
1063
,
1091
,
1096
,
1106
,
1111
,
1121
,
1124
,
1127
,
11
29
,
1135
,
1142
,
1145
,
1167
,
1185
,
1209
,
1232
,
1236
,
1254
,
11
30
,
1136
,
1143
,
1146
,
1168
,
1186
,
1210
,
1233
,
1237
,
1255
,
126
2
,
1294
,
1314
,
1335
,
1344
,
1367
,
1370
,
1376
,
1384
,
1392
,
126
3
,
1295
,
1315
,
1336
,
1345
,
1368
,
1371
,
1377
,
1385
,
1393
,
140
0
,
1410
,
1417
,
1420
,
1423
,
1429
,
1432
,
1447
,
1451
,
1455
,
140
1
,
1411
,
1418
,
1421
,
1424
,
1430
,
1433
,
1448
,
1452
,
1456
,
14
59
,
1463
,
1468
,
1473
,
1478
,
1483
,
1488
,
1493
,
1498
,
1503
,
14
60
,
1464
,
1469
,
1474
,
1479
,
1484
,
1489
,
1494
,
1499
,
1504
,
150
8
,
1513
,
1518
,
1523
,
1527
,
1531
,
1539
,
1547
,
1551
,
1564
,
150
9
,
1514
,
1519
,
1524
,
1528
,
1532
,
1540
,
1548
,
1552
,
1565
,
156
4
,
1578
,
1578
,
1587
,
1590
,
1606
,
1639
,
1643
,
1649
,
1656
,
156
5
,
1579
,
1579
,
1588
,
1591
,
1607
,
1640
,
1644
,
1650
,
1657
,
167
1
,
1675
,
1679
,
1680
,
1686
,
1687
,
1688
,
1689
,
1690
,
1694
,
167
2
,
1676
,
1680
,
1681
,
1687
,
1688
,
1689
,
1690
,
1691
,
1695
,
169
5
,
1695
,
1695
,
1705
,
1706
,
1710
,
1710
,
1711
,
1711
,
1716
,
169
6
,
1696
,
1696
,
1706
,
1707
,
1711
,
1711
,
1712
,
1712
,
1717
,
17
19
,
1729
,
1732
,
1738
,
1739
,
1743
,
1751
,
1755
,
1765
,
1770
,
17
20
,
1730
,
1733
,
1739
,
1740
,
1744
,
1752
,
1756
,
1766
,
1771
,
178
7
,
1787
,
1792
,
1792
,
1799
,
1799
,
1807
,
1810
,
1816
,
1819
,
178
8
,
1788
,
1793
,
1793
,
1800
,
1800
,
1808
,
1811
,
1817
,
1820
,
182
5
,
1829
,
1836
,
1843
,
1850
,
1857
,
1868
,
1877
,
1881
,
1888
,
182
6
,
1830
,
1837
,
1844
,
1851
,
1858
,
1869
,
1878
,
1882
,
1889
,
189
1
,
1897
,
1897
189
2
,
1898
,
1898
};
};
#endif
#endif
...
...
src/compiler/glslang_tab.h
View file @
ba2cfe7c
...
@@ -44,6 +44,7 @@ extern int yydebug;
...
@@ -44,6 +44,7 @@ extern int yydebug;
#define YYLTYPE TSourceLoc
#define YYLTYPE TSourceLoc
#define YYLTYPE_IS_DECLARED 1
#define YYLTYPE_IS_DECLARED 1
#define SH_MAX_TOKEN_LENGTH 256 // WebGL spec.
...
...
src/compiler/preprocessor/Preprocessor.cpp
View file @
ba2cfe7c
...
@@ -81,6 +81,11 @@ void Preprocessor::predefineMacro(const char* name, int value)
...
@@ -81,6 +81,11 @@ void Preprocessor::predefineMacro(const char* name, int value)
mImpl
->
macroSet
[
name
]
=
macro
;
mImpl
->
macroSet
[
name
]
=
macro
;
}
}
void
Preprocessor
::
setMaxTokenLength
(
size_t
maxLength
)
{
mImpl
->
tokenizer
.
setMaxTokenLength
(
maxLength
);
}
void
Preprocessor
::
lex
(
Token
*
token
)
void
Preprocessor
::
lex
(
Token
*
token
)
{
{
bool
validToken
=
false
;
bool
validToken
=
false
;
...
...
src/compiler/preprocessor/Preprocessor.h
View file @
ba2cfe7c
...
@@ -37,6 +37,12 @@ class Preprocessor
...
@@ -37,6 +37,12 @@ class Preprocessor
bool
init
(
size_t
count
,
const
char
*
const
string
[],
const
int
length
[]);
bool
init
(
size_t
count
,
const
char
*
const
string
[],
const
int
length
[]);
// Adds a pre-defined macro.
// Adds a pre-defined macro.
void
predefineMacro
(
const
char
*
name
,
int
value
);
void
predefineMacro
(
const
char
*
name
,
int
value
);
// Sets maximum allowed token length.
// If token length exceeds this limit,
// the token text will be truncated to the given maximum length, and
// TOKEN_TOO_LONG diagnostic will be generated.
// The maximum length defaults to 256.
void
setMaxTokenLength
(
size_t
maxLength
);
void
lex
(
Token
*
token
);
void
lex
(
Token
*
token
);
...
...
src/compiler/preprocessor/Tokenizer.cpp
View file @
ba2cfe7c
...
@@ -2290,11 +2290,9 @@ void ppfree (void * ptr , yyscan_t yyscanner)
...
@@ -2290,11 +2290,9 @@ void ppfree (void * ptr , yyscan_t yyscanner)
namespace
pp
{
namespace
pp
{
// TODO(alokp): Maximum token length should ideally be specified by
Tokenizer
::
Tokenizer
(
Diagnostics
*
diagnostics
)
// the preprocessor client, i.e., the compiler.
:
mHandle
(
0
),
const
size_t
Tokenizer
::
kMaxTokenLength
=
256
;
mMaxTokenLength
(
256
)
Tokenizer
::
Tokenizer
(
Diagnostics
*
diagnostics
)
:
mHandle
(
0
)
{
{
mContext
.
diagnostics
=
diagnostics
;
mContext
.
diagnostics
=
diagnostics
;
}
}
...
@@ -2327,11 +2325,11 @@ void Tokenizer::setLineNumber(int line)
...
@@ -2327,11 +2325,11 @@ void Tokenizer::setLineNumber(int line)
void
Tokenizer
::
lex
(
Token
*
token
)
void
Tokenizer
::
lex
(
Token
*
token
)
{
{
token
->
type
=
pplex
(
&
token
->
text
,
&
token
->
location
,
mHandle
);
token
->
type
=
pplex
(
&
token
->
text
,
&
token
->
location
,
mHandle
);
if
(
token
->
text
.
size
()
>
k
MaxTokenLength
)
if
(
token
->
text
.
size
()
>
m
MaxTokenLength
)
{
{
mContext
.
diagnostics
->
report
(
Diagnostics
::
TOKEN_TOO_LONG
,
mContext
.
diagnostics
->
report
(
Diagnostics
::
TOKEN_TOO_LONG
,
token
->
location
,
token
->
text
);
token
->
location
,
token
->
text
);
token
->
text
.
erase
(
k
MaxTokenLength
);
token
->
text
.
erase
(
m
MaxTokenLength
);
}
}
token
->
flags
=
0
;
token
->
flags
=
0
;
...
...
src/compiler/preprocessor/Tokenizer.h
View file @
ba2cfe7c
...
@@ -32,13 +32,13 @@ class Tokenizer : public Lexer
...
@@ -32,13 +32,13 @@ class Tokenizer : public Lexer
bool
leadingSpace
;
bool
leadingSpace
;
bool
lineStart
;
bool
lineStart
;
};
};
static
const
std
::
size_t
kMaxTokenLength
;
Tokenizer
(
Diagnostics
*
diagnostics
);
Tokenizer
(
Diagnostics
*
diagnostics
);
~
Tokenizer
();
~
Tokenizer
();
bool
init
(
size_t
count
,
const
char
*
const
string
[],
const
int
length
[]);
bool
init
(
size_t
count
,
const
char
*
const
string
[],
const
int
length
[]);
void
setMaxTokenLength
(
size_t
maxLength
)
{
mMaxTokenLength
=
maxLength
;
}
void
setFileNumber
(
int
file
);
void
setFileNumber
(
int
file
);
void
setLineNumber
(
int
line
);
void
setLineNumber
(
int
line
);
...
@@ -51,6 +51,7 @@ class Tokenizer : public Lexer
...
@@ -51,6 +51,7 @@ class Tokenizer : public Lexer
void
*
mHandle
;
// Scanner handle.
void
*
mHandle
;
// Scanner handle.
Context
mContext
;
// Scanner extra.
Context
mContext
;
// Scanner extra.
size_t
mMaxTokenLength
;
};
};
}
// namespace pp
}
// namespace pp
...
...
src/compiler/preprocessor/Tokenizer.l
View file @
ba2cfe7c
...
@@ -267,11 +267,9 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
...
@@ -267,11 +267,9 @@ FRACTIONAL_CONSTANT ({DIGIT}*"."{DIGIT}+)|({DIGIT}+".")
namespace pp {
namespace pp {
// TODO(alokp): Maximum token length should ideally be specified by
Tokenizer::Tokenizer(Diagnostics* diagnostics)
// the preprocessor client, i.e., the compiler.
: mHandle(0),
const size_t Tokenizer::kMaxTokenLength = 256;
mMaxTokenLength(256)
Tokenizer::Tokenizer(Diagnostics* diagnostics) : mHandle(0)
{
{
mContext.diagnostics = diagnostics;
mContext.diagnostics = diagnostics;
}
}
...
@@ -304,11 +302,11 @@ void Tokenizer::setLineNumber(int line)
...
@@ -304,11 +302,11 @@ void Tokenizer::setLineNumber(int line)
void Tokenizer::lex(Token* token)
void Tokenizer::lex(Token* token)
{
{
token->type = yylex(&token->text, &token->location, mHandle);
token->type = yylex(&token->text, &token->location, mHandle);
if (token->text.size() >
kMaxTokenLength)
if (token->text.size() >
mMaxTokenLength)
{
{
mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
mContext.diagnostics->report(Diagnostics::TOKEN_TOO_LONG,
token->location, token->text);
token->location, token->text);
token->text.erase(
kMaxTokenLength);
token->text.erase(
mMaxTokenLength);
}
}
token->flags = 0;
token->flags = 0;
...
...
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