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
f48faec3
Commit
f48faec3
authored
Dec 21, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PP: Non-functional: Make a proper class out of the atom <-> string mapping.
parent
224b1f73
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
99 deletions
+90
-99
revision.h
glslang/Include/revision.h
+1
-1
Pp.cpp
glslang/MachineIndependent/preprocessor/Pp.cpp
+23
-23
PpAtom.cpp
glslang/MachineIndependent/preprocessor/PpAtom.cpp
+5
-54
PpContext.cpp
glslang/MachineIndependent/preprocessor/PpContext.cpp
+0
-2
PpContext.h
glslang/MachineIndependent/preprocessor/PpContext.h
+57
-15
PpScanner.cpp
glslang/MachineIndependent/preprocessor/PpScanner.cpp
+4
-4
No files found.
glslang/Include/revision.h
View file @
f48faec3
...
@@ -2,5 +2,5 @@
...
@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.172
0
"
#define GLSLANG_REVISION "Overload400-PrecQual.172
1
"
#define GLSLANG_DATE "21-Dec-2016"
#define GLSLANG_DATE "21-Dec-2016"
glslang/MachineIndependent/preprocessor/Pp.cpp
View file @
f48faec3
This diff is collapsed.
Click to expand it.
glslang/MachineIndependent/preprocessor/PpAtom.cpp
View file @
f48faec3
...
@@ -150,61 +150,12 @@ const struct {
...
@@ -150,61 +150,12 @@ const struct {
namespace
glslang
{
namespace
glslang
{
//
//
// Map an existing string to an atom.
//
// Return 0 if no existing string.
//
int
TPpContext
::
LookUpString
(
const
char
*
s
)
{
auto
it
=
atomMap
.
find
(
s
);
return
it
==
atomMap
.
end
()
?
0
:
it
->
second
;
}
//
// Map a new or existing string to an atom, inventing a new atom if necessary.
//
int
TPpContext
::
LookUpAddString
(
const
char
*
s
)
{
int
atom
=
LookUpString
(
s
);
if
(
atom
==
0
)
{
atom
=
nextAtom
++
;
AddAtomFixed
(
s
,
atom
);
}
return
atom
;
}
//
// Lookup up mapping of atom -> string.
//
const
char
*
TPpContext
::
GetAtomString
(
int
atom
)
{
if
((
size_t
)
atom
>=
stringMap
.
size
())
return
"<bad token>"
;
const
TString
*
atomString
=
stringMap
[
atom
];
return
atomString
?
atomString
->
c_str
()
:
"<bad token>"
;
}
//
// Add mappings:
// - string -> atom
// - atom -> string
//
void
TPpContext
::
AddAtomFixed
(
const
char
*
s
,
int
atom
)
{
auto
it
=
atomMap
.
insert
(
std
::
pair
<
TString
,
int
>
(
s
,
atom
)).
first
;
if
(
stringMap
.
size
()
<
(
size_t
)
atom
+
1
)
stringMap
.
resize
(
atom
+
100
,
0
);
stringMap
[
atom
]
=
&
it
->
first
;
}
//
// Initialize the atom table.
// Initialize the atom table.
//
//
void
TPpContext
::
InitAtomTable
()
TStringAtomMap
::
TStringAtomMap
()
{
{
badToken
.
assign
(
"<bad token>"
);
// Add single character tokens to the atom table:
// Add single character tokens to the atom table:
const
char
*
s
=
"~!%^&*()-+=|,.<>/?;:[]{}#
\\
"
;
const
char
*
s
=
"~!%^&*()-+=|,.<>/?;:[]{}#
\\
"
;
char
t
[
2
];
char
t
[
2
];
...
@@ -212,13 +163,13 @@ void TPpContext::InitAtomTable()
...
@@ -212,13 +163,13 @@ void TPpContext::InitAtomTable()
t
[
1
]
=
'\0'
;
t
[
1
]
=
'\0'
;
while
(
*
s
)
{
while
(
*
s
)
{
t
[
0
]
=
*
s
;
t
[
0
]
=
*
s
;
A
ddAtomFixed
(
t
,
s
[
0
]);
a
ddAtomFixed
(
t
,
s
[
0
]);
s
++
;
s
++
;
}
}
// Add multiple character scanner tokens :
// Add multiple character scanner tokens :
for
(
size_t
ii
=
0
;
ii
<
sizeof
(
tokens
)
/
sizeof
(
tokens
[
0
]);
ii
++
)
for
(
size_t
ii
=
0
;
ii
<
sizeof
(
tokens
)
/
sizeof
(
tokens
[
0
]);
ii
++
)
A
ddAtomFixed
(
tokens
[
ii
].
str
,
tokens
[
ii
].
val
);
a
ddAtomFixed
(
tokens
[
ii
].
str
,
tokens
[
ii
].
val
);
nextAtom
=
PpAtomLast
;
nextAtom
=
PpAtomLast
;
}
}
...
...
glslang/MachineIndependent/preprocessor/PpContext.cpp
View file @
f48faec3
...
@@ -87,8 +87,6 @@ TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, T
...
@@ -87,8 +87,6 @@ TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, T
rootFileName
(
rootFileName
),
rootFileName
(
rootFileName
),
currentSourceFile
(
rootFileName
)
currentSourceFile
(
rootFileName
)
{
{
InitAtomTable
();
ifdepth
=
0
;
ifdepth
=
0
;
for
(
elsetracker
=
0
;
elsetracker
<
maxIfNesting
;
elsetracker
++
)
for
(
elsetracker
=
0
;
elsetracker
<
maxIfNesting
;
elsetracker
++
)
elseSeen
[
elsetracker
]
=
false
;
elseSeen
[
elsetracker
]
=
false
;
...
...
glslang/MachineIndependent/preprocessor/PpContext.h
View file @
f48faec3
...
@@ -115,6 +115,62 @@ public:
...
@@ -115,6 +115,62 @@ public:
char
name
[
MaxTokenLength
+
1
];
char
name
[
MaxTokenLength
+
1
];
};
};
class
TStringAtomMap
{
//
// Implementation is in PpAtom.cpp
//
// Maintain a bi-directional mapping between relevant preprocessor strings and
// "atoms" which a unique integers (small, contiguous, not hash-like) per string.
//
public
:
TStringAtomMap
();
// Map string -> atom.
// Return 0 if no existing string.
int
getAtom
(
const
char
*
s
)
const
{
auto
it
=
atomMap
.
find
(
s
);
return
it
==
atomMap
.
end
()
?
0
:
it
->
second
;
}
// Map a new or existing string -> atom, inventing a new atom if necessary.
int
getAddAtom
(
const
char
*
s
)
{
int
atom
=
getAtom
(
s
);
if
(
atom
==
0
)
{
atom
=
nextAtom
++
;
addAtomFixed
(
s
,
atom
);
}
return
atom
;
}
// Map atom -> string.
const
char
*
getString
(
int
atom
)
const
{
return
stringMap
[
atom
]
->
c_str
();
}
protected
:
TStringAtomMap
(
TStringAtomMap
&
);
TStringAtomMap
&
operator
=
(
TStringAtomMap
&
);
TUnorderedMap
<
TString
,
int
>
atomMap
;
TVector
<
const
TString
*>
stringMap
;
// these point into the TString in atomMap
int
nextAtom
;
// Bad source characters can lead to bad atoms, so gracefully handle those by
// pre-filling the table with them (to avoid if tests later).
TString
badToken
;
// Add bi-directional mappings:
// - string -> atom
// - atom -> string
void
addAtomFixed
(
const
char
*
s
,
int
atom
)
{
auto
it
=
atomMap
.
insert
(
std
::
pair
<
TString
,
int
>
(
s
,
atom
)).
first
;
if
(
stringMap
.
size
()
<
(
size_t
)
atom
+
1
)
stringMap
.
resize
(
atom
+
100
,
&
badToken
);
stringMap
[
atom
]
=
&
it
->
first
;
}
};
class
TInputScanner
;
class
TInputScanner
;
// This class is the result of turning a huge pile of C code communicating through globals
// This class is the result of turning a huge pile of C code communicating through globals
...
@@ -196,6 +252,7 @@ protected:
...
@@ -196,6 +252,7 @@ protected:
TPpContext
(
TPpContext
&
);
TPpContext
(
TPpContext
&
);
TPpContext
&
operator
=
(
TPpContext
&
);
TPpContext
&
operator
=
(
TPpContext
&
);
TStringAtomMap
atomStrings
;
char
*
preamble
;
// string to parse, all before line 1 of string 0, it is 0 if no preamble
char
*
preamble
;
// string to parse, all before line 1 of string 0, it is 0 if no preamble
int
preambleLength
;
int
preambleLength
;
char
**
strings
;
// official strings of shader, starting a string 0 line 1
char
**
strings
;
// official strings of shader, starting a string 0 line 1
...
@@ -538,21 +595,6 @@ protected:
...
@@ -538,21 +595,6 @@ protected:
std
::
string
rootFileName
;
std
::
string
rootFileName
;
std
::
stack
<
TShader
::
Includer
::
IncludeResult
*>
includeStack
;
std
::
stack
<
TShader
::
Includer
::
IncludeResult
*>
includeStack
;
std
::
string
currentSourceFile
;
std
::
string
currentSourceFile
;
//
// From PpAtom.cpp
//
typedef
TUnorderedMap
<
TString
,
int
>
TAtomMap
;
typedef
TVector
<
const
TString
*>
TStringMap
;
TAtomMap
atomMap
;
TStringMap
stringMap
;
int
nextAtom
;
void
InitAtomTable
();
void
AddAtomFixed
(
const
char
*
s
,
int
atom
);
int
LookUpString
(
const
char
*
s
);
int
LookUpAddString
(
const
char
*
s
);
const
char
*
GetAtomString
(
int
atom
);
};
};
}
// end namespace glslang
}
// end namespace glslang
...
...
glslang/MachineIndependent/preprocessor/PpScanner.cpp
View file @
f48faec3
...
@@ -774,7 +774,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
...
@@ -774,7 +774,7 @@ int TPpContext::tokenize(TPpToken& ppToken)
parseContext
.
ppError
(
ppToken
.
loc
,
"character literals not supported"
,
"
\'
"
,
""
);
parseContext
.
ppError
(
ppToken
.
loc
,
"character literals not supported"
,
"
\'
"
,
""
);
continue
;
continue
;
default
:
default
:
strcpy
(
ppToken
.
name
,
GetAtom
String
(
token
));
strcpy
(
ppToken
.
name
,
atomStrings
.
get
String
(
token
));
break
;
break
;
}
}
...
@@ -836,8 +836,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
...
@@ -836,8 +836,8 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
case
PpAtomAnd
:
case
PpAtomAnd
:
case
PpAtomOr
:
case
PpAtomOr
:
case
PpAtomXor
:
case
PpAtomXor
:
strcpy
(
ppToken
.
name
,
GetAtom
String
(
resultToken
));
strcpy
(
ppToken
.
name
,
atomStrings
.
get
String
(
resultToken
));
strcpy
(
pastedPpToken
.
name
,
GetAtom
String
(
token
));
strcpy
(
pastedPpToken
.
name
,
atomStrings
.
get
String
(
token
));
break
;
break
;
default
:
default
:
parseContext
.
ppError
(
ppToken
.
loc
,
"not supported for these tokens"
,
"##"
,
""
);
parseContext
.
ppError
(
ppToken
.
loc
,
"not supported for these tokens"
,
"##"
,
""
);
...
@@ -853,7 +853,7 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
...
@@ -853,7 +853,7 @@ int TPpContext::tokenPaste(int token, TPpToken& ppToken)
// correct the kind of token we are making, if needed (identifiers stay identifiers)
// correct the kind of token we are making, if needed (identifiers stay identifiers)
if
(
resultToken
!=
PpAtomIdentifier
)
{
if
(
resultToken
!=
PpAtomIdentifier
)
{
int
newToken
=
LookUpString
(
ppToken
.
name
);
int
newToken
=
atomStrings
.
getAtom
(
ppToken
.
name
);
if
(
newToken
>
0
)
if
(
newToken
>
0
)
resultToken
=
newToken
;
resultToken
=
newToken
;
else
else
...
...
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