Skip to content

Commit

Permalink
SQL Parser updates for bug 2961855.
Browse files Browse the repository at this point in the history
When parsing an Oracle package, the function prototypes did not have the
appropriate scope added to the tags.
Test case used is: test/bug2961855.sql.




git-svn-id: https://ctags.svn.sourceforge.net/svnroot/ctags/trunk@756 c5d04d22-be80-434c-894e-aa346cc9e8e8
  • Loading branch information
dfishburn committed May 26, 2010
1 parent 6276584 commit 475d4a0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
19 changes: 19 additions & 0 deletions Test/bug2961855.sql
@@ -0,0 +1,19 @@
// When it should be demo_pkg.test_func and demo_pkg.test_var
// Tags are created for:
// packages
// demo_pkg
// variables
// test_var
//
// But no tags for the function.
//
//
create or replace package demo_pkg is
test_var number;

function test_func return varchar2;
function more.test_func2 return varchar2;
function test_func3 return varchar2;

end demo_pkg;

38 changes: 35 additions & 3 deletions sql.c
Expand Up @@ -783,6 +783,16 @@ static void skipToMatched(tokenInfo *const token)
}
}

static void copyToken (tokenInfo *const dest, tokenInfo *const src)
{
dest->lineNumber = src->lineNumber;
dest->filePosition = src->filePosition;
dest->type = src->type;
dest->keyword = src->keyword;
vStringCopy(dest->string, src->string);
vStringCopy(dest->scope, src->scope);
}

static void skipArgumentList (tokenInfo *const token)
{
/*
Expand All @@ -801,6 +811,7 @@ static void skipArgumentList (tokenInfo *const token)
static void parseSubProgram (tokenInfo *const token)
{
tokenInfo *const name = newToken ();
vString * saveScope = vStringNew ();

/*
* This must handle both prototypes and the body of
Expand Down Expand Up @@ -840,16 +851,33 @@ static void parseSubProgram (tokenInfo *const token)
*
* RETURN @name;
* END;
*
* Note, a Package adds scope to the items within.
* create or replace package demo_pkg is
* test_var number;
* function test_func return varchar2;
* function more.test_func2 return varchar2;
* end demo_pkg;
* So the tags generated here, contain the package name:
* demo_pkg.test_var
* demo_pkg.test_func
* demo_pkg.more.test_func2
*/
const sqlKind kind = isKeyword (token, KEYWORD_function) ?
SQLTAG_FUNCTION : SQLTAG_PROCEDURE;
Assert (isKeyword (token, KEYWORD_function) ||
isKeyword (token, KEYWORD_procedure));
readToken (name);

vStringCopy(saveScope, token->scope);
readToken (token);
copyToken (name, token);
readToken (token);

if (isType (token, TOKEN_PERIOD))
{
readToken (name);
addToScope(token, name->string);
readToken (token);
copyToken (name, token);
readToken (token);
}
if (isType (token, TOKEN_OPEN_PAREN))
Expand Down Expand Up @@ -940,7 +968,9 @@ static void parseSubProgram (tokenInfo *const token)
vStringClear (token->scope);
}
}
vStringCopy(token->scope, saveScope);
deleteToken (name);
vStringDelete(saveScope);
}

static void parseRecord (tokenInfo *const token)
Expand Down Expand Up @@ -1566,7 +1596,7 @@ static void parsePackage (tokenInfo *const token)
* or by specifying a package body
* CREATE OR REPLACE PACKAGE BODY pkg_name AS
* CREATE OR REPLACE PACKAGE BODY owner.pkg_name AS
*/
*/
tokenInfo *const name = newToken ();
readToken (name);
if (isKeyword (name, KEYWORD_body))
Expand All @@ -1591,7 +1621,9 @@ static void parsePackage (tokenInfo *const token)
if (isType (name, TOKEN_IDENTIFIER) ||
isType (name, TOKEN_STRING))
makeSqlTag (name, SQLTAG_PACKAGE);
addToScope (token, name->string);
parseBlock (token, FALSE);
vStringClear (token->scope);
}
findCmdTerm (token, FALSE);
deleteToken (name);
Expand Down

0 comments on commit 475d4a0

Please sign in to comment.