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

4034 : p(std::make_unique<CCodeParser::Private>())
4035{
4036 codeYYlex_init_extra(&p->state,&p->yyscanner);
4037#ifdef FLEX_DEBUG
4038 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4039#endif
4041}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4048
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 4043 of file code.l.

4044{
4045 codeYYlex_destroy(p->yyscanner);
4046}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4066 of file code.l.

4067{
4068 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4069 return yyextra->insideCodeLine;
4070}

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

4077{
4078 yyscan_t yyscanner = p->yyscanner;
4079 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
4080 DBG_CTX((stderr,"***parseCode() exBlock=%d exName=%s fd=%p scopeName=%s searchCtx=%s\n",
4081 exBlock,qPrint(exName),(void*)fd,qPrint(scopeName),searchCtx?qPrint(searchCtx->name()):"<none>"));
4082
4083 if (s.isEmpty()) return;
4084
4085 DebugLex debugLex(Debug::Lex_code, __FILE__, fd ? qPrint(fd->fileName()): !exName.isEmpty() ? qPrint(exName) : nullptr);
4086
4087 od.stripCodeComments(stripCodeComments);
4088 yyextra->code = &od;
4089 yyextra->inputString = s.data();
4090 yyextra->fileName = fd ? fd->fileName():"";
4091 yyextra->absFileName = fd ? fd->absFilePath():"";
4092 yyextra->inputPosition = 0;
4093 codeYYrestart(nullptr,yyscanner);
4094 yyextra->currentFontClass = nullptr;
4095 yyextra->searchCtx = searchCtx;
4096 yyextra->collectXRefs = collectXRefs;
4097 yyextra->inFunctionTryBlock = FALSE;
4098 yyextra->symbolResolver.setFileScope(fd);
4099 yyextra->foldStack.clear();
4100 yyextra->insideSpecialComment = false;
4101
4102 if (startLine!=-1)
4103 yyextra->yyLineNr = startLine;
4104 else
4105 yyextra->yyLineNr = 1;
4106
4107 if (endLine!=-1)
4108 yyextra->inputLines = endLine+1;
4109 else
4110 yyextra->inputLines = yyextra->yyLineNr + countLines(yyscanner) - 1;
4111
4112 yyextra->curlyCount = 0;
4113 yyextra->bodyCurlyCount = 0;
4114 yyextra->bracketCount = 0;
4115 yyextra->sharpCount = 0;
4116 yyextra->insideTemplate = FALSE;
4117 yyextra->theCallContext.clear();
4118 while (!yyextra->scopeStack.empty()) yyextra->scopeStack.pop();
4119 yyextra->scopeName = scopeName;
4120 DBG_CTX((stderr,"parseCCode %s\n",qPrint(scopeName)));
4121 yyextra->exampleBlock = exBlock;
4122 yyextra->exampleName = exName;
4123 yyextra->sourceFileDef = fd;
4124 yyextra->lineNumbers = fd && showLineNumbers;
4125 if (fd==nullptr)
4126 {
4127 // create a dummy filedef for the example
4128 yyextra->exampleFileDef = createFileDef(QCString(),(!exName.isEmpty()?exName:"generated"));
4129 yyextra->sourceFileDef = yyextra->exampleFileDef.get();
4130 }
4131 yyextra->lang = lang;
4132 yyextra->insideObjC = lang==SrcLangExt::ObjC;
4133 if (yyextra->sourceFileDef)
4134 {
4135 setCurrentDoc(yyscanner,"l00001");
4136 }
4137 yyextra->currentDefinition = searchCtx ? searchCtx : getResolvedNamespace(scopeName);
4138 yyextra->currentMemberDef = nullptr;
4139 yyextra->searchingForBody = exBlock;
4140 yyextra->insideBody = FALSE;
4141 yyextra->bracketCount = 0;
4142 if (!yyextra->exampleName.isEmpty())
4143 {
4144 yyextra->exampleFile = convertNameToFile(yyextra->exampleName+"-example",FALSE,TRUE);
4145 DBG_CTX((stderr,"yyextra->exampleFile=%s\n",qPrint(yyextra->exampleFile)));
4146 }
4147 yyextra->includeCodeFragment = inlineFragment;
4148 DBG_CTX((stderr,"** exBlock=%d exName=%s include=%d\n",exBlock,qPrint(exName),inlineFragment));
4149 if (!yyextra->insideCodeLine)
4150 {
4151 startCodeLine(yyscanner);
4152 }
4153 yyextra->type.clear();
4154 yyextra->name.clear();
4155 yyextra->args.clear();
4156 yyextra->parmName.clear();
4157 yyextra->parmType.clear();
4158 if (memberDef) setParameterList(yyscanner,memberDef);
4159 BEGIN( Body );
4160 codeYYlex(yyscanner);
4161 yyextra->lexInit=TRUE;
4162 if (yyextra->insideCodeLine)
4163 {
4164 endCodeLine(yyscanner);
4165 }
4166 if (Config_getBool(HTML_CODE_FOLDING))
4167 {
4168 while (!yyextra->foldStack.empty())
4169 {
4170 yyextra->code->endFold();
4171 yyextra->foldStack.pop_back();
4172 }
4173 }
4174 if (yyextra->exampleFileDef)
4175 {
4176 // delete the temporary file definition used for this example
4177 yyextra->exampleFileDef.reset();
4178 yyextra->sourceFileDef=nullptr;
4179 }
4180 // write the tooltips
4181 yyextra->tooltipManager.writeTooltips(od);
4182}
virtual const QCString & name() const =0
static void endCodeLine(yyscan_t yyscanner)
Definition code.l:2478
#define DBG_CTX(x)
Definition code.l:73
static void startCodeLine(yyscan_t yyscanner)
Definition code.l:2409
static int countLines(yyscan_t yyscanner)
Definition code.l:3454
yyguts_t * yyscan_t
Definition code.l:24
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition code.l:2277
static void setParameterList(yyscan_t yyscanner, const MemberDef *md)
Definition code.l:2623
#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:687
#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 4048 of file code.l.

4049{
4050 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4051 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4052 yyextra->theVarContext.clear();
4053 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4054 yyextra->codeClassMap.clear();
4055 yyextra->curClassBases.clear();
4056 yyextra->anchorCount = 0;
4057 yyextra->insideCodeLine = false;
4058}

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4060 of file code.l.

4061{
4062 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4063 yyextra->insideCodeLine = inp;
4064}

References p.

Member Data Documentation

◆ p

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

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