Core: Fixed memory info in FreeBSD, ide: Refactoring CodeBase

git-svn-id: svn://ultimatepp.org/upp/trunk@14617 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-06-22 06:38:59 +00:00
parent 960c046dd8
commit 9dce52264a
31 changed files with 351 additions and 187 deletions

View file

@ -181,7 +181,7 @@ void GetSystemMemoryStatus(uint64& total, uint64& available)
}
#endif
#ifdef PLATFORM_FREEBSD
int64 page_size;
u_int page_size;
struct vmtotal vmt;
size_t vmt_size, uint_size;
@ -190,8 +190,8 @@ void GetSystemMemoryStatus(uint64& total, uint64& available)
if(sysctlbyname("vm.vmtotal", &vmt, &vmt_size, NULL, 0) >= 0 &&
sysctlbyname("vm.stats.vm.v_page_size", &page_size, &uint_size, NULL, 0) >= 0) {
available = vmt.t_free * page_size;
total = vmt.t_avm * page_size;
available = vmt.t_free * (u_int64_t)page_size;
total = vmt.t_avm * (u_int64_t)page_size;
return;
}
#endif

View file

@ -325,7 +325,7 @@ public:
void Insert(int i, const Array& x, int offset, int count);
template <class Range>
void InsertRange(int i, const Range& r);
void Insert(int i, Array&& x) { vector.InsertPick(i, pick(x.vector)); }
void Insert(int i, Array&& x) { vector.Insert(i, pick(x.vector)); }
void Append(const Array& x) { Insert(GetCount(), x); }
void Append(const Array& x, int o, int c) { Insert(GetCount(), x, o, c); }
void Append(Array&& x) { InsertPick(GetCount(), pick(x)); }

View file

@ -86,6 +86,12 @@ void CppBase::Sweep(const Index<int>& file, bool keep)
Remove(remove);
}
void CppBase::Append(CppBase&& base)
{
for(int i = 0; i < base.GetCount(); i++)
GetAdd(base.GetKey(i)).Append(pick(base[i]));
}
void CppBase::RemoveFile(int filei)
{
Index<int> h;

View file

@ -5,8 +5,11 @@
namespace Upp {
// Functions in this header can be called without mutexes...
struct CppBaseLock { // Use this in any function that is using CppBase
CppBaseLock();
~CppBaseLock();
};
bool IsCPPFile(const String& file);
bool IsHFile(const String& path);
@ -147,6 +150,7 @@ struct CppBase : ArrayMap<String, Array<CppItem> > {
void Sweep(const Index<int>& file, bool keep = true);
void RemoveFiles(const Index<int>& remove_file) { Sweep(remove_file, false); }
void RemoveFile(int filei);
void Append(CppBase&& base);
void Dump(Stream& s);
};

View file

@ -9,6 +9,7 @@ file
keyword.i,
ppconfig.cpp,
macro.cpp,
util.cpp,
ppfile.cpp,
srcfiles.cpp,
cpp.cpp,

View file

@ -78,7 +78,9 @@ String GetIncludePath();
String GetSegmentFile(int segment_id);
const PPFile& GetPPFile(const char *path);
void MakePP(const Index<String>& paths); // this is the only place to change PPFile info, cannot be run concurrently with anything else
const PPFile& GetPPFile(const char *path); // only returns information created by MakePP
String GetIncludePath(const String& s, const String& filedir);
bool IncludesFile(const String& parent_path, const String& header_path);

View file

@ -4,7 +4,7 @@
namespace Upp {
#define LLOG(x) // DLOG(x)
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
void Parser::ThrowError(const String& e)
{
@ -27,6 +27,7 @@ inline const char *bew(const char *s, const char *t)
return t;
}
// String == String comparison is likely faster than String == const char * comparison
static String s_operator("operator");
static String s_virtual("virtual");
static String s_inline("inline");

View file

@ -1,8 +1,7 @@
#include "CppBase.h"
#include "Internal.h"
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
namespace Upp {
@ -20,7 +19,6 @@ SrcFile::SrcFile() :
SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preprocess, only removes (or processes) comment and directives
{
DTIMING("PreProcess");
SrcFile res;
bool include = true;
int lineno = 0;
@ -67,12 +65,15 @@ SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preproces
s[3] == 'i' && s[4] == 'n' && s[5] == 'e' && !iscid(s[6])) {
s += 6;
while(*s == ' ' || *s == '\t') s++;
String macro;
const char *b = s;
while(iscid(*s))
macro.Cat(*s++);
s++;
String macro(b, s);
if(*s == '(') {
b = s;
while(*s != ')' && *s)
macro.Cat(*s++);
s++;
macro.Cat(b, s);
macro << ')';
}
if(include)

View file

@ -4,7 +4,7 @@
namespace Upp {
#define LLOG(x) // DLOG(x)
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
bool DoQualify(ScopeInfo& nf, const String& type, const String& usings, String& qt);

View file

@ -4,7 +4,7 @@
namespace Upp {
#define LLOG(x)
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
ScopeInfo::ScopeInfo(const CppBase& base, int scopei)
: scopei(scopei), base(base)

View file

@ -3,7 +3,7 @@
namespace Upp {
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
#define LLOG(x) // DLOG(x)
void Cpp::ParamAdd(Vector<String>& param, const char *s, const char *e)

View file

@ -160,13 +160,12 @@ void Lex::Next()
if(c == '\0') return;
switch(c) {
case_id: {
String x;
x.Reserve(12);
x.Cat(c);
const char *b = ptr - 1;
while(iscid(*ptr))
x.Cat(*ptr++);
ptr++;
String x(b, ptr);
int q = id.FindAdd(x);
if(q == tk_rval_ - 256) { // simple hack for transitionary macro
if(q == tk_rval_ - 256) { // simple hack for old rval macro
AddCode('&');
AddCode('&');
}

View file

@ -3,87 +3,31 @@
namespace Upp {
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
#define LLOG(x) // DLOG(x)
bool IsCPPFile(const String& path)
{
return findarg(ToLower(GetFileExt(path)) , ".c", ".cpp", ".cc" , ".cxx", ".icpp") >= 0;
}
static std::atomic<int> s_PPserial;
static VectorMap<String, PPMacro> sAllMacros; // Only MakePP can write to this
static ArrayMap<String, PPFile> sPPfile; // Only MakePP can write to this
bool IsHFile(const String& path)
{
return findarg(ToLower(GetFileExt(path)) , ".h", ".hpp", ".hxx" , ".hh") >= 0;
}
static VectorMap<String, Time> s_PathFileTime;
static StaticMutex s_PathFileTimeMutex;
void SetSpaces(String& l, int pos, int count)
{
StringBuffer s(l);
memset(~s + pos, ' ', count);
l = s;
}
static VectorMap<String, String> s_IncludePath;
static String s_Include_Path;
static StaticMutex s_IncludePathMutex;
const char *SkipString(const char *s)
{
CParser p(s);
try {
p.ReadOneString(*s);
}
catch(CParser::Error) {}
s = p.GetPtr();
while((byte)*(s - 1) <= ' ')
s--;
return s;
}
static StaticMutex s_FlatPPMutex;
static ArrayMap<String, FlatPP> s_FlatPP; // ArrayMap to allow read access
void RemoveComments(String& l, bool& incomment)
int NextPPSerial()
{
int q = -1;
int w = -1;
if(incomment)
q = w = 0;
else {
const char *s = l;
while(*s) {
if(*s == '\"')
s = SkipString(s);
else
if(s[0] == '/' && s[1] == '/') {
q = int(s - ~l);
SetSpaces(l, q, l.GetCount() - q);
return;
}
else
if(s[0] == '/' && s[1] == '*') {
q = int(s - ~l);
break;
}
else
s++;
}
if(q >= 0)
w = q + 2;
}
while(q >= 0) {
int eq = l.Find("*/", w);
if(eq < 0) {
incomment = true;
SetSpaces(l, q, l.GetCount() - q);
return;
}
SetSpaces(l, q, eq + 2 - q);
incomment = false;
q = l.Find("/*");
w = q + 2;
}
return ++s_PPserial;
}
static VectorMap<String, PPMacro> sAllMacros;
static ArrayMap<String, PPFile> sPPfile;
static int sPPserial;
void SweepPPFiles(const Index<String>& keep)
{
CppBaseLock __;
Index<int> pp_segment_id;
int unlinked_count = 0;
for(int i = 0; i < sPPfile.GetCount(); i++)
@ -198,6 +142,10 @@ void PPFile::Parse(Stream& in)
keywords.Clear();
int linei = 0;
Md5Stream md5;
int current_serial = 0;
VectorMap<String, PPMacro> local_macro; // gather all macros first to reduce locking
while(!in.IsEof()) {
String l = in.GetLine();
const char *ll = l;
@ -218,48 +166,75 @@ void PPFile::Parse(Stream& in)
if(next_segment) {
PPItem& m = item.Add();
m.type = PP_DEFINES;
m.segment_id = ++sPPserial;
m.segment_id = current_serial = NextPPSerial();
next_segment = false;
local_segments.Add(sPPserial);
local_segments.Add(current_serial);
}
CppMacro def;
String id = def.Define(p.GetPtr());
if(id.GetCount()) {
PPMacro& l = local_macro.Add(id);
l.segment_id = current_serial;
l.line = linei;
l.macro = def;
/*
PPMacro m;
m.segment_id = sPPserial;
m.segment_id = current_serial;
m.line = linei;
m.macro = def;
ppmacro.Add(sAllMacros.Put(id, m));
*/
md5.Put("#", 1);
md5.Put(id);
md5.Put(0);
md5.Put(m.macro.md5, 16);
md5.Put(l.macro.md5, 16);
}
}
else
if(p.Id("undef")) {
if(p.IsId()) {
String id = p.ReadId();
md5.Put("#", 1);
md5.Put(id);
md5.Put(1);
if(id.GetCount()) {
md5.Put("#", 1);
md5.Put(id);
md5.Put(1);
int q = local_macro.FindLast(id); // heuristic: only local undefs are allowed
while(q >= 0) {
PPMacro& um = local_macro[q];
if(!um.macro.IsUndef()) { // found corresponding macro to undef
PPItem& m = item.Add();
m.type = PP_DEFINES;
m.segment_id = current_serial = NextPPSerial();
um.undef_segment_id = m.segment_id;
next_segment = true;
local_segments.Add(current_serial);
PPMacro& l = local_macro.Add(id);
l.segment_id = current_serial;
l.line = linei;
l.macro.SetUndef();
}
q = local_macro.FindPrev(q);
}
}
/*
int segmenti = -1;
PPMacro *um = FindPPMacro(id, local_segments, segmenti);
if(um && segmenti) { // heuristic: only local undefs are allowed
if(um && segmenti) {
PPItem& m = item.Add();
m.type = PP_DEFINES;
m.segment_id = ++sPPserial;
m.segment_id = current_serial = NextPPSerial();
um->undef_segment_id = m.segment_id;
next_segment = true;
local_segments.Add(sPPserial);
local_segments.Add(current_serial);
if(id.GetCount()) {
PPMacro m;
m.segment_id = sPPserial;
m.segment_id = current_serial;
m.line = linei;
m.macro.SetUndef();
ppmacro.Add(sAllMacros.Put(id, m));
}
}
*/
}
}
else
@ -365,6 +340,10 @@ void PPFile::Parse(Stream& in)
remove.Add(i++);
}
keywords.Remove(remove);
INTERLOCKED { // this is the only place that is allowed to write to sAllMacros
for(int i = 0; i < local_macro.GetCount(); i++)
ppmacro.Add(sAllMacros.Put(local_macro.GetKey(i), local_macro[i]));
}
}
void PPFile::Dump() const
@ -387,21 +366,50 @@ void PPFile::Dump() const
DUMPC(includes);
}
static VectorMap<String, String> sIncludePath;
static ArrayMap<String, FlatPP> sFlatPP;
static String sInclude_Path;
void PPSync(const String& include_path)
{
CppBaseLock __;
LLOG("* PPSync");
sIncludePath.Clear();
sFlatPP.Clear();
sInclude_Path = include_path;
{
Mutex::Lock __(s_IncludePathMutex);
s_IncludePath.Clear();
s_Include_Path = include_path;
}
{
Mutex::Lock __(s_FlatPPMutex);
s_FlatPP.Clear();
}
}
void InvalidateFileTimeCache()
{
Mutex::Lock __(s_PathFileTimeMutex);
s_PathFileTime.Clear();
}
void InvalidateFileTimeCache(const String& path)
{
LLOG("InvalidateFileTimeCache " << path);
Mutex::Lock __(s_PathFileTimeMutex);
s_PathFileTime.UnlinkKey(path);
}
Time GetFileTimeCached(const String& p)
{
LTIMING("GetFileTimeCached");
Mutex::Lock __(s_PathFileTimeMutex);
int q = s_PathFileTime.Find(p);
if(q >= 0)
return s_PathFileTime[q];
Time m = FileGetTime(p);
s_PathFileTime.Put(p, m);
return m;
}
String GetIncludePath()
{
return sInclude_Path;
Mutex::Lock __(s_IncludePathMutex);
return s_Include_Path;
}
String GetIncludePath0(const char *s, const char *filedir)
@ -432,57 +440,47 @@ String GetIncludePath0(const char *s, const char *filedir)
return Null;
}
static VectorMap<String, Time> sPathFileTime;
void InvalidateFileTimeCache()
{
sPathFileTime.Clear();
}
void InvalidateFileTimeCache(const String& path)
{
LLOG("InvalidateFileTimeCache " << path);
sPathFileTime.UnlinkKey(path);
}
Time GetFileTimeCached(const String& p)
{
LTIMING("GetFileTimeCached");
int q = sPathFileTime.Find(p);
if(q >= 0)
return sPathFileTime[q];
Time m = FileGetTime(p);
sPathFileTime.Put(p, m);
return m;
}
String GetIncludePath(const String& s, const String& filedir)
{
LTIMING("GetIncludePath");
Mutex::Lock __(s_IncludePathMutex);
String key;
key << s << "#" << filedir;
int q = sIncludePath.Find(key);
int q = s_IncludePath.Find(key);
if(q >= 0)
return sIncludePath[q];
return s_IncludePath[q];
LTIMING("GetIncludePath 2");
String p = GetIncludePath0(s, filedir);
sIncludePath.Add(key, p);
s_IncludePath.Add(key, p);
LLOG("GetIncludePath " << s << " " << filedir << ": " << p);
return p;
}
void MakePP(const Index<String>& paths)
{
Vector<String> todo;
Vector<PPFile *> pp;
for(int i = 0; i < paths.GetCount(); i++) {
String path = paths[i];
PPFile& f = sPPfile.GetPut(path);
Time tm = GetFileTimeCached(path);
if(f.filetime != tm) {
f.filetime = tm;
pp.Add(&f);
todo.Add(path);
}
}
CoFor(todo.GetCount(), [&](int i) {
FileIn in(todo[i]);
pp[i]->Parse(in);
});
}
const PPFile& GetPPFile(const char *path)
{
LTIMING("GetPPFile");
Time tm = GetFileTimeCached(path);
PPFile& f = sPPfile.GetPut(path);
LLOG("GetPPFile " << path << ", " << f.filetime << ", " << tm);
if(f.filetime != tm) {
f.filetime = tm;
FileIn in(path);
f.Parse(in);
}
return f;
static PPFile zero;
return sPPfile.Get(path, zero);
}
bool IsSameFile(const String& f1, const String& f2)
@ -494,12 +492,13 @@ const FlatPP& GetFlatPPFile(const char *path, Index<String>& visited)
{
LTIMING("GetFlatPPFile");
LLOG("GetFlatPPFile " << path);
int q = sFlatPP.Find(path);
Mutex::Lock __(s_FlatPPMutex);
int q = s_FlatPP.Find(path);
if(q >= 0) {
LLOG("From cache");
return sFlatPP[q];
return s_FlatPP[q];
}
FlatPP& fp = sFlatPP.Add(path);
FlatPP& fp = s_FlatPP.Add(path);
const PPFile& pp = GetPPFile(path);
int n = visited.GetCount();
visited.FindAdd(path);
@ -622,21 +621,26 @@ const Index<String>& GetNamespaceEndMacros()
void SetPPDefs(const String& defs)
{
CppBaseLock __;
sDefs = defs;
LoadPPConfig();
}
void CleanPP()
{
CppBaseLock __;
sAllMacros.Clear();
sPPfile.Clear();
sPPserial = 0;
s_PPserial = 0;
LoadPPConfig();
}
void SerializePPFiles(Stream& s)
{
CppBaseLock __;
int sPPserial = s_PPserial;
s % sAllMacros % sPPfile % sPPserial;
s_PPserial = sPPserial;
if(s.IsLoading())
LoadPPConfig();

View file

@ -3,7 +3,7 @@
namespace Upp {
#define LTIMING(x) DTIMING(x)
#define LTIMING(x) // DTIMING(x)
static VectorMap<String, String> sSrcFile;
static Index<uint64> sIncludes;
@ -25,6 +25,7 @@ String NormalizeSourcePath(const String& path)
void ClearSources()
{
CppBaseLock __;
sSrcFile.Clear();
sIncludes.Clear();
}
@ -41,6 +42,7 @@ const VectorMap<String, String>& GetAllSourceMasters()
void GatherSources(const String& master_path, const String& path_, Vector<int>& parents)
{
CppBaseLock __;
String path = NormalizeSourcePath(path_);
if(sSrcFile.Find(path) >= 0)
return;
@ -50,11 +52,15 @@ void GatherSources(const String& master_path, const String& path_, Vector<int>&
sSrcFile.Add(path, master_path);
parents.Add(ii);
const PPFile& f = GetPPFile(path);
Index<String> todo;
for(int i = 0; i < f.includes.GetCount(); i++) {
String p = GetIncludePath(f.includes[i], GetFileFolder(path));
if(p.GetCount())
GatherSources(master_path, p, parents);
todo.FindAdd(p);
}
MakePP(todo); // parse PP files in parallel to accelerate things...
for(String p : todo)
GatherSources(master_path, p, parents);
parents.Drop();
}

94
uppsrc/CppBase/util.cpp Normal file
View file

@ -0,0 +1,94 @@
#include "CppBase.h"
#include "Internal.h"
namespace Upp {
static StaticMutex sGLock;
static thread_local int sGLockLevel = 0;
CppBaseLock::CppBaseLock()
{
if(sGLockLevel++ == 0)
sGLock.Enter();
}
CppBaseLock::~CppBaseLock()
{
ASSERT(sGLockLevel > 0);
if(--sGLockLevel == 0)
sGLock.Leave();
}
bool IsCPPFile(const String& path)
{
return findarg(ToLower(GetFileExt(path)) , ".c", ".cpp", ".cc" , ".cxx", ".icpp") >= 0;
}
bool IsHFile(const String& path)
{
return findarg(ToLower(GetFileExt(path)) , ".h", ".hpp", ".hxx" , ".hh") >= 0;
}
void SetSpaces(String& l, int pos, int count)
{
StringBuffer s(l);
memset(~s + pos, ' ', count);
l = s;
}
const char *SkipString(const char *s)
{
CParser p(s);
try {
p.ReadOneString(*s);
}
catch(CParser::Error) {}
s = p.GetPtr();
while((byte)*(s - 1) <= ' ')
s--;
return s;
}
void RemoveComments(String& l, bool& incomment)
{
int q = -1;
int w = -1;
if(incomment)
q = w = 0;
else {
const char *s = l;
while(*s) {
if(*s == '\"')
s = SkipString(s);
else
if(s[0] == '/' && s[1] == '/') {
q = int(s - ~l);
SetSpaces(l, q, l.GetCount() - q);
return;
}
else
if(s[0] == '/' && s[1] == '*') {
q = int(s - ~l);
break;
}
else
s++;
}
if(q >= 0)
w = q + 2;
}
while(q >= 0) {
int eq = l.Find("*/", w);
if(eq < 0) {
incomment = true;
SetSpaces(l, q, l.GetCount() - q);
return;
}
SetSpaces(l, q, eq + 2 - q);
incomment = false;
q = l.Find("/*");
w = q + 2;
}
}
};

View file

@ -222,6 +222,8 @@ void Progress::SetText(const String& s)
void Progress::Setxt()
{
if(!IsMainThread())
return;
info = Format(text, pos);
Process();
}

View file

@ -65,6 +65,7 @@ Size SplashCtrl::MakeLogo(Ctrl& parent, Array<Ctrl>& ctrl)
Label& v1 = ctrl.Create<Label>();
l.SetImage(logo);
Size sz = Size(isz.cx, isz.cy/* + 80*/);
CppBaseLock __;
const CppBase& cpp = CodeBase();
int total = 0;
for(int i = 0; i < cpp.GetCount(); i++)

View file

@ -2,6 +2,7 @@
void AssistEditor::Annotate(const String& filename)
{
CppBaseLock __;
int fi = GetSourceFileIndex(filename);
CppBase& base = CodeBase();
ClearAnnotations();

View file

@ -1000,6 +1000,7 @@ String AssistEditor::MakeDefinition(const String& cls, const String& _n)
void Ide::IdeGotoCodeRef(String coderef)
{
LLOG("IdeGotoLink " << coderef);
CppBaseLock __;
if(IsNull(coderef)) return;
String scope, item;
SplitCodeRef(coderef, scope, item);

View file

@ -2,7 +2,7 @@
#include <plugin/lz4/lz4.h>
#define LTIMING(x) // RTIMING(x)
#define LTIMING(x) // DTIMING(x)
#define LLOG(x) // DLOG(x)
#define LTIMESTOP(x) // RTIMESTOP(x)
@ -26,6 +26,12 @@ INITIALIZER(CodeBase)
InitializeTopicModule();
}
CppBase& CodeBase()
{
static CppBase b;
return b;
}
ArrayMap<String, SourceFileInfo> source_file;
void SourceFileInfo::Serialize(Stream& s)
@ -87,12 +93,6 @@ String CodeBaseCacheFile()
return AppendFileName(CodeBaseCacheDir(), GetVarsName() + '.' + IdeGetCurrentMainPackage() + '.' + IdeGetCurrentBuildMethod() + ".codebase");
}
CppBase& CodeBase()
{
static CppBase b;
return b;
}
static bool s_console;
void BrowserScanError(int line, const String& text, int file)
@ -103,6 +103,7 @@ void BrowserScanError(int line, const String& text, int file)
void SerializeCodeBase(Stream& s)
{
CppBaseLock __;
MLOG(s.IsLoading());
source_file.Serialize(s);
MLOG("source_file " << MemoryUsedKb());
@ -114,6 +115,7 @@ void SerializeCodeBase(Stream& s)
void SaveCodeBase()
{
CppBaseLock __;
LTIMING("SaveCodeBase");
LLOG("Save code base " << CodeBase().GetCount());
RealizeDirectory(CodeBaseCacheDir());
@ -126,6 +128,7 @@ void SaveCodeBase()
bool TryLoadCodeBase(const char *pattern)
{
CppBaseLock __;
LLOG("+++ Trying to load " << pattern);
FindFile ff(pattern);
String path;
@ -152,6 +155,7 @@ bool TryLoadCodeBase(const char *pattern)
void LoadCodeBase()
{
CppBaseLock __;
MLOG("LoadCodeBase start: " << MemoryUsedKb());
TryLoadCodeBase(CodeBaseCacheFile()) ||
TryLoadCodeBase(AppendFileName(CodeBaseCacheDir(), GetVarsName() + ".*." + IdeGetCurrentBuildMethod() + ".codebase")) ||
@ -165,12 +169,14 @@ void FinishCodeBase()
{
LTIMING("FinishBase");
CppBaseLock __;
Qualify(CodeBase());
}
void LoadDefs()
{
LTIMING("LoadDefs");
CppBaseLock __;
Vector<String> defs;
defs.Add(ConfigFile("global.defs"));
const Workspace& wspc = GetIdeWorkspace();
@ -200,6 +206,7 @@ void LoadDefs()
void BaseInfoSync(Progress& pi)
{ // clears temporary caches (file times etc..)
CppBaseLock __;
PPSync(TheIde()->IdeGetIncludePath());
LTIMESTOP("Gathering files");
@ -209,6 +216,9 @@ void BaseInfoSync(Progress& pi)
LTIMING("Gathering files");
pi.SetText("Gathering files");
pi.SetTotal(wspc.GetCount());
{
RTIMESTOP("GatherSources");
for(int pass = 0; pass < 2; pass++)
for(int i = 0; i < wspc.GetCount(); i++) {
pi.Step();
@ -221,6 +231,7 @@ void BaseInfoSync(Progress& pi)
GatherSources(path, path);
}
}
}
SweepPPFiles(GetAllSources());
}
@ -242,18 +253,20 @@ Index<String> sTimePath;
Time GetDependsTime(const Vector<int>& file)
{
LTIMING("CreateTimePrint");
static Index<String> path;
String r;
Time tm = Time::Low();
for(int i = 0; i < file.GetCount(); i++)
if(file[i] < sTimePath.GetCount())
tm = max(tm, GetFileTimeCached(sTimePath[file[i]]));
INTERLOCKED {
static Index<String> path;
for(int i = 0; i < file.GetCount(); i++)
if(file[i] < sTimePath.GetCount())
tm = max(tm, GetFileTimeCached(sTimePath[file[i]]));
}
return tm;
}
bool CheckFile(SourceFileInfo& f, const String& path)
{
LTIMING("CheckFile");
CppBaseLock __;
Time ftm = GetFileTimeCached(path);
bool tmok = f.time == ftm;
f.time = ftm;
@ -275,25 +288,10 @@ bool CheckFile(SourceFileInfo& f, const String& path)
return r;
}
void ParseFiles(Progress& pi, const Index<int>& parse_file)
{
pi.SetTotal(parse_file.GetCount());
pi.SetPos(0);
pi.AlignText(ALIGN_LEFT);
for(int i = 0; i < parse_file.GetCount(); i++) {
String path = GetSourceFilePath(parse_file[i]);
pi.SetText(GetFileName(GetFileFolder(path)) + "/" + GetFileName(path));
pi.Step();
FileIn fi(path);
LDUMP(path);
LDUMP(parse_file[i]);
ParseSrc(fi, parse_file[i], callback1(BrowserScanError, i));
}
}
void UpdateCodeBase2(Progress& pi)
{
CLOG("============= UpdateCodeBase2 " << GetSysTime());
CppBaseLock __;
pi.SetText("Checking source files");
pi.SetPos(0);
Index<int> keep_file;
@ -330,12 +328,27 @@ void UpdateCodeBase2(Progress& pi)
if(!source_file.IsUnlinked(i))
CLOG(i << " " << source_file.GetKey(i) << " " << source_file[i].dependencies_md5sum << " " << source_file[i].time);
#endif
ParseFiles(pi, parse_file);
// This is the only place where parsing runs in parallel
pi.SetTotal(parse_file.GetCount());
pi.SetPos(0);
pi.AlignText(ALIGN_LEFT);
LLOG("=========================");
RTIMESTOP("Parsing files");
CoFor(parse_file.GetCount(), [&](int i) {
String path = GetSourceFilePath(parse_file[i]);
pi.SetText(GetFileName(GetFileFolder(path)) + "/" + GetFileName(path));
pi.Step();
FileIn fi(path);
LDUMP(path);
LDUMP(parse_file[i]);
ParseSrc(fi, parse_file[i], callback1(BrowserScanError, i));
});
}
void UpdateCodeBase(Progress& pi)
{
CppBaseLock __;
BaseInfoSync(pi);
UpdateCodeBase2(pi);
@ -345,6 +358,7 @@ void ParseSrc(Stream& in, int file, Event<int, const String&> error)
{
String path = GetSourceFilePath(file);
CLOG("====== Parse " << file << ": " << path);
CppBase base;
Vector<String> pp;
String ext = ToLower(GetFileExt(path));
if(ext == ".lay")
@ -356,15 +370,19 @@ void ParseSrc(Stream& in, int file, Event<int, const String&> error)
if(ext == ".sch")
pp.Append(PreprocessSchFile(path));
else
PreprocessParse(CodeBase(), in, file, path, error);
PreprocessParse(base, in, file, path, error);
for(int i = 0; i < pp.GetCount(); i++)
Parse(CodeBase(), pp[i], file, FILE_OTHER, path, error, Vector<String>(), Index<String>());
Parse(base, pp[i], file, FILE_OTHER, path, error, Vector<String>(), Index<String>());
INTERLOCKED
CodeBase().Append(pick(base));
}
void CodeBaseScanFile0(Stream& in, const String& fn)
{
LLOG("===== CodeBaseScanFile " << fn);
CppBaseLock __;
InvalidateFileTimeCache(NormalizeSourcePath(fn));
PPSync(TheIde()->IdeGetIncludePath());
@ -379,6 +397,7 @@ void CodeBaseScanFile0(Stream& in, const String& fn)
void CodeBaseScanFile(Stream& in, const String& fn)
{
CppBaseLock __;
CodeBaseScanFile0(in, fn);
FinishCodeBase();
}
@ -386,6 +405,7 @@ void CodeBaseScanFile(Stream& in, const String& fn)
void CodeBaseScanFile(const String& fn, bool auto_check)
{
LLOG("CodeBaseScanFile " << fn);
CppBaseLock __;
String md5sum = GetPPMD5(fn);
FileIn in(fn);
CodeBaseScanFile(in, fn);
@ -404,6 +424,7 @@ void CodeBaseScanFile(const String& fn, bool auto_check)
void ClearCodeBase()
{
// TODO: Create combined defs
CppBaseLock __;
CleanPP();
CodeBase().Clear();
source_file.Clear();
@ -414,6 +435,7 @@ void SyncCodeBase()
LTIMING("SyncCodeBase");
LTIMESTOP("SyncCodeBase");
CLOG("============= Sync code base");
CppBaseLock __;
if(IsNull(IdeGetCurrentMainPackage())) {
ClearCodeBase();
return;
@ -426,6 +448,7 @@ void SyncCodeBase()
void NewCodeBase()
{
CppBaseLock __;
ReduceCodeBaseCache();
if(IsNull(IdeGetCurrentMainPackage())) {
ClearCodeBase();
@ -445,6 +468,7 @@ void NewCodeBase()
void RescanCodeBase()
{
CppBaseLock __;
ClearCodeBase();
s_console = true;
Progress pi;
@ -456,5 +480,6 @@ void RescanCodeBase()
bool ExistsBrowserItem(const String& item)
{
CppBaseLock __;
return GetCodeRefItem(item);
}

View file

@ -20,6 +20,7 @@ class Browser;
void ReduceCacheFolder(const char *path, int max_total);
// Use CppBaseLock when accessing this
CppBase& CodeBase();
struct SourceFileInfo {

View file

@ -78,6 +78,7 @@ void CodeBrowser::Load()
Vector<Value> ndx;
Index<int> fi;
Index<String> fs;
CppBaseLock __;
for(int i = 0; i < CodeBase().GetCount(); i++) {
String s = CodeBase().GetKey(i);
const Array<CppItem>& n = CodeBase()[i];
@ -151,6 +152,7 @@ int ItemCompareLexical(const Value& v1, const Value& v2)
void GatherMethods(const String& type, VectorMap<String, bool>& inherited, bool g, Index<String>& done)
{
CppBaseLock __;
if(done.Find(type) >= 0) return;
done.Add(type);
int q = CodeBase().Find(type);
@ -182,6 +184,7 @@ void GatherMethods(const String& type, VectorMap<String, bool>& inherited, bool
void CodeBrowser::LoadScope()
{
CppBaseLock __;
String find = ToUpper((String)~search);
Value key = item.GetKey();
int sc = item.GetCursorSc();

View file

@ -169,6 +169,7 @@ bool IsCodeRefType(const String& type)
{
if(type.GetCount() == 0)
return false;
CppBaseLock __;
return CodeBase().Find(type) >= 0;
}
@ -384,6 +385,7 @@ void TopicEditor::FixTopic()
String nest;
if(!EditText(nest, "Fix topic", "Nest"))
return;
CppBaseLock __;
CppBase& base = CodeBase();
int q = base.Find(nest);
if(q < 0) {

View file

@ -34,6 +34,7 @@ const CppItem *GetCodeRefItem(const String& ref, const String& rfile)
String scope;
String item;
SplitCodeRef(ref, scope, item);
CppBaseLock __;
int q = CodeBase().Find(scope);
if(q < 0)
return NULL;

View file

@ -12,6 +12,7 @@
bool GetIdScope(String& os, const String& scope, const String& id, Index<String>& done)
{
CppBaseLock __;
if(done.Find(scope) >= 0)
return Null;
done.Add(scope);
@ -113,6 +114,7 @@ bool Ide::OpenLink(const String& s, int pos)
void Ide::ContextGoto0(int pos)
{
CppBaseLock __;
if(designer)
return;
int lp = pos;

View file

@ -209,6 +209,7 @@ bool Navigator::NavLine::operator<(const NavLine& b) const
Vector<Navigator::NavLine> Navigator::GetNavLines(const NavItem& m)
{
CppBaseLock __;
Vector<NavLine> l;
int q = CodeBase().Find(m.nest);
if(q < 0 || IsNull(m.qitem))
@ -434,6 +435,7 @@ void Navigator::TriggerSearch()
void Navigator::NavGroup(bool local)
{
CppBaseLock __;
for(int i = 0; i < nitem.GetCount(); i++) {
NavItem& m = nitem[i];
String g = m.nest;
@ -473,6 +475,7 @@ bool Navigator::SortByNames(const NavItem *a, const NavItem *b)
void Navigator::Search()
{
CppBaseLock __;
sortitems.Check(sorting);
int sc = scope.GetScroll();
String key = scope.GetKey();

View file

@ -23,6 +23,7 @@ void AssistEditor::SwapSContext(ParserContext& p)
bool Ide::SwapSIf(const char *cref)
{
CppBaseLock __;
if(designer || !editor.assist_active)
return false;
ParserContext p;

View file

@ -41,6 +41,7 @@ void ThisbacksDlg::CbEdit(One<Ctrl>& ctrl)
ThisbacksDlg::ThisbacksDlg(const String& scope)
{
CppBaseLock __;
CtrlLayoutOKCancel(*this, "THISBACKs");
list.AddColumn("Defined in");
list.AddColumn("Type");
@ -65,6 +66,7 @@ ThisbacksDlg::ThisbacksDlg(const String& scope)
void ThisbacksDlg::GatherCallbacks(const String& pfx, Index<String>& done,
const String& scope, int access)
{
CppBaseLock __;
if(IsNull(scope))
return;
String h = pfx + scope;

View file

@ -281,7 +281,7 @@ struct WorkspaceWork {
String separator;
bool operator==(const Sepfo& s) const { return package == s.package && separator == s.separator; }
unsigned GetHashValue() const { return CombineHash(Upp::GetHashValue(package),
hash_t GetHashValue() const { return CombineHash(Upp::GetHashValue(package),
Upp::GetHashValue(separator)); }
void Serialize(Stream& s) { s % package % separator; }
Sepfo(const String& package, const String& separator) : package(package), separator(separator) {}

View file

@ -9,6 +9,7 @@ struct AssistItemInfo : CppItem {
void GatherVirtuals(ArrayMap<String, AssistItemInfo>& item, const String& scope,
Index<String>& done)
{
CppBaseLock __;
if(IsNull(scope))
return;
if(done.Find(scope) >= 0)

View file

@ -807,7 +807,7 @@ static void GetLineIndex(String file, HashBase& hash, Vector<String>& lines)
while(e > b && (byte)e[-1] <= ' ')
e--;
String s(b, e);
hash.Add(GetHashValue(s));
hash.Add(FoldHash(GetHashValue(s)));
lines.Add(s);
}
}