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

#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, const CodeParserOptions &options) 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 4058 of file code.l.

4058 : p(std::make_unique<CCodeParser::Private>())
4059{
4060 codeYYlex_init_extra(&p->state,&p->yyscanner);
4061#ifdef FLEX_DEBUG
4062 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4063#endif
4065}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4072
std::unique_ptr< Private > p
Definition code.h:47
@ Lex_code
Definition debug.h:53
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:133

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

Referenced by CCodeParser().

◆ ~CCodeParser()

CCodeParser::~CCodeParser ( )
override

Definition at line 4067 of file code.l.

4068{
4069 codeYYlex_destroy(p->yyscanner);
4070}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4090 of file code.l.

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

References p.

◆ parseCode()

void CCodeParser::parseCode ( OutputCodeList & codeOutList,
const QCString & scopeName,
const QCString & input,
SrcLangExt lang,
bool stripCodeComments,
const CodeParserOptions & options )
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]optionsAdditional options to configure the parser.

Implements CodeParserInterface.

Definition at line 4096 of file code.l.

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

References FileDef::absFilePath(), CodeParserOptions::collectXRefs(), Config_getBool, convertNameToFile(), countLines(), createFileDef(), QCString::data(), DBG_CTX, endCodeLine(), CodeParserOptions::endLine(), CodeParserOptions::exampleName(), CodeParserOptions::fileDef(), FileDef::fileName(), getResolvedNamespace(), CodeParserOptions::inlineFragment(), QCString::isEmpty(), CodeParserOptions::isExample(), Debug::Lex_code, CodeParserOptions::memberDef(), Definition::name(), p, qPrint(), CodeParserOptions::searchCtx(), setCurrentDoc(), setParameterList(), CodeParserOptions::showLineNumbers(), startCodeLine(), CodeParserOptions::startLine(), and OutputCodeList::stripCodeComments().

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

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

References DBG_CTX, and p.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4084 of file code.l.

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

References p.

Member Data Documentation

◆ p

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

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