From d97e486fb43db64a601b5cd3d0c7c17c2199a279 Mon Sep 17 00:00:00 2001 From: Cheryl Foil Date: Tue, 1 Jul 2008 21:02:36 +0000 Subject: [PATCH] Small modifications to place comments into the parse tree (Fairly inflexible at the moment) git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-cherylfoil@10620 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/CParse/cscanner.c | 10 ++++++++++ Source/CParse/parser.y | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Source/CParse/cscanner.c b/Source/CParse/cscanner.c index 2a0d341b5..140b7fedd 100644 --- a/Source/CParse/cscanner.c +++ b/Source/CParse/cscanner.c @@ -426,6 +426,14 @@ int yylook(void) { if ((strncmp(loc,"/*@SWIG@",6) == 0) && (loc[Len(cmt)-3] == '@')) { scanner_locator(cmt); } + + if (strncmp(loc, "/**", 3) == 0 || strncmp(loc, "///", 3) == 0||strncmp(loc, "/*!", 3) == 0||strncmp(loc, "//!", 3) == 0) { + printf("Doxygen Comment: %s lines %d-%d [%s]\n", Char(Scanner_file(scan)), Scanner_start_line(scan), Scanner_line(scan), loc); + yylval.str = NewString(loc); + return DOXYGENSTRING; + } + + } break; case SWIG_TOKEN_ENDLINE: @@ -897,6 +905,8 @@ int yylex(void) { return (ID); case POUND: return yylex(); + case SWIG_TOKEN_COMMENT: + return yylex(); default: return (l); } diff --git a/Source/CParse/parser.y b/Source/CParse/parser.y index 4fe8b47ed..6a835c7f3 100644 --- a/Source/CParse/parser.y +++ b/Source/CParse/parser.y @@ -55,6 +55,14 @@ static int max_class_levels = 0; static int class_level = 0; static Node **class_decl = NULL; +/* ----------------------------------------------------------------------------- + * Doxygen Comment Globals + * ----------------------------------------------------------------------------- */ + +int isComment = 0; /* boolean for parsing Doxygen Comments */ +String *currentComment = 0; /* Location of the stored Doxygen Comment */ +static String *sideDoxComments = 0; + /* ----------------------------------------------------------------------------- * Assist Functions * ----------------------------------------------------------------------------- */ @@ -71,6 +79,12 @@ static Node *new_node(const String_or_char *tag) { set_nodeType(n,tag); Setfile(n,cparse_file); Setline(n,cparse_line); + /* Sets Comment if a Comment is Availible */ + if(isComment){ + String *copyComment = Copy(currentComment); + Setattr(n,"comment",copyComment); + isComment = 0; + } return n; } @@ -1440,6 +1454,7 @@ static void tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { %token OPERATOR %token COPERATOR %token PARSETYPE PARSEPARM PARSEPARMS +%token DOXYGENSTRING %left CAST %left QUESTIONMARK @@ -1511,6 +1526,7 @@ static void tag_nodes(Node *n, const String_or_char *attrname, DOH *value) { %type type_specifier primitive_type_list ; %type fname stringtype; %type featattr; +%type doxygen_comment; %% @@ -1568,6 +1584,7 @@ interface : interface declaration { declaration : swig_directive { $$ = $1; } | c_declaration { $$ = $1; } | cpp_declaration { $$ = $1; } + | doxygen_comment { $$ = $1; } | SEMI { $$ = 0; } | error { $$ = 0; @@ -2811,6 +2828,7 @@ warn_directive : WARN string { } ; + /* ====================================================================== * C Parsing * ====================================================================== */ @@ -3132,6 +3150,20 @@ c_constructor_decl : storage_class type LPAREN parms RPAREN ctor_end { } ; +/* ------------------------------------------------------------ + A Doxygen Comment (a string in Doxygen Format) + ------------------------------------------------------------ */ + +doxygen_comment : DOXYGENSTRING + { + currentComment = NewString($1); + isComment = 1; + $$ = 0; + } + ; + + + /* ====================================================================== * C++ Support * ====================================================================== */ @@ -5977,4 +6009,3 @@ ParmList *Swig_cparse_parms(String *s) { /* Printf(stdout,"typeparse: '%s' ---> '%s'\n", s, top); */ return top; } -