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
9ffc72d1
Unverified
Commit
9ffc72d1
authored
Feb 06, 2018
by
John Kessenich
Committed by
GitHub
Feb 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1238 from zeux/pp-string-buffer
Preprocessor: Use std::string instead of std::stringstream
parents
2651ccae
75cffdf9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
28 deletions
+37
-28
ShaderLang.cpp
glslang/MachineIndependent/ShaderLang.cpp
+37
-28
No files found.
glslang/MachineIndependent/ShaderLang.cpp
View file @
9ffc72d1
...
...
@@ -912,7 +912,7 @@ bool ProcessDeferred(
class
SourceLineSynchronizer
{
public
:
SourceLineSynchronizer
(
const
std
::
function
<
int
()
>&
lastSourceIndex
,
std
::
string
stream
*
output
)
std
::
string
*
output
)
:
getLastSourceIndex
(
lastSourceIndex
),
output
(
output
),
lastSource
(
-
1
),
lastLine
(
0
)
{}
// SourceLineSynchronizer(const SourceLineSynchronizer&) = delete;
// SourceLineSynchronizer& operator=(const SourceLineSynchronizer&) = delete;
...
...
@@ -927,7 +927,7 @@ public:
// used. We also need to output a newline to separate the output
// from the previous source string (if there is one).
if
(
lastSource
!=
-
1
||
lastLine
!=
0
)
*
output
<<
std
::
endl
;
*
output
+=
'\n'
;
lastSource
=
getLastSourceIndex
();
lastLine
=
-
1
;
return
true
;
...
...
@@ -942,7 +942,7 @@ public:
syncToMostRecentString
();
const
bool
newLineStarted
=
lastLine
<
tokenLine
;
for
(;
lastLine
<
tokenLine
;
++
lastLine
)
{
if
(
lastLine
>
0
)
*
output
<<
std
::
endl
;
if
(
lastLine
>
0
)
*
output
+=
'\n'
;
}
return
newLineStarted
;
}
...
...
@@ -956,8 +956,8 @@ private:
// A function for getting the index of the last valid source string we've
// read tokens from.
const
std
::
function
<
int
()
>
getLastSourceIndex
;
// output str
eam
for newlines.
std
::
string
stream
*
output
;
// output str
ing
for newlines.
std
::
string
*
output
;
// lastSource is the source string index (starting from 0) of the last token
// processed. It is tracked in order for newlines to be inserted when a new
// source string starts. -1 means we haven't started processing any source
...
...
@@ -988,27 +988,33 @@ struct DoPreprocessing {
parseContext
.
setScanner
(
&
input
);
ppContext
.
setInput
(
input
,
versionWillBeError
);
std
::
string
stream
outputStream
;
std
::
string
outputBuffer
;
SourceLineSynchronizer
lineSync
(
std
::
bind
(
&
TInputScanner
::
getLastValidSourceIndex
,
&
input
),
&
output
Stream
);
std
::
bind
(
&
TInputScanner
::
getLastValidSourceIndex
,
&
input
),
&
output
Buffer
);
parseContext
.
setExtensionCallback
([
&
lineSync
,
&
output
Stream
](
parseContext
.
setExtensionCallback
([
&
lineSync
,
&
output
Buffer
](
int
line
,
const
char
*
extension
,
const
char
*
behavior
)
{
lineSync
.
syncToLine
(
line
);
outputStream
<<
"#extension "
<<
extension
<<
" : "
<<
behavior
;
outputBuffer
+=
"#extension "
;
outputBuffer
+=
extension
;
outputBuffer
+=
" : "
;
outputBuffer
+=
behavior
;
});
parseContext
.
setLineCallback
([
&
lineSync
,
&
output
Stream
,
&
parseContext
](
parseContext
.
setLineCallback
([
&
lineSync
,
&
output
Buffer
,
&
parseContext
](
int
curLineNum
,
int
newLineNum
,
bool
hasSource
,
int
sourceNum
,
const
char
*
sourceName
)
{
// SourceNum is the number of the source-string that is being parsed.
lineSync
.
syncToLine
(
curLineNum
);
outputStream
<<
"#line "
<<
newLineNum
;
outputBuffer
+=
"#line "
;
outputBuffer
+=
std
::
to_string
(
newLineNum
);
if
(
hasSource
)
{
output
Stream
<<
" "
;
output
Buffer
+=
' '
;
if
(
sourceName
!=
nullptr
)
{
outputStream
<<
"
\"
"
<<
sourceName
<<
"
\"
"
;
outputBuffer
+=
'\"'
;
outputBuffer
+=
sourceName
;
outputBuffer
+=
'\"'
;
}
else
{
output
Stream
<<
sourceNum
;
output
Buffer
+=
std
::
to_string
(
sourceNum
)
;
}
}
if
(
parseContext
.
lineDirectiveShouldSetNextLine
())
{
...
...
@@ -1016,33 +1022,36 @@ struct DoPreprocessing {
// directive. So the new line number for the current line is
newLineNum
-=
1
;
}
output
Stream
<<
std
::
endl
;
output
Buffer
+=
'\n'
;
// And we are at the next line of the #line directive now.
lineSync
.
setLineNum
(
newLineNum
+
1
);
});
parseContext
.
setVersionCallback
(
[
&
lineSync
,
&
output
Stream
](
int
line
,
int
version
,
const
char
*
str
)
{
[
&
lineSync
,
&
output
Buffer
](
int
line
,
int
version
,
const
char
*
str
)
{
lineSync
.
syncToLine
(
line
);
outputStream
<<
"#version "
<<
version
;
outputBuffer
+=
"#version "
;
outputBuffer
+=
std
::
to_string
(
version
);
if
(
str
)
{
outputStream
<<
" "
<<
str
;
outputBuffer
+=
' '
;
outputBuffer
+=
str
;
}
});
parseContext
.
setPragmaCallback
([
&
lineSync
,
&
output
Stream
](
parseContext
.
setPragmaCallback
([
&
lineSync
,
&
output
Buffer
](
int
line
,
const
glslang
::
TVector
<
glslang
::
TString
>&
ops
)
{
lineSync
.
syncToLine
(
line
);
output
Stream
<<
"#pragma "
;
output
Buffer
+=
"#pragma "
;
for
(
size_t
i
=
0
;
i
<
ops
.
size
();
++
i
)
{
output
Stream
<<
ops
[
i
]
;
output
Buffer
+=
ops
[
i
].
c_str
()
;
}
});
parseContext
.
setErrorCallback
([
&
lineSync
,
&
output
Stream
](
parseContext
.
setErrorCallback
([
&
lineSync
,
&
output
Buffer
](
int
line
,
const
char
*
errorMessage
)
{
lineSync
.
syncToLine
(
line
);
outputStream
<<
"#error "
<<
errorMessage
;
outputBuffer
+=
"#error "
;
outputBuffer
+=
errorMessage
;
});
int
lastToken
=
EndOfInput
;
// lastToken records the last token processed.
...
...
@@ -1058,7 +1067,7 @@ struct DoPreprocessing {
// Don't emit whitespace onto empty lines.
// Copy any whitespace characters at the start of a line
// from the input to the output.
output
Stream
<<
std
::
string
(
ppToken
.
loc
.
column
-
1
,
' '
);
output
Buffer
+=
std
::
string
(
ppToken
.
loc
.
column
-
1
,
' '
);
}
// Output a space in between tokens, but not at the start of a line,
...
...
@@ -1068,13 +1077,13 @@ struct DoPreprocessing {
(
unNeededSpaceTokens
.
find
((
char
)
token
)
==
std
::
string
::
npos
)
&&
(
unNeededSpaceTokens
.
find
((
char
)
lastToken
)
==
std
::
string
::
npos
)
&&
(
noSpaceBeforeTokens
.
find
((
char
)
token
)
==
std
::
string
::
npos
))
{
output
Stream
<<
" "
;
output
Buffer
+=
' '
;
}
lastToken
=
token
;
output
Stream
<<
ppToken
.
name
;
output
Buffer
+=
ppToken
.
name
;
}
while
(
true
);
output
Stream
<<
std
::
endl
;
*
outputString
=
outputStream
.
str
(
);
output
Buffer
+=
'\n'
;
*
outputString
=
std
::
move
(
outputBuffer
);
bool
success
=
true
;
if
(
parseContext
.
getNumErrors
()
>
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