void PPFile::CheckEndNamespace(Vector<int>& namespace_block, int level, Md5Stream& md5) { if(namespace_block.GetCount() && namespace_block.Top() == level) { namespace_block.Drop(); item.Add().type = PP_NAMESPACE_END; md5.Put('.'); } }
String CppMacro::Define(const char *s) { CParser p(s); String id; try { if(!p.IsId()) return Null; p.NoSkipSpaces().NoSkipComments(); // '#define TEST(x)' is difference form '#define TEST (x)' - later is parameterless id = p.ReadId(); param.Clear(); if(p.Char('(')) { p.SkipSpaces(); p.Spaces(); while(p.IsId()) { if(param.GetCount()) param << ","; param << p.ReadId(); p.Char(','); } if(p.Char3('.', '.', '.')) param << '.'; p.Char(')'); if(param.GetCount() == 0) // #define foo() bar - need to 'eat' parenthesis, cheap way param = "."; } const char *b = p.GetPtr(); while(!p.IsEof() && !p.IsChar2('/', '/')) p.SkipTerm(); body = String(b, p.GetPtr()); Md5Stream m; m.Put(param); m.Put(body); m.Finish(md5); } catch(CParser::Error) { return Null; } return id; }
void GetAllMacros(Md5Stream& md5, const String& id, Index<int>& segment_id) { Vector< Tuple2<int, int> > pos; Vector<const CppMacro *> def; String r; int q = sAllMacros.Find(id); while(q >= 0) { const PPMacro& m = sAllMacros[q]; int si = segment_id.Find(m.segment_id); if(si >= 0) { pos.Add(MakeTuple(si, m.line)); def.Add(&m.macro); } q = sAllMacros.FindNext(q); } IndexSort(pos, def); int n = def.GetCount(); if(n) { md5.Put(&n, sizeof(int)); md5.Put(id); for(int i = 0; i < n; i++) md5.Put(def[i]->md5, 16); } }