Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
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
glslang
Commits
4ee2f752
Commit
4ee2f752
authored
Nov 07, 2018
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PP: More clearly distinguish funtion-like and object-like macros
parent
0a339ec2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
15 deletions
+17
-15
cppSimple.vert.out
Test/baseResults/cppSimple.vert.out
+3
-3
cppSimple.vert
Test/cppSimple.vert
+2
-2
Pp.cpp
glslang/MachineIndependent/preprocessor/Pp.cpp
+8
-6
PpContext.h
glslang/MachineIndependent/preprocessor/PpContext.h
+4
-4
No files found.
Test/baseResults/cppSimple.vert.out
View file @
4ee2f752
...
@@ -35,9 +35,9 @@ ERROR: 0:155: '#else' : unexpected tokens following directive
...
@@ -35,9 +35,9 @@ ERROR: 0:155: '#else' : unexpected tokens following directive
ERROR: 0:158: '#else' : #else after #else
ERROR: 0:158: '#else' : #else after #else
ERROR: 0:160: '#endif' : unexpected tokens following directive
ERROR: 0:160: '#endif' : unexpected tokens following directive
ERROR: 0:164: '#define' : duplicate macro parameter
ERROR: 0:164: '#define' : duplicate macro parameter
ERROR: 0:173: '#define' : Macro redefined;
different number of arguments
: m4
ERROR: 0:173: '#define' : Macro redefined;
function-like versus object-like
: m4
ERROR: 0:17
8: '#define' : Macro redefined; different number of arguments
: m5
ERROR: 0:17
7: '#define' : Macro redefined; function-like versus object-like
: m5
ERROR: 0:18
2
: '#define' : Macro redefined; different number of arguments: m6
ERROR: 0:18
1
: '#define' : Macro redefined; different number of arguments: m6
ERROR: 0:185: '#define' : Macro redefined; different substitutions: m7
ERROR: 0:185: '#define' : Macro redefined; different substitutions: m7
ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8
ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8
ERROR: 0:196: '#define' : Macro redefined; different argument names: m9
ERROR: 0:196: '#define' : Macro redefined; different argument names: m9
...
...
Test/cppSimple.vert
100644 → 100755
View file @
4ee2f752
...
@@ -170,7 +170,7 @@ int a = length("aoenatuh"); // ERROR
...
@@ -170,7 +170,7 @@ int a = length("aoenatuh"); // ERROR
// ERROR
// ERROR
#define m4(b)
#define m4(b)
#define m4
(b)
#define m4
// ERROR
// ERROR
#define m5 (b)
#define m5 (b)
...
@@ -178,7 +178,7 @@ int a = length("aoenatuh"); // ERROR
...
@@ -178,7 +178,7 @@ int a = length("aoenatuh"); // ERROR
// ERROR
// ERROR
#define m6(a)
#define m6(a)
#define m6
#define m6
(a,b)
// ERROR (whitespace)
// ERROR (whitespace)
#define m7 (a)
#define m7 (a)
...
...
glslang/MachineIndependent/preprocessor/Pp.cpp
View file @
4ee2f752
...
@@ -109,11 +109,12 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
...
@@ -109,11 +109,12 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
// save the macro name
// save the macro name
const
int
defAtom
=
atomStrings
.
getAddAtom
(
ppToken
->
name
);
const
int
defAtom
=
atomStrings
.
getAddAtom
(
ppToken
->
name
);
TSourceLoc
defineLoc
=
ppToken
->
loc
;
// because ppToken might go to the next line before we report errors
// gather parameters to the macro, between (...)
// gather parameters to the macro, between (...)
token
=
scanToken
(
ppToken
);
token
=
scanToken
(
ppToken
);
if
(
token
==
'('
&&
!
ppToken
->
space
)
{
if
(
token
==
'('
&&
!
ppToken
->
space
)
{
mac
.
emptyArgs
=
1
;
mac
.
functionLike
=
1
;
do
{
do
{
token
=
scanToken
(
ppToken
);
token
=
scanToken
(
ppToken
);
if
(
mac
.
args
.
size
()
==
0
&&
token
==
')'
)
if
(
mac
.
args
.
size
()
==
0
&&
token
==
')'
)
...
@@ -123,7 +124,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
...
@@ -123,7 +124,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
return
token
;
return
token
;
}
}
mac
.
emptyArgs
=
0
;
const
int
argAtom
=
atomStrings
.
getAddAtom
(
ppToken
->
name
);
const
int
argAtom
=
atomStrings
.
getAddAtom
(
ppToken
->
name
);
// check for duplication of parameter name
// check for duplication of parameter name
...
@@ -149,7 +149,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
...
@@ -149,7 +149,6 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
}
}
// record the definition of the macro
// record the definition of the macro
TSourceLoc
defineLoc
=
ppToken
->
loc
;
// because ppToken is going to go to the next line before we report errors
while
(
token
!=
'\n'
&&
token
!=
EndOfInput
)
{
while
(
token
!=
'\n'
&&
token
!=
EndOfInput
)
{
mac
.
body
.
putToken
(
token
,
ppToken
);
mac
.
body
.
putToken
(
token
,
ppToken
);
token
=
scanToken
(
ppToken
);
token
=
scanToken
(
ppToken
);
...
@@ -164,7 +163,9 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
...
@@ -164,7 +163,9 @@ int TPpContext::CPPdefine(TPpToken* ppToken)
// Already defined -- need to make sure they are identical:
// Already defined -- need to make sure they are identical:
// "Two replacement lists are identical if and only if the preprocessing tokens in both have the same number,
// "Two replacement lists are identical if and only if the preprocessing tokens in both have the same number,
// ordering, spelling, and white-space separation, where all white-space separations are considered identical."
// ordering, spelling, and white-space separation, where all white-space separations are considered identical."
if
(
existing
->
args
.
size
()
!=
mac
.
args
.
size
()
||
existing
->
emptyArgs
!=
mac
.
emptyArgs
)
if
(
existing
->
functionLike
!=
mac
.
functionLike
)
parseContext
.
ppError
(
defineLoc
,
"Macro redefined; function-like versus object-like:"
,
"#define"
,
atomStrings
.
getString
(
defAtom
));
else
if
(
existing
->
args
.
size
()
!=
mac
.
args
.
size
())
parseContext
.
ppError
(
defineLoc
,
"Macro redefined; different number of arguments:"
,
"#define"
,
atomStrings
.
getString
(
defAtom
));
parseContext
.
ppError
(
defineLoc
,
"Macro redefined; different number of arguments:"
,
"#define"
,
atomStrings
.
getString
(
defAtom
));
else
{
else
{
if
(
existing
->
args
!=
mac
.
args
)
if
(
existing
->
args
!=
mac
.
args
)
...
@@ -1190,13 +1191,14 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
...
@@ -1190,13 +1191,14 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
TSourceLoc
loc
=
ppToken
->
loc
;
// in case we go to the next line before discovering the error
TSourceLoc
loc
=
ppToken
->
loc
;
// in case we go to the next line before discovering the error
in
->
mac
=
macro
;
in
->
mac
=
macro
;
if
(
macro
->
args
.
size
()
>
0
||
macro
->
emptyArgs
)
{
if
(
macro
->
functionLike
)
{
int
token
=
scanToken
(
ppToken
);
int
token
=
scanToken
(
ppToken
);
if
(
newLineOkay
)
{
if
(
newLineOkay
)
{
while
(
token
==
'\n'
)
while
(
token
==
'\n'
)
token
=
scanToken
(
ppToken
);
token
=
scanToken
(
ppToken
);
}
}
if
(
token
!=
'('
)
{
if
(
token
!=
'('
)
{
// function-like macro called with object-like syntax: okay, don't expand
UngetToken
(
token
,
ppToken
);
UngetToken
(
token
,
ppToken
);
delete
in
;
delete
in
;
return
MacroExpandNotStarted
;
return
MacroExpandNotStarted
;
...
...
glslang/MachineIndependent/preprocessor/PpContext.h
View file @
4ee2f752
...
@@ -267,12 +267,12 @@ public:
...
@@ -267,12 +267,12 @@ public:
//
//
struct
MacroSymbol
{
struct
MacroSymbol
{
MacroSymbol
()
:
emptyArgs
(
0
),
busy
(
0
),
undef
(
0
)
{
}
MacroSymbol
()
:
functionLike
(
0
),
busy
(
0
),
undef
(
0
)
{
}
TVector
<
int
>
args
;
TVector
<
int
>
args
;
TokenStream
body
;
TokenStream
body
;
unsigned
emptyArgs
:
1
;
unsigned
functionLike
:
1
;
// 0 means object-like, 1 means function-like
unsigned
busy
:
1
;
unsigned
busy
:
1
;
unsigned
undef
:
1
;
unsigned
undef
:
1
;
};
};
typedef
TMap
<
int
,
MacroSymbol
>
TSymbolMap
;
typedef
TMap
<
int
,
MacroSymbol
>
TSymbolMap
;
...
...
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