void SerializePPFiles(Stream& s) { s % sAllMacros % sPPfile % sPPserial; if(s.IsLoading()) LoadPPConfig(); #if 0 if(s.IsLoading()) { _DBG_ DDUMP(sPPfile.GetCount()); DDUMP(sAllMacros.GetCount()); DDUMP(sPPserial); Index<int> psegment; for(int i = 0; i < sPPfile.GetCount(); i++) { const PPFile& p = sPPfile[i]; for(int j = 0; j < p.item.GetCount(); j++) psegment.FindAdd(p.item[j].segment_id); } DDUMP(psegment.GetCount()); int n = 0; _DBG_ Index<int> msegment; for(int i = 0; i < sAllMacros.GetCount(); i++) { _DBG_ if(sAllMacros.IsUnlinked(i)) n++; else msegment.FindAdd(sAllMacros[i].segment_id); } DLOG("UNLINKED " << n); DLOG("Segments " << msegment.GetCount()); }
void LoadPPConfig() { for(int i = 0; i < sAllMacros.GetCount(); i++) if(sAllMacros[i].segment_id == 0 && !sAllMacros.IsUnlinked(i)) sAllMacros.Unlink(i); s_namespace_macro.Clear(); s_namespace_end_macro.Clear(); StringStream ss(sDefs); int linei = 0; while(!ss.IsEof()) { String l = ss.GetLine(); try { CParser p(l); if(p.Char('#')) { if(p.Id("define")) { CppMacro def; String id = def.Define(p.GetPtr()); if(id.GetCount()) { PPMacro m; m.segment_id = 0; m.line = linei; m.macro = def; sAllMacros.Put(id, m); if(findarg(TrimBoth(def.body), "}", "};") >= 0) s_namespace_end_macro.Add(id); try { CParser p(def.body); if(p.Id("namespace") && p.IsId()) { String n = p.ReadId(); if(p.Char('{') && p.IsEof()) s_namespace_macro.Add(id, n); } } catch(CParser::Error) {} } } } } catch(CParser::Error) {} linei++; } }
void SweepPPFiles(const Index<String>& keep) { Index<int> pp_segment_id; int unlinked_count = 0; for(int i = 0; i < sPPfile.GetCount(); i++) if(sPPfile.IsUnlinked(i)) unlinked_count++; else if(keep.Find(sPPfile.GetKey(i)) < 0) { unlinked_count++; sPPfile.Unlink(i); } else { const PPFile& p = sPPfile[i]; for(int j = 0; j < p.item.GetCount(); j++) pp_segment_id.FindAdd(p.item[j].segment_id); } if(unlinked_count > sPPfile.GetCount() / 2) { CleanPP(); return; } unlinked_count = 0; for(int i = 0; i < sAllMacros.GetCount(); i++) { if(sAllMacros.IsUnlinked(i)) unlinked_count++; else if(sAllMacros[i].segment_id && pp_segment_id.Find(sAllMacros[i].segment_id) < 0) { sAllMacros.Unlink(i); unlinked_count++; } if(unlinked_count > sAllMacros.GetCount() / 2) { CleanPP(); return; } } }