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 4060 of file code.l.

4060 : p(std::make_unique<CCodeParser::Private>())
4061{
4062 codeYYlex_init_extra(&p->state,&p->yyscanner);
4063#ifdef FLEX_DEBUG
4064 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4065#endif
4067}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4074
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 4069 of file code.l.

4070{
4071 codeYYlex_destroy(p->yyscanner);
4072}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4092 of file code.l.

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

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 4098 of file code.l.

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

References FileDef::absFilePath(), Config_getBool, convertNameToFile(), countLines(), createFileDef(), QCString::data(), DBG_CTX, endCodeLine(), FALSE, FileDef::fileName(), getResolvedNamespace(), QCString::isEmpty(), Debug::Lex_code, Definition::name(), ObjC, 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 4074 of file code.l.

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

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4086 of file code.l.

4087{
4088 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4089 yyextra->insideCodeLine = inp;
4090}

References p.

Member Data Documentation

◆ p

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

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