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

4045 : p(std::make_unique<CCodeParser::Private>())
4046{
4047 codeYYlex_init_extra(&p->state,&p->yyscanner);
4048#ifdef FLEX_DEBUG
4049 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4050#endif
4052}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4059
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 4054 of file code.l.

4055{
4056 codeYYlex_destroy(p->yyscanner);
4057}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4077 of file code.l.

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

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

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

4060{
4061 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4062 DBG_CTX((stderr,"***CodeParser::reset()\n"));
4063 yyextra->theVarContext.clear();
4064 while (!yyextra->scopeNameLengthStack.empty()) yyextra->scopeNameLengthStack.pop_back();
4065 yyextra->codeClassMap.clear();
4066 yyextra->curClassBases.clear();
4067 yyextra->anchorCount = 0;
4068 yyextra->insideCodeLine = false;
4069}

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4071 of file code.l.

4072{
4073 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4074 yyextra->insideCodeLine = inp;
4075}

References p.

Member Data Documentation

◆ p

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

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