diff options
Diffstat (limited to 'src/pyscanner.l')
-rw-r--r-- | src/pyscanner.l | 185 |
1 files changed, 52 insertions, 133 deletions
diff --git a/src/pyscanner.l b/src/pyscanner.l index 2320bca..efdc943 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -65,17 +65,17 @@ */ -static ParserInterface *g_thisParser; +static OutlineParserInterface *g_thisParser; static const char * inputString; static int inputPosition; static QFile inputFile; static Protection protection; -static Entry* current_root = 0 ; -static Entry* current = 0 ; -static Entry* previous = 0 ; -static Entry* bodyEntry = 0 ; +static std::shared_ptr<Entry> current_root; +static std::shared_ptr<Entry> current; +static std::shared_ptr<Entry> previous; +static std::shared_ptr<Entry> bodyEntry; static int yyLineNr = 1 ; static QCString yyFileName; static MethodTypes mtype; @@ -145,16 +145,14 @@ static void initEntry() current->virt = virt; current->stat = gstat; current->lang = SrcLangExt_Python; - current->setParent(current_root); - Doxygen::docGroup.initGroupInfo(current); + Doxygen::docGroup.initGroupInfo(current.get()); gstat = FALSE; } static void newEntry() { previous = current; - current_root->addSubEntry(current); - current = new Entry ; + current_root->moveToSubEntryAndRefresh(current); initEntry(); } @@ -240,8 +238,7 @@ static void addFrom(bool all) current->fileName = yyFileName; //printf("Adding using declaration: found:%s:%d name=%s\n",yyFileName.data(),yyLineNr,current->name.data()); current->section=all ? Entry::USINGDIR_SEC : Entry::USINGDECL_SEC; - current_root->addSubEntry(current); - current = new Entry ; + current_root->moveToSubEntryAndRefresh(current); initEntry(); } //----------------------------------------------------------------------------- @@ -261,43 +258,6 @@ static void incLineNr() yyLineNr++; } -#if 0 -// Appends the current-name to current-type; -// Destroys current-name. -// Destroys current->args and current->argList -static void addType( Entry* current ) -{ - uint tl=current->type.length(); - if ( tl>0 && !current->name.isEmpty() && current->type.at(tl-1)!='.') - { - current->type += ' ' ; - } - current->type += current->name ; - current->name.resize(0) ; - tl=current->type.length(); - if ( tl>0 && !current->args.isEmpty() && current->type.at(tl-1)!='.') - { - current->type += ' ' ; - } - current->type += current->args ; - current->args.resize(0) ; - current->argList->clear(); -} - -static QCString stripQuotes(const char *s) -{ - QCString name; - if (s==0 || *s==0) return name; - name=s; - if (name.at(0)=='"' && name.at(name.length()-1)=='"') - { - name=name.mid(1,name.length()-2); - } - return name; -} -#endif -//----------------------------------------------------------------- - //----------------------------------------------------------------- static void startCommentBlock(bool brief) { @@ -313,15 +273,6 @@ static void startCommentBlock(bool brief) } } -/* -static void appendDocBlock() { - previous = current; - current_root->addSubEntry(current); - current = new Entry; - initEntry(); -} -*/ - static void handleCommentBlock(const QCString &doc,bool brief) { //printf("handleCommentBlock(doc=[%s] brief=%d docBlockInBody=%d docBlockJavaStyle=%d\n", @@ -341,7 +292,7 @@ static void handleCommentBlock(const QCString &doc,bool brief) QCString processedDoc = preprocessCommentBlock(doc,yyFileName,lineNr); while (parseCommentBlock( g_thisParser, - (docBlockInBody && previous) ? previous : current, + (docBlockInBody && previous) ? previous.get() : current.get(), processedDoc, // text yyFileName, // file lineNr, @@ -427,7 +378,7 @@ static void searchFoundDef() current->type.resize(0); current->name.resize(0); current->args.resize(0); - current->argList->clear(); + current->argList.clear(); g_packageCommentAllowed = FALSE; gstat=FALSE; //printf("searchFoundDef at=%d\n",yyLineNr); @@ -436,7 +387,7 @@ static void searchFoundDef() static void searchFoundClass() { current->section = Entry::CLASS_SEC; - current->argList->clear(); + current->argList.clear(); current->type += "class" ; current->fileName = yyFileName; current->startLine = yyLineNr; @@ -765,8 +716,7 @@ STARTDOCSYMS "##" current->fileName = yyFileName; //printf("Adding using declaration: found:%s:%d name=%s\n",yyFileName.data(),yyLineNr,current->name.data()); current->section=Entry::USINGDECL_SEC; - current_root->addSubEntry(current); - current = new Entry ; + current_root->moveToSubEntryAndRefresh(current); initEntry(); BEGIN(Search); } @@ -978,6 +928,10 @@ STARTDOCSYMS "##" BEGIN(FunctionParams); } ")" { // end of parameter list + if (current->argList.empty()) + { + current->argList.noParameters=TRUE; + } current->args = argListToString(current->argList); g_funcParamsEnd = TRUE; } @@ -992,10 +946,10 @@ STARTDOCSYMS "##" } {IDENTIFIER} { // Name of parameter lineCount(); - Argument *a = new Argument; - current->argList->append(a); - current->argList->getLast()->name = QCString(yytext).stripWhiteSpace(); - current->argList->getLast()->type = g_argType; + Argument a; + a.name = QCString(yytext).stripWhiteSpace(); + a.type = g_argType; + current->argList.push_back(a); g_argType = ""; } "=" { // default value @@ -1082,8 +1036,8 @@ STARTDOCSYMS "##" "," { if (g_braceCount == 0) { - if (current->argList->getLast()) - current->argList->getLast()->type += g_defVal.data(); + if (!current->argList.empty()) + current->argList.back().type += g_defVal; if (*yytext != ',') unput(*yytext); BEGIN(FunctionParams); @@ -1132,8 +1086,8 @@ STARTDOCSYMS "##" "," { if (g_braceCount == 0) { - if (current->argList->getLast()) - current->argList->getLast()->defval=QCString(g_defVal.data()).stripWhiteSpace(); + if (!current->argList.empty()) + current->argList.back().defval=QCString(g_defVal).stripWhiteSpace(); if (*yytext == ')') unput(*yytext); BEGIN(FunctionParams); @@ -1291,8 +1245,8 @@ STARTDOCSYMS "##" } {SCOPE} { - current->extends->append( - new BaseInfo(substitute(yytext,".","::"),Public,Normal) + current->extends.push_back( + BaseInfo(substitute(yytext,".","::"),Public,Normal) ); //Has base class-do stuff } @@ -1452,9 +1406,10 @@ STARTDOCSYMS "##" // do something based on the type of the IDENTIFIER if (current->type.isEmpty()) { - QListIterator<Entry> eli(*(current_root->children())); - Entry *child; - for (eli.toFirst();(child=eli.current());++eli) + //QListIterator<Entry> eli(*(current_root->children())); + //Entry *child; + //for (eli.toFirst();(child=eli.current());++eli) + for (const auto &child : current_root->children()) { if (child->name == QCString(yytext)) { @@ -1619,7 +1574,7 @@ STARTDOCSYMS "##" incLineNr(); docBlock += yytext; } - \\. { // espaced char + \\. { // escaped char docBlock += yytext; } . { @@ -1654,7 +1609,7 @@ STARTDOCSYMS "##" addToString(yytext); incLineNr(); } - \\. { // espaced char + \\. { // escaped char addToString(yytext); } "\"\"\"" { // triple double quotes @@ -1677,7 +1632,7 @@ STARTDOCSYMS "##" addToString(yytext); incLineNr(); } - \\. { // espaced char + \\. { // escaped char addToString(yytext); } "'''" { // triple single quotes @@ -1751,13 +1706,12 @@ STARTDOCSYMS "##" //---------------------------------------------------------------------------- -static void parseCompounds(Entry *rt) +static void parseCompounds(std::shared_ptr<Entry> rt) { //printf("parseCompounds(%s)\n",rt->name.data()); - EntryListIterator eli(*rt->children()); - Entry *ce; - for (;(ce=eli.current());++eli) + for (int i=0; i<rt->children().size(); ++i) { + std::shared_ptr<Entry> ce = rt->children()[i]; if (!ce->program.isEmpty()) { //printf("-- %s ---------\n%s\n---------------\n", @@ -1768,30 +1722,29 @@ static void parseCompounds(Entry *rt) pyscannerYYrestart( pyscannerYYin ) ; if (ce->section&Entry::COMPOUND_MASK) { - current_root = ce ; + current_root = ce; BEGIN( Search ); } else if (ce->parent()) { - current_root = ce->parent(); + current_root = rt; //printf("Searching for member variables in %s parent=%s\n", // ce->name.data(),ce->parent->name.data()); BEGIN( SearchMemVars ); } yyFileName = ce->fileName; yyLineNr = ce->bodyLine ; - if (current) delete current; - current = new Entry; + current = std::make_shared<Entry>(); initEntry(); - Doxygen::docGroup.enterCompound(yyFileName,yyLineNr,ce->name); - + QCString name = ce->name; + Doxygen::docGroup.enterCompound(yyFileName,yyLineNr,name); + pyscannerYYlex() ; g_lexInit=TRUE; - delete current; current=0; ce->program.resize(0); - Doxygen::docGroup.leaveCompound(yyFileName,yyLineNr,ce->name); + Doxygen::docGroup.leaveCompound(yyFileName,yyLineNr,name); } parseCompounds(ce); @@ -1801,7 +1754,7 @@ static void parseCompounds(Entry *rt) //---------------------------------------------------------------------------- -static void parseMain(const char *fileName,const char *fileBuf,Entry *rt) +static void parseMain(const char *fileName,const char *fileBuf,const std::shared_ptr<Entry> &rt) { initParser(); @@ -1836,7 +1789,7 @@ static void parseMain(const char *fileName,const char *fileBuf,Entry *rt) g_moduleScope+=baseName; } - current = new Entry; + current = std::make_shared<Entry>(); initEntry(); current->name = g_moduleScope; current->section = Entry::NAMESPACE_SEC; @@ -1845,11 +1798,11 @@ static void parseMain(const char *fileName,const char *fileBuf,Entry *rt) current->startLine = yyLineNr; current->bodyLine = yyLineNr; - rt->addSubEntry(current); + current_root = current; + + rt->moveToSubEntryAndRefresh(current); - current_root = current ; initParser(); - current = new Entry; Doxygen::docGroup.enterFile(yyFileName,yyLineNr); @@ -1863,7 +1816,6 @@ static void parseMain(const char *fileName,const char *fileBuf,Entry *rt) Doxygen::docGroup.leaveFile(yyFileName,yyLineNr); current_root->program.resize(0); - delete current; current=0; parseCompounds(current_root); @@ -1934,9 +1886,9 @@ void pyscanFreeScanner() //---------------------------------------------------------------------------- -void PythonLanguageScanner::parseInput(const char *fileName, +void PythonOutlineParser::parseInput(const char *fileName, const char *fileBuf, - Entry *root, + const std::shared_ptr<Entry> &root, bool /*sameTranslationUnit*/, QStrList & /*filesInSameTranslationUnit*/) { @@ -1949,50 +1901,17 @@ void PythonLanguageScanner::parseInput(const char *fileName, // printAST(global_root); } -bool PythonLanguageScanner::needsPreprocessing(const QCString &) +bool PythonOutlineParser::needsPreprocessing(const QCString &) const { return FALSE; } -void PythonLanguageScanner::parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt /*lang*/, - bool isExampleBlock, - const char *exampleName, - FileDef *fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) -{ - ::parsePythonCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs); -} - -void PythonLanguageScanner::parsePrototype(const char *text) +void PythonOutlineParser::parsePrototype(const char *text) { ::parsePrototype(text); } -void PythonLanguageScanner::resetCodeParserState() -{ - ::resetPythonCodeParserState(); -} - //---------------------------------------------------------------------------- -#if !defined(YY_FLEX_SUBMINOR_VERSION) -//---------------------------------------------------------------------------- -extern "C" { // some bogus code to keep the compiler happy - void pyscannerYYdummy() { yy_flex_realloc(0,0); } -} -#endif - #include "pyscanner.l.h" |