summaryrefslogtreecommitdiff
path: root/src/code.l
diff options
context:
space:
mode:
authorJinWang An <jinwang.an@samsung.com>2022-12-27 12:33:07 +0900
committerJinWang An <jinwang.an@samsung.com>2022-12-27 12:33:07 +0900
commit15e5c5601a13a41757e2a5e1a9105d1714d40215 (patch)
treeb3d78685874664026425debdf3298c29c8eb5dda /src/code.l
parent558fa54c62ec59357cb5c40a411f16f1c1754f33 (diff)
downloaddoxygen-15e5c5601a13a41757e2a5e1a9105d1714d40215.tar.gz
doxygen-15e5c5601a13a41757e2a5e1a9105d1714d40215.tar.bz2
doxygen-15e5c5601a13a41757e2a5e1a9105d1714d40215.zip
Imported Upstream version 1.9.3upstream/1.9.3
Diffstat (limited to 'src/code.l')
-rw-r--r--src/code.l108
1 files changed, 78 insertions, 30 deletions
diff --git a/src/code.l b/src/code.l
index 9af97b8..a0054ab 100644
--- a/src/code.l
+++ b/src/code.l
@@ -18,6 +18,10 @@
%option extra-type="struct codeYY_state *"
%top{
#include <stdint.h>
+// forward declare yyscan_t to improve type safety
+#define YY_TYPEDEF_YY_SCANNER_T
+struct yyguts_t;
+typedef yyguts_t *yyscan_t;
}
%{
@@ -30,6 +34,7 @@
#include <memory>
#include <algorithm>
#include <unordered_map>
+#include <unordered_set>
#include <stack>
#include <vector>
#include <string>
@@ -98,17 +103,13 @@ struct codeYY_state
QCString parmType;
QCString parmName;
- bool beginCodeLine = true; //!< signals whether or not we should with the first line
- //!< write a start line code or not. Essential
- //!< when this code parser is called from another
- //!< code parser.
-
const char * inputString = 0; //!< the code fragment as text
yy_size_t inputPosition = 0; //!< read offset during parsing
+ QCString fileName;
int inputLines = 0; //!< number of line in the code fragment
int yyLineNr = 0; //!< current line number
yy_size_t yyColNr = 0; //!< current column number
- bool needsTermination = FALSE;
+ bool insideCodeLine = FALSE;
bool exampleBlock = FALSE;
QCString exampleName;
@@ -188,7 +189,7 @@ static bool isCastKeyword(const char *s);
//-------------------------------------------------------------------
#if USE_STATE2STRING
-static const char *stateToString(yyscan_t yyscanner,int state);
+static const char *stateToString(int state);
#endif
static void saveObjCContext(yyscan_t yyscanner);
@@ -264,6 +265,9 @@ static std::mutex g_usingDirectiveMutex;
#undef YY_INPUT
#define YY_INPUT(buf,result,max_size) result=yyread(yyscanner,buf,max_size);
+// otherwise the filename would be the name of the converted file (*.cpp instead of *.l)
+static inline const char *getLexerFILE() {return __FILE__;}
+#include "doxygen_lex.h"
%}
@@ -277,10 +281,11 @@ TEMPLIST "<"[^\"\}\{\(\)\/\n\>]*">"
SCOPETNAME (((({ID}{TEMPLIST}?){BN}*)?{SEP}{BN}*)*)((~{BN}*)?{ID})
SCOPEPREFIX ({ID}{TEMPLIST}?{BN}*{SEP}{BN}*)+
KEYWORD_OBJC ("@public"|"@private"|"@protected"|"@class"|"@implementation"|"@interface"|"@end"|"@selector"|"@protocol"|"@optional"|"@required"|"@throw"|"@synthesize"|"@property")
-KEYWORD ("asm"|"__assume"|"auto"|"class"|"const"|"delete"|"enum"|"explicit"|"extern"|"false"|"friend"|"gcnew"|"gcroot"|"set"|"get"|"inline"|"internal"|"mutable"|"namespace"|"new"|"null"|"nullptr"|"override"|"operator"|"pin_ptr"|"private"|"protected"|"public"|"raise"|"register"|"remove"|"self"|"sizeof"|"static"|"struct"|"__super"|"function"|"template"|"generic"|"this"|"true"|"typedef"|"typeid"|"typename"|"union"|"using"|"virtual"|"volatile"|"abstract"|"final"|"import"|"synchronized"|"transient"|"alignas"|"alignof"|"concept"|"requires"|"decltype"|{KEYWORD_OBJC}|"constexpr"|"consteval"|"constinit"|"co_await"|"co_return"|"co_yield"|"static_assert"|"noexcept"|"thread_local")
+ /* please also pay attention to skipLanguageSpecificKeyword when changing the list of keywords. */
+KEYWORD ("asm"|"__assume"|"auto"|"class"|"const"|"delete"|"enum"|"explicit"|"extern"|"false"|"friend"|"gcnew"|"gcroot"|"set"|"get"|"inline"|"internal"|"mutable"|"namespace"|"new"|"null"|"nullptr"|"override"|"operator"|"pin_ptr"|"private"|"protected"|"public"|"raise"|"register"|"remove"|"self"|"sizeof"|"static"|"struct"|"__super"|"function"|"template"|"generic"|"this"|"true"|"typedef"|"typeid"|"typename"|"union"|"using"|"virtual"|"volatile"|"abstract"|"final"|"import"|"synchronized"|"transient"|"alignas"|"alignof"|"concept"|"requires"|"decltype"|{KEYWORD_OBJC}|"constexpr"|"consteval"|"constinit"|"co_await"|"co_return"|"co_yield"|"static_assert"|"noexcept"|"thread_local"|"enum"{B}+("class"|"struct"))
FLOWKW ("break"|"catch"|"continue"|"default"|"do"|"else"|"finally"|"return"|"switch"|"throw"|"throws"|"@catch"|"@finally")
FLOWCONDITION ("case"|"for"|"foreach"|"for each"|"goto"|"if"|"try"|"while"|"@try")
-TYPEKW ("bool"|"byte"|"char"|"double"|"float"|"int"|"long"|"object"|"short"|"signed"|"unsigned"|"void"|"wchar_t"|"size_t"|"boolean"|"id"|"SEL"|"string"|"nullptr")
+TYPEKW ("bool"|"byte"|"char"|"char8_t"|"char16_t"|"char32_t"|"double"|"float"|"int"|"long"|"object"|"short"|"signed"|"unsigned"|"void"|"wchar_t"|"size_t"|"boolean"|"id"|"SEL"|"string"|"nullptr")
TYPEKWSL ("LocalObject"|"Object"|"Value")
CASTKW ("const_cast"|"dynamic_cast"|"reinterpret_cast"|"static_cast")
CHARLIT (("'"\\[0-7]{1,3}"'")|("'"\\."'")|("'"[^' \\\n]{1,4}"'"))
@@ -343,7 +348,6 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
%x SkipComment
%x SkipCxxComment
%x RemoveSpecialCComment
-%x StripSpecialCComment
%x Body
%x FuncCall
%x MemberCall
@@ -1529,7 +1533,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
yyextra->code->codify(yytext);
endFontClass(yyscanner);
}
-<MemberCall2,FuncCall>{ID}(({B}*"<"[^\n\[\](){}<>]*">")?({B}*"::"{B}*{ID})?)* {
+<MemberCall2,FuncCall>("::")?{ID}(({B}*"<"[^\n\[\](){}<>]*">")?({B}*"::"{B}*{ID})?)* {
if (isCastKeyword(yytext))
{
REJECT;
@@ -1939,7 +1943,7 @@ ENDQopt ("const"|"volatile"|"sealed"|"override")({BN}+("const"|"volatile"|"seale
BEGIN( yyextra->lastCContext ) ;
}
}
-<SkipCPP>\n/.*\n {
+<SkipCPP>\n/(.|\n) {
endFontClass(yyscanner);
BEGIN( yyextra->lastSkipCppContext ) ;
unput('\n');
@@ -2371,24 +2375,26 @@ static void startCodeLine(yyscan_t yyscanner)
yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
yyextra->currentMemberDef->getOutputFileBase(),
yyextra->currentMemberDef->anchor(),
- yyextra->yyLineNr);
+ yyextra->yyLineNr,!yyextra->includeCodeFragment);
setCurrentDoc(yyscanner,lineAnchor);
}
else if (d->isLinkableInProject())
{
yyextra->code->writeLineNumber(d->getReference(),
d->getOutputFileBase(),
- QCString(),yyextra->yyLineNr);
+ QCString(),yyextra->yyLineNr,!yyextra->includeCodeFragment);
setCurrentDoc(yyscanner,lineAnchor);
}
}
else
{
- yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr);
+ yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr,
+ !yyextra->includeCodeFragment);
}
}
DBG_CTX((stderr,"startCodeLine(%d)\n",yyextra->yyLineNr));
yyextra->code->startCodeLine(yyextra->sourceFileDef && yyextra->lineNumbers);
+ yyextra->insideCodeLine = true;
if (yyextra->currentFontClass)
{
yyextra->code->startFontClass(QCString(yyextra->currentFontClass));
@@ -2403,13 +2409,17 @@ static void endCodeLine(yyscan_t yyscanner)
DBG_CTX((stderr,"endCodeLine(%d)\n",yyextra->yyLineNr));
endFontClass(yyscanner);
yyextra->code->endCodeLine();
+ yyextra->insideCodeLine = false;
}
static void nextCodeLine(yyscan_t yyscanner)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
const char * fc = yyextra->currentFontClass;
- endCodeLine(yyscanner);
+ if (yyextra->insideCodeLine)
+ {
+ endCodeLine(yyscanner);
+ }
if (yyextra->yyLineNr<yyextra->inputLines)
{
yyextra->currentFontClass = fc;
@@ -3349,9 +3359,7 @@ static int countLines(yyscan_t yyscanner)
}
if (p>yyextra->inputString && *(p-1)!='\n')
{ // last line does not end with a \n, so we add an extra
- // line and explicitly terminate the line after parsing.
- count++,
- yyextra->needsTermination=TRUE;
+ count++;
}
return count;
}
@@ -3726,8 +3734,41 @@ static QCString escapeComment(yyscan_t yyscanner,const char *s)
static bool skipLanguageSpecificKeyword(yyscan_t yyscanner,const char *keyword)
{
struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
- QCString kw(keyword);
- return yyextra->lang==SrcLangExt_Cpp && (kw == "remove" || kw == "set" || kw == "get");
+ static std::unordered_set<std::string> non_cpp_keywords = {
+ "__assume", "__super", "abstract", "function",
+ "gcnew", "gcroot", "generic", "get",
+ "internal", "null", "pin_ptr", "raise",
+ "remove", "self", "set", "transient"};
+ static std::unordered_set<std::string> non_java_keywords = {
+ "alignas", "alignof", "and", "and_eq", "asm",
+ "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand",
+ "bitor", "bool", "char8_t", "char16_t", "char32_t",
+ "compl", "concept", "consteval", "constexpr", "constinit",
+ "const_cast", "co_await", "co_return", "co_yield", "decltype",
+ "delete", "dynamic_cast", "explicit", "export", "extern",
+ "friend", "inline", "mutable", "namespace", "noexcept",
+ "not", "not_eq", "nullptr", "operator", "or",
+ "or_eq", "reflexpr", "register", "reinterpret_cast", "requires",
+ "signed", "sizeof", "static_assert", "static_cast", "struct",
+ "template", "thread_local", "typedef", "typeid", "typename",
+ "union", "unsigned", "using", "virtual", "wchar_t",
+ "xor", "xor_eq",
+ "override"
+ };
+ bool retval;
+ switch (yyextra->lang)
+ {
+ case SrcLangExt_Cpp:
+ retval = (non_cpp_keywords.find(keyword) != non_cpp_keywords.end());
+ break;
+ case SrcLangExt_Java:
+ retval = (non_java_keywords.find(keyword) != non_java_keywords.end());
+ break;
+ default:
+ retval = false;
+ break;
+ }
+ return retval;
}
static bool isCastKeyword(const char *keyword)
@@ -3833,12 +3874,19 @@ void CCodeParser::resetCodeParserState()
yyextra->codeClassMap.clear();
yyextra->curClassBases.clear();
yyextra->anchorCount = 0;
+ yyextra->insideCodeLine = false;
}
-void CCodeParser::setStartCodeLine(const bool inp)
+void CCodeParser::setInsideCodeLine(bool inp)
{
struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
- yyextra->beginCodeLine = inp;
+ yyextra->insideCodeLine = inp;
+}
+
+bool CCodeParser::insideCodeLine() const
+{
+ struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
+ return yyextra->insideCodeLine;
}
void CCodeParser::parseCode(CodeOutputInterface &od,const QCString &className,const QCString &s,
@@ -3858,10 +3906,10 @@ void CCodeParser::parseCode(CodeOutputInterface &od,const QCString &className,co
yyextra->code = &od;
yyextra->inputString = s.data();
+ yyextra->fileName = fd ? fd->fileName():"";
yyextra->inputPosition = 0;
codeYYrestart(0,yyscanner);
yyextra->currentFontClass = 0;
- yyextra->needsTermination = FALSE;
yyextra->searchCtx = searchCtx;
yyextra->collectXRefs = collectXRefs;
yyextra->inFunctionTryBlock = FALSE;
@@ -3915,7 +3963,10 @@ void CCodeParser::parseCode(CodeOutputInterface &od,const QCString &className,co
}
yyextra->includeCodeFragment = inlineFragment;
DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",exBlock,qPrint(exName),inlineFragment));
- if (yyextra->beginCodeLine) startCodeLine(yyscanner);
+ if (!yyextra->insideCodeLine)
+ {
+ startCodeLine(yyscanner);
+ }
yyextra->type.resize(0);
yyextra->name.resize(0);
yyextra->args.resize(0);
@@ -3925,11 +3976,9 @@ void CCodeParser::parseCode(CodeOutputInterface &od,const QCString &className,co
BEGIN( Body );
codeYYlex(yyscanner);
yyextra->lexInit=TRUE;
- if (yyextra->needsTermination)
+ if (yyextra->insideCodeLine)
{
- endFontClass(yyscanner);
- DBG_CTX((stderr,"endCodeLine(%d)\n",yyextra->yyLineNr));
- yyextra->code->endCodeLine();
+ endCodeLine(yyscanner);
}
if (cleanupSourceDef)
{
@@ -3941,7 +3990,6 @@ void CCodeParser::parseCode(CodeOutputInterface &od,const QCString &className,co
yyextra->tooltipManager.writeTooltips(od);
printlex(yy_flex_debug, FALSE, __FILE__, fd ? qPrint(fd->fileName()): NULL);
- return;
}
#if USE_STATE2STRING