Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
2e3642e6
Kaydet (Commit)
2e3642e6
authored
Eki 15, 2012
tarafından
Luboš Luňák
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
convenience functions for source rewriters
Change-Id: I36e2b49bc615db0b12b03ffa755fa51acc6830a0
üst
6c997887
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
10 deletions
+107
-10
lclstaticfix.cxx
compilerplugins/clang/lclstaticfix.cxx
+2
-7
lclstaticfix.hxx
compilerplugins/clang/lclstaticfix.hxx
+1
-3
plugin.cxx
compilerplugins/clang/plugin.cxx
+86
-0
plugin.hxx
compilerplugins/clang/plugin.hxx
+18
-0
No files found.
compilerplugins/clang/lclstaticfix.cxx
Dosyayı görüntüle @
2e3642e6
...
...
@@ -22,7 +22,7 @@ namespace loplugin
{
LclStaticFix
::
LclStaticFix
(
ASTContext
&
context
,
Rewriter
&
rewriter
)
:
Plugin
(
context
),
rewriter
(
rewriter
)
:
RewritePlugin
(
context
,
rewriter
)
{
}
...
...
@@ -46,12 +46,7 @@ bool LclStaticFix::VisitFunctionDecl( FunctionDecl* declaration )
return
true
;
if
(
name
.
compare
(
0
,
4
,
"lcl_"
)
!=
0
)
return
true
;
if
(
rewriter
.
InsertText
(
declaration
->
getLocStart
(),
"static "
))
{
// the logic is backwards, true here meant it failed, so report
report
(
DiagnosticsEngine
::
Warning
,
"cannot fix lcl_ function (result of macro expansion?) [loplugin]"
,
declaration
->
getLocStart
());
}
insertText
(
declaration
->
getLocStart
(),
"static "
);
return
true
;
}
...
...
compilerplugins/clang/lclstaticfix.hxx
Dosyayı görüntüle @
2e3642e6
...
...
@@ -18,14 +18,12 @@ namespace loplugin
class
LclStaticFix
:
public
RecursiveASTVisitor
<
LclStaticFix
>
,
public
Plugin
,
public
Rewrite
Plugin
{
public
:
explicit
LclStaticFix
(
ASTContext
&
context
,
Rewriter
&
rewriter
);
void
run
();
bool
VisitFunctionDecl
(
FunctionDecl
*
declaration
);
private
:
Rewriter
&
rewriter
;
};
}
// namespace
...
...
compilerplugins/clang/plugin.cxx
Dosyayı görüntüle @
2e3642e6
...
...
@@ -52,6 +52,92 @@ bool Plugin::ignoreLocation( SourceLocation loc )
return
context
.
getSourceManager
().
isInSystemHeader
(
context
.
getSourceManager
().
getExpansionLoc
(
loc
));
}
RewritePlugin
::
RewritePlugin
(
ASTContext
&
context
,
Rewriter
&
rewriter
)
:
Plugin
(
context
)
,
rewriter
(
rewriter
)
{
}
bool
RewritePlugin
::
insertText
(
SourceLocation
Loc
,
StringRef
Str
,
bool
InsertAfter
,
bool
indentNewLines
)
{
if
(
rewriter
.
InsertText
(
Loc
,
Str
,
InsertAfter
,
indentNewLines
))
return
reportEditFailure
(
Loc
);
return
true
;
}
bool
RewritePlugin
::
insertTextAfter
(
SourceLocation
Loc
,
StringRef
Str
)
{
if
(
rewriter
.
InsertTextAfter
(
Loc
,
Str
))
return
reportEditFailure
(
Loc
);
return
true
;
}
bool
RewritePlugin
::
insertTextAfterToken
(
SourceLocation
Loc
,
StringRef
Str
)
{
if
(
rewriter
.
InsertTextAfterToken
(
Loc
,
Str
))
return
reportEditFailure
(
Loc
);
return
true
;
}
bool
RewritePlugin
::
insertTextBefore
(
SourceLocation
Loc
,
StringRef
Str
)
{
if
(
rewriter
.
InsertTextBefore
(
Loc
,
Str
))
return
reportEditFailure
(
Loc
);
return
true
;
}
bool
RewritePlugin
::
removeText
(
SourceLocation
Start
,
unsigned
Length
,
RewriteOptions
opts
)
{
if
(
rewriter
.
RemoveText
(
Start
,
Length
,
opts
))
return
reportEditFailure
(
Start
);
return
true
;
}
bool
RewritePlugin
::
removeText
(
CharSourceRange
range
,
RewriteOptions
opts
)
{
if
(
rewriter
.
RemoveText
(
range
,
opts
))
return
reportEditFailure
(
range
.
getBegin
());
return
true
;
}
bool
RewritePlugin
::
removeText
(
SourceRange
range
,
RewriteOptions
opts
)
{
if
(
rewriter
.
RemoveText
(
range
,
opts
))
return
reportEditFailure
(
range
.
getBegin
());
return
true
;
}
bool
RewritePlugin
::
replaceText
(
SourceLocation
Start
,
unsigned
OrigLength
,
StringRef
NewStr
)
{
if
(
rewriter
.
ReplaceText
(
Start
,
OrigLength
,
NewStr
))
return
reportEditFailure
(
Start
);
return
true
;
}
bool
RewritePlugin
::
replaceText
(
SourceRange
range
,
StringRef
NewStr
)
{
if
(
rewriter
.
ReplaceText
(
range
,
NewStr
))
return
reportEditFailure
(
range
.
getBegin
());
return
true
;
}
bool
RewritePlugin
::
replaceText
(
SourceRange
range
,
SourceRange
replacementRange
)
{
if
(
rewriter
.
ReplaceText
(
range
,
replacementRange
))
return
reportEditFailure
(
range
.
getBegin
());
return
true
;
}
bool
RewritePlugin
::
reportEditFailure
(
SourceLocation
loc
)
{
DiagnosticsEngine
&
diag
=
context
.
getDiagnostics
();
diag
.
Report
(
loc
,
diag
.
getCustomDiagID
(
DiagnosticsEngine
::
Warning
,
"cannot perform source modification (macro expansion involved?) [loplugin]"
));
return
false
;
}
/**
Class that manages all LO modules.
*/
...
...
compilerplugins/clang/plugin.hxx
Dosyayı görüntüle @
2e3642e6
...
...
@@ -39,7 +39,25 @@ class RewritePlugin
public
:
explicit
RewritePlugin
(
ASTContext
&
context
,
Rewriter
&
rewriter
);
protected
:
typedef
Rewriter
::
RewriteOptions
RewriteOptions
;
// These following insert/remove/replaceText functions map to functions
// in clang::Rewriter, with two differences:
// - they (more intuitively) return false on failure rather than true
// - they report a warning when the change cannot be done
bool
insertText
(
SourceLocation
Loc
,
StringRef
Str
,
bool
InsertAfter
=
true
,
bool
indentNewLines
=
false
);
bool
insertTextAfter
(
SourceLocation
Loc
,
StringRef
Str
);
bool
insertTextAfterToken
(
SourceLocation
Loc
,
StringRef
Str
);
bool
insertTextBefore
(
SourceLocation
Loc
,
StringRef
Str
);
bool
removeText
(
SourceLocation
Start
,
unsigned
Length
,
RewriteOptions
opts
=
RewriteOptions
());
bool
removeText
(
CharSourceRange
range
,
RewriteOptions
opts
=
RewriteOptions
());
bool
removeText
(
SourceRange
range
,
RewriteOptions
opts
=
RewriteOptions
());
bool
replaceText
(
SourceLocation
Start
,
unsigned
OrigLength
,
StringRef
NewStr
);
bool
replaceText
(
SourceRange
range
,
StringRef
NewStr
);
bool
replaceText
(
SourceRange
range
,
SourceRange
replacementRange
);
Rewriter
&
rewriter
;
private
:
bool
reportEditFailure
(
SourceLocation
loc
);
};
inline
...
...
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