Skip to main content

The CCodeParser Class Reference

Declaration

class CCodeParser { ... }

Included Headers

#include <src/code.h>

Base class

classCodeParserInterface

Abstract interface for code parsers. More...

Public Constructors Index

CCodeParser ()

Public Destructor Index

~CCodeParser () override

Public Member Functions Index

voidparseCode (OutputCodeList &codeOutIntf, const QCString &scopeName, const QCString &input, SrcLangExt lang, bool stripCodeComments, bool isExampleBlock, const QCString &exampleName=QCString(), const FileDef *fileDef=nullptr, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, const MemberDef *memberDef=nullptr, bool showLineNumbers=TRUE, const Definition *searchCtx=nullptr, bool collectXRefs=TRUE) override

Parses a source file or fragment with the goal to produce highlighted and cross-referenced output. More...

voidresetCodeParserState () override

Resets the state of the code parser. More...

voidsetInsideCodeLine (bool inp)
boolinsideCodeLine () const

Private Member Attributes Index

std::unique_ptr< Private >p

Definition at line 29 of file code.h.

Public Constructors

CCodeParser()

CCodeParser::CCodeParser ()

Declaration at line 32 of file code.h, definition at line 4066 of file code.l.

4067{
4068 codeYYlex_init_extra(&p->state,&p->yyscanner);
4069#ifdef FLEX_DEBUG
4070 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4071#endif
4073}

References CCodeParser, Debug::isFlagSet, Debug::Lex_code, p and resetCodeParserState.

Referenced by CCodeParser.

Public Destructor

~CCodeParser()

CCodeParser::~CCodeParser ()

Declaration at line 33 of file code.h, definition at line 4075 of file code.l.

4076{
4077 codeYYlex_destroy(p->yyscanner);
4078}

Reference p.

Public Member Functions

insideCodeLine()

bool CCodeParser::insideCodeLine ()

Declaration at line 53 of file code.h, definition at line 4098 of file code.l.

4099{
4100 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4101 return yyextra->insideCodeLine;
4102}

Reference p.

parseCode()

void CCodeParser::parseCode (OutputCodeList & codeOutList, const QCString & scopeName, const QCString & input, SrcLangExt lang, bool stripCodeComments, bool isExampleBlock, const QCString & exampleName=QCString(), const FileDef * fileDef=nullptr, int startLine=-1, int endLine=-1, bool inlineFragment=FALSE, const MemberDef * memberDef=nullptr, bool showLineNumbers=TRUE, const Definition * searchCtx=nullptr, bool collectXRefs=TRUE)
virtual

Parses a source file or fragment with the goal to produce highlighted and cross-referenced output.

Parameters
[in] codeOutList

interface for writing the result.

[in] scopeName

Name of scope to which the code belongs.

[in] input

Actual code in the form of a string

[in] lang

The programming language of the code fragment.

[in] stripCodeComments

signals whether or not for the code block the doxygen comments should be stripped.

[in] isExampleBlock

TRUE iff the code is part of an example.

[in] exampleName

Name of the example.

[in] fileDef

File definition to which the code is associated.

[in] startLine

Starting line in case of a code fragment.

[in] endLine

Ending line of the code fragment.

[in] inlineFragment

Code fragment that is to be shown inline as part of the documentation.

[in] memberDef

Member definition to which the code is associated (non null in case of an inline fragment for a member).

[in] showLineNumbers

if set to TRUE and also fileDef is not 0, line numbers will be added to the source fragment

[in] searchCtx

context under which search data has to be stored.

[in] collectXRefs

collect cross-reference relations.

Declaration at line 35 of file code.h, definition at line 4104 of file code.l.

4104void CCodeParser::parseCode(OutputCodeList &od,const QCString &scopeName,const QCString &s,
4105 SrcLangExt lang,bool stripCodeComments,bool exBlock,const QCString &exName,const FileDef *fd,
4106 int startLine,int endLine,bool inlineFragment,
4107 const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx,
4108 bool collectXRefs)
4109{
4110 yyscan_t yyscanner = p->yyscanner;
4111 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4112 DBG_CTX((stderr,"***parseCode() exBlock=%d exName=%s fd=%p scopeName=%s searchCtx=%s\n",
4113 exBlock,qPrint(exName),(void*)fd,qPrint(scopeName),searchCtx?qPrint(searchCtx->name()):"<none>"));
4114
4115 if (s.isEmpty()) return;
4116
4117 DebugLex debugLex(Debug::Lex_code, __FILE__, fd ? qPrint(fd->fileName()): !exName.isEmpty() ? qPrint(exName) : nullptr);
4118
4119 od.stripCodeComments(stripCodeComments);
4120 yyextra->code = &od;
4121 yyextra->inputString = s.data();
4122 yyextra->fileName = fd ? fd->fileName():"";
4123 yyextra->absFileName = fd ? fd->absFilePath():"";
4124 yyextra->inputPosition = 0;
4125 codeYYrestart(nullptr,yyscanner);
4126 yyextra->currentFontClass = nullptr;
4127 yyextra->searchCtx = searchCtx;
4128 yyextra->collectXRefs = collectXRefs;
4129 yyextra->inFunctionTryBlock = FALSE;
4130 yyextra->symbolResolver.setFileScope(fd);
4131 yyextra->foldStack.clear();
4132 yyextra->insideSpecialComment = false;
4133
4134 if (startLine!=-1)
4135 yyextra->yyLineNr = startLine;
4136 else
4137 yyextra->yyLineNr = 1;
4138
4139 if (endLine!=-1)
4140 yyextra->inputLines = endLine+1;
4141 else
4142 yyextra->inputLines = yyextra->yyLineNr + countLines(yyscanner) - 1;
4143
4144 yyextra->curlyCount = 0;
4145 yyextra->bodyCurlyCount = 0;
4146 yyextra->bracketCount = 0;
4147 yyextra->sharpCount = 0;
4148 yyextra->insideTemplate = FALSE;
4149 yyextra->theCallContext.clear();
4150 while (!yyextra->scopeStack.empty()) yyextra->scopeStack.pop();
4151 yyextra->scopeName = scopeName;
4152 DBG_CTX((stderr,"parseCCode %s\n",qPrint(scopeName)));
4153 yyextra->exampleBlock = exBlock;
4154 yyextra->exampleName = exName;
4155 yyextra->sourceFileDef = fd;
4156 yyextra->lineNumbers = fd && showLineNumbers;
4157 if (fd==nullptr)
4158 {
4159 // create a dummy filedef for the example
4160 yyextra->exampleFileDef = createFileDef(QCString(),(!exName.isEmpty()?exName:"generated"));
4161 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
4162 }
4163 yyextra->lang = lang;
4164 yyextra->insideObjC = lang==SrcLangExt::ObjC;
4165 if (yyextra->sourceFileDef)
4166 {
4167 setCurrentDoc(yyscanner,"l00001");
4168 }
4169 yyextra->currentDefinition = searchCtx ? searchCtx : getResolvedNamespace(scopeName);
4170 yyextra->currentMemberDef = nullptr;
4171 yyextra->searchingForBody = exBlock;
4172 yyextra->insideBody = FALSE;
4173 yyextra->bracketCount = 0;
4174 if (!yyextra->exampleName.isEmpty())
4175 {
4176 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example",FALSE,TRUE);
4177 DBG_CTX((stderr,"yyextra->exampleFile=%s\n",qPrint(yyextra->exampleFile)));
4178 }
4179 yyextra->includeCodeFragment = inlineFragment;
4180 DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",exBlock,qPrint(exName),inlineFragment));
4181 if (!yyextra->insideCodeLine)
4182 {
4183 startCodeLine(yyscanner);
4184 }
4185 yyextra->type.clear();
4186 yyextra->name.clear();
4187 yyextra->args.clear();
4188 yyextra->parmName.clear();
4189 yyextra->parmType.clear();
4190 if (memberDef) setParameterList(yyscanner,memberDef);
4191 BEGIN( Body );
4192 codeYYlex(yyscanner);
4193 yyextra->lexInit=TRUE;
4194 if (yyextra->insideCodeLine)
4195 {
4196 endCodeLine(yyscanner);
4197 }
4198 if (Config_getBool(HTML_CODE_FOLDING))
4199 {
4200 while (!yyextra->foldStack.empty())
4201 {
4202 yyextra->code->endFold();
4203 yyextra->foldStack.pop_back();
4204 }
4205 }
4206 if (yyextra->exampleFileDef)
4207 {
4208 // delete the temporary file definition used for this example
4209 yyextra->exampleFileDef.reset();
4210 yyextra->sourceFileDef=nullptr;
4211 }
4212 // write the tooltips
4213 yyextra->tooltipManager.writeTooltips(od);
4214}

References FileDef::absFilePath, Config_getBool, convertNameToFile, countLines, createFileDef, QCString::data, DBG_CTX, endCodeLine, FALSE, FileDef::fileName, getResolvedNamespace, QCString::isEmpty, Debug::Lex_code, Definition::name, p, qPrint, setCurrentDoc, setParameterList, startCodeLine, OutputCodeList::stripCodeComments and TRUE.

resetCodeParserState()

void CCodeParser::resetCodeParserState ()
virtual

Resets the state of the code parser.

Since multiple code fragments can together form a single example, an explicit function is used to reset the code parser state.

See Also

parseCode()

Declaration at line 51 of file code.h, definition at line 4080 of file code.l.

4081{
4082 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4083 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4084 yyextra->theVarContext.clear();
4085 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4086 yyextra->codeClassMap.clear();
4087 yyextra->curClassBases.clear();
4088 yyextra->anchorCount = 0;
4089 yyextra->insideCodeLine = false;
4090}

References DBG_CTX and p.

Referenced by CCodeParser.

setInsideCodeLine()

void CCodeParser::setInsideCodeLine (bool inp)

Declaration at line 52 of file code.h, definition at line 4092 of file code.l.

4093{
4094 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4095 yyextra->insideCodeLine = inp;
4096}

Reference p.

Private Member Attributes

p

std::unique_ptr<Private> CCodeParser::p

Definition at line 56 of file code.h.

56 std::unique_ptr<Private> p;

Referenced by CCodeParser, insideCodeLine, parseCode, resetCodeParserState, setInsideCodeLine and ~CCodeParser.


The documentation for this class was generated from the following files:


Generated via doxygen2docusaurus by Doxygen 1.14.0.