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
 
- Public Member Functions inherited from CodeParserInterface

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

4051 : p(std::make_unique<CCodeParser::Private>())
4052{
4053 codeYYlex_init_extra(&p->state,&p->yyscanner);
4054#ifdef FLEX_DEBUG
4055 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4056#endif
4058}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4065
std::unique_ptr< Private > p
Definition code.h:56
@ Lex_code
Definition debug.h:51
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:135

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

Referenced by CCodeParser().

◆ ~CCodeParser()

CCodeParser::~CCodeParser ( )
override

Definition at line 4060 of file code.l.

4061{
4062 codeYYlex_destroy(p->yyscanner);
4063}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4083 of file code.l.

4084{
4085 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4086 return yyextra->insideCodeLine;
4087}

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

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

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

4066{
4067 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4068 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4069 yyextra->theVarContext.clear();
4070 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4071 yyextra->codeClassMap.clear();
4072 yyextra->curClassBases.clear();
4073 yyextra->anchorCount = 0;
4074 yyextra->insideCodeLine = false;
4075}

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4077 of file code.l.

4078{
4079 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4080 yyextra->insideCodeLine = inp;
4081}

References p.

Member Data Documentation

◆ p

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

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