1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RY_PD_PARSE_NODE_H
18 #define RY_PD_PARSE_NODE_H
20 #include "tokenizer.h"
21 #include "cpp_output.h"
22 #include "templatizer.h"
24 extern CTokenizer Tokenizer
;
26 extern std::string getFunctionPrefix
;
27 extern std::string setFunctionPrefix
;
28 extern std::string newFunction
;
29 extern std::string deleteFunction
;
31 extern std::string indexVariable
;
32 extern std::string valueVariable
;
33 extern std::string keyVariable
;
34 extern std::string objectVariable
;
36 extern std::string staticCreateFunction
;
37 extern std::string staticRemoveFunction
;
38 extern std::string staticSetUserFactoryFunction
;
39 extern std::string staticLoadFunction
;
40 extern std::string staticUnloadFunction
;
41 extern std::string staticGetFunction
;
43 extern std::string initFunction
;
44 extern std::string destroyFunction
;
45 extern std::string registerFunction
;
46 extern std::string registerAttributesFunction
;
47 extern std::string unregisterFunction
;
48 extern std::string unregisterAttributesFunction
;
49 extern std::string fetchFunction
;
50 extern std::string setParentFunction
;
51 extern std::string setUnnotifiedParentFunction
;
52 extern std::string getTableFunction
;
53 extern std::string unlinkFunction
;
55 extern std::string staticInitFactoryFunction
;
56 extern std::string staticFactoryFunction
;
57 extern std::string staticFetchFunction
;
58 extern std::string staticInitFunction
;
60 extern std::string logStartFunction
;
61 extern std::string logStopFunction
;
78 CParseNode() : Parent(NULL
), FileNode(NULL
), DbNode(NULL
), Env(NULL
) {}
83 for (i
=0; i
<Nodes
.size(); ++i
)
88 std::vector
<CParseNode
*> Nodes
;
89 CTokenizer::CToken StartToken
;
91 std::string Description
;
96 virtual bool prolog() { return true; }
97 virtual bool epilog() { return true; }
106 for (i
=0; i
<Nodes
.size(); ++i
)
107 if (!Nodes
[i
]->execute())
116 void error(const std::string
&errMsg
, const char *errType
= "semantic")
118 Tokenizer
.error(StartToken
, errType
, errMsg
.c_str() );
122 CParseNode
* getNode(const std::string
&name
)
125 for (i
=0; i
<Nodes
.size(); ++i
)
126 if (Nodes
[i
]->Name
== name
)
132 void getFileLine(uint
&line
, uint
&col
, std::string
&file
)
134 Tokenizer
.getFileLine(StartToken
, line
, col
, file
);
138 CFileNode
* getFileNode();
139 CDbNode
* getDbNode();
144 CCppOutput
& hOutput();
145 CCppOutput
& cppOutput();
146 CCppOutput
& inlineOutput();
148 CTypeNode
* getTypeNode(const std::string
&name
, bool genError
= true);
149 CEnumNode
* getEnumNode(const std::string
&name
, bool genError
= true);
150 CDimensionNode
* getDimensionNode(const std::string
&name
, bool genError
= true);
151 CIndexNode
* getIndexNode(const std::string
&name
, bool genError
= true);
152 CClassNode
* getClassNode(const std::string
&name
, bool genError
= true);
154 CTemplatizerEnv
* Env
;
156 void setEnv(const std::string
& var
, const T
& val
)
158 nlassert(Env
!= NULL
);
161 void define(const std::string
& var
)
163 nlassert(Env
!= NULL
);
166 void define(bool isdef
, const std::string
& var
)
168 nlassert(Env
!= NULL
);
178 class CDbNode
: public CParseNode
181 CDbNode() : DbXml(false), DbSummary(false) {}
184 bool addTypeNode(const std::string
&name
, const std::string
&displayName
= std::string(""), const std::string
&defaultValue
= std::string(""));
187 std::vector
<CFileNode
*> FileNodes
;
188 std::vector
<CTypeNode
*> TypeNodes
;
189 std::vector
<CClassNode
*> ClassNodes
;
190 std::vector
<CLogMsgNode
*> LogNodes
;
193 CCppOutput DbHppInline
;
196 CCppOutput DbSummary
;
198 std::string MainFile
;
202 std::vector
<std::string
> xmlDescription
;
203 CFunctionGenerator initDb
;
204 CFunctionGenerator readyDb
;
205 CFunctionGenerator updateDb
;
206 CFunctionGenerator releaseDb
;
207 CFunctionGenerator logChatDb
;
208 CFunctionGenerator logTellDb
;
210 std::set
<std::string
> Implemented
;
213 virtual bool prolog();
214 virtual bool epilog();
221 void buildClassOrder(std::vector
<CClassNode
*>& classesOrder
, std::vector
<CFileNode
*>& filesOrder
);
223 void generateClassesDeclaration();
224 void generateIncludes(std::vector
<CFileNode
*>& filesOrder
);
226 void generateClassesContent(std::vector
<CClassNode
*>& classesOrder
);
228 void generateLogContent();
230 std::string
getDbFile() { return MainFile
.empty() ? Name
: MainFile
; }
232 // get file path from this file
233 std::string
getFileNoExtPath(const std::string
& file
);
240 class CFileNode
: public CParseNode
244 CFileNode() : SeparatedFlag(false), IncludeStandard(false), IncludePDSLib(false), IncludeDbFile(false), Generate(true) { }
246 std::string IncludeAs
;
251 CCppOutput HppInline
;
254 bool IncludeStandard
;
257 std::vector
<CIncludeNode
*> IncludeNodes
;
261 std::set
<CFileNode
*> Dependencies
;
263 void checkDependencies(std::set
<CFileNode
*> &beingChecked
,
264 std::set
<CFileNode
*> &checkedFiles
,
265 std::vector
<CFileNode
*> &filesOrder
);
268 virtual bool prolog();
269 virtual bool epilog();
272 virtual bool generateProlog();
273 virtual bool generateEpilog();
278 // get file path from this file
279 std::string
getFileNoExtPath(const std::string
& file
);
285 class CIncludeNode
: public CParseNode
290 virtual bool prolog();
296 class CUsePchNode
: public CParseNode
301 virtual bool prolog();
307 class CCppCodeNode
: public CParseNode
314 virtual bool prolog();
320 class CTypeNode
: public CParseNode
333 std::string StorageType
;
334 std::string DisplayName
;
336 CParseNode
* ToCppType
;
337 CParseNode
* ToStorageType
;
347 std::string DefaultValue
;
349 virtual bool isEnum() { return false; }
350 virtual bool isDimension() { return false; }
351 virtual bool isIndex() { return false; }
353 virtual std::string
checkCode(const std::string
& var
) { return ""; }
355 std::string
storageToCpp()
357 if (ToCppType
!= NULL
)
358 return "__pds_cnv_type_"+NLMISC::toString(Id
)+"_s2c";
360 return "("+CppType
+")";
363 std::string
cppToStorage()
365 if (ToStorageType
!= NULL
)
366 return "__pds_cnv_type_"+NLMISC::toString(Id
)+"_c2s";
368 return "("+StorageType
+")";
373 std::string
castToCpp(const std::string
& var
)
375 if (CppType
!= StorageType
)
377 return storageToCpp()+"("+var
+")";
385 std::string
castToStorage(const std::string
& var
)
387 if (CppType
!= StorageType
)
389 return cppToStorage()+"("+var
+")";
397 std::string
getCppType()
399 if (CppType
== "CEntityId")
400 return "NLMISC::CEntityId";
401 else if (CppType
== "CSheetId")
402 return "NLMISC::CSheetId";
410 std::string
castToPDS(const std::string
& var
)
414 return "(uint32)"+var
;
418 return "("+StorageType
+")"+var
;
422 //return "("+getName()+")";
423 return castToStorage(var
);
427 std::string
castFromUser(const std::string
& var
)
429 return "("+getName()+")"+var
;
434 virtual std::string
getName() { return DisplayName
.empty() ? Name
: DisplayName
; }
436 std::string
getDefaultValue()
438 if (DefaultValue
.empty())
440 if (CppType
== "CEntityId") return "NLMISC::CEntityId::Unknown";
441 if (CppType
== "CSheetId") return "NLMISC::CSheetId::Unknown";
442 return castFromUser("0");
452 virtual std::string
getPrintfFmt()
454 if (CppType
== "CEntityId" || CppType
== "CSheetId")
456 if (CppType
== "double" || CppType
== "float")
458 if (CppType
== "sint64")
459 return "%\"NL_I64\"d";
460 if (CppType
== "uint64")
461 return "%\"NL_I64\"u";
462 if (CppType
== "sint32" || CppType
== "sint16" || CppType
== "sint8")
464 if (CppType
== "uint32" || CppType
== "uint16" || CppType
== "uint8")
466 if (CppType
== "char" || CppType
== "ucchar")
468 if (CppType
== "bool")
473 virtual std::string
getPrintfVal(const std::string
& var
)
475 if (CppType
== "CEntityId" || CppType
== "CSheetId")
476 return var
+".toString()";
477 if (CppType
== "double" || CppType
== "float" ||
478 CppType
== "sint64" || CppType
== "uint64" ||
479 CppType
== "sint32" || CppType
== "sint16" || CppType
== "sint8" ||
480 CppType
== "uint32" || CppType
== "uint16" || CppType
== "uint8" ||
481 CppType
== "char" || CppType
== "ucchar")
483 if (CppType
== "bool")
484 return "("+var
+" ? \"true\" : \"false\")";
485 return "(uint32)"+var
;
490 virtual bool prolog();
493 virtual bool generateContent();
495 virtual void generateApplyCode(CClassGenerator::SMethodId
& method
, const std::string
& token
, const std::string
& value
)
497 method
.add("__pdr.pop("+token
+", "+value
+");");
500 virtual void generateStoreCode(CClassGenerator::SMethodId
& method
, const std::string
& token
, const std::string
& value
)
502 method
.add("__pdr.push("+token
+", "+value
+");");
515 class CDeclarationNode
;
518 enum TDeclarationType
534 TDeclarationType Type
;
539 class CClassNode
: public CParseNode
544 IsBackReferenced(false),
545 HasInheritance(false),
550 DerivatedFlag(false),
552 ParentIsHidden(false),
553 ForceReference(false),
559 HasTableAccess(false),
560 indexUsedInInit(false),
561 indexUsedInDestroy(false),
562 indexUsedInFetch(false),
563 tableAndRowIndicesUsedInFetch(false),
564 indexUsedInRegister(false),
565 indexUsedInUnregister(false),
566 indexUsedInNotifyInit(false),
567 indexUsedInNotifyRelease(false)
571 std::string Inherited
;
572 std::string ClassKey
;
573 std::string Implements
;
574 std::set
<CClassNode
*> Dependencies
;
576 std::vector
<std::string
> ChildrenClasses
;
577 bool IsBackReferenced
;
587 std::string ParentClass
;
592 CClassNode
*MapClass
;
594 std::vector
<CDeclarationNode
*> Init
;
595 std::string InitProto
;
596 std::string InitCallArgs
;
602 std::vector
<CDeclarationNode
*> Attributes
;
607 std::set
<std::string
> Friends
;
608 std::set
<std::string
> ForwardFriends
;
610 std::set
<CClassNode
*> Legacy
;
613 virtual bool prolog();
614 virtual bool epilog();
616 CDeclarationNode
* getDeclarationNode(const std::string
&name
);
617 CDeclarationNode
* getKey();
618 CDeclarationNode
* getClassKey();
619 CDeclarationNode
* getDeclaration(const std::string
& name
);
623 void checkClassReferences();
624 void fillAttributes();
626 void computeFriends();
628 void checkDependencies(std::set
<CClassNode
*> &beingChecked
,
629 std::set
<CClassNode
*> &checkedClasses
,
630 std::vector
<CClassNode
*> &classesOrder
);
634 void computeAttributesColumns();
636 std::string
getId() { return (HasInheritance
? NLMISC::toString("__BaseTable") : NLMISC::toString(Id
)); }
638 std::string
getUserCode(const std::string
& name
);
644 CClassGenerator::SMethodId InitId
;
645 CClassGenerator::SMethodId DestroyId
;
646 CClassGenerator::SMethodId FetchId
;
647 CClassGenerator::SMethodId RegisterId
;
648 CClassGenerator::SMethodId RegisterAttributesId
;
649 CClassGenerator::SMethodId UnregisterId
;
650 CClassGenerator::SMethodId UnregisterAttributesId
;
651 CClassGenerator::SMethodId SetParentId
;
652 CClassGenerator::SMethodId SetUnnotifiedParentId
;
653 CClassGenerator::SMethodId NotifyInitId
;
654 CClassGenerator::SMethodId NotifyReleaseId
;
656 CClassGenerator::SMethodId UserInitId
;
657 CClassGenerator::SMethodId UserReleaseId
;
660 CClassGenerator::SMethodId ClearId
;
661 CClassGenerator::SMethodId StoreId
;
662 CClassGenerator::SMethodId ApplyId
;
664 bool indexUsedInInit
;
665 bool indexUsedInDestroy
;
666 bool indexUsedInFetch
;
667 bool tableAndRowIndicesUsedInFetch
;
668 bool indexUsedInRegister
;
669 bool indexUsedInUnregister
;
670 bool indexUsedInNotifyInit
;
671 bool indexUsedInNotifyRelease
;
673 bool generateContent();
674 void generateContentInCall(CCallContext
*context
);
677 class CDeclarationNode
: public CParseNode
683 WriteTriggerFlag(false),
699 bool WriteTriggerFlag
;
704 std::string ParentClass
;
705 std::string ParentField
;
710 std::string ArrayIndex
;
712 std::string ForwardRefAttribute
;
718 std::string DefaultValue
;
723 std::string CodeSpecializer
;
724 std::string UserCode
;
727 std::vector
<CUserCode
> UserCodes
;
729 std::string
getUserCode(const std::string
&name
, const std::string
&specialize
= std::string(""))
732 // first look for a specialized code
733 for (i
=0; i
<UserCodes
.size(); ++i
)
734 if (UserCodes
[i
].Event
== name
&& UserCodes
[i
].CodeSpecializer
== specialize
)
735 return UserCodes
[i
].UserCode
;
736 // then look for a default code
737 for (i
=0; i
<UserCodes
.size(); ++i
)
738 if (UserCodes
[i
].Event
== name
&& UserCodes
[i
].CodeSpecializer
.empty())
739 return UserCodes
[i
].UserCode
;
743 TDeclarationType DeclarationType
;
746 std::vector
<CColumn
> ColumnList
;
753 CClassNode
* ClassNode
;
754 CClassNode
* getParentClass() { return dynamic_cast<CClassNode
*>(Parent
); }
757 virtual bool prolog();
758 virtual bool epilog();
761 std::string
getFunc() const { return lcFirst(getFunctionPrefix
+Name
); }
762 std::string
setFunc() const { return lcFirst(setFunctionPrefix
+Name
); }
763 std::string
newFunc() const { return lcFirst(newFunction
+Name
); }
764 std::string
deleteFunc() const { return lcFirst(deleteFunction
+Name
); }
765 std::string
unlinkFunc() const { return lcFirst(unlinkFunction
+Name
); }
766 std::string
cppName() const { return "_"+Name
; }
767 std::string
tokenName() const { return "__Tok"+Name
; }
770 std::string
displayPrintfPrefix();
771 std::string
displayCppCode(std::string replVar
= "");
772 std::string
toUint64(std::string replVar
= "");
775 void generateContent(CCallContext
*context
= NULL
);
777 void generateTypeContent(CCallContext
*context
= NULL
);
778 void generateClassContent(CCallContext
*context
= NULL
);
779 void generateBackRefContent();
780 void generateForwardRefContent();
781 void generateArrayTypeContent(CCallContext
*context
= NULL
);
782 void generateArrayClassContent(CCallContext
*context
= NULL
);
783 void generateArrayRefContent(CCallContext
*context
= NULL
);
784 void generateSetContent(CCallContext
*context
= NULL
);
787 void generateArrayApplyCode();
788 void generateArrayStoreCode();
789 void generateArrayEndCode();
791 void generateClassPtrApplyCode(const std::string
& value
);
792 void generateClassPtrStoreCode(const std::string
& value
);
794 std::string
getAccessorName(CCallContext
*context
, const std::string
& accessortype
, const std::string
& sep
= "::");
802 class CIndexNode
: public CTypeNode
809 StorageType
= "uint32";
812 virtual bool isIndex() { return true; }
814 virtual std::string
getSizeName() { return Name
+"Size"; }
815 virtual uint
getSize() = 0;
817 virtual std::string
getIndexName(uint32 value
) const
819 return NLMISC::toString(value
);
822 virtual std::string
getToStringCode(const std::string
& var
) const
824 return "NLMISC::toString("+var
+")";
827 virtual std::string
getFromStringCode(const std::string
& var
) const
829 return "atoi("+var
+")";
832 virtual std::string
checkCode(const std::string
& var
) { return "nlassert("+var
+"<"+getSizeName()+");"; }
839 class CEnumNode
: public CIndexNode
853 std::vector
<std::pair
<std::string
, uint32
> > Values
;
854 std::string EndRange
;
856 virtual bool isEnum() { return true; }
857 virtual std::string
getName()
859 std::string trunc
= Name
.substr(1);
860 return "C"+trunc
+"::"+(DisplayName
.empty() ? Name
: DisplayName
);
863 virtual uint
getSize() { return MaxValue
-MinValue
; }
869 virtual bool generateContent();
871 std::string
getIndexName(uint32 value
) const
876 for (i
=0; i
<Values
.size(); ++i
)
877 if (Values
[i
].second
== value
)
878 result
= Values
[i
].first
;
883 std::string
getUnscopedUseSize() const
885 return "___"+Name
+"_useSize";
888 std::string
getUnknownValue() const
893 std::string
getUseSize() const
895 std::string trunc
= Name
.substr(1);
896 return "C"+trunc
+"::"+getUnscopedUseSize();
899 std::string
getSizeName()
901 std::string trunc
= Name
.substr(1);
902 return "C"+trunc
+"::"+getUnscopedUseSize();
905 virtual std::string
getToStringCode(const std::string
& var
) const
907 std::string trunc
= Name
.substr(1);
908 return "C"+trunc
+"::toString("+var
+")";
911 virtual std::string
getFromStringCode(const std::string
& var
) const
913 std::string trunc
= Name
.substr(1);
914 return "C"+trunc
+"::fromString("+var
+")";
917 virtual void generateApplyCode(CClassGenerator::SMethodId
& method
, const std::string
& token
, const std::string
& value
)
920 method
.add("std::string\tvaluename;");
921 method
.add("__pdr.pop("+token
+", valuename);");
922 method
.add(value
+" = "+getFromStringCode("valuename")+";");
926 virtual void generateStoreCode(CClassGenerator::SMethodId
& method
, const std::string
& token
, const std::string
& value
)
929 method
.add("std::string\tvaluename = "+getToStringCode(value
)+";");
930 method
.add("__pdr.push("+token
+", valuename);");
935 class CEnumSimpleValueNode
: public CEnumNode
939 std::vector
<std::string
> Names
;
945 class CEnumRangeNode
: public CEnumNode
959 class CDimensionNode
: public CIndexNode
968 virtual bool isDimension() { return true; }
969 std::string
getSizeName() { return Name
+"Size"; }
976 virtual uint
getSize() { return Dimension
; }
979 virtual bool generateContent();
986 class CLogMsgNode
: public CParseNode
990 CLogMsgNode() : Context(false)
1000 std::vector
<std::pair
<std::string
, std::string
> > Params
;
1001 std::vector
<std::string
> Logs
;
1007 void generateContent();
1010 class CExtLogTypeNode
: public CParseNode
1014 std::string ExtLogType
;
1028 std::vector
<CDeclarationNode
*> Context
;
1030 std::string RootTable
;
1031 std::string RootRow
;
1034 CCallContext(CDeclarationNode
* decl
= NULL
)
1037 Context
.push_back(decl
);
1040 bool hasRootEntityIdKey()
1042 CDeclarationNode
* k
= getRootCaller()->getClassKey();
1045 return (getRootCaller()->getTypeNode(getRootCaller()->getKey()->Type
)->CppType
== "CEntityId");
1051 * Generates the name of the pointed variable
1052 * For instance: PhysicalScoresBase, where PhysicalScores is an array and Base is an attribute in this array
1053 * Actually concats all fields names
1055 std::string
getCallString()
1059 for (i
=0; i
<Context
.size(); ++i
)
1060 res
+= Context
[i
]->Name
;
1064 CClassNode
* getRootCaller()
1066 return (CClassNode
*)Context
[0]->Parent
;
1069 CDeclarationNode
* getRootDeclaration()
1075 * Generates the access prototype argument list
1076 * Actually only generates indexes for arrays
1078 std::string
getDebugCallStringFmt()
1083 for (i
=0; i
<Context
.size(); ++i
)
1085 CDeclarationNode
* decl
= Context
[i
];
1087 if (decl
->DeclarationType
== ArrayClass
|| decl
->DeclarationType
== ArrayType
)
1092 CTypeNode
* tnd
= decl
->getTypeNode(decl
->ArrayIndex
);
1093 res
+= indexVariable
+NLMISC::toString(idx
++)+"="+tnd
->getPrintfFmt();
1102 * Generates the access prototype argument list
1103 * Actually only generates indexes for arrays
1105 std::string
getDebugCallStringVal()
1110 for (i
=0; i
<Context
.size(); ++i
)
1112 CDeclarationNode
* decl
= Context
[i
];
1114 if (decl
->DeclarationType
== ArrayClass
|| decl
->DeclarationType
== ArrayType
)
1119 CTypeNode
* tnd
= decl
->getTypeNode(decl
->ArrayIndex
);
1120 res
+= tnd
->getPrintfVal(indexVariable
+NLMISC::toString(idx
++));
1129 * Generates the access prototype argument list
1130 * Actually only generates indexes for arrays
1132 std::string
getCallArgList()
1137 for (i
=0; i
<Context
.size(); ++i
)
1139 CDeclarationNode
* decl
= Context
[i
];
1141 if (decl
->DeclarationType
== ArrayClass
|| decl
->DeclarationType
== ArrayType
)
1146 CTypeNode
* tnd
= decl
->getTypeNode(decl
->ArrayIndex
);
1147 res
+= tnd
->getName()+ " "+indexVariable
+NLMISC::toString(idx
++);
1154 * Generates the c++ path to the variable
1155 * For instance: _PhysicalScores[__i0].Base, where PhysicalScores is an array and Base is an attribute in this array
1157 std::string
getCallPath()
1162 for (i
=0; i
<Context
.size(); ++i
)
1164 CDeclarationNode
* decl
= Context
[i
];
1169 res
+= decl
->cppName();
1171 if (decl
->DeclarationType
== ArrayClass
|| decl
->DeclarationType
== ArrayType
)
1173 res
+= "["+indexVariable
+NLMISC::toString(idx
++)+"]";
1180 * Generates the c++ path to the variable
1181 * For instance: _PhysicalScores[__i0].Base, where PhysicalScores is an array and Base is an attribute in this array
1183 std::string
getUserCodeContext()
1188 if (Context
.empty())
1191 res
= Context
[0]->getParentClass()->Name
;
1193 for (i
=0; i
<Context
.size(); ++i
)
1194 res
+= "."+Context
[i
]->Name
;
1200 * Generates check code for all types accessors
1202 std::vector
<std::string
> getCheckCode()
1204 std::vector
<std::string
> res
;
1207 for (i
=0; i
<Context
.size(); ++i
)
1209 CDeclarationNode
* decl
= Context
[i
];
1211 if (decl
->DeclarationType
== ArrayType
|| decl
->DeclarationType
== ArrayRef
|| decl
->DeclarationType
== ArrayClass
)
1213 CIndexNode
* ind
= decl
->getIndexNode(decl
->ArrayIndex
);
1214 std::string code
= ind
->checkCode(indexVariable
+NLMISC::toString(idx
++));
1216 res
.push_back(code
);
1224 * Get current context index
1226 uint
getContextIndex()
1230 for (i
=0; i
<Context
.size(); ++i
)
1232 CDeclarationNode
* decl
= Context
[i
];
1233 if (decl
->DeclarationType
== ArrayClass
|| decl
->DeclarationType
== ArrayType
)
1239 CCallContext
getSubContext(CDeclarationNode
* decl
)
1241 CCallContext ctx
= *this;
1242 ctx
.Context
.push_back(decl
);
1246 std::string
getColumn()
1251 for (i
=0; i
<Context
.size(); ++i
)
1253 CDeclarationNode
* decl
= Context
[i
];
1254 if (decl
->Column
!= 0)
1258 res
+= NLMISC::toString(decl
->Column
);
1261 if (decl
->DeclarationType
== ArrayType
|| decl
->DeclarationType
== ArrayRef
)
1265 res
+= indexVariable
+NLMISC::toString(idx
++);
1267 else if (decl
->DeclarationType
== ArrayClass
)
1271 CClassNode
* sub
= decl
->getClassNode(decl
->Type
);
1272 res
+= indexVariable
+NLMISC::toString(idx
++)+"*"+NLMISC::toString(sub
->Columns
);
1292 inline CFileNode
* CParseNode::getFileNode()
1294 if (FileNode
!= NULL
)
1297 CParseNode
* node
= this;
1298 CFileNode
* fnode
= NULL
;
1300 while (node
!= NULL
&& (fnode
= dynamic_cast<CFileNode
*>(node
)) == NULL
)
1301 node
= node
->Parent
;
1304 error("Can't find file node", "internal");
1311 inline CDbNode
* CParseNode::getDbNode()
1316 CParseNode
* node
= this;
1317 CDbNode
* fnode
= NULL
;
1319 while (node
!= NULL
&& (fnode
= dynamic_cast<CDbNode
*>(node
)) == NULL
)
1320 node
= node
->Parent
;
1323 error("Can't find db node", "internal");
1330 inline CCppOutput
& CParseNode::hOutput()
1332 CFileNode
*fnode
= getFileNode();
1336 inline CCppOutput
& CParseNode::cppOutput()
1338 CFileNode
*fnode
= getFileNode();
1342 inline CCppOutput
& CParseNode::inlineOutput()
1344 CFileNode
*fnode
= getFileNode();
1345 return fnode
->HppInline
;
1349 inline CTypeNode
*CParseNode::getTypeNode(const std::string
&name
, bool genError
)
1351 CDbNode
* db
= getDbNode();
1353 for (i
=0; i
<db
->TypeNodes
.size(); ++i
)
1354 if (db
->TypeNodes
[i
]->Name
== name
)
1355 return db
->TypeNodes
[i
];
1357 error("Can't find type '"+name
+"'");
1361 inline CEnumNode
*CParseNode::getEnumNode(const std::string
&name
, bool genError
)
1363 CEnumNode
* node
= dynamic_cast<CEnumNode
*>(getTypeNode(name
, genError
));
1364 if (node
== NULL
&& genError
)
1365 error("Can't find enum '"+name
+"'");
1369 inline CDimensionNode
*CParseNode::getDimensionNode(const std::string
&name
, bool genError
)
1371 CDimensionNode
* node
= dynamic_cast<CDimensionNode
*>(getTypeNode(name
, genError
));
1372 if (node
== NULL
&& genError
)
1373 error("Can't find dimension '"+name
+"'");
1377 inline CIndexNode
*CParseNode::getIndexNode(const std::string
&name
, bool genError
)
1379 CIndexNode
* node
= dynamic_cast<CIndexNode
*>(getTypeNode(name
, genError
));
1380 if (node
== NULL
&& genError
)
1381 error("Can't find index type '"+name
+"' (neither enum nor dimension)");
1385 inline CClassNode
*CParseNode::getClassNode(const std::string
&name
, bool genError
)
1387 CDbNode
* db
= getDbNode();
1389 for (i
=0; i
<db
->ClassNodes
.size(); ++i
)
1390 if (db
->ClassNodes
[i
]->Name
== name
)
1391 return db
->ClassNodes
[i
];
1393 error("Can't find class '"+name
+"'");
1397 inline bool CDbNode::addTypeNode(const std::string
&name
, const std::string
&displayName
, const std::string
&defaultValue
)
1399 CTypeNode
*node
= new CTypeNode();
1402 node
->DisplayName
= displayName
;
1403 node
->CppType
= name
;
1404 node
->StorageType
= name
;
1406 node
->ToCppType
= NULL
;
1407 node
->ToStorageType
= NULL
;
1409 node
->DefaultValue
= defaultValue
;
1411 node
->ExternFlag
= false;
1412 node
->InternFlag
= true;
1413 node
->Parent
= this;
1415 Nodes
.insert(Nodes
.begin(), node
);
1421 inline CDeclarationNode
* CClassNode::getDeclarationNode(const std::string
&name
)
1423 CDeclarationNode
*node
;
1424 if ((node
= dynamic_cast<CDeclarationNode
*>(getNode(name
))) == NULL
)
1425 error("declaration '"+name
+"' not found");
1429 inline bool CClassNode::useEntityId()
1431 //return !ClassKey.empty() && getTypeNode(getKey()->Type)->CppType == "CEntityId";
1432 CDeclarationNode
* k
= getClassKey();
1433 return k
!=NULL
&& getTypeNode(k
->Type
)->CppType
== "CEntityId";
1436 inline CDeclarationNode
* CClassNode::getClassKey()
1438 if (ClassKey
.empty())
1440 if (Inherited
.empty())
1442 CClassNode
* p
= getClassNode(Inherited
);
1443 return p
->getClassKey();
1452 inline CDeclarationNode
* CClassNode::getKey()
1454 CDeclarationNode
* key
= NULL
;
1455 CClassNode
* classNode
= this;
1456 while (classNode
!= NULL
)
1458 key
= dynamic_cast<CDeclarationNode
*>(classNode
->getNode(classNode
->ClassKey
));
1461 classNode
= getClassNode(Inherited
, false);
1463 error("key declaration '"+ClassKey
+"' not found");
1465 //return getDeclarationNode(ClassKey);
1468 inline CDeclarationNode
* CClassNode::getDeclaration(const std::string
& name
)
1470 CDeclarationNode
* decl
= NULL
;
1471 CClassNode
* classNode
= this;
1472 while (classNode
!= NULL
)
1474 decl
= dynamic_cast<CDeclarationNode
*>(classNode
->getNode(name
));
1477 classNode
= getClassNode(classNode
->Inherited
, false);
1479 error("declaration '"+name
+"' not found");