Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
15346fae
Commit
15346fae
authored
17 years ago
by
Chris Lattner
Browse files
Options
Downloads
Patches
Plain Diff
avoid pasting L + "foo" into L"foo".
llvm-svn: 46000
parent
877ca774
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
clang/Driver/PrintPreprocessedOutput.cpp
+27
-2
27 additions, 2 deletions
clang/Driver/PrintPreprocessedOutput.cpp
clang/test/Preprocessor/output_paste_avoid.c
+6
-0
6 additions, 0 deletions
clang/test/Preprocessor/output_paste_avoid.c
with
33 additions
and
2 deletions
clang/Driver/PrintPreprocessedOutput.cpp
+
27
−
2
View file @
15346fae
...
@@ -420,8 +420,8 @@ static void InitAvoidConcatTokenInfo() {
...
@@ -420,8 +420,8 @@ static void InitAvoidConcatTokenInfo() {
TokenInfo
[
tok
::
equal
]
|=
aci_avoid_equal
;
// ==
TokenInfo
[
tok
::
equal
]
|=
aci_avoid_equal
;
// ==
}
}
/// StartsWithL - Return true if the spelling of this token starts with 'L'.
static
bool
StartsWithL
(
const
Token
&
Tok
,
Preprocessor
&
PP
)
{
static
bool
StartsWithL
(
const
Token
&
Tok
,
Preprocessor
&
PP
)
{
char
Buffer
[
256
];
if
(
!
Tok
.
needsCleaning
())
{
if
(
!
Tok
.
needsCleaning
())
{
SourceManager
&
SrcMgr
=
PP
.
getSourceManager
();
SourceManager
&
SrcMgr
=
PP
.
getSourceManager
();
return
*
SrcMgr
.
getCharacterData
(
SrcMgr
.
getPhysicalLoc
(
Tok
.
getLocation
()))
return
*
SrcMgr
.
getCharacterData
(
SrcMgr
.
getPhysicalLoc
(
Tok
.
getLocation
()))
...
@@ -429,6 +429,7 @@ static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
...
@@ -429,6 +429,7 @@ static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
}
}
if
(
Tok
.
getLength
()
<
256
)
{
if
(
Tok
.
getLength
()
<
256
)
{
char
Buffer
[
256
];
const
char
*
TokPtr
=
Buffer
;
const
char
*
TokPtr
=
Buffer
;
PP
.
getSpelling
(
Tok
,
TokPtr
);
PP
.
getSpelling
(
Tok
,
TokPtr
);
return
TokPtr
[
0
]
==
'L'
;
return
TokPtr
[
0
]
==
'L'
;
...
@@ -437,6 +438,28 @@ static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
...
@@ -437,6 +438,28 @@ static bool StartsWithL(const Token &Tok, Preprocessor &PP) {
return
PP
.
getSpelling
(
Tok
)[
0
]
==
'L'
;
return
PP
.
getSpelling
(
Tok
)[
0
]
==
'L'
;
}
}
/// IsIdentifierL - Return true if the spelling of this token is literally 'L'.
static
bool
IsIdentifierL
(
const
Token
&
Tok
,
Preprocessor
&
PP
)
{
if
(
!
Tok
.
needsCleaning
())
{
if
(
Tok
.
getLength
()
!=
1
)
return
false
;
SourceManager
&
SrcMgr
=
PP
.
getSourceManager
();
return
*
SrcMgr
.
getCharacterData
(
SrcMgr
.
getPhysicalLoc
(
Tok
.
getLocation
()))
==
'L'
;
}
if
(
Tok
.
getLength
()
<
256
)
{
char
Buffer
[
256
];
const
char
*
TokPtr
=
Buffer
;
if
(
PP
.
getSpelling
(
Tok
,
TokPtr
)
!=
1
)
return
false
;
return
TokPtr
[
0
]
==
'L'
;
}
return
PP
.
getSpelling
(
Tok
)
==
"L"
;
}
/// AvoidConcat - If printing PrevTok immediately followed by Tok would cause
/// AvoidConcat - If printing PrevTok immediately followed by Tok would cause
/// the two individual tokens to be lexed as a single token, return true (which
/// the two individual tokens to be lexed as a single token, return true (which
/// causes a space to be printed between them). This allows the output of -E
/// causes a space to be printed between them). This allows the output of -E
...
@@ -513,7 +536,9 @@ bool PrintPPOutputPPCallbacks::AvoidConcat(const Token &PrevTok,
...
@@ -513,7 +536,9 @@ bool PrintPPOutputPPCallbacks::AvoidConcat(const Token &PrevTok,
if
(
StartsWithL
(
Tok
,
PP
))
if
(
StartsWithL
(
Tok
,
PP
))
return
true
;
return
true
;
return
false
;
// Otherwise, this is a narrow character or string. If the *identifier* is
// a literal 'L', avoid pasting L "foo" -> L"foo".
return
IsIdentifierL
(
PrevTok
,
PP
);
case
tok
::
numeric_constant
:
case
tok
::
numeric_constant
:
return
isalnum
(
FirstChar
)
||
Tok
.
is
(
tok
::
numeric_constant
)
||
return
isalnum
(
FirstChar
)
||
Tok
.
is
(
tok
::
numeric_constant
)
||
FirstChar
==
'+'
||
FirstChar
==
'-'
||
FirstChar
==
'.'
;
FirstChar
==
'+'
||
FirstChar
==
'-'
||
FirstChar
==
'.'
;
...
...
This diff is collapsed.
Click to expand it.
clang/test/Preprocessor/output_paste_avoid.c
+
6
−
0
View file @
15346fae
// RUN: clang -E %s | grep '+ + - - + + = = =' &&
// RUN: clang -E %s | grep '+ + - - + + = = =' &&
// RUN: clang -E %s | not grep -F '...'
// RUN: clang -E %s | not grep -F '...'
// RUN: clang -E %s | not grep -F 'L"str"'
// This should print as ".. ." to avoid turning into ...
// This should print as ".. ." to avoid turning into ...
#define y(a) ..a
#define y(a) ..a
...
@@ -10,3 +11,8 @@ y(.)
...
@@ -10,3 +11,8 @@ y(.)
#define f(x) =x=
#define f(x) =x=
+
PLUS
-
EMPTY
-
PLUS
+
f
(
=
)
+
PLUS
-
EMPTY
-
PLUS
+
f
(
=
)
// Should expand to L "str" not L"str"
#define test(x) L#x
test
(
str
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment