Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
glshader
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Johannes Braun
glshader
Commits
3f6546c7
Commit
3f6546c7
authored
Aug 18, 2018
by
Johannes Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix faulty macro replacement for seemingly function-like macros as well as empty-argument-macros
parent
d654c363
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
7 deletions
+38
-7
examples/from_file/main.cpp
examples/from_file/main.cpp
+7
-1
src/preprocessor/macro.cpp
src/preprocessor/macro.cpp
+30
-5
src/preprocessor/preprocessor.cpp
src/preprocessor/preprocessor.cpp
+1
-1
No files found.
examples/from_file/main.cpp
View file @
3f6546c7
...
...
@@ -21,8 +21,14 @@ int main()
constexpr
const
char
*
source
=
R"(
#include "inc.glsl"
#define MY_FUN sin
#define OTHER_FUN() cos
void main()
{}
{
int x = int(MY_FUN(177.f));
int y = int(OTHER_FUN( )(12.f));
}
)"
;
const
glsp
::
processed_file
src
=
process_state
.
preprocess_source
(
source
,
"Shader"
);
...
...
src/preprocessor/macro.cpp
View file @
3f6546c7
...
...
@@ -27,21 +27,46 @@ namespace glshader::process::impl::macro
while
(
cls
::
is_name_char
(
text_ptr
))
++
text_ptr
;
const
std
::
string
str
(
begin
,
text_ptr
);
const
bool
has_trailing_brackets
=
*
skip
::
space
(
text_ptr
)
==
'('
&&
*
skip
::
space
(
skip
::
space
(
text_ptr
)
+
1
)
==
')'
;
const
std
::
string
str
=
std
::
string
(
begin
,
text_ptr
)
+
(
has_trailing_brackets
?
"()"
:
""
);
return
is_defined
(
str
,
processed
);
}
std
::
string
expand_macro
(
const
std
::
string
&
name
,
const
char
*
param_start
,
const
int
param_length
,
std
::
string
expand_macro
(
std
::
string
name
,
const
char
*
param_start
,
int
param_length
,
const
files
::
path
&
current_file
,
const
int
current_line
,
processed_file
&
processed
)
{
std
::
stringstream
stream
;
if
(
processed
.
definitions
.
count
(
name
)
==
0
)
{
if
(
param_length
==
0
)
{
name
=
name
+
"()"
;
param_start
=
nullptr
;
if
(
processed
.
definitions
.
count
(
name
)
==
0
)
return
name
;
}
else
{
int
param_len
=
(
skip
::
space
(
param_start
)
-
param_start
);
if
(
param_len
==
param_length
)
{
name
=
name
+
"()"
;
param_start
=
nullptr
;
if
(
processed
.
definitions
.
count
(
name
)
==
0
)
return
name
;
}
else
{
return
name
;
}
}
}
auto
info
=
processed
.
definitions
.
at
(
name
);
if
(
info
.
parameters
.
empty
())
return
info
.
replacement
;
return
info
.
replacement
+
(
param_start
?
std
::
string
(
param_start
-
1
,
param_length
+
2
)
:
""
)
;
std
::
vector
<
std
::
string
>
inputs
;
...
...
src/preprocessor/preprocessor.cpp
View file @
3f6546c7
...
...
@@ -171,7 +171,7 @@ namespace glshader::process
{
text_ptr
=
skip
::
to_next_token
(
directive_name
);
const
auto
name_begin
=
text_ptr
;
while
(
!
cls
::
is_space
(
text_ptr
)
&&
!
cls
::
is_newline
(
text_ptr
)
&&
*
text_ptr
!=
'('
)
while
(
!
cls
::
is_space
(
text_ptr
)
&&
!
cls
::
is_newline
(
text_ptr
)
&&
(
*
text_ptr
!=
'('
||
(
*
text_ptr
==
'('
&&
*
skip
::
space
(
text_ptr
+
1
)
==
')'
))
)
++
text_ptr
;
if
(
const
auto
space_skipped
=
skip
::
space
(
text_ptr
);
...
...
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