From fbb02d75f34ba52834928f86b94be9f47a80d2fa Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 22 Jul 2021 13:51:46 +0000 Subject: [PATCH] ide: Main config is now reading flags from sources git-svn-id: svn://ultimatepp.org/upp/trunk@16031 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CppBase/CppBase.h | 2 ++ uppsrc/CppBase/Internal.h | 2 +- uppsrc/CppBase/Parser.cpp | 4 ++-- uppsrc/CppBase/Pre.cpp | 21 ++++++++++++++--- uppsrc/CppBase/cpp.cpp | 3 +++ uppsrc/ide/Browser/Base.cpp | 2 +- uppsrc/ide/Browser/Browser.iml | 26 ++++++++++---------- uppsrc/ide/Browser/ItemDisplay.cpp | 3 +++ uppsrc/ide/Core/Core.h | 2 ++ uppsrc/ide/Core/Ide.cpp | 13 ++++++++++ uppsrc/ide/MainConfig.cpp | 38 +++++++++++++++++++----------- uppsrc/ide/ide.lay | 12 +++++----- uppsrc/ide/idewin.cpp | 1 + 13 files changed, 90 insertions(+), 39 deletions(-) diff --git a/uppsrc/CppBase/CppBase.h b/uppsrc/CppBase/CppBase.h index a2fcc53c0..c114ae2b5 100644 --- a/uppsrc/CppBase/CppBase.h +++ b/uppsrc/CppBase/CppBase.h @@ -38,6 +38,7 @@ enum Kind { MACRO, FRIENDCLASS, NAMESPACE, + FLAGTEST, }; inline bool IsCppType(int i) @@ -130,6 +131,7 @@ struct CppItem { bool IsCode() const { return IsCppCode(kind); } bool IsData() const { return IsCppData(kind); } bool IsMacro() const { return IsCppMacro(kind); } + bool IsFlagTest() const { return kind == FLAGTEST; } bool IsTemplate() const { return IsCppTemplate(kind); } void Serialize(Stream& s); diff --git a/uppsrc/CppBase/Internal.h b/uppsrc/CppBase/Internal.h index 2715f5005..218a9d940 100644 --- a/uppsrc/CppBase/Internal.h +++ b/uppsrc/CppBase/Internal.h @@ -418,7 +418,7 @@ struct Parser : ParserContext { typedef Parser CLASSNAME; public: - void AddMacro(int lineno, const String& macro); + void AddMacro(int lineno, const String& macro, int kind = MACRO); bool dobody; Function qualify; // used to qualify local variable names (needs main codebase and its mutex) diff --git a/uppsrc/CppBase/Parser.cpp b/uppsrc/CppBase/Parser.cpp index e2e75992e..98962b709 100644 --- a/uppsrc/CppBase/Parser.cpp +++ b/uppsrc/CppBase/Parser.cpp @@ -1208,14 +1208,14 @@ CppItem& Parser::Item(const String& scope, const String& using_namespace, const return im; } -void Parser::AddMacro(int lineno, const String& macro) +void Parser::AddMacro(int lineno, const String& macro, int kind) { String name; const char *s = macro; while(*s && iscid(*s)) name.Cat(*s++); CppItem& im = Item("", "", macro, name); - im.kind = MACRO; + im.kind = kind; im.line = lineno; im.access = PUBLIC; } diff --git a/uppsrc/CppBase/Pre.cpp b/uppsrc/CppBase/Pre.cpp index e78ada2d1..8680381b4 100644 --- a/uppsrc/CppBase/Pre.cpp +++ b/uppsrc/CppBase/Pre.cpp @@ -17,7 +17,7 @@ SrcFile::SrcFile() : { } -SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preprocess, only removes (or processes) comment and directives +SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preprocess, only removes (or processes) comments and directives { SrcFile res; bool include = true; @@ -56,8 +56,7 @@ SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preproces if(*rm == '\0') res.blankLinesRemoved++; else - if(*rm == '#') - { + if(*rm == '#') { const char *s = rm + 1; while(*s == ' ' || *s == '\t') s++; @@ -79,6 +78,22 @@ SrcFile PreProcess(Stream& in, Parser& parser) // This is not really C preproces if(include) parser.AddMacro(lineno, macro); } + else + if(s[0] == 'i' && s[1] == 'f') { + CParser p(s + 2); + try { + while(!p.IsEof()) { + if(p.IsId()) { + String id = p.ReadId(); + if(id.StartsWith("flag")) + parser.AddMacro(lineno, id, FLAGTEST); + } + else + p.SkipTerm(); + } + } + catch(CParser::Error) {} + } res.preprocessorLinesRemoved++; } else { diff --git a/uppsrc/CppBase/cpp.cpp b/uppsrc/CppBase/cpp.cpp index 3de54a7b9..0256101d0 100644 --- a/uppsrc/CppBase/cpp.cpp +++ b/uppsrc/CppBase/cpp.cpp @@ -297,6 +297,9 @@ void Cpp::Do(const String& sourcefile, Stream& in, const String& currentfile, bo segment_id.Add(--segment_serial); } } + else + if(p.Id("if") || p.Id("ifdef") || p.Id("ifndef")) // FLAGTEST support + result.Cat(l + "\n"); else { result.Cat('\n'); #ifdef IGNORE_ELSE diff --git a/uppsrc/ide/Browser/Base.cpp b/uppsrc/ide/Browser/Base.cpp index c56a4f6b5..47386d6fe 100644 --- a/uppsrc/ide/Browser/Base.cpp +++ b/uppsrc/ide/Browser/Base.cpp @@ -131,7 +131,7 @@ static bool s_console; void BrowserScanError(int line, const String& text, int file) { if(s_console) - IdePutErrorLine(String().Cat() << source_file.GetKey(file) << " (" << line << "): " << text); + PostCallback([=] { IdePutErrorLine(String().Cat() << source_file.GetKey(file) << " (" << line << "): " << text); }); } void SerializeCodeBase(Stream& s) diff --git a/uppsrc/ide/Browser/Browser.iml b/uppsrc/ide/Browser/Browser.iml index f870c43b6..9f7b51871 100644 --- a/uppsrc/ide/Browser/Browser.iml +++ b/uppsrc/ide/Browser/Browser.iml @@ -25,6 +25,7 @@ IMAGE_ID(template_struct) IMAGE_ID(unknown) IMAGE_ID(inherited) IMAGE_ID(type_def) +IMAGE_ID(flagtest) IMAGE_ID(macro) IMAGE_ID(All) IMAGE_ID(Ref) @@ -91,15 +92,16 @@ IMAGE_DATA(88,92,13,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) IMAGE_END_DATA(1824, 25) IMAGE_BEGIN_DATA -IMAGE_DATA(120,156,237,86,75,18,131,32,12,205,190,93,120,14,238,195,121,228,60,238,188,129,135,240,62,148,88,161,105,228,19,196) -IMAGE_DATA(50,237,76,51,147,169,210,247,94,62,70,4,238,48,64,71,179,187,107,41,126,154,38,171,181,150,242,172,183,117,93,37) -IMAGE_DATA(60,203,173,192,59,224,11,188,36,222,27,214,183,115,46,209,151,230,47,237,79,109,255,133,184,239,180,11,94,6,203,60) -IMAGE_DATA(181,22,240,203,178,108,78,241,145,181,160,195,254,75,173,189,233,228,188,5,95,153,207,191,222,124,189,64,248,210,249,249) -IMAGE_DATA(156,13,219,203,96,251,5,236,101,198,53,113,116,174,216,46,133,247,184,110,10,77,246,56,170,17,91,171,209,168,225,198) -IMAGE_DATA(242,173,225,250,88,222,13,187,31,11,245,183,242,91,243,167,220,51,253,107,125,126,173,243,243,139,118,115,223,70,182,25) -IMAGE_DATA(240,93,41,230,47,172,49,105,143,236,250,82,221,156,197,176,198,197,227,158,194,246,212,197,227,88,73,23,143,98,236,56) -IMAGE_DATA(150,212,125,226,148,251,205,247,204,31,3,17,231,178,61,247,44,58,124,41,52,180,157,43,237,60,131,43,244,180,134,70) -IMAGE_DATA(174,68,67,129,210,35,140,150,58,174,73,53,16,111,192,4,174,191,150,230,65,99,210,92,50,181,80,15,122,148,187,231) -IMAGE_DATA(127,232,135,31,26,116,62,104,37,110,41,126,36,111,81,253,25,171,226,178,248,213,113,25,191,121,254,160,109,254,187,217) -IMAGE_DATA(3,109,187,176,84,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) -IMAGE_END_DATA(352, 5) +IMAGE_DATA(120,156,237,87,217,113,132,48,12,213,127,242,177,117,208,143,235,65,245,240,183,29,80,4,253,40,22,177,25,69,248,144) +IMAGE_DATA(49,235,201,78,162,29,13,139,121,239,233,176,57,12,159,240,128,129,70,193,157,21,191,44,11,57,231,172,60,138,182,109) +IMAGE_DATA(155,133,71,218,42,188,19,190,194,203,226,163,113,125,129,115,139,190,53,127,107,127,90,251,111,196,253,78,27,124,51,176) +IMAGE_DATA(145,209,15,60,98,24,203,253,222,5,223,90,175,177,159,127,13,15,231,158,221,99,55,220,12,169,73,205,77,244,126,109) +IMAGE_DATA(93,215,221,37,62,49,118,232,168,107,185,177,31,58,37,239,193,55,230,243,95,111,185,94,16,124,235,250,121,157,61,246) +IMAGE_DATA(155,129,198,5,28,101,252,180,153,189,79,234,149,205,231,60,142,149,38,71,156,212,72,141,181,104,180,112,83,249,182,112) +IMAGE_DATA(99,172,232,168,206,231,74,253,189,252,222,252,37,247,74,255,122,231,175,119,253,188,163,125,248,119,163,122,24,52,125,210) +IMAGE_DATA(0,98,222,19,79,125,171,110,201,82,88,244,241,180,231,176,35,117,121,111,82,211,229,125,137,218,155,100,117,191,113,147) +IMAGE_DATA(63,150,123,22,247,68,140,163,196,167,171,105,46,6,188,41,92,8,118,117,147,69,207,39,248,66,47,107,56,230,90,52) +IMAGE_DATA(38,152,220,12,51,73,231,49,171,6,227,17,240,224,198,255,214,60,100,76,153,75,161,22,233,135,158,228,134,252,79,253) +IMAGE_DATA(136,139,134,93,47,180,26,183,22,63,145,183,169,254,130,53,113,85,252,230,184,138,223,189,254,160,111,253,15,179,47,3) +IMAGE_DATA(79,36,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) +IMAGE_END_DATA(384, 6) diff --git a/uppsrc/ide/Browser/ItemDisplay.cpp b/uppsrc/ide/Browser/ItemDisplay.cpp index b2d18f55c..36e0ad7c0 100644 --- a/uppsrc/ide/Browser/ItemDisplay.cpp +++ b/uppsrc/ide/Browser/ItemDisplay.cpp @@ -102,6 +102,9 @@ void PaintCppItemImage(Draw& w, int& x, int ry, int access, int kind, bool focus case MACRO: img = BrowserImg::macro(); break; + case FLAGTEST: + img = BrowserImg::flagtest(); + break; case FRIENDCLASS: img = BrowserImg::friend_class(); break; diff --git a/uppsrc/ide/Core/Core.h b/uppsrc/ide/Core/Core.h index 0c4977330..f78ec5f18 100644 --- a/uppsrc/ide/Core/Core.h +++ b/uppsrc/ide/Core/Core.h @@ -128,6 +128,8 @@ bool IdeConsoleWait(int slot); void IdeConsoleOnFinish(Event<> cb); void IdeGotoCodeRef(String s); +String GetSourcePackage(const String& path); + String GetDefaultMethod(); VectorMap GetMethodVars(const String& method); String GetMethodPath(const String& method); diff --git a/uppsrc/ide/Core/Ide.cpp b/uppsrc/ide/Core/Ide.cpp index 90ed647c3..b7ed42eba 100644 --- a/uppsrc/ide/Core/Ide.cpp +++ b/uppsrc/ide/Core/Ide.cpp @@ -19,6 +19,19 @@ const Workspace& GetIdeWorkspace() return x; } +String GetSourcePackage(const String& path) +{ + String p = ToLower(NormalizePath(path)); + const Workspace& w = GetIdeWorkspace(); + for(int i = 0; i < w.GetCount(); i++) { + String pn = w[i]; + String pp = ToLower(GetFileFolder(PackagePath(pn))); + if(p.StartsWith(pp) && findarg(p[pp.GetCount()], '/', '\\') >= 0) + return pn; + } + return Null; +} + String IdeContext::GetDefaultMethod() { return LoadFile(ConfigFile("default_method")); diff --git a/uppsrc/ide/MainConfig.cpp b/uppsrc/ide/MainConfig.cpp index 81db5889c..18ceafb91 100644 --- a/uppsrc/ide/MainConfig.cpp +++ b/uppsrc/ide/MainConfig.cpp @@ -37,6 +37,25 @@ void sSetOption(One& ctrl) void MainConfigDlg::FlagDlg() { + VectorMap> flags; + { + CodeBaseLock __; + const CppBase& b = CodeBase(); + for(int i = 0; i < b.GetCount(); i++) { + String nest = b.GetKey(i); + const Array& ci = b[i]; + for(int j = 0; j < ci.GetCount(); j++) { + const CppItem& m = ci[j]; + if(m.kind == FLAGTEST) { + String n = m.name; + n.TrimStart("flag"); + flags.GetAdd(n).FindAdd(GetSourcePackage(GetSourceFilePath(m.file))); + } + } + } + } + SortByKey(flags); + WithConfLayout cfg; CtrlLayoutOKCancel(cfg, "Configuration flags"); cfg.Sizeable().MaximizeBox(); @@ -47,20 +66,11 @@ void MainConfigDlg::FlagDlg() cfg.accepts.AddColumn("Set").Ctrls(sSetOption); cfg.accepts.AddColumn("Flag"); cfg.accepts.AddColumn("Packages"); - cfg.accepts.SetCount(accepts.GetCount()); cfg.accepts.SetLineCy(Zy(20)); cfg.accepts.ColumnWidths("26 122 204"); - for(int i = 0; i < accepts.GetCount(); i++) { - String acc = accepts[i]; - Vector pkg; - for(int p = 0; p < wspc.GetCount(); p++) - if(FindIndex(wspc.package[p].accepts, acc) >= 0) - pkg.Add(wspc[p]); - Sort(pkg, GetLanguageInfo()); - cfg.accepts.Set(i, CC_NAME, accepts[i]); - cfg.accepts.Set(i, CC_PACKAGES, Join(pkg, ",")); - } - + for(const auto& f : ~flags) + cfg.accepts.Add(false, f.key, Join(f.value.GetKeys(), ", ")); + cfg.other.SetFilter(FlagFilterM); cfg.gui <<= false; cfg.debugcode <<= false; @@ -69,7 +79,7 @@ void MainConfigDlg::FlagDlg() String f = flg[i]; if(!SetSw(f, cfg.gui, "GUI") && !SetSw(f, cfg.debugcode, "DEBUGCODE")) { - int x = (*f == '.' ? cfg.accepts.Find(f.Mid(1), CC_NAME) : -1); + int x = (*f == '.' ? cfg.accepts.Find(f.Mid(1), CC_NAME) : -1) || cfg.accepts.Find(f, CC_NAME); if(x >= 0) cfg.accepts.Set(x, CC_SET, true); else { @@ -87,7 +97,7 @@ void MainConfigDlg::FlagDlg() << GetSw(cfg.debugcode, "DEBUGCODE"); for(int i = 0; i < cfg.accepts.GetCount(); i++) if(cfg.accepts.Get(i, CC_SET)) - flags << '.' << cfg.accepts.Get(i, CC_NAME) << ' '; + flags << cfg.accepts.Get(i, CC_NAME) << ' '; flags << cfg.other.GetText().ToString(); fe = Join(SplitFlags0(flags), " ").ToWString(); } diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index af91bb5c4..1eeab3b79 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -17,14 +17,14 @@ LAYOUT(ConfigLayout, 724, 214) ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 80).BottomPosZ(4, 22)) END_LAYOUT -LAYOUT(ConfLayout, 368, 416) +LAYOUT(ConfLayout, 368, 752) ITEM(Upp::Option, gui, SetLabel(t_("GUI application")).LeftPosZ(8, 112).TopPosZ(4, 16)) ITEM(Upp::Option, debugcode, SetLabel(t_("Allowing debuging code in release mode")).LeftPosZ(124, 240).TopPosZ(4, 16)) - ITEM(Upp::ArrayCtrl, accepts, AutoHideSb(true).VertGrid(false).HorzGrid(false).HSizePosZ(8, 4).VSizePosZ(28, 64)) - ITEM(Upp::Label, dv___3, SetLabel(t_("&Other flags:")).LeftPosZ(8, 58).BottomPosZ(39, 19)) - ITEM(Upp::EditString, other, HSizePosZ(68, 4).BottomPosZ(39, 19)) - ITEM(Upp::Button, ok, SetLabel(t_("OK")).RightPosZ(72, 64).BottomPosZ(8, 24)) - ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 64).BottomPosZ(8, 24)) + ITEM(Upp::ArrayCtrl, accepts, AutoHideSb(true).VertGrid(false).HorzGrid(false).HSizePosZ(8, 4).VSizePosZ(28, 60)) + ITEM(Upp::Label, dv___3, SetLabel(t_("&Other flags:")).LeftPosZ(8, 58).BottomPosZ(37, 19)) + ITEM(Upp::EditString, other, HSizePosZ(68, 4).BottomPosZ(37, 19)) + ITEM(Upp::Button, ok, SetLabel(t_("OK")).RightPosZ(72, 64).BottomPosZ(6, 24)) + ITEM(Upp::Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 64).BottomPosZ(6, 24)) END_LAYOUT LAYOUT(CustomLayout, 608, 410) diff --git a/uppsrc/ide/idewin.cpp b/uppsrc/ide/idewin.cpp index f49931551..7a234c7b4 100644 --- a/uppsrc/ide/idewin.cpp +++ b/uppsrc/ide/idewin.cpp @@ -171,6 +171,7 @@ String Ide::IdeGetCurrentMainPackage() void Ide::IdePutErrorLine(const String& line) { if(console.verbosebuild) { + GuiLock __; SetBottom(Ide::BERRORS); ConsoleRunEnd(); ConsoleLine(line, true);