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 #ifndef CLING_CTAGS_AUTOLOAD_CALLBACK_H
#define CLING_CTAGS_CALLBACK_H #define CLING_CTAGS_AUTOLOAD_CALLBACK_H
#include "cling/Interpreter/Interpreter.h" #include "cling/Interpreter/Interpreter.h"
#include "cling/Interpreter/InterpreterCallbacks.h" #include "cling/Interpreter/InterpreterCallbacks.h"
@ -14,7 +14,7 @@ unless these objects are loaded.
.rawInput 0 .rawInput 0
#include "cling/TagsExtension/TagManager.h" #include "cling/TagsExtension/TagManager.h"
#include "cling/TagsExtension/Callback.h" #include "cling/TagsExtension/AutoloadCallback.h"
cling::TagManager t; cling::TagManager t;
gCling->setCallbacks(new cling::AutoloadCallback(gCling,&t)); gCling->setCallbacks(new cling::AutoloadCallback(gCling,&t));
@ -35,12 +35,12 @@ namespace cling {
bool LookupObject (clang::LookupResult &R, clang::Scope *); bool LookupObject (clang::LookupResult &R, clang::Scope *);
cling::TagManager* getTagManager(); TagManager* getTagManager() { return m_Tags; }
private: private:
cling::Interpreter* m_Interpreter; Interpreter* m_Interpreter;
cling::TagManager* m_Tags; 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" #include "readtags.h"
namespace cling { namespace cling {
///\brief Implements tag operations for Ctags ///\brief Implements tag operations for Ctags
class CtagsFileWrapper:public TagFileWrapper { class CtagsFileWrapper : public TagFileWrapper {
public: public:
CtagsFileWrapper(std::string path, bool recurse=true,bool fileP=false); CtagsFileWrapper(std::string path, bool recurse = true, bool fileP = false);
~CtagsFileWrapper(){} ~CtagsFileWrapper(){}
std::map<std::string,LookupResult> match std::map<std::string,LookupResult>
(std::string name, bool partialMatch=false); 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: private:
void generate(const std::vector<std::string>& cmd, void generate(const std::vector<std::string>& cmd,
std::string tagfile="adhoc"); std::string tagfile = "adhoc");
void generate(std::string file); void generate(std::string file);
void read(); void read();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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