Obey coding rules and indentation.

This commit is contained in:
Vassil Vassilev 2014-05-24 15:15:28 +02:00 committed by sftnight
parent 08c26eb004
commit 56b5dc86dd
14 changed files with 134 additions and 129 deletions

View File

@ -1,5 +1,5 @@
#ifndef CLING_CTAGS_CALLBACK_H
#define CLING_CTAGS_CALLBACK_H
#ifndef CLING_CTAGS_AUTOLOAD_CALLBACK_H
#define CLING_CTAGS_AUTOLOAD_CALLBACK_H
#include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/InterpreterCallbacks.h"
@ -14,7 +14,7 @@ unless these objects are loaded.
.rawInput 0
#include "cling/TagsExtension/TagManager.h"
#include "cling/TagsExtension/Callback.h"
#include "cling/TagsExtension/AutoloadCallback.h"
cling::TagManager t;
gCling->setCallbacks(new cling::AutoloadCallback(gCling,&t));
@ -35,12 +35,12 @@ namespace cling {
bool LookupObject (clang::LookupResult &R, clang::Scope *);
cling::TagManager* getTagManager();
TagManager* getTagManager() { return m_Tags; }
private:
cling::Interpreter* m_Interpreter;
cling::TagManager* m_Tags;
Interpreter* m_Interpreter;
TagManager* m_Tags;
};
}// end namespace cling
} // end namespace cling
#endif
#endif // CLING_CTAGS_AUTOLOAD_CALLBACK_H

View File

@ -2,22 +2,22 @@
#include "readtags.h"
namespace cling {
///\brief Implements tag operations for Ctags
class CtagsFileWrapper:public TagFileWrapper {
class CtagsFileWrapper : public TagFileWrapper {
public:
CtagsFileWrapper(std::string path, bool recurse=true,bool fileP=false);
CtagsFileWrapper(std::string path, bool recurse = true, bool fileP = false);
~CtagsFileWrapper(){}
std::map<std::string,LookupResult> match
(std::string name, bool partialMatch=false);
std::map<std::string,LookupResult>
match(std::string name, bool partialMatch = false);
bool newFile(){return m_Generated;}
bool newFile() const { return m_Generated; }
bool validFile(){return m_Validfile;}
bool validFile() const { return m_Validfile; }
private:
void generate(const std::vector<std::string>& cmd,
std::string tagfile="adhoc");
std::string tagfile = "adhoc");
void generate(std::string file);
void read();

View File

@ -1,10 +1,11 @@
#ifndef CLING_TAG_MANAGER_H
#define CLING_TAG_MANAGER_H
#include <vector>
#include <map>
#include "cling/Interpreter/Interpreter.h"
#include "cling/TagsExtension/Wrapper.h"
#include <map>
#include <vector>
namespace cling {
///\brief Class for managing all the available tag files
class TagManager {
@ -14,14 +15,16 @@ namespace cling {
///\brief Information from a tag file lookup
class LookupInfo{
public:
LookupInfo(std::string h,std::string n,std::string t);
LookupInfo(std::string h, std::string n, std::string t);
std::string header;
std::string name;
std::string type;
};
///\brief Add a new path from which a single tag file is generated
/// If recurse is true, path is recursively scanned but not preprocessed
/// else only the files directly in path are preprocessed and tagged
///
void AddTagFile(std::string path, bool recurse=true);
std::size_t size() { return m_Tags.size(); }
@ -34,7 +37,6 @@ namespace cling {
private:
std::vector<TagFileWrapper*> m_Tags;
TableType m_Table;
};
}//end namespace cling
#endif
}// end namespace cling
#endif // CLING_TAG_MANAGER_H

View File

@ -1,42 +1,44 @@
#ifndef CLING_CTAGS_WRAPPER_H
#define CLING_CTAGS_WRAPPER_H
// #include "readtags.h"
#include <vector>
#include <cstdlib>
#include <map>
#include <string>
#include <vector>
namespace cling {
///\brief Different tag generating systems must inherit from TagFileWrapper
/// An object of a derived class represents a single tag file,
/// which may be generated from multiple header/source files
/// which may be generated from multiple header/source files.
class TagFileWrapper {
public:
TagFileWrapper(std::string Path):m_Path(Path){}
TagFileWrapper(std::string Path) : m_Path(Path) {}
struct LookupResult{
std::string name;
std::string kind;
};
///\brief Returns a map which associates a name with header files
/// and type of the name
/// When partialMatch is true, name can be a prefix of the values returned
/// and type of the name.
/// When partialMatch is true, name can be a prefix of the values returned.
///
virtual std::map<std::string,LookupResult>
match(std::string name, bool partialMatch=false)=0;
match(std::string name, bool partialMatch=false) = 0;
///\brief True if the file was generated and not already present
virtual bool newFile()=0;
///\brief True if the file was generated and not already present.
///
virtual bool newFile() = 0;
///\brief True if the file is in a valid state
virtual bool validFile()=0;
///\brief True if the file is in a valid state.
///
virtual bool validFile() = 0;
virtual ~TagFileWrapper(){}
virtual ~TagFileWrapper() {}
bool operator==(const TagFileWrapper& t) {return m_Path==t.m_Path;}
bool operator==(const TagFileWrapper& t) { return m_Path==t.m_Path; }
private:
std::string m_Path;
};
} //end namespace cling
#endif
#endif // CLING_CTAGS_WRAPPER_H

View File

@ -148,6 +148,7 @@ namespace cling {
// TODO: Some fine grained diagnostics
return result;
}
// T := 'T' FilePath Comment
// FilePath := AnyString
// AnyString := .*^('\t' Comment)
@ -169,7 +170,6 @@ namespace cling {
return result;
}
// >RedirectCommand := '>' FilePath
// FilePath := AnyString
// AnyString := .*^(' ' | '\t')

View File

@ -74,12 +74,13 @@ namespace cling {
MetaSema::ActionResult MetaSema::actOnTCommand(llvm::StringRef file) {
//llvm::outs()<<file<<": directory to be recursively tagged.\n";
AutoloadCallback *ctic= static_cast<AutoloadCallback*> (m_Interpreter.getCallbacks());
AutoloadCallback *ctic
= static_cast<AutoloadCallback*>(m_Interpreter.getCallbacks());
//FIXME: Temporary Implementation
// May cause a segfault if .T is used when the CTags callback is not set
// This will require modifying Interpreter to 'know' about the extension
if (ctic){
auto path=m_Interpreter.lookupFileOrLibrary(file);
auto path = m_Interpreter.lookupFileOrLibrary(file);
if(path != "")
file = path;
ctic->getTagManager()->AddTagFile(file);

View File

@ -71,8 +71,6 @@ namespace cling {
///
ActionResult actOnTCommand(llvm::StringRef file);
///\brief < Redirect command.
///
///\param[in] file - The file where the output is redirected

View File

@ -4,49 +4,44 @@
#include "clang/Sema/Sema.h"
#include "llvm/Support/Path.h"
using namespace clang;
namespace cling {
bool AutoloadCallback::LookupObject (clang::LookupResult &R, clang::Scope *){
bool AutoloadCallback::LookupObject (LookupResult &R, Scope *) {
std::string in=R.getLookupName().getAsString();
clang::Sema& sema= m_Interpreter->getSema();
Sema& sema= m_Interpreter->getSema();
unsigned id = sema.getDiagnostics().getCustomDiagID
(clang::DiagnosticsEngine::Level::Warning,
"Note: '%0' can be found in %1");
unsigned idn = sema.getDiagnostics().getCustomDiagID
(clang::DiagnosticsEngine::Level::Note,
"Type : %0 , Full Path: %1");
unsigned id
= sema.getDiagnostics().getCustomDiagID (DiagnosticsEngine::Level::Warning,
"Note: '%0' can be found in %1");
unsigned idn
= sema.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Level::Note,
"Type : %0 , Full Path: %1");
for (auto it = m_Tags->begin(in); it != m_Tags->end(in); ++it)
{
for (auto it = m_Tags->begin(in); it != m_Tags->end(in); ++it) {
auto lookup = it->second;
clang::SourceLocation loc = R.getNameLoc();
SourceLocation loc = R.getNameLoc();
if (loc.isInvalid())
continue;
sema.Diags.Report(R.getNameLoc(),id)
<< lookup.name
<< llvm::sys::path::filename(lookup.header);
sema.Diags.Report(R.getNameLoc(), id)
<< lookup.name
<< llvm::sys::path::filename(lookup.header);
sema.Diags.Report(R.getNameLoc(),idn)
<< lookup.type
<< lookup.header;
<< lookup.type
<< lookup.header;
}
return false;
}
AutoloadCallback::AutoloadCallback
(cling::Interpreter* interp, TagManager *t) :
InterpreterCallbacks(interp,true),
m_Interpreter(interp),
m_Tags(t) {
//TODO : Invoke stdandard c++ tagging here
}
TagManager* AutoloadCallback::getTagManager() {
return m_Tags;
AutoloadCallback::AutoloadCallback(Interpreter* interp, TagManager *t) :
InterpreterCallbacks(interp,true), m_Interpreter(interp), m_Tags(t) {
//TODO : Invoke stdandard c++ tagging here
// FIXME: There is an m_Interpreter in the base class InterpreterCallbacks.
}
}//end namespace cling

View File

@ -8,7 +8,7 @@
add_cling_library(clingCtagsExtension
CtagsWrapper.cpp
Callback.cpp
AutoloadCallback.cpp
readtags.cpp
TagManager.cpp
FSUtils.cpp

View File

@ -1,8 +1,11 @@
#include "cling/TagsExtension/CtagsWrapper.h"
#include "llvm/ADT/StringRef.h"
#include "FSUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "cling/TagsExtension/CtagsWrapper.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
namespace cling {
CtagsFileWrapper::CtagsFileWrapper(std::string path, bool recurse, bool fileP)
@ -17,7 +20,7 @@ namespace cling {
if (recurse) {
std::vector<std::string> list;
llvm::error_code ec;
llvm::sys::fs::recursive_directory_iterator rdit(path,ec);
llvm::sys::fs::recursive_directory_iterator rdit(path, ec);
while (rdit != decltype(rdit)()) {
auto entry = *rdit;
@ -44,11 +47,10 @@ namespace cling {
}
///auto pair=splitPath(path);
///TODO Preprocess the files in list and generate tags for them
}
}
std::map<std::string,TagFileWrapper::LookupResult>
std::map<std::string, TagFileWrapper::LookupResult>
CtagsFileWrapper::match(std::string name, bool partialMatch){
std::map<std::string,LookupResult> map;
tagEntry entry;
@ -65,7 +67,6 @@ namespace cling {
}
return map;
}
void CtagsFileWrapper::generate(std::string file) {
@ -76,34 +77,35 @@ namespace cling {
m_Generated=false;
return;
}
std::string cmd = "ctags --language-force=c++ -f "+m_Tagpath+m_Tagfilename+" "+file;
std::string cmd = "ctags --language-force=c++ -f "
+ m_Tagpath + m_Tagfilename + " " + file;
// llvm::errs()<<cmd<<"\n";
system(cmd.c_str());
}
//no more than `arglimit` arguments in a single invocation
void CtagsFileWrapper::generate
(const std::vector<std::string>& paths, std::string dirpath){
void CtagsFileWrapper::generate(const std::vector<std::string>& paths,
std::string dirpath) {
std::string concat;
m_Tagpath = generateTagPath();
m_Tagfilename = pathToFileName(dirpath);
if (!needToGenerate(m_Tagpath,m_Tagfilename, dirpath)){
if (!needToGenerate(m_Tagpath, m_Tagfilename, dirpath)){
m_Generated = false;
return;
}
auto it=paths.begin(),end=paths.end();
while (it != end){
concat+=(*it+" ");
auto it = paths.begin(), end = paths.end();
while (it != end) {
concat += (*it + " ");
it++;
}
//TODO: Convert these to twine
std::string filename = " -f "+m_Tagpath+m_Tagfilename+" ";
std::string filename = " -f " + m_Tagpath+m_Tagfilename + " ";
std::string lang = " --language-force=c++ ";
std::string sorted = " --sort=yes ";
std::string append = " -a ";
std::string cmd = "ctags "+append+lang+filename+sorted+concat;
std::string cmd = "ctags "+ append + lang + filename + sorted + concat;
// llvm::errs()<<cmd<<"\n";
@ -112,8 +114,8 @@ namespace cling {
}
void CtagsFileWrapper::read() {
m_Tagfile.tf = tagsOpen
((m_Tagpath+m_Tagfilename).c_str(), &(m_Tagfile.tfi));
m_Tagfile.tf
= tagsOpen((m_Tagpath + m_Tagfilename).c_str(), &(m_Tagfile.tfi));
//std::cout<<"File "<<tagpath+tagfilename<<" read.\n";
if (m_Tagfile.tfi.status.opened == false)

View File

@ -1,32 +1,34 @@
#include "FSUtils.h"
#include <string>
#include <cstdlib>
#include <algorithm>
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include <algorithm>
#include <cstdlib>
#include <string>
namespace cling {
std::pair<std::string,std::string> splitPath(std::string path){
auto filename=llvm::sys::path::filename(path);
std::pair<std::string,std::string> splitPath(std::string path) {
auto filename = llvm::sys::path::filename(path);
llvm::SmallString<128> p(path.begin(),path.end());
llvm::sys::path::remove_filename(p);
return {p.c_str(),filename};
return { p.c_str(),filename };
}
std::string pathToFileName(std::string path){
for(auto& c:path)
std::string pathToFileName(std::string path) {
for(auto& c : path)
if(c == '/')
c = '_';
return path;
}
bool fileIsNewer(std::string path,std::string dir){
bool fileIsNewer(std::string path, std::string dir){
return true;//TODO Timestamp checks go here
}
bool needToGenerate(std::string tagpath,
std::string filename, std::string dirpath){
bool needToGenerate(std::string tagpath, std::string filename,
std::string dirpath){
if( llvm::sys::fs::exists(tagpath+filename)) {
return false;
}
@ -46,24 +48,25 @@ namespace cling {
#else
const char preferred_separator = '/';
#endif
return {preferred_separator};
return { preferred_separator };
}
std::string generateTagPath(){
std::string generateTagPath() {
llvm::SmallString<30> home_ss;
llvm::sys::path::home_directory(home_ss);
std::string homedir=home_ss.c_str();
std::string homedir = home_ss.c_str();
if (homedir == "")
homedir = ".";
std::string tagdir=get_separator() +".cling/";
std::string result=homedir+tagdir;
std::string tagdir = get_separator() + ".cling/";
std::string result = homedir + tagdir;
llvm::sys::fs::create_directory(result);
return result;
}
bool isHeaderFile(llvm::StringRef str){
return str.endswith(".h")
||str.endswith(".hpp")
||str.find("include")!=llvm::StringRef::npos;
|| str.endswith(".hpp")
|| str.find("include") != llvm::StringRef::npos;
}
}//end namespace cling

View File

@ -1,13 +1,15 @@
#ifndef CLING_FS_UTILS_H
#define CLING_FS_UTILS_H
#include "llvm/ADT/StringRef.h"
namespace cling {
std::string pathToFileName(std::string path);
bool fileIsNewer(std::string path, std::string dir);
bool needToGenerate(std::string tagpath,
std::string filename, std::string dirpath);
bool needToGenerate(std::string tagpath, std::string filename,
std::string dirpath);
std::string generateTagPath();
@ -15,5 +17,5 @@ namespace cling {
std::pair<std::string,std::string> splitPath(std::string path);
} //end namespace cling
#endif
} // end namespace cling
#endif // CLING_FS_UTILS_H

View File

@ -1,14 +1,17 @@
#include "cling/TagsExtension/TagManager.h"
#include "cling/TagsExtension/CtagsWrapper.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
namespace cling {
TagManager::TagManager(){}
void TagManager::AddTagFile(std::string path, bool recurse){
TagManager::TagManager() {}
void TagManager::AddTagFile(std::string path, bool recurse) {
bool fileP = false;
if (llvm::sys::fs::is_regular_file(path)) {
fileP = true;
@ -22,31 +25,27 @@ namespace cling {
path = str.c_str();
}
TagFileWrapper* tf = new CtagsFileWrapper(path,recurse,fileP);
TagFileWrapper* tf = new CtagsFileWrapper(path, recurse, fileP);
if (!tf->validFile()) {
llvm::errs() << "Reading Tag File: " << path << " failed.\n";
return;
}
bool eq = false;
for (auto& t:m_Tags) {
for (auto& t : m_Tags) {
if (*t == *tf ) {
eq=true;
eq = true;
break;
}
}
if (!eq) {
m_Tags.push_back(tf);
}
}
TagManager::TableType::iterator
TagManager::begin(std::string name){
TagManager::TableType::iterator TagManager::begin(std::string name) {
m_Table.erase(name);
for (auto& t:m_Tags){
for (auto match:t->match(name, true)){
for (auto& t : m_Tags){
for (auto match : t->match(name, true)){
LookupInfo l(match.first, match.second.name, match.second.kind);
m_Table.insert({name, l});
}
@ -54,14 +53,15 @@ namespace cling {
auto r = m_Table.equal_range(name);
return r.first;
}
TagManager::TableType::iterator
TagManager::end(std::string name){
TagManager::TableType::iterator TagManager::end(std::string name) {
auto r = m_Table.equal_range(name);
return r.second;
}
TagManager::LookupInfo::LookupInfo
(std::string h, std::string n, std::string t):
header(h), name(n), type(t){}
TagManager::LookupInfo::LookupInfo (std::string h, std::string n,
std::string t)
: header(h), name(n), type(t){}
TagManager::~TagManager() {
for (auto& tag : m_Tags )

View File

@ -1 +1 @@
class TestClass{};
class TestClass{};