From 9e9774675173fe45c8372540512a2581bb105c4d Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Fri, 24 Jul 2015 01:56:59 +0200 Subject: [PATCH] ruby: Use nestlevel instead of string lists This will simplify some upcoming fixes. --- tagmanager/ctags/ruby.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tagmanager/ctags/ruby.c b/tagmanager/ctags/ruby.c index 02c12c6dc..782b146bd 100644 --- a/tagmanager/ctags/ruby.c +++ b/tagmanager/ctags/ruby.c @@ -19,6 +19,7 @@ #include "entry.h" #include "parse.h" +#include "nestlevel.h" #include "read.h" #include "vstring.h" @@ -41,7 +42,7 @@ static kindOption RubyKinds [] = { { TRUE, 'C', "context", "contexts" } }; -static stringList* nesting = NULL; +static NestingLevels* nesting = NULL; #define SCOPE_SEPARATOR '.' @@ -52,22 +53,21 @@ static stringList* nesting = NULL; static void enterUnnamedScope (void); /* -* Returns a string describing the scope in 'list'. +* Returns a string describing the scope in 'nls'. * We record the current scope as a list of entered scopes. * Scopes corresponding to 'if' statements and the like are * represented by empty strings. Scopes corresponding to * modules and classes are represented by the name of the * module or class. */ -static vString* stringListToScope (const stringList* list) +static vString* nestingLevelsToScope (const NestingLevels* nls) { - unsigned int i; + int i; unsigned int chunks_output = 0; vString* result = vStringNew (); - const unsigned int max = stringListCount (list); - for (i = 0; i < max; ++i) + for (i = 0; i < nls->n; ++i) { - vString* chunk = stringListItem (list, i); + const vString* chunk = nls->levels[i].name; if (vStringLength (chunk) > 0) { if (chunks_output++ > 0) @@ -178,7 +178,7 @@ static void emitRubyTag (vString* name, rubyKind kind) } vStringTerminate (name); - scope = stringListToScope (nesting); + scope = nestingLevelsToScope (nesting); qualified_name = vStringValue (name); unqualified_name = strrchr (qualified_name, SCOPE_SEPARATOR); @@ -205,7 +205,7 @@ static void emitRubyTag (vString* name, rubyKind kind) tag.kind = RubyKinds [kind].letter; makeTagEntry (&tag); - stringListAdd (nesting, vStringNewCopy (name)); + nestingLevelsPush (nesting, name, kind); vStringClear (name); vStringDelete (scope); @@ -355,7 +355,10 @@ static void readAndEmitTag (const unsigned char** cp, rubyKind expected_kind) static void enterUnnamedScope (void) { - stringListAdd (nesting, vStringNewInit ("")); + vString *name = vStringNewInit (""); + NestingLevel *parent = nestingLevelsGetCurrent (nesting); + nestingLevelsPush (nesting, name, parent ? parent->type : K_UNDEFINED); + vStringDelete (name); } static void findRubyTags (void) @@ -363,7 +366,7 @@ static void findRubyTags (void) const unsigned char *line; boolean inMultiLineComment = FALSE; - nesting = stringListNew (); + nesting = nestingLevelsNew (); /* FIXME: this whole scheme is wrong, because Ruby isn't line-based. * You could perfectly well write: @@ -484,11 +487,10 @@ static void findRubyTags (void) else expect_separator = FALSE; } - else if (canMatchKeyword (&cp, "end") && stringListCount (nesting) > 0) + else if (canMatchKeyword (&cp, "end") && nesting->n > 0) { /* Leave the most recent scope. */ - vStringDelete (stringListLast (nesting)); - stringListRemoveLast (nesting); + nestingLevelsPop (nesting); } else if (*cp == '"') { @@ -514,7 +516,7 @@ static void findRubyTags (void) } } } - stringListDelete (nesting); + nestingLevelsFree (nesting); } extern parserDefinition* RubyParser (void) -- 2.11.4.GIT