Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: oBFusCATed on August 13, 2012, 10:57:24 pm

Title: Two problems with r8232
Post by: oBFusCATed on August 13, 2012, 10:57:24 pm
I've just updated to r8232 and there are two problems:
1. Suddenly the default color for everything is gray instead of black. I don't know why this happens, but I've not modified colors in the 2-3 year or at all.
    The preview in the syntax highlight settings panel looks correct. Also removing the default.conf makes this problem go away.
(http://cmpt.benbmp.org/codeblocks/screens/codeblocks_lexer_colors_broken.png)

2. Just tested to remove the default.conf file and I've got a pleasant red surprise:
(http://cmpt.benbmp.org/codeblocks/screens/codeblocks_compilers_red.png)

I have no time to investigate what is causing this issues, so I'll be happy if someone does it for me :-P
My previous revision was 8164.

p.s. do we need to store the recent file/project list in the default.conf file? Should this is save in another file?
Title: Re: Two problems with r8232
Post by: Alpha on August 14, 2012, 12:43:52 am
1. Suddenly the default color for everything is gray instead of black. I don't know why this happens, but I've not modified colors in the 2-3 year or at all.
Sorry, I really need to stop messing with the lexer :).  I rev8230 shifts many of the items in the C/C++ lexer, so if the default.conf has any saved color schemes, it is unlikely to load them correctly.  (PS: try the new check boxes under C++ editor settings.)

2. Just tested to remove the default.conf file and I've got a pleasant red surprise:
Code::Blocks always highlights items in red if at the point of loading, their master paths are empty (which they all are when a new profile is started).
In the XML compiler branch, this dialog has been modified so that (among other things) detected compilers are not erroneously highlighted.
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 14, 2012, 12:52:25 am
Sorry, I really need to stop messing with the lexer :).  I rev8230 shifts many of the items in the C/C++ lexer, so if the default.conf has any saved color schemes, it is unlikely to load them correctly.  (PS: try the new check boxes under C++ editor settings.)
I don't know the details, but you must make sure that current profiles work as before or we will get tons of people complaining about it!

Code::Blocks always highlights items in red if at the point of loading, their master paths are empty (which they all are when a new profile is started).
In the XML compiler branch, this dialog has been modified so that (among other things) detected compilers are not erroneously highlighted.
Is this (the red backgrounds) some new feature as I've never seen in before?
I don't think this is something that is user friendly, so it needs to be fixed or at least it needs to be made a bit less disturbing and a bit more clear.
Title: Re: Two problems with r8232
Post by: Alpha on August 14, 2012, 01:10:52 am
Sorry, I really need to stop messing with the lexer :).  I rev8230 shifts many of the items in the C/C++ lexer, so if the default.conf has any saved color schemes, it is unlikely to load them correctly.  (PS: try the new check boxes under C++ editor settings.)
I don't know the details, but you must make sure that current profiles work as before or we will get tons of people complaining about it!
I will explore it to see if there is anything that can be done, however to my current knowledge, the way custom color schemes are saved would make this extremely difficult to create an automatic upgrade.  (I could be wrong on this.)

Is this (the red backgrounds) some new feature as I've never seen in before?
I don't think this is something that is user friendly, so it needs to be fixed or at least it needs to be made a bit less disturbing and a bit more clear.
It has been in there at least since the last stable (two years ago), and probably longer.  The modifications in the XML compiler branch are a little more friendly; even there, however, more needs to be done...
Title: Re: Two problems with r8232
Post by: Alpha on August 14, 2012, 02:39:10 am
sdk/editorcolourset.cpp, line 521
Code
    for (OptionSetsMap::iterator it = m_Sets.begin(); it != m_Sets.end(); ++it)
    {
        if (it->first == HL_NONE || it->first == HL_AUTO)
            continue;
        wxString lang = it->first;

        bool gsaved = false;

        key.Clear();
        key << _T("/colour_sets/") << m_Name << _T('/') << lang;
        for (unsigned int i = 0; i < it->second.m_Colours.GetCount(); ++i)
        {
            OptionColour* opt = it->second.m_Colours.Item(i);
            wxString tmpKey;
            tmpKey << key << _T("/style") << wxString::Format(_T("%d"), i); // <-- how can something saved numerically be auto-magically updated?
[...]
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 14, 2012, 08:06:19 pm
Alpha: Probably you have to look what is happening in the load function, not in the save function.
Title: Re: Two problems with r8232
Post by: Alpha on August 14, 2012, 10:38:47 pm
I guess I was not quite clear.
Line 652
Code
        for (unsigned int i = 0; i < it->second.m_Colours.GetCount(); ++i)
        {
            OptionColour* opt = it->second.m_Colours.Item(i);
            if (!opt)
                continue;
            wxString tmpKey;
            tmpKey << key << _T("/style") << wxString::Format(_T("%d"), i); // <-- remap required here

            if (cfg->Exists(tmpKey + _T("/name")))
                opt->name = cfg->Read(tmpKey + _T("/name"));
            else
            {
                // make sure we didn't create it accidentally
                cfg->DeleteSubPath(tmpKey);
                continue;
            }

            if (cfg->Exists(tmpKey + _T("/fore")))
                opt->fore = cfg->ReadColour(tmpKey + _T("/fore"), opt->fore);
            if (cfg->Exists(tmpKey + _T("/back")))
                opt->back = cfg->ReadColour(tmpKey + _T("/back"), opt->back);
            if (cfg->Exists(tmpKey + _T("/bold")))
                opt->bold = cfg->ReadBool(tmpKey + _T("/bold"), opt->bold);
            if (cfg->Exists(tmpKey + _T("/italics")))
                opt->italics = cfg->ReadBool(tmpKey + _T("/italics"), opt->italics);
            if (cfg->Exists(tmpKey + _T("/underlined")))
                opt->underlined = cfg->ReadBool(tmpKey + _T("/underlined"), opt->underlined);

            if (cfg->Exists(tmpKey + _T("/isStyle")))
                opt->isStyle = cfg->ReadBool(tmpKey + _T("/isStyle"), opt->isStyle);
        }
The only way this loading function could be adapted (because OptionColour's are saved numerically) is if it had manually created remap database, and even then, it would only work if it knew which versions it was mapping from->to.  Does Code::Blocks have a method by which it can retrieve the previous version number default.conf was saved with?
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 14, 2012, 10:54:29 pm
So, I guess, the changes to the lexer have to be reverted, as I predict massive amount of unhappy users attacking the forum.

btw: What do I need to do in order to fix my syntax highlight?

p.s. probably the new styles should be save in newer, better way, but the old should be kept as they are.
Title: Re: Two problems with r8232
Post by: MortenMacFly on August 15, 2012, 06:45:55 am
btw: What do I need to do in order to fix my syntax highlight?
I still don't get what the problem is here really., I don't have such issue - it works just fine. What modifications are we talking about? There is no new functionality in the editor's "Syntax highlight" options...?!
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 15, 2012, 09:37:45 am
I still don't get what the problem is here really., I don't have such issue - it works just fine. What modifications are we talking about? There is no new functionality in the editor's "Syntax highlight" options...?!
The problem is that between 8164 and 8232 something changed and now some strings are gray instead of black as they were before the upgrade.
I have no time to bisect it to find the wrong revision, unfortunately.
Title: Re: Two problems with r8232
Post by: Pecan on August 15, 2012, 02:06:05 pm
I still don't get what the problem is here really., I don't have such issue - it works just fine. What modifications are we talking about? There is no new functionality in the editor's "Syntax highlight" options...?!
The problem is that between 8164 and 8232 something changed and now some strings are gray instead of black as they were before the upgrade.
I have no time to bisect it to find the wrong revision, unfortunately.

I also completely lost my custom editor highlighting with the current SVN.
Every color I'd previously set was now a different color. This was/is a hugh pain in the butt. I finally gave up on attempting to save my color scheme and deleted the .conf, starting over again.
Title: Re: Two problems with r8232
Post by: Alpha on August 15, 2012, 02:48:16 pm
I still don't get what the problem is here really., I don't have such issue - it works just fine. What modifications are we talking about? There is no new functionality in the editor's "Syntax highlight" options...?!
The problem is that between 8164 and 8232 something changed and now some strings are gray instead of black as they were before the upgrade.
I have no time to bisect it to find the wrong revision, unfortunately.
It happened here:
rev8230 shifts many of the items in the C/C++ lexer [...]
Specifically:
Code
http://svn.berlios.de/wsvn/codeblocks?op=comp&compare[]=/trunk/src/sdk/resources/lexers/lexer_cpp.xml@8229&compare[]=/trunk/src/sdk/resources/lexers/lexer_cpp.xml@8230
The change made here enables code that is greyed out by preprocessor commands to still be syntax highlighted (previously it all just turned black).
(This does, in my opinion, make code much more readable, however) In order to achieve it, I had to add many new sections to lexer_cpp.xml.  The addition of new sections means that loading custom color schemes (by the current system) will apply the saved data to the wrong sections (due to the offset).

So, I guess, the changes to the lexer have to be reverted, as I predict massive amount of unhappy users attacking the forum.
I also completely lost my custom editor highlighting with the current SVN.
Sorry.
I think a temporary partial revert of the file src/sdk/resources/lexers/lexer_cpp.xml might be the best option.  I have an idea that could resolve this issue, but it may be some time before I have a working patch.
Title: Re: Two problems with r8232
Post by: MortenMacFly on August 15, 2012, 08:39:38 pm
Sorry.
I think a temporary partial revert of the file src/sdk/resources/lexers/lexer_cpp.xml might be the best option.  I have an idea that could resolve this issue, but it may be some time before I have a working patch.
Thanks for the explanation. Its not nice, but actually the wrong part is the loading of the lexers. I guess we will change these lexer files form time to time and as I understand everytime we do so, the custom syntax highlighting will be broken.

Now I also understand why I don't see it. I don't have custom syntax highlighting - so I was just seeing the improvement. 8)

So the question is: Shall we really revert, or actually fix the loading? Nevertheless fixing the loading might not mean to necessarily also update old schemes though. :-\
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 15, 2012, 09:02:59 pm
So the question is: Shall we really revert, or actually fix the loading? Nevertheless fixing the loading might not mean to necessarily also update old schemes though. :-\
If you plan to have a nightly build, before this problem is fixed, you'll have to revert it as there will be many people which will suffer and many people will complain, so the will put some suffering on our shoulders.
If there is no plan for a nightly and you plan to fix it in the next couple of weeks, I'm OK with not reverting it.

Funnily, I thought, I have not modified my highlighting, but I carry my home dir with all the upgrades/reinstalls, so I might have some changes done many years ago.
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 15, 2012, 09:05:16 pm
BTW: Is there any reason that the syntax highlight preview looks correct, so the code is different, I think this is pretty bad, don't you think so?
Title: Re: Two problems with r8232
Post by: ouch on August 15, 2012, 09:10:55 pm
I suffered from the grey plague as well... :) Simply hitting the "Reset Defaults" button and saving the changes seemed to fix the conf file. The only thing I change from the defaults is changing the comment colors to grey. That grey-ish blue color messes with my brain... lol

oh, and I'm all for making progress on the lexers, so I say keep the changes even if it breaks everything.
Title: Re: Two problems with r8232
Post by: Alpha on August 16, 2012, 03:32:40 am
This patch should fix (almost) all custom color scheme loading problems.  It also adds evaluation of back-ticked expressions during define collection, and enables preprocessor interpretation by default (it is fine if this last part is left out, however, having tested it on both Windows and Linux now, I think most users would likely prefer it on).
Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 8236)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -1576,7 +1576,7 @@
     ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
 
     // Interpret #if/#else/#endif to grey out code that is not active
-    control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), false) ? _T("1") : _T("0"));
+    control->SetProperty(_T("lexer.cpp.track.preprocessor"), mgr->ReadBool(_T("/track_preprocessor"), true) ? _T("1") : _T("0"));
 
     // code folding
     if (mgr->ReadBool(_T("/folding/show_folds"), true))
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 8236)
+++ src/sdk/editormanager.cpp (working copy)
@@ -3045,8 +3045,8 @@
 {
     cbProject* prj = Manager::Get()->GetProjectManager()->GetActiveProject();
     if (   !prj
-        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/track_preprocessor"), false)
-        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/collect_prj_defines"), false) )
+        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/track_preprocessor"),  true)
+        || !Manager::Get()->GetConfigManager(wxT("editor"))->ReadBool(wxT("/collect_prj_defines"), true) )
     {
         event.Skip();
         return;
@@ -3067,13 +3067,39 @@
         lst = &prj->GetFilesList();
         id  = prj->GetCompilerID();
     }
+    Compiler* comp = CompilerFactory::GetCompiler(id); // get global flags
+    if (comp)
+        AppendArray(comp->GetCompilerOptions(), compilerFlags);
 
     wxArrayString defines;
     for (size_t i = 0; i < compilerFlags.Count(); ++i)
     {
-        if (   (compilerFlags[i].Left(2) == wxT("-D"))
-            || (compilerFlags[i].Left(2) == wxT("/D")) )
+        if (   compilerFlags[i].StartsWith(wxT("-D"))
+            || compilerFlags[i].StartsWith(wxT("/D")) )
+        {
             defines.Add(compilerFlags[i].Mid(2));
+        }
+        else if (   compilerFlags[i].StartsWith(wxT("`"))
+                 && compilerFlags[i].EndsWith(wxT("`"))  )
+        {
+            wxArrayString out;
+            long ret = 0;
+            {
+                wxLogNull logNo; // no need to warn if execution fails
+                ret = wxExecute(compilerFlags[i].Mid(1, compilerFlags[i].Length() - 2), out);
+            }
+            if (ret == 0)
+            {
+                out = GetArrayFromString(out[0], wxT(" ")); // pkg-config gives only single line output
+                AppendArray(out, compilerFlags); // append for processing
+            }
+        }
+        else if (   compilerFlags[i] == wxT("-ansi")
+                 || compilerFlags[i] == wxT("-std=c90")
+                 || compilerFlags[i] == wxT("-std=c++98"))
+        {
+            defines.Add(wxT("__STRICT_ANSI__"));
+        }
     }
 
     defines.Add(wxT("__cplusplus"));
Index: src/sdk/editorcolourset.cpp
===================================================================
--- src/sdk/editorcolourset.cpp (revision 8236)
+++ src/sdk/editorcolourset.cpp (working copy)
@@ -658,7 +658,22 @@
             tmpKey << key << _T("/style") << wxString::Format(_T("%d"), i);
 
             if (cfg->Exists(tmpKey + _T("/name")))
-                opt->name = cfg->Read(tmpKey + _T("/name"));
+            {
+                wxString name = cfg->Read(tmpKey + _T("/name"));
+                for (size_t j = 0; opt->name != name && i + j < it->second.m_Colours.GetCount(); ++j) // search forwards first
+                {
+                    opt = it->second.m_Colours.Item(i + j);
+                }
+                for (int j = -1; opt->name != name && i + j >= 0; --j) // then search backwards if it was not found
+                {
+                    opt = it->second.m_Colours.Item(i + j);
+                }
+                if (opt->name != name)
+                {
+                    cfg->DeleteSubPath(tmpKey); // unknown key, clear it out
+                    continue;
+                }
+            }
             else
             {
                 // make sure we didn't create it accidentally
Index: src/sdk/editorconfigurationdlg.cpp
===================================================================
--- src/sdk/editorconfigurationdlg.cpp (revision 8236)
+++ src/sdk/editorconfigurationdlg.cpp (working copy)
@@ -140,8 +140,8 @@
     XRCCTRL(*this, "cmbViewWS",                   wxComboBox)->SetSelection(cfg->ReadInt(_T("/view_whitespace"),         0));
     XRCCTRL(*this, "rbTabText",                   wxRadioBox)->SetSelection(cfg->ReadBool(_T("/tab_text_relative"),      true)? 1 : 0);
 
-    XRCCTRL(*this, "chkTrackPreprocessor",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/track_preprocessor"),         false));
-    XRCCTRL(*this, "chkCollectPrjDefines",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/collect_prj_defines"),        false));
+    XRCCTRL(*this, "chkTrackPreprocessor",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/track_preprocessor"),         true));
+    XRCCTRL(*this, "chkCollectPrjDefines",        wxCheckBox)->SetValue(cfg->ReadBool(_T("/collect_prj_defines"),        true));
     XRCCTRL(*this, "chkPlatDefines",              wxCheckBox)->SetValue(cfg->ReadBool(_T("/platform_defines"),           false));
     XRCCTRL(*this, "chkColoursWxSmith",           wxCheckBox)->SetValue(cfg->ReadBool(_T("/highlight_wxsmith"),          true));
 

BTW: Is there any reason that the syntax highlight preview looks correct, so the code is different
I have no idea how this happens (and I cannot reproduce it).
Title: Re: Two problems with r8232
Post by: MortenMacFly on August 16, 2012, 06:04:39 am
This patch should fix (almost) all custom color scheme loading problems. [...]
Code
+                ret = wxExecute(compilerFlags[i].Mid(1, compilerFlags[i].Length() - 2), out);
An exec command every time? Couldn't this be at least cached? Maybe that should even be a function of the compiler... (not a specific one, but the compiler framework. Because the compile has to do it, too IIRC... (I want to avoid having duplicate code.)
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 16, 2012, 08:29:41 am
Alpha: it is considered a good style separating changes in different patches/commits as this makes reviewing it easier. And it they are committed separately the svn blame will be more useful at a later time.
Title: Re: Two problems with r8232
Post by: MortenMacFly on August 16, 2012, 01:22:23 pm
Alpha: it is considered a good style separating changes in different patches/commits as this makes reviewing it easier. And it they are committed separately the svn blame will be more useful at a later time.
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Title: Re: Two problems with r8232
Post by: Alpha on August 16, 2012, 03:36:58 pm
This patch should fix (almost) all custom color scheme loading problems.
Never mind; it only worked by a fluke.
BTW: Is there any reason that the syntax highlight preview looks correct, so the code is different
I have no idea how this happens (and I cannot reproduce it).
I had misunderstood the way color schemes were loaded/saved.  Items with multiple indexes are actually saved once for each index, which is why the preview looked different than the actual code.  The preview reinitialized all the values, however the actual code loaded (in this case) style "Comment (normal)" into the second index (11) that I added to "Default".

An exec command every time? Couldn't this be at least cached? Maybe that should even be a function of the compiler... (not a specific one, but the compiler framework. Because the compile has to do it, too IIRC... (I want to avoid having duplicate code.)
Right; I just noticed this now makes switching build targets a little slow.
Making wxString ExpandBackticks(wxString& str) (from sdk/compilercommandgenerator.cpp) global (and BackticksMap m_Backticks) looks like a solution.
Title: Re: Two problems with r8232
Post by: Alpha on August 16, 2012, 04:41:24 pm
This time, I think I got the loading function to work properly.  (The save function is currently unmodified, so file format is currently backwards compatible, but not as efficient as it could be.)  Execution is now cached in a globally accessible location.
Title: Re: Two problems with r8232
Post by: oBFusCATed on August 16, 2012, 06:45:27 pm
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Sorry, but the patch explanation made me believe the patch can be applied in two steps and there are some optional parts.
Title: Re: Two problems with r8232
Post by: Alpha on August 16, 2012, 07:35:44 pm
Huh? This patch is needed in one to work. There is nothing to separate, or what did you mean? Collecting preprocessor defines is needed fr the highlighting function to work correctly.
Sorry, but the patch explanation made me believe the patch can be applied in two steps and there are some optional parts.
My fault; I failed to describe the connection to the original patch (which inadvertently caused the problems).
Title: Re: Two problems with r8232
Post by: Alpha on August 18, 2012, 06:54:55 pm
In patch tracker (http://developer.berlios.de/patch/?func=detailpatch&patch_id=3319&group_id=5358) so it does not get lost.