| eRPC Generator (erpcgen) Rev. 1.8.1 NXP Semiconductors

- Main Page
- Classes
- Files

- File List

SymbolScanner.h
1 /*
2 * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
3 * Copyright 2016-2017 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__SYMBOLSCANNER_H_
11 #define _EMBEDDED_RPC__SYMBOLSCANNER_H_
12
13 #include "AstWalker.h"
14 #include "types/AliasType.h"
15 #include "types/EnumMember.h"
16 #include "types/EnumType.h"
17 #include "types/Interface.h"
18 #include "types/Program.h"
19 #include "types/StructType.h"
20 #include "types/SymbolScope.h"
21 #include "types/UnionType.h"
22
24 // Classes
26
27 namespace erpcgen {
28
32 class SymbolScanner : public AstWalker
33 {
34 public:
42 SymbolScanner(SymbolScope *globals)
43 : m_globals(globals)
44 , m_currentInterface(nullptr)
45 , m_currentStruct(nullptr)
46 , m_currentProgram(nullptr)
47 , m_currentEnum(nullptr)
48 , m_currentAlias(nullptr)
49 , m_currentUnion(nullptr)
50 {
51 }
52
61 SymbolScanner(SymbolScope *globals, std::string fileName)
62 : AstWalker(fileName)
63 , m_globals(globals)
64 , m_currentInterface(nullptr)
65 , m_currentStruct(nullptr)
66 , m_currentProgram(nullptr)
67 , m_currentEnum(nullptr)
68 , m_currentAlias(nullptr)
69 , m_currentUnion(nullptr)
70 {
71 }
72
76 virtual ~SymbolScanner() {}
77
83 Program *getProgram() { return m_currentProgram; }
84
85 protected:
86 SymbolScope
87 *m_globals;
88 Interface *m_currentInterface;
89 StructType *m_currentStruct;
90 Program *m_currentProgram;
91 EnumType *m_currentEnum;
92 AliasType *m_currentAlias;
93 UnionType *m_currentUnion;
94 std::vector<UnionCase *> m_emptyUnionCases;
95 std::map<std::string, DataType *> m_forwardDeclarations;
104 virtual void handleRoot(AstNode *node, bottom_up);
105
115 virtual AstNode *handleProgram(AstNode *node, top_down);
116
126 virtual AstNode *handleProgram(AstNode *node, bottom_up);
127
137 virtual AstNode *handleConst(AstNode *node, bottom_up);
138
151 virtual AstNode *handleType(AstNode *node, top_down);
152
164 virtual AstNode *handleType(AstNode *node, bottom_up);
165
177 virtual AstNode *handleEnum(AstNode *node, top_down);
178
190 virtual AstNode *handleEnum(AstNode *node, bottom_up);
191
203 virtual AstNode *handleEnumMember(AstNode *node, bottom_up);
204
212 bool enumMemberHasValue(AstNode *enumMember);
213
223 virtual AstNode *handleExpr(AstNode *node, bottom_up);
224
242 virtual AstNode *handleBinaryOp(AstNode *node, bottom_up);
243
261 virtual AstNode *handleUnaryOp(AstNode *node, bottom_up);
262
277 virtual AstNode *handleStruct(AstNode *node, top_down);
278
290 virtual AstNode *handleStruct(AstNode *node, bottom_up);
291
304 virtual AstNode *handleStructMember(AstNode *node, bottom_up);
305
306 // TODO: Update doxygen for union functions
318 virtual AstNode *handleUnion(AstNode *node, top_down);
319
331 virtual AstNode *handleUnion(AstNode *node, bottom_up);
332
342 virtual AstNode *handleUnionCase(AstNode *node, top_down);
343
355 virtual AstNode *handleUnionCase(AstNode *node, bottom_up);
356
371 virtual AstNode *handleInterface(AstNode *node, top_down);
372
384 virtual AstNode *handleInterface(AstNode *node, bottom_up);
385
398 virtual AstNode *handleFunction(AstNode *node, top_down);
399
411 virtual AstNode *handleFunction(AstNode *node, bottom_up);
412
427 virtual AstNode *handleParam(AstNode *node, top_down);
428
440 virtual AstNode *handleParam(AstNode *node, bottom_up);
441
449 void setParameterDirection(StructMember *param, AstNode *directionNode);
450
461 Value *getValueFromSymbol(Token &tok);
462
471 DataType *getDataTypeForConst(AstNode *typeNode);
472
481 bool containsStructEnumDeclaration(const AstNode *typeNode);
482
499 DataType *lookupDataType(const AstNode *typeNode);
500
514 DataType *createListType(const AstNode *typeNode);
515
528 DataType *createArrayType(const AstNode *typeNode);
529
547 DataType *lookupDataTypeByName(const Token &tok, SymbolScope *scope, bool recursive = true);
548
561 uint64_t getIntExprValue(const AstNode *exprNode);
562
571 bool rhsIsAStringLiteral(AstNode *rhs);
572
581 bool rhsIsAnExpression(AstNode *rhs);
582
591 Value *getValueForConst(AstNode *const node, DataType *const constDataType);
592
599 void addAnnotations(AstNode *childTok, Symbol *symbol);
600
607 void checkAnnotationBeforeAdding(AstNode *annotation, Symbol *symbol);
608
616 Value *getAnnotationValue(AstNode *annotationNode);
617
625 Annotation::program_lang_t getAnnotationLang(AstNode *annotationNode);
626
633 void scanStructForAnnotations();
634
644 void addDoxygenComments(Symbol *symbol, AstNode *above, AstNode *trailing);
645
657 StructMember *createCallbackParam(StructMember *structMember, const std::string &name);
658
664 void addForwardDeclaration(DataType *dataType);
665
671 void removeForwardDeclaration(DataType *dataType);
672
678 void addGlobalSymbol(Symbol *symbol);
679 };
680
681 } // namespace erpcgen
682
683 #endif // _EMBEDDED_RPC__SYMBOLSCANNER_H_
erpcgen::SymbolScanner::handleStructMember
virtual AstNode * handleStructMember(AstNode *node, bottom_up)
This function end handle struct member.
Definition: SymbolScanner.cpp:729
erpcgen::SymbolScanner::addDoxygenComments
void addDoxygenComments(Symbol *symbol, AstNode *above, AstNode *trailing)
This function sets to given symbol given doxygen comments.
Definition: SymbolScanner.cpp:1686
erpcgen::SymbolScanner::~SymbolScanner
virtual ~SymbolScanner()
Destructor.
Definition: SymbolScanner.h:76
erpcgen::SymbolScanner::getAnnotationLang
Annotation::program_lang_t getAnnotationLang(AstNode *annotationNode)
Helper function to get programming language type if specified for which is annotation intended...
Definition: SymbolScanner.cpp:1539
erpcgen::SymbolScanner::lookupDataTypeByName
DataType * lookupDataTypeByName(const Token &tok, SymbolScope *scope, bool recursive=true)
This function returns pointer to new type object.
Definition: SymbolScanner.cpp:1315
erpcgen::SymbolScanner::handleEnumMember
virtual AstNode * handleEnumMember(AstNode *node, bottom_up)
This function end handle enum member.
Definition: SymbolScanner.cpp:252
erpcgen::SymbolScanner::checkAnnotationBeforeAdding
void checkAnnotationBeforeAdding(AstNode *annotation, Symbol *symbol)
This function check annotation just before it will be added to symbol.
Definition: SymbolScanner.cpp:1562
erpcgen::SymbolScanner::containsStructEnumDeclaration
bool containsStructEnumDeclaration(const AstNode *typeNode)
Returns true when given Astnode is enum or structure declaration.
Definition: SymbolScanner.cpp:1339
erpcgen::SymbolScanner::lookupDataType
DataType * lookupDataType(const AstNode *typeNode)
This function returns pointer to new type object.
Definition: SymbolScanner.cpp:1345
erpcgen::SymbolScanner
Scans for symbol names.
Definition: SymbolScanner.h:32
erpcgen::SymbolScanner::rhsIsAStringLiteral
bool rhsIsAStringLiteral(AstNode *rhs)
Determines if the right hand side of a constant declaration is a string literal.
Definition: SymbolScanner.cpp:130
erpcgen::StructMember
Member of a struct.
Definition: StructMember.h:38
erpcgen::SymbolScanner::getIntExprValue
uint64_t getIntExprValue(const AstNode *exprNode)
This function returns token integer value.
Definition: SymbolScanner.cpp:1433
erpcgen::SymbolScanner::m_currentInterface
Interface * m_currentInterface
Definition: SymbolScanner.h:88
erpcgen::SymbolScanner::handleStruct
virtual AstNode * handleStruct(AstNode *node, top_down)
This function start handle struct.
Definition: SymbolScanner.cpp:628
erpcgen::SymbolScanner::m_currentStruct
StructType * m_currentStruct
Definition: SymbolScanner.h:89
erpcgen::SymbolScanner::handleUnaryOp
virtual AstNode * handleUnaryOp(AstNode *node, bottom_up)
This function end handle unary operator.
Definition: SymbolScanner.cpp:533
erpcgen::SymbolScanner::handleConst
virtual AstNode * handleConst(AstNode *node, bottom_up)
This function handles a constant definition.
Definition: SymbolScanner.cpp:53
erpcgen::AliasType
Typedef.
Definition: AliasType.h:26
erpcgen::AstNode
Homogeneous AST node class.
Definition: AstNode.h:36
erpcgen::SymbolScanner::handleParam
virtual AstNode * handleParam(AstNode *node, top_down)
This function start handle function parameter.
Definition: SymbolScanner.cpp:1177
erpcgen::SymbolScanner::getDataTypeForConst
DataType * getDataTypeForConst(AstNode *typeNode)
This function returns the data type for a constant variable.
Definition: SymbolScanner.cpp:135
erpcgen::AstWalker
Performs a depth-first walk of an AST.
Definition: AstWalker.h:41
erpcgen::Program
Program declaration.
Definition: Program.h:28
erpcgen::StructType
Structure data type.
Definition: StructType.h:29
erpcgen::Symbol
Base class for all named declarations in the IDL.
Definition: Symbol.h:28
erpcgen::SymbolScanner::getAnnotationValue
Value * getAnnotationValue(AstNode *annotationNode)
Helper function to get Value from annotation AstNode.
Definition: SymbolScanner.cpp:1523
erpcgen::SymbolScanner::handleEnum
virtual AstNode * handleEnum(AstNode *node, top_down)
This function end handle enum.
Definition: SymbolScanner.cpp:185
erpcgen::SymbolScanner::addGlobalSymbol
void addGlobalSymbol(Symbol *symbol)
This function add symbol into global symbol scope.
Definition: SymbolScanner.cpp:1771
erpcgen::SymbolScanner::SymbolScanner
SymbolScanner(SymbolScope *globals, std::string fileName)
This function is constructor of symbol scanner class.
Definition: SymbolScanner.h:61
erpcgen::SymbolScanner::handleProgram
virtual AstNode * handleProgram(AstNode *node, top_down)
This function start handle program.
Definition: SymbolScanner.cpp:602
erpcgen::SymbolScanner::enumMemberHasValue
bool enumMemberHasValue(AstNode *enumMember)
Check to see if enum member is assigned a value by the user.
Definition: SymbolScanner.cpp:290
erpcgen::SymbolScanner::handleExpr
virtual AstNode * handleExpr(AstNode *node, bottom_up)
This function start handle expression.
Definition: SymbolScanner.cpp:1308
erpcgen::SymbolScanner::getValueForConst
Value * getValueForConst(AstNode *const node, DataType *const constDataType)
Gets the value object for the const variable.
Definition: SymbolScanner.cpp:67
Value
Abstract base class for values of arbitrary types.
Definition: Value.h:27
erpcgen::SymbolScanner::m_currentEnum
EnumType * m_currentEnum
Definition: SymbolScanner.h:91
erpcgen::SymbolScanner::m_currentProgram
Program * m_currentProgram
Definition: SymbolScanner.h:90
erpcgen::SymbolScanner::handleInterface
virtual AstNode * handleInterface(AstNode *node, top_down)
This function start handle interface.
Definition: SymbolScanner.cpp:987
erpcgen::SymbolScanner::handleFunction
virtual AstNode * handleFunction(AstNode *node, top_down)
This function start handle function.
Definition: SymbolScanner.cpp:1016
erpcgen::SymbolScanner::getProgram
Program * getProgram()
Program is out of global symbol scope.
Definition: SymbolScanner.h:83
erpcgen::SymbolScope
A scoped namespace containing symbols.
Definition: SymbolScope.h:28
erpcgen::SymbolScanner::createCallbackParam
StructMember * createCallbackParam(StructMember *structMember, const std::string &name)
This function creates new function parameter.
Definition: SymbolScanner.cpp:1701
erpcgen::SymbolScanner::rhsIsAnExpression
bool rhsIsAnExpression(AstNode *rhs)
Determines if the right hand side of a constant declaration is an expression.
Definition: SymbolScanner.cpp:126
erpcgen::SymbolScanner::addAnnotations
void addAnnotations(AstNode *childTok, Symbol *symbol)
This function add annotations to vector of symbol annotations.
Definition: SymbolScanner.cpp:1476
erpcgen::DataType
Base class for data types.
Definition: DataType.h:26
erpcgen::SymbolScanner::m_globals
SymbolScope * m_globals
Definition: SymbolScanner.h:87
erpcgen::Token
Encapsulates all information about a token.
Definition: Token.h:60
erpcgen::SymbolScanner::createArrayType
DataType * createArrayType(const AstNode *typeNode)
This function returns pointer to new array object.
Definition: SymbolScanner.cpp:1382
erpcgen::SymbolScanner::getValueFromSymbol
Value * getValueFromSymbol(Token &tok)
Get value from symbol table for name defined by given token.
Definition: SymbolScanner.cpp:1397
erpcgen::AstWalker::bottom_up
Specifier type to select bottom-up handler using ADL.
Definition: AstWalker.h:81
erpcgen::SymbolScanner::handleUnionCase
virtual AstNode * handleUnionCase(AstNode *node, top_down)
Definition: SymbolScanner.cpp:863
erpcgen::EnumType
Enumerate data type.
Definition: EnumType.h:28
erpcgen::SymbolScanner::handleBinaryOp
virtual AstNode * handleBinaryOp(AstNode *node, bottom_up)
This function end handle binary operator.
Definition: SymbolScanner.cpp:310
erpcgen::SymbolScanner::setParameterDirection
void setParameterDirection(StructMember *param, AstNode *directionNode)
set parameter direction: in, out, inout
Definition: SymbolScanner.cpp:1277
erpcgen::SymbolScanner::handleRoot
virtual void handleRoot(AstNode *node, bottom_up)
This function is called at the end of scanning.
Definition: SymbolScanner.cpp:33
erpcgen::SymbolScanner::m_forwardDeclarations
std::map< std::string, DataType * > m_forwardDeclarations
Definition: SymbolScanner.h:95
erpcgen::SymbolScanner::createListType
DataType * createListType(const AstNode *typeNode)
This function returns pointer to new list object.
Definition: SymbolScanner.cpp:1370
erpcgen::SymbolScanner::handleType
virtual AstNode * handleType(AstNode *node, top_down)
This function start handle type.
Definition: SymbolScanner.cpp:148
erpcgen::UnionType
Discriminated union data type.
Definition: UnionType.h:28
erpcgen::SymbolScanner::scanStructForAnnotations
void scanStructForAnnotations()
Controlling annotations used on structure members.
Definition: SymbolScanner.cpp:1612
erpcgen::Interface
An interface that contains functions.
Definition: Interface.h:29
erpcgen::SymbolScanner::SymbolScanner
SymbolScanner(SymbolScope *globals)
This function is constructor of symbol scanner class.
Definition: SymbolScanner.h:42
erpcgen::SymbolScanner::handleUnion
virtual AstNode * handleUnion(AstNode *node, top_down)
Handles Union data type while traversing down the AST.
Definition: SymbolScanner.cpp:765
erpcgen::SymbolScanner::m_emptyUnionCases
std::vector< UnionCase * > m_emptyUnionCases
Definition: SymbolScanner.h:94
erpcgen::SymbolScanner::removeForwardDeclaration
void removeForwardDeclaration(DataType *dataType)
This function unregister union/structure declarations.
Definition: SymbolScanner.cpp:1755
erpcgen::SymbolScanner::m_currentUnion
UnionType * m_currentUnion
Definition: SymbolScanner.h:93
erpcgen
Definition: AstNode.h:26
erpcgen::SymbolScanner::m_currentAlias
AliasType * m_currentAlias
Definition: SymbolScanner.h:92
erpcgen::AstWalker::top_down
Specifier type to select top-down handler using ADL.
Definition: AstWalker.h:78
erpcgen::SymbolScanner::addForwardDeclaration
void addForwardDeclaration(DataType *dataType)
This function registers forward union/structure declarations.
Definition: SymbolScanner.cpp:1727