Doxygen
Loading...
Searching...
No Matches
CCodeParser Class Reference

#include <src/code.h>

Inheritance diagram for CCodeParser:
Collaboration diagram for CCodeParser:

Classes

struct  Private

Public Member Functions

 CCodeParser ()
 ~CCodeParser () override
void parseCode (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.
void resetCodeParserState () override
 Resets the state of the code parser.
void setInsideCodeLine (bool inp)
bool insideCodeLine () const

Private Attributes

std::unique_ptr< Privatep

Detailed Description

Definition at line 29 of file code.h.

Constructor & Destructor Documentation

◆ CCodeParser()

CCodeParser::CCodeParser ( )

Definition at line 4063 of file code.l.

4063 : p(std::make_unique<CCodeParser::Private>())
4064{
4065 codeYYlex_init_extra(&p->state,&p->yyscanner);
4066#ifdef FLEX_DEBUG
4067 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4068#endif
4070}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4077
std::unique_ptr< Private > p
Definition code.h:56
@ Lex_code
Definition debug.h:52
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132

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

Referenced by CCodeParser().

◆ ~CCodeParser()

CCodeParser::~CCodeParser ( )
override

Definition at line 4072 of file code.l.

4073{
4074 codeYYlex_destroy(p->yyscanner);
4075}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4095 of file code.l.

4096{
4097 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4098 return yyextra->insideCodeLine;
4099}

References 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 )
overridevirtual

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

Parameters
[in]codeOutListinterface for writing the result.
[in]scopeNameName of scope to which the code belongs.
[in]inputActual code in the form of a string
[in]langThe programming language of the code fragment.
[in]stripCodeCommentssignals whether or not for the code block the doxygen comments should be stripped.
[in]isExampleBlockTRUE iff the code is part of an example.
[in]exampleNameName of the example.
[in]fileDefFile definition to which the code is associated.
[in]startLineStarting line in case of a code fragment.
[in]endLineEnding line of the code fragment.
[in]inlineFragmentCode fragment that is to be shown inline as part of the documentation.
[in]memberDefMember definition to which the code is associated (non null in case of an inline fragment for a member).
[in]showLineNumbersif set to TRUE and also fileDef is not 0, line numbers will be added to the source fragment
[in]searchCtxcontext under which search data has to be stored.
[in]collectXRefscollect cross-reference relations.

Implements CodeParserInterface.

Definition at line 4101 of file code.l.

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

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 ( )
overridevirtual

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()

Implements CodeParserInterface.

Definition at line 4077 of file code.l.

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

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4089 of file code.l.

4090{
4091 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4092 yyextra->insideCodeLine = inp;
4093}

References p.

Member Data Documentation

◆ p

std::unique_ptr<Private> CCodeParser::p
private

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