Thread: [Icomplete-general] icomplete/src main.c,1.6,1.7 treeold.c,1.2,1.3
Brought to you by:
maxauthority
From: MaxAuthority <max...@us...> - 2006-04-19 17:32:23
|
Update of /cvsroot/icomplete/icomplete/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15721/src Modified Files: main.c treeold.c Log Message: Version 0.4 released, with namespace support Index: treeold.c =================================================================== RCS file: /cvsroot/icomplete/icomplete/src/treeold.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** treeold.c 7 Apr 2006 00:15:08 -0000 1.2 --- treeold.c 19 Apr 2006 17:32:15 -0000 1.3 *************** *** 20,23 **** --- 20,27 ---- #include "treeold.h" + // added by maxime COSTE, see the remark in main.c about this + extern char* g_used_namespaces; + extern char* g_scope_namespaces; + //brc: new subroutine static void add_tree_child (Tree* tree, const char* class) *************** *** 59,71 **** Tree *tree = root; ! //brc: namespace workaround: if no namespace is present, try to find the class ! // also in std:: ! if (!nspace) { char buffer[512]; ! strcpy(buffer,"std::"); ! strcat(buffer,cname); ! add_tree_child(tree,buffer); } int i = 0; // counters if (tfile && info.status.opened) --- 63,126 ---- Tree *tree = root; ! // if namespaces were listed, try also to find classes in these namespaces ! // NOTE : there is a case where this wont work : ! // namespace blah { namespace foo { ... } } in a header ! // using namespace blah; foo::thing in the file ! ! // first, scope namespaces, these may be chained (i.e. nsp1::nsp2::nsp3...) ! // but in order (I mean, if nsp1 appears first in the file, I dont think ! // nsp2::nsp1 may exist ! if (g_scope_namespaces) { char buffer[512]; ! // remember that namespaces is a zero separated string list terminated ! // by a double zero ! for (char* pointer = g_scope_namespaces; *pointer != 0; ! pointer += strlen(pointer)+1) { ! // verify that the namespace is not already in the name being tested ! if (!strstr(class, pointer)) ! { ! // please note that 254 + 2 + 256 = 511... ! strncpy (buffer, pointer, 254); ! strncat (buffer, "::", 2); ! strncat (buffer, class, 255); ! #if DEBUG >= 2 ! printf ("testing class %s\n", buffer); ! #endif ! add_tree_child (tree, buffer); ! } ! else ! { ! // if this namespace is already in the name, then, either ! // next namespaces are already and then there is no point in ! // continuing, either they arent, and if we continue we will ! // test something like "nsp2::nsp1" even if nsp2 cannot be ! // in nsp1 ! break; ! } ! } } + // used namespaces, these cannot be chained because they shall + // be complete (i.e. you must type "using namespace nsp1::nsp2::nsp3) + // and so in the namespace list I already got "nsp1::nsp2::nsp3" + if (g_used_namespaces && !nspace) + { + char buffer[512]; + // remember that namespaces is a zero separated string list terminated + // by a double zero + for (char* pointer = g_used_namespaces; *pointer != 0; + pointer += strlen(pointer)+1) { + // please note that 254 + 2 + 256 = 511... + strncpy (buffer, pointer, 254); + strncat (buffer, "::", 2); + strncat (buffer, class, 255); + #if DEBUG >= 2 + printf ("testing class %s\n", buffer); + #endif + add_tree_child (tree, buffer); + } + + } + int i = 0; // counters if (tfile && info.status.opened) Index: main.c =================================================================== RCS file: /cvsroot/icomplete/icomplete/src/main.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** main.c 7 Apr 2006 00:15:08 -0000 1.6 --- main.c 19 Apr 2006 17:32:15 -0000 1.7 *************** *** 16,19 **** --- 16,34 ---- #include "treeold.h" + // added by maxime COSTE, I know global variables are evil, but + // it seems to be much cleaner than changing a lot of function definition + // just to add a namespace parameter they will pass to other functions they + // will call which will again pass it to other functions until we reach the + // ones which needs the list of namespaces (and I also know my english is poor) + // + // used namespaces and scope namespaces are separated for speed reason : + // scope namespaces may be imbricated so we must test possibilities like + // nsp1::nsp2 and nsp2::nsp1 (in fact we could parse and see wich is the + // good one) + // used namespaces shall be okay cause one must write + // "using namespace foo::bar" + char* g_used_namespaces; + char* g_scope_namespaces; + /* open the supplied filename and read it until given line and column number * returning the malloc'ed buffer *************** *** 101,104 **** --- 116,205 ---- } + // return a zero separated list of strings containing + // all the first substring match of the regex in the buffer + // the substrings are in the order they are found in the buffer + char* list_substrings (char* buf, regex_t* re) + { + regmatch_t pm[2]; + memset (&pm[0], -1, sizeof(pm)); + + char* substrings; + long pos = 0; + substrings = malloc (10); + + while (regexec (re, buf, 2, &pm[0], 0) == 0) /* while matches found... */ + { + int len = pm[1].rm_eo - pm[1].rm_so; + + substrings = realloc (substrings, pos+len+2); + + strncpy (substrings+pos, buf + pm[1].rm_so, len); + *(substrings+pos+len) = 0; + #if DEBUG >= 2 + printf ("adding substring %s \n", substrings+pos); + #endif + pos += len+1; + + buf += pm[0].rm_eo; + } + *(substrings+pos) = 0; + + + return substrings; + + } + + // list the namespaces in the file, putting all the used namespace + // in used_namespaces as a zero separated string list, and all + // namespaces of the current scope in scope_namespaces + void list_namespaces (char* buf, char** used_namespaces, + char** scope_namespaces) + { + regex_t re; + // find all using namespace * and add it to the used_namespace list + const char* pattern = + "using[ \t\n]+namespace[ \t\n]+([a-zA-Z0-9_:]+)"; + + regcomp (&re, pattern, REG_EXTENDED); + *used_namespaces = list_substrings (buf, &re); + regfree (&re); + + // special case : the std namespaces, on my computer + // with gcc 3.4.6, the glibcxx uses _GLIBCXX_STD + // how _GLIBCXX_STD works is just too complicated for + // the -I option of ctags, that is why I add this + // hack. + unsigned size = 0; + int std_used = 0; + for (char* pointer = *used_namespaces; *pointer != 0; + pointer += strlen (pointer)+1) + { + if (!strncmp (pointer, "std", 3)) + { + std_used = 1; + } + size += strlen(pointer)+1; + } + if (std_used) + { + int len = strlen ("_GLIBCXX_STD"); + *used_namespaces = realloc (*used_namespaces, + size + len + 2); + strncpy (*used_namespaces+size, "_GLIBCXX_STD", len); + *(*used_namespaces+size+len) = 0; + *(*used_namespaces+size+len+1) = 0; + #if DEBUG >= 2 + printf ("namespace _GLIBCXX_STD added\n"); + #endif + } + // end of special case + + // find all namespace * {Â blocks + pattern = "namespace[ \t\n]+([a-zA-Z0-9]+)[ \t\n]*\\{"; + regcomp (&re, pattern, REG_EXTENDED); + *scope_namespaces = list_substrings (buf, &re); + regfree (&re); + } + /* forks and executes ctags to rebuild a tags file * storing cache_value in the tags file */ *************** *** 238,241 **** --- 339,344 ---- } + list_namespaces(buf, &g_used_namespaces, &g_scope_namespaces); + /* real parsing starts here */ Expression exp; *************** *** 262,265 **** --- 365,370 ---- find_entries(&exp, &sc); + free (g_used_namespaces); + free (g_scope_namespaces); } *************** *** 275,278 **** --- 380,386 ---- exp.function[0] = '\0'; + g_used_namespaces = NULL; + g_scope_namespaces = NULL; + find_entries (&exp, &sc); } |