Orb/Doxygen/src/scanner.l
changeset 4 468f4c8d3d5b
parent 3 d8fccb2cd802
equal deleted inserted replaced
3:d8fccb2cd802 4:468f4c8d3d5b
     1 /*****************************************************************************
     1 /*****************************************************************************
     2  *
     2  *
     3  * 
     3  * 
     4  *
     4  *
     5  * Copyright (C) 1997-2008 by Dimitri van Heesch.
     5  * Copyright (C) 1997-2010 by Dimitri van Heesch.
     6  *
     6  *
     7  * Permission to use, copy, modify, and distribute this software and its
     7  * Permission to use, copy, modify, and distribute this software and its
     8  * documentation under the terms of the GNU General Public License is hereby 
     8  * documentation under the terms of the GNU General Public License is hereby 
     9  * granted. No representations are made about the suitability of this software 
     9  * granted. No representations are made about the suitability of this software 
    10  * for any purpose. It is provided "as is" without express or implied warranty.
    10  * for any purpose. It is provided "as is" without express or implied warranty.
   143 static bool             insideFormula;
   143 static bool             insideFormula;
   144 static bool  	        insideTryBlock=FALSE;
   144 static bool  	        insideTryBlock=FALSE;
   145 static bool             insideCode;
   145 static bool             insideCode;
   146 static bool             needsSemi;
   146 static bool             needsSemi;
   147 
   147 
   148 static int              depthIf;
   148 //static int              depthIf;
   149 static int  	        initBracketCount;
   149 static int  	        initBracketCount;
   150 static QCString         memberGroupRelates;
   150 static QCString         memberGroupRelates;
   151 static QCString         memberGroupInside;
   151 static QCString         memberGroupInside;
   152 static QCString         xrefItemKey;
   152 static QCString         xrefItemKey;
   153 static QCString         xrefItemTitle;
   153 static QCString         xrefItemTitle;
   564 FILE      ({FILESCHAR}*{FILEECHAR}+("."{FILESCHAR}*{FILEECHAR}+)*)|("\""[^\n\"]+"\"")
   564 FILE      ({FILESCHAR}*{FILEECHAR}+("."{FILESCHAR}*{FILEECHAR}+)*)|("\""[^\n\"]+"\"")
   565 ID        "$"?[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*
   565 ID        "$"?[a-z_A-Z\x80-\xFF][a-z_A-Z0-9\x80-\xFF]*
   566 SCOPEID   {ID}({ID}*{BN}*"::"{BN}*)*({ID}?)
   566 SCOPEID   {ID}({ID}*{BN}*"::"{BN}*)*({ID}?)
   567 SCOPENAME "$"?(({ID}?{BN}*"::"{BN}*)*)(((~|!){BN}*)?{ID})
   567 SCOPENAME "$"?(({ID}?{BN}*"::"{BN}*)*)(((~|!){BN}*)?{ID})
   568 TSCOPE    {ID}("<"[a-z_A-Z0-9 \t\*\&,]*">")?
   568 TSCOPE    {ID}("<"[a-z_A-Z0-9 \t\*\&,]*">")?
   569 FTSCOPE   {ID}("<"[a-z_A-Z0-9\*\&,]*">")?
       
   570 CSSCOPENAME (({ID}?{BN}*"."{BN}*)*)((~{BN}*)?{ID})
   569 CSSCOPENAME (({ID}?{BN}*"."{BN}*)*)((~{BN}*)?{ID})
   571 PRE       [pP][rR][eE]
   570 PRE       [pP][rR][eE]
   572 CODE      [cC][oO][dD][eE]
   571 CODE      [cC][oO][dD][eE]
   573 CHARLIT   (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^' \\\n]{1,4}"'"))
   572 CHARLIT   (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^' \\\n]{1,4}"'"))
   574 PHPKW	  ("require"|"require_once"|"include"|"include_once"|"echo")[^a-zA-Z0-9_;]
   573 PHPKW	  ("require"|"require_once"|"include"|"include_once"|"echo")[^a-zA-Z0-9_;]
  1601 					  {
  1600 					  {
  1602 					    current->tArgLists = new QList<ArgumentList>;
  1601 					    current->tArgLists = new QList<ArgumentList>;
  1603 					    current->tArgLists->setAutoDelete(TRUE);
  1602 					    current->tArgLists->setAutoDelete(TRUE);
  1604 					  }
  1603 					  }
  1605 					  ArgumentList *al = new ArgumentList;
  1604 					  ArgumentList *al = new ArgumentList;
  1606 					  current->spec |= (yytext[0]=='g') ? Entry::Generic : Entry::Template;
  1605 					  //current->spec |= (yytext[0]=='g') ? Entry::Generic : Entry::Template;
  1607 					  current->tArgLists->append(al);
  1606 					  current->tArgLists->append(al);
  1608 					  currentArgumentList = al;
  1607 					  currentArgumentList = al;
  1609 					  templateStr="<";
  1608 					  templateStr="<";
  1610 					  fullArgString = templateStr;
  1609 					  fullArgString = templateStr;
  1611 					  copyArgString = &templateStr;
  1610 					  copyArgString = &templateStr;
  1830   				          current->type+=yytext;
  1829   				          current->type+=yytext;
  1831   					}
  1830   					}
  1832 <QtPropType>{B}+			{
  1831 <QtPropType>{B}+			{
  1833   				          current->type+=yytext;
  1832   				          current->type+=yytext;
  1834   					}
  1833   					}
  1835 <QtPropType>({FTSCOPE}"::")*{FTSCOPE}	{
  1834 <QtPropType>({TSCOPE}"::")*{TSCOPE}	{
  1836   					  current->type+=yytext;
  1835   					  current->type+=yytext;
  1837                                           BEGIN(QtPropName);
  1836                                           BEGIN(QtPropName);
  1838   					}
  1837   					}
  1839 <QtPropName>{ID}			{
  1838 <QtPropName>{ID}			{
  1840   					  current->name=yytext;
  1839   					  current->name=yytext;
  1999 					  curlyCount=0;
  1998 					  curlyCount=0;
  2000 					  lastCurlyContext = TryFunctionBlockEnd ;
  1999 					  lastCurlyContext = TryFunctionBlockEnd ;
  2001   					  BEGIN( SkipCurly );
  2000   					  BEGIN( SkipCurly );
  2002 					}
  2001 					}
  2003 <TryFunctionBlock>.
  2002 <TryFunctionBlock>.
  2004 <TryFunctionBlockEnd>"catch"		{ BEGIN(TryFunctionBlock); }
  2003 <TryFunctionBlockEnd>{BN}*"catch"	{ lineCount(); BEGIN(TryFunctionBlock); // {BN}* added to fix bug 611193
  2005 <TryFunctionBlockEnd>\n			{ unput(*yytext); // added to fix bug id 601138
  2004 					}
       
  2005 <TryFunctionBlockEnd>\n			{ unput(*yytext); // rule added to fix bug id 601138
  2006   					  BEGIN( FindMembers );
  2006   					  BEGIN( FindMembers );
  2007 					}
  2007 					}
  2008 <TryFunctionBlockEnd>.			{ unput(*yytext);
  2008 <TryFunctionBlockEnd>.			{ unput(*yytext);
  2009   					  BEGIN( FindMembers );
  2009   					  BEGIN( FindMembers );
  2010 					}
  2010 					}
  2309 					    BEGIN(EndCppQuote);
  2309 					    BEGIN(EndCppQuote);
  2310 					  }
  2310 					  }
  2311 					  else
  2311 					  else
  2312 					  {
  2312 					  {
  2313                                             lastStringContext=YY_START;
  2313                                             lastStringContext=YY_START;
  2314   					    current->initializer+=*yytext; 
  2314   					    current->initializer=yytext; 
  2315   					    pCopyQuotedGString=&current->initializer;
  2315   					    pCopyQuotedGString=&current->initializer;
  2316 					    BEGIN(CopyGString);
  2316 					    BEGIN(CopyGString);
  2317 					  }
  2317 					  }
  2318 					}
  2318 					}
  2319 <ReadInitializer>"->"			{
  2319 <ReadInitializer>"->"			{
  2666   					}
  2666   					}
  2667 <BitFields>.				{
  2667 <BitFields>.				{
  2668   					  current->bitfields+=*yytext;
  2668   					  current->bitfields+=*yytext;
  2669   					}
  2669   					}
  2670 <FindMembers>[;,]			{ 
  2670 <FindMembers>[;,]			{ 
  2671 					  //printf("scanner.l: <FindMembers>[;,] name=%s, endBodyLine=%d\n", current->name.data(), current->endBodyLine);
       
  2672   					  QCString oldType = current->type.copy();
  2671   					  QCString oldType = current->type.copy();
  2673 					  if (current->bodyLine==-1)
  2672 					  if (current->bodyLine==-1)
  2674 					  {
  2673 					  {
  2675 					    current->bodyLine = yyLineNr;
  2674 					    current->bodyLine = yyLineNr;
  2676 					  }
  2675 					  }
  2693 					    	current->spec = 0;
  2692 					    	current->spec = 0;
  2694 					    }
  2693 					    }
  2695 					    current->section = Entry::VARIABLE_SEC ;
  2694 					    current->section = Entry::VARIABLE_SEC ;
  2696 					    current->fileName = yyFileName;
  2695 					    current->fileName = yyFileName;
  2697 					    current->startLine = yyLineNr;
  2696 					    current->startLine = yyLineNr;
  2698 						//printf("scanner.l: <FindMembers>[;,] file=%s line=%d\n", current->fileName.data(), current->startLine);
       
  2699 					    current_root->addSubEntry( current ) ;
  2697 					    current_root->addSubEntry( current ) ;
  2700 					    needNewCurrent=TRUE;
  2698 					    needNewCurrent=TRUE;
  2701 					  }
  2699 					  }
  2702 					  if ( *yytext == ',')
  2700 					  if ( *yytext == ',')
  2703 					  {
  2701 					  {
  3197 					      //p=p->parent;
  3195 					      //p=p->parent;
  3198 					      if (p==current) p=current_root; else p=p->parent();
  3196 					      if (p==current) p=current_root; else p=p->parent();
  3199 					    }
  3197 					    }
  3200 					  }
  3198 					  }
  3201 					  //printf("msName=%s current->name=%s\n",msName.data(),current->name.data());
  3199 					  //printf("msName=%s current->name=%s\n",msName.data(),current->name.data());
  3202 					  if (!msName.isEmpty() && msName!=current->name) // skip typedef T {} T;
  3200 					  if (!msName.isEmpty() 
       
  3201 					      /*&& msName!=current->name*/) // skip typedef T {} T;, removed due to bug608493
  3203 					  {
  3202 					  {
  3204 					    static bool typedefHidesStruct = Config_getBool("TYPEDEF_HIDES_STRUCT");
  3203 					    static bool typedefHidesStruct = Config_getBool("TYPEDEF_HIDES_STRUCT");
  3205 					    // case 1: typedef struct _S { ... } S_t; 
  3204 					    // case 1: typedef struct _S { ... } S_t; 
  3206 					    // -> omit typedef and use S_t as the struct name
  3205 					    // -> omit typedef and use S_t as the struct name
  3207 					    if (typedefHidesStruct && 
  3206 					    if (typedefHidesStruct && 
  4030   					  current->type=current->type.simplifyWhiteSpace();
  4029   					  current->type=current->type.simplifyWhiteSpace();
  4031 					  current->args=removeRedundantWhiteSpace(current->args);
  4030 					  current->args=removeRedundantWhiteSpace(current->args);
  4032 					                // was: current->args.simplifyWhiteSpace();
  4031 					                // was: current->args.simplifyWhiteSpace();
  4033 					  current->fileName = yyFileName;
  4032 					  current->fileName = yyFileName;
  4034 					  current->startLine = yyLineNr;
  4033 					  current->startLine = yyLineNr;
  4035 					  static QRegExp re("([^)]*\\[*&][^)]*)"); // (...*...)
  4034 					  static QRegExp re("([^)]*[*&][^)]*)"); // (...*...)
  4036 					  if (*yytext!=';' || (current_root->section&Entry::COMPOUND_MASK) )
  4035 					  if (*yytext!=';' || (current_root->section&Entry::COMPOUND_MASK) )
  4037 					  {
  4036 					  {
  4038 					    int tempArg=current->name.find('<');
  4037 					    int tempArg=current->name.find('<');
  4039 					    QCString tempName;
  4038 					    QCString tempName;
  4040 					    if (tempArg==-1) tempName=current->name; else tempName=current->name.left(tempArg);
  4039 					    if (tempArg==-1) tempName=current->name; else tempName=current->name.left(tempArg);
  4041 					    if (!current->type.isEmpty() &&
  4040 					    if (!current->type.isEmpty() &&
  4042 						(current->type.find(re,0)!=-1 || current->type.left(8)=="typedef "))
  4041 						(current->type.find(re,0)!=-1 || current->type.left(8)=="typedef "))
  4043 					    {
  4042 					    {
  4044 					      //printf("Scanner.l: found in class variable: `%s' `%s' `%s'\n", current->type.data(),current->name.data(),current->args.data());
  4043 					      //printf("Scanner.l: found in class variable: `%s' `%s' `%s'\n", current->type.data(),current->name.data(),current->args.data());
       
  4044 					      if (isTypedef && current->type.left(8)!="typedef ")
       
  4045 					      {
       
  4046 						current->type.prepend("typedef ");
       
  4047 					      }
  4045 					      current->section = Entry::VARIABLE_SEC ;
  4048 					      current->section = Entry::VARIABLE_SEC ;
  4046 					    }
  4049 					    }
  4047 					    else	      
  4050 					    else	      
  4048 					    {
  4051 					    {
  4049 					      //printf("Scanner.l: found in class function: `%s' `%s' `%s'\n", current->type.data(),current->name.data(),current->args.data());
  4052 					      //printf("Scanner.l: found in class function: `%s' `%s' `%s'\n", current->type.data(),current->name.data(),current->args.data());
  4055 					  {
  4058 					  {
  4056 					    //printf("Scanner.l: prototype? type=`%s' name=`%s' args=`%s'\n",current->type.data(),current->name.data(),current->args.data());
  4059 					    //printf("Scanner.l: prototype? type=`%s' name=`%s' args=`%s'\n",current->type.data(),current->name.data(),current->args.data());
  4057 					    if (!current->type.isEmpty() && 
  4060 					    if (!current->type.isEmpty() && 
  4058 						(current->type.find(re,0)!=-1 || current->type.left(8)=="typedef "))
  4061 						(current->type.find(re,0)!=-1 || current->type.left(8)=="typedef "))
  4059 					    {
  4062 					    {
       
  4063 					      if (isTypedef && current->type.left(8)!="typedef ")
       
  4064 					      {
       
  4065 						current->type.prepend("typedef ");
       
  4066 					      }
  4060 					      //printf("Scanner.l: found function variable!\n");
  4067 					      //printf("Scanner.l: found function variable!\n");
  4061 					      current->section = Entry::VARIABLE_SEC;
  4068 					      current->section = Entry::VARIABLE_SEC;
  4062 					    }
  4069 					    }
  4063 					    else
  4070 					    else
  4064 					    {
  4071 					    {
  4321 <SkipString,SkipPHPString>"/*"|"*/"|"//" { }
  4328 <SkipString,SkipPHPString>"/*"|"*/"|"//" { }
  4322 <SkipString,SkipPHPString>\n		{
  4329 <SkipString,SkipPHPString>\n		{
  4323   					  yyLineNr++;
  4330   					  yyLineNr++;
  4324   					}
  4331   					}
  4325 <SkipString,SkipPHPString>.		{ }
  4332 <SkipString,SkipPHPString>.		{ }
       
  4333 <CompoundName>":"			{ // for "class : public base {} var;" construct, see bug 608359
       
  4334   					  unput(':');
       
  4335 					  BEGIN(ClassVar);
       
  4336   					}
  4326 <Bases,CompoundName>";"			{ 
  4337 <Bases,CompoundName>";"			{ 
  4327 					  current->section = Entry::EMPTY_SEC ;
  4338 					  current->section = Entry::EMPTY_SEC ;
  4328 					  current->type.resize(0) ;
  4339 					  current->type.resize(0) ;
  4329 					  current->name.resize(0) ;
  4340 					  current->name.resize(0) ;
  4330 					  current->args.resize(0) ;
  4341 					  current->args.resize(0) ;
  4359 					  {
  4370 					  {
  4360 					    current->tArgLists = new QList<ArgumentList>;
  4371 					    current->tArgLists = new QList<ArgumentList>;
  4361 					    current->tArgLists->setAutoDelete(TRUE);
  4372 					    current->tArgLists->setAutoDelete(TRUE);
  4362 					  }
  4373 					  }
  4363 					  ArgumentList *al = new ArgumentList;
  4374 					  ArgumentList *al = new ArgumentList;
  4364 					  current->spec |= Entry::Template;
  4375 					  // check bug 612858 before enabling the next line
       
  4376 					  //current->spec |= Entry::Template;
  4365 					  current->tArgLists->append(al);
  4377 					  current->tArgLists->append(al);
  4366 					  currentArgumentList = al;
  4378 					  currentArgumentList = al;
  4367 					  templateStr="<";
  4379 					  templateStr="<";
  4368 					  current->name += "<";
  4380 					  current->name += "<";
  4369 					  fullArgString = templateStr;
  4381 					  fullArgString = templateStr;
  4837 					}
  4849 					}
  4838 <SkipRound>"("				{ ++roundCount; }
  4850 <SkipRound>"("				{ ++roundCount; }
  4839 <SkipRound>")"				{ if (--roundCount<=0)
  4851 <SkipRound>")"				{ if (--roundCount<=0)
  4840 					    BEGIN ( lastSkipRoundContext );
  4852 					    BEGIN ( lastSkipRoundContext );
  4841 					}
  4853 					}
       
  4854 <SkipRound>\"				{
       
  4855   					  lastStringContext=SkipRound;
       
  4856 					  BEGIN(SkipString);
       
  4857   					}
  4842 <Bases>","|(">"({BN}*"{")?)|({BN}+"implements"{BN}*)	{ lineCount();
  4858 <Bases>","|(">"({BN}*"{")?)|({BN}+"implements"{BN}*)	{ lineCount();
  4843                                           if (insideProtocolList)
  4859                                           if (insideProtocolList)
  4844 					  {
  4860 					  {
  4845 					    baseName+="-p";
  4861 					    baseName+="-p";
  4846 					  }
  4862 					  }
  5486     {
  5502     {
  5487       //printf("-- %s ---------\n%s\n---------------\n",
  5503       //printf("-- %s ---------\n%s\n---------------\n",
  5488       //  ce->name.data(),ce->program.data());
  5504       //  ce->name.data(),ce->program.data());
  5489       // init scanner state
  5505       // init scanner state
  5490       padCount=0;
  5506       padCount=0;
  5491       depthIf = 0;
  5507       //depthIf = 0;
  5492       inputString = ce->program;
  5508       inputString = ce->program;
  5493       inputPosition = 0;
  5509       inputPosition = 0;
  5494       scanYYrestart( scanYYin ) ;
  5510       scanYYrestart( scanYYin ) ;
  5495       if (ce->section==Entry::ENUM_SEC)
  5511       if (ce->section==Entry::ENUM_SEC)
  5496 	BEGIN( FindFields ) ;
  5512 	BEGIN( FindFields ) ;
  5568       
  5584       
  5569       delete current; current=0;
  5585       delete current; current=0;
  5570       ce->program.resize(0);
  5586       ce->program.resize(0);
  5571 
  5587 
  5572 
  5588 
  5573       if (depthIf>0)
  5589       //if (depthIf>0)
  5574       {
  5590       //{
  5575 	warn(yyFileName,yyLineNr,"Documentation block ended in the middle of a conditional section!");
  5591       //	warn(yyFileName,yyLineNr,"Documentation block ended in the middle of a conditional section!");
  5576       }
  5592       //}
  5577     }
  5593     }
  5578     parseCompounds(ce);
  5594     parseCompounds(ce);
  5579   }
  5595   }
  5580 }
  5596 }
  5581 
  5597 
  5589   inputString = fileBuf;
  5605   inputString = fileBuf;
  5590   inputPosition = 0;
  5606   inputPosition = 0;
  5591   g_inputFromFile = FALSE;
  5607   g_inputFromFile = FALSE;
  5592 
  5608 
  5593   //anonCount     = 0;  // don't reset per file
  5609   //anonCount     = 0;  // don't reset per file
  5594   depthIf       = 0;
  5610   //depthIf       = 0;
  5595   protection    = Public;
  5611   protection    = Public;
  5596   mtype         = Method;
  5612   mtype         = Method;
  5597   gstat         = FALSE;
  5613   gstat         = FALSE;
  5598   virt          = Normal;
  5614   virt          = Normal;
  5599   current_root  = rt;
  5615   current_root  = rt;
  5639     }
  5655     }
  5640 
  5656 
  5641     //forceEndGroup();
  5657     //forceEndGroup();
  5642     groupLeaveFile(yyFileName,yyLineNr);
  5658     groupLeaveFile(yyFileName,yyLineNr);
  5643 
  5659 
  5644     if (depthIf>0)
  5660     //if (depthIf>0)
  5645     {
  5661     //{
  5646       warn(yyFileName,yyLineNr,"Documentation block ended in the middle of a conditional section!");
  5662     //  warn(yyFileName,yyLineNr,"Documentation block ended in the middle of a conditional section!");
  5647     }
  5663     //}
  5648 
  5664 
  5649     rt->program.resize(0);
  5665     rt->program.resize(0);
  5650     delete current; current=0;
  5666     delete current; current=0;
  5651 
  5667 
  5652     parseCompounds(rt);
  5668     parseCompounds(rt);
  5741                    const char * exampleName,
  5757                    const char * exampleName,
  5742                    FileDef * fileDef,
  5758                    FileDef * fileDef,
  5743                    int startLine,
  5759                    int startLine,
  5744                    int endLine,
  5760                    int endLine,
  5745                    bool inlineFragment,
  5761                    bool inlineFragment,
  5746 		   MemberDef *memberDef
  5762 		   MemberDef *memberDef,
       
  5763 		   bool showLineNumbers
  5747                   )
  5764                   )
  5748 {
  5765 {
  5749   ::parseCCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName,
  5766   ::parseCCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName,
  5750                fileDef,startLine,endLine,inlineFragment,memberDef);
  5767                fileDef,startLine,endLine,inlineFragment,memberDef,
       
  5768 	       showLineNumbers);
  5751 }
  5769 }
  5752 
  5770 
  5753 bool CLanguageScanner::needsPreprocessing(const QCString &extension)
  5771 bool CLanguageScanner::needsPreprocessing(const QCString &extension)
  5754 {
  5772 {
  5755   QCString fe=extension.lower();
  5773   QCString fe=extension.lower();