help-global
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch: parsing initialization lists in C++ constructors


From: vova gorsunov
Subject: patch: parsing initialization lists in C++ constructors
Date: Wed, 10 Feb 2010 17:02:54 +0300

Hi, I hacked together following patch to parse C++ initialization
lists in the built-in parser


Index: libparser/Cpp.c
===================================================================
RCS file: /sources/global/global/libparser/Cpp.c,v
retrieving revision 1.2
diff -u -r1.2 Cpp.c
--- libparser/Cpp.c 5 Feb 2010 00:50:09 -0000 1.2
+++ libparser/Cpp.c 10 Feb 2010 12:53:29 -0000
@@ -568,6 +568,33 @@
  break;
  }
 }
+
+static void process_expression(const struct parser_param *param) {
+ int c;
+ while((c = nexttoken(");", cpp_reserved_word)) != EOF) {
+ if(SYMBOL == c) {
+ PUT(PARSER_REF_SYM, token, lineno, sp);
+ } else if(')' == c || ';' == c)
+ return;
+ }
+}
+
+static void process_initialization_list(const struct parser_param *param) {
+ int c;
+ while ((c = nexttoken("({,", cpp_reserved_word)) != EOF) {
+ if('{' == c) {
+ pushbacktoken();
+ return;
+ } else if('(' == c) {
+ /* can be pretty much anything */
+ process_expression(param);
+ } else if(SYMBOL == c) {
+ PUT(PARSER_REF_SYM, token, lineno, sp);
+ }
+ }
+}
+
+
 /*
  * function_definition: return if function definition or not.
  *
@@ -610,7 +637,7 @@
  return 0;
  }
  brace_level = 0;
- while ((c = nexttoken(",;[](){}=", cpp_reserved_word)) != EOF) {
+ while ((c = nexttoken(",;[](){}=:", cpp_reserved_word)) != EOF) {
  switch (c) {
  case SHARP_IFDEF:
  case SHARP_IFNDEF:
@@ -639,6 +666,10 @@
  break;
  else if (c == '=')
  break;
+ else if(':' == c) {
+ process_initialization_list(param);
+ return 1;
+ }
  /* pick up symbol */
  if (c == SYMBOL)
  PUT(PARSER_REF_SYM, token, lineno, sp);
@@ -646,6 +677,7 @@
  return 0;
 }

+
 /*
  * condition_macro:
  *
Index: libutil/token.c
===================================================================
RCS file: /sources/global/global/libutil/token.c,v
retrieving revision 1.24
diff -u -r1.24 token.c
--- libutil/token.c 25 Dec 2008 05:39:05 -0000 1.24
+++ libutil/token.c 10 Feb 2010 12:53:34 -0000
@@ -185,6 +185,9 @@
  *p   = 0;
  if (reserved && (c = (*reserved)(token, tlen)) == 0)
  break;
+ } else {
+ if (interested == NULL || strchr(interested, c))
+ break;
  }
  } else if (c == '%' && ymode) {
  /* recognize '%%' as a token if it is reserved word. */

Hope that'll work for you

/vg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]