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 DString &scopeName, const DString &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< Private > p

Detailed Description

Definition at line 24 of file code.h.

Constructor & Destructor Documentation

◆ CCodeParser()

CCodeParser::CCodeParser ( )

Definition at line 4054 of file code.l.

4054 : p(std::make_unique<CCodeParser::Private>())
4055{
4056 codeYYlex_init_extra(&p->state,&p->yyscanner);
4057#ifdef FLEX_DEBUG
4058 codeYYset_debug(Debug::isFlagSet(Debug::Lex_code)?1:0,p->yyscanner);
4059#endif
4061}
void resetCodeParserState() override
Resets the state of the code parser.
Definition code.l:4068
std::unique_ptr< Private > p
Definition code.h:42
@ Lex_code
Definition debug.h:54
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 4063 of file code.l.

4064{
4065 codeYYlex_destroy(p->yyscanner);
4066}

References p.

Member Function Documentation

◆ insideCodeLine()

bool CCodeParser::insideCodeLine ( ) const

Definition at line 4086 of file code.l.

4087{
4088 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4089 return yyextra->insideCodeLine;
4090}
#define yyguts_t
Definition code.l:23

References p, and yyguts_t.

◆ parseCode()

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

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

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

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

References DBG_CTX, p, and yyguts_t.

Referenced by CCodeParser().

◆ setInsideCodeLine()

void CCodeParser::setInsideCodeLine ( bool inp)

Definition at line 4080 of file code.l.

4081{
4082 struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner;
4083 yyextra->insideCodeLine = inp;
4084}

References p, and yyguts_t.

Member Data Documentation

◆ p

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

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