CE Symbol.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. namespace Edit{
  4. /******************************************************************************/
  5. DECLARE_CACHE(Symbol, Symbols, SymbolPtr); // 'Symbols' cache storing 'Symbol' objects which can be accessed by 'SymbolPtr' pointer
  6. /******************************************************************************/
  7. STRUCT(Symbol , Str) // C++ Symbol
  8. //{
  9. enum TYPE : Byte
  10. {
  11. UNKNOWN ,
  12. KEYWORD , // built-in C++ keyword
  13. PREPROC , // built-in C++ preprocessor keyword
  14. ENUM , // enum X {..}
  15. ENUM_ELM , // enum .. {X}
  16. TYPEDEF , // typedef .. X;
  17. NAMESPACE, // namespace X {..}
  18. CLASS , // struct/class/union X {..}
  19. TYPENAME , // template<typename TYPE>
  20. FUNC_LIST, // list of polymorphic funcion symbols within the same symbol ('funcs' member is a list of them)
  21. FUNC , // global function or class method or pointer to such
  22. VAR , // member
  23. SPACE , // braces {} used for separating local variables like: "Int x; {Int x;}"
  24. LABEL , // label "label:" used together with 'goto'
  25. };
  26. enum MODIFIER // modifiers are designed to have all modifiers disabled by default, and they are only enabled if needed (m|=option), in some circumstances they are set FlagSet(m, option, on/off)
  27. {
  28. MODIF_REF =1<< 0, // TYPE& (this is set only to Symbol::value.modifiers, however this can be set to Symbol::modifiers in case of function references "void (&func)()")
  29. MODIF_DEF_VALUE =1<< 1, // TYPE= (if has default value)
  30. MODIF_STATIC =1<< 2, // static TYPE
  31. MODIF_INLINE =1<< 3, // inline TYPE
  32. MODIF_VIRTUAL =1<< 4, // virtual TYPE
  33. MODIF_FRIEND =1<< 5, // friend TYPE
  34. MODIF_MUTABLE =1<< 6, // mutable TYPE
  35. MODIF_EXPLICIT =1<< 7, // explicit TYPE
  36. MODIF_EXTERN =1<< 8, // extern TYPE
  37. MODIF_PRIVATE =1<< 9, // private TYPE
  38. MODIF_PROTECTED =1<<10, // protected TYPE
  39. MODIF_CONST_MEM_ADDR =1<<11, // const_mem_addr TYPE
  40. MODIF_CTOR =1<<12, // this function (FUNC_LIST and FUNC) is a constructor
  41. MODIF_DTOR =1<<13, // this function (FUNC_LIST and FUNC) is a destructor
  42. MODIF_FUNC_BODY =1<<14, // this symbol is a function which contains a body (sometimes there can be 2 functions declaration/definition, only one of them has the body)
  43. MODIF_FUNC_CONST =1<<15, // this symbol is a function which has 'const' modifier "void func()const {}" and cannot modify object members
  44. MODIF_FUNC_PARAM =1<<16, // if this symbol is a function parameter "void func(int param)" <- 'param'
  45. MODIF_DATA_TYPE =1<<17, // if is a data type (void, int, class, enum, typedef, template) this needs to be a member and not method because some KEYWORD's are a data type and some are not
  46. MODIF_UNION =1<<18, // if class is actually a union
  47. MODIF_NAMELESS =1<<19, // if symbol is nameless
  48. MODIF_TRANSPARENT =1<<20, // if symbol is nameless class and doesn't have any instances, for example "class {};" (doesn't have a name or any instances), following example is not transparent "class {} value;" (this is because class members can be accessed through "value."), this is also always set for FUNC_LIST symbols
  49. MODIF_SKIP_SUGGESTIONS=1<<21, // if skip this symbol from suggestions list
  50. MODIF_FOLLOW_BY_SPACE =1<<22, // if automatically follow by space when typing
  51. MODIF_OUTSIDE_METHOD =1<<23, // this is a class method defined outside of class body (FUNC type) "class A {void func();} void A::func() {}"
  52. MODIF_TYPEDEF =1<<24, // for struct/class/union/enum: class A was defined with typedef before it "typedef class A {} B", for typedef: typedef B was defined directly after class definition "typedef class A {} B"
  53. MODIF_CPP_MODIFIER =1<<25, // if the symbol is a C++ modifier (const, static, virtual, friend, mutable, explicit, ..)
  54. MODIF_ES_ONLY =1<<26, // if the symbol is a keyword supported only in Esenthel Script (not pure C++)
  55. MODIF_ALL_UP_CASE =1<<27, // if base name of the symbol is made completely out of upper case characters (used in suggestions)
  56. MODIF_SAME_FUNC =MODIF_FUNC_CONST, // virtual should not be included
  57. MODIF_SAME_FUNC_PARAM=MODIF_REF,
  58. MODIF_ACCESS =MODIF_PRIVATE|MODIF_PROTECTED,
  59. MODIF_CTOR_DTOR =MODIF_CTOR|MODIF_DTOR,
  60. MODIF_VALUE =MODIF_REF|MODIF_DEF_VALUE|MODIF_MUTABLE, // modifiers that can be used by Symbol::Modif::modifiers
  61. };
  62. enum HELPER // helpers used during processing only
  63. {
  64. HELPER_FORCE_CTOR =1<<0, // force empty constructor for classes (with member initializers, used during creation of the headers)
  65. HELPER_PROCESSED =1<<1, // used during C++ creation (declaration)
  66. HELPER_PROCESSED_FULL =1<<2, // used during C++ creation (definition )
  67. HELPER_ADJUSTED_INDEXES=1<<3, // if symbol indexes have been already adjusted (used during header parsing)
  68. HELPER_FUNC_PARSED =1<<4, // if function was already parsed
  69. };
  70. enum DIM_CODE // custom codes which can be used for 'array_dims'
  71. {
  72. DIM_MIN =-2,
  73. DIM_PTR =-2, // this specifies that this is actually a pointer, and not array dimension, this is used to specify pointers to arrays "int x[2]; &x" for "&x" symbol 'array_dims' would be set to {2, DIM_PTR}
  74. DIM_UNKNOWN=-1, // this specifies that dimension is not yet known, must be calculated from some formula like "const int x=5; x+2" or by counting number of default values "int x[]={1,2,3};"
  75. DIM_INVALID= 0, // this specifies that dimension is invalid , for example "int x[0], y[-1], z[non_existing_+symbol];"
  76. };
  77. enum ACCESS_LEVEL : Byte
  78. {
  79. ACCESS_PRIVATE ,
  80. ACCESS_PROTECTED,
  81. ACCESS_PUBLIC ,
  82. };
  83. static ACCESS_LEVEL ModifToAccessLevel(UInt modifiers)
  84. {
  85. if(modifiers&MODIF_PRIVATE )return ACCESS_PRIVATE ;
  86. if(modifiers&MODIF_PROTECTED)return ACCESS_PROTECTED;
  87. return ACCESS_PUBLIC ;
  88. }
  89. static UInt AccessLevelToModif(ACCESS_LEVEL level)
  90. {
  91. switch(level)
  92. {
  93. default : return 0 ; // ACCESS_PUBLIC
  94. case ACCESS_PRIVATE : return MODIF_PRIVATE ;
  95. case ACCESS_PROTECTED: return MODIF_PROTECTED;
  96. }
  97. }
  98. static void SetPrivate (UInt &modifiers) {modifiers&=~MODIF_ACCESS; modifiers|=MODIF_PRIVATE ;}
  99. static void SetProtected(UInt &modifiers) {modifiers&=~MODIF_ACCESS; modifiers|=MODIF_PROTECTED;}
  100. static void SetPublic (UInt &modifiers) {modifiers&=~MODIF_ACCESS; }
  101. STRUCT(Modif , SymbolPtr) // pointer to symbol with modifiers
  102. //{
  103. Byte const_level ; // bit mask where each bit specifies const for object or pointers (bit 0: "const TYPE obj", bit 1: "TYPE *const obj", bit 2: "TYPE * *const obj")
  104. SByte ptr_level , // amount of pointers "", "*", "**", ..
  105. src_template_i;
  106. UInt modifiers ; // MODIFIER (when using this for expression calculation then don't include MODIFIER from the original Symbol but only its values, see more at MODIF_REF)
  107. Mems<Int> array_dims ; // array dimensions in reversed order, for example "int x[2][3];" would have array_dims={3,2}; (value can be also one of DIM_CODE codes) first element in 'array_dims' specifies the most low-level index in memory mapping, "int x[A:2][B:3]" stores elements in following linear mapping - A0B0, A0B1, A0B2, A1B0, A1B1, A1B2
  108. Memc<Modif> templates ; // contains a list of all known templates for this symbol, for example this which points to symbol 'D' of following formula "A<B,C>::D<E>" will have 3 elements: A.T0->B, A.T1->C, D.T0->E
  109. SymbolPtr src_template ; // pointer to symbol of TYPENAME type, for above example "A.T0->B" : 'src_template->A.T0' and 'this->B'
  110. void operator=(C SymbolPtr &sp ) {SymbolPtr &t=T; t=sp;}
  111. void clear (Bool clear_templates);
  112. Bool isConst (); // test last pointer or array if it's const
  113. Bool isObj (); // test if it's not pointer and not array
  114. Bool isPtr (); // test if last pointer or array is pointer
  115. Bool isArray (); // test if last array is not a pointer
  116. Bool anyPtr (); // test if pointer or if any array has a pointer
  117. Bool isVoidPtr(); // test if this object is exactly a 'Ptr' or 'CPtr'
  118. Bool basicType(); // test if is a C++ native type or pointer of any kind
  119. Int rawSize (Bool ref_as_ptr_size, RecTest &rt=ConstCast(RecTest()));
  120. Int firstMemberSize( RecTest &rt=ConstCast(RecTest())); // get size of first member in the class (or size of this if it's a var)
  121. Bool hasConstructor ( RecTest &rt=ConstCast(RecTest()));
  122. Bool hasDestructor ( RecTest &rt=ConstCast(RecTest()));
  123. Bool constMemAddrOK ( );
  124. Str modifName (Bool spaces=true, Bool include_const=true, Bool include_ref=true, Bool invalid_array_as_1=false, Bool template_space=false);
  125. Bool same (Modif &modif, Bool test_const, Bool test_ref);
  126. Bool sameFuncParamValue(Modif &modif);
  127. void setConst (Bool on=true);
  128. void proceedToFinal(Memc<Modif> *templates, Bool func_call=false, RecTest &rt=ConstCast(RecTest()));
  129. void proceedTo (Modif &src , RecTest &rt=ConstCast(RecTest()));
  130. Bool save(File &f, StrLibrary &sl)
  131. {
  132. sl.putStr(f, name()); f.putMulti(const_level, ptr_level, modifiers);
  133. f.cmpUIntV(array_dims.elms()); FREPA (array_dims)f.cmpUIntV(((array_dims[i]>=DIM_MIN) ? array_dims[i] : DIM_INVALID)+DIM_MIN);
  134. f.cmpUIntV(templates .elms()); FREPAO(templates ).save(f, sl); sl.putStr(f, src_template.name());
  135. return true;
  136. }
  137. Bool load(File &f, StrLibrary &sl)
  138. {
  139. require(sl.getStr(f)); f.getMulti(const_level, ptr_level, modifiers);
  140. array_dims.setNum(f.decUIntV()); FREPA (array_dims)array_dims[i]=f.decUIntV()-DIM_MIN;
  141. templates .setNum(f.decUIntV()); FREPAO(templates ).load(f, sl); src_template=sl.getStr(f);
  142. return true;
  143. }
  144. Modif() {const_level=0; ptr_level=0; src_template_i=-1; modifiers=0;}
  145. };
  146. TYPE type ; // symbol type
  147. VAR_TYPE var_type ; // var type
  148. ACCESS_LEVEL access_level ; // access level, used when parsing classes (struct will have ACCESS_PUBLIC, class will have ACCESS_PRIVATE), this may be changed when parsing class and encountering "private, protected, public" keywords inside
  149. Byte level , // amount of parents (symbol depth/level)
  150. func_ptr_level ,
  151. class_pack , // class member packing (1,2,4,8,16,..) setup with #pragma pack(..)
  152. helper ; // HELPER
  153. Short valid , // if main definition still exists (number of main definitions )
  154. valid_decl ; // if main declaration still exists (number of main declarations)
  155. UShort nameless_children; // amount of nameless children - {} spaces or nameless variables
  156. UInt modifiers ; // MODIFIER
  157. Str full_name ; // full name like "EE\Game\Chr" (not followed by separator)
  158. Memc<SymbolPtr> funcs ; // if type==FUNC_LIST , then 'funcs' contains a list of polymorphic functions
  159. Memc<SymbolPtr> templates ; // if type==FUNC || type==CLASS, then 'templates' contains a list of template parameters for this class/func (of TYPE::TYPENAME type), for example: "template<typename TYPE> struct X{};" templates[0]=TYPE (this doesn't include templates of parents)
  160. Modif value ; // if type==FUNC || type==VAR , then 'value' is a type of the value (it's not a var by itself, Symbol points to data type), if type==TYPEDEF then 'value' points to the base type symbol
  161. Memc<SymbolPtr> params ; // if type==FUNC , then 'params' contains a list of parameters for this func (of TYPE::VAR,FUNC type)
  162. Memc<SymbolPtr> ctor_inits ; // if type==FUNC , then 'ctor_inits' contains a list of specified constructor initializers, if type==CLASS then 'ctor_inits' contains a list of all members with default values
  163. Memc<Symbol*> dependencies , // used when generating list of all headers, this contains a list of classes that current class depends on (all 'dependencies' must be included before this class in order to compile in C++) these are base classes, non-pointer non-ref members, and all the same for nested classes
  164. children ; // used during manual compilation, contains a list of all symbols which parent is 'this'
  165. Memc<Modif> base ; // base classes which this class extends, modifiers can be used to determine class access or template params
  166. SymbolPtr parent ; // parent of the symbol
  167. Int raw_offset , // for global variables this is the memory position in the global heap, for local variables this is the offset in the local stack (relative to function entry), for function parameters this is the offset in the parameter stack, for functions this is the index of function body in the code environment, for labels this is the index of the label
  168. nameless_index ,
  169. token_index ; // index of token in source which defines the symbol
  170. VecI2 type_range , // type describing the symbol start/end token indexes
  171. def_range , // symbol definition start/end token indexes
  172. def_val_range ; // default value start/end token indexes
  173. Source *source ; // source that this symbol belongs to
  174. Symbol()
  175. {
  176. type=UNKNOWN;
  177. modifiers=0;
  178. level=0;
  179. valid=valid_decl=0;
  180. token_index=0; source=null;
  181. clear();
  182. }
  183. void clear() // don't clear 'level', 'valid', 'valid_decl', 'token_index', 'source', 'type' (why 'type' not?)
  184. {
  185. var_type =VAR_NONE;
  186. access_level=ACCESS_PUBLIC;
  187. func_ptr_level=0;
  188. class_pack =4;
  189. nameless_children=0;
  190. helper=0;
  191. modifiers&=~MODIF_ALL_UP_CASE; // clear everything except 'MODIF_ALL_UP_CASE'
  192. funcs .clear();
  193. templates .clear();
  194. value .clear(true);
  195. params .clear();
  196. ctor_inits .clear();
  197. dependencies.clear();
  198. children .clear();
  199. base .clear();
  200. parent .clear();
  201. raw_offset =-1;
  202. nameless_index= 0;
  203. type_range.set(0, -1); def_range.set(0, -1); def_val_range.set(0, -1);
  204. }
  205. // don't save/load ('valid', 'valid_decl' - managed by SymbolDef/SymbolDecl), ('name', 'full_name' - setup by load from name), ('access_level', 'nameless_children', 'raw_offset', 'nameless_index' - not needed)
  206. Bool save(File &f, StrLibrary &sl)
  207. {
  208. f.putMulti(type, var_type, level, func_ptr_level, class_pack, modifiers);
  209. f.cmpIntV(token_index).cmpIntV(type_range.x).cmpIntV(type_range.y).cmpIntV(def_range.x).cmpIntV(def_range.y); if(modifiers&MODIF_DEF_VALUE)f.cmpIntV(def_val_range.x).cmpIntV(def_val_range.y);
  210. value.save(f, sl);
  211. f.cmpUIntV(funcs .elms()); FREPA(funcs )sl.putStr(f, funcs [i].name());
  212. f.cmpUIntV(templates .elms()); FREPA(templates )sl.putStr(f, templates [i].name());
  213. f.cmpUIntV(params .elms()); FREPA(params )sl.putStr(f, params [i].name());
  214. f.cmpUIntV(ctor_inits.elms()); FREPA(ctor_inits)sl.putStr(f, ctor_inits[i].name());
  215. f.cmpUIntV(base .elms()); FREPAO(base).save(f, sl);
  216. sl.putStr(f, parent.name());
  217. return true;
  218. }
  219. Bool load(File &f, StrLibrary &sl, Source &source)
  220. {
  221. f.getMulti(type, var_type, level, func_ptr_level, class_pack, modifiers);
  222. f.decIntV(token_index).decIntV(type_range.x).decIntV(type_range.y).decIntV(def_range.x).decIntV(def_range.y); if(modifiers&MODIF_DEF_VALUE)f.decIntV(def_val_range.x).decIntV(def_val_range.y);
  223. value.load(f, sl);
  224. funcs .setNum(f.decUIntV()); FREPA(funcs )funcs [i]=sl.getStr(f);
  225. templates .setNum(f.decUIntV()); FREPA(templates )templates [i]=sl.getStr(f);
  226. params .setNum(f.decUIntV()); FREPA(params )params [i]=sl.getStr(f);
  227. ctor_inits.setNum(f.decUIntV()); FREPA(ctor_inits)ctor_inits[i]=sl.getStr(f);
  228. base .setNum(f.decUIntV()); FREPAO(base).load(f, sl);
  229. parent=sl.getStr(f);
  230. T.source=&source;
  231. return true;
  232. }
  233. Bool load(C Str &name) // this is always called at symbol creation in the cache
  234. {
  235. // setup params on symbol creation
  236. full_name=name;
  237. Str &s=T; s=GetBase(name);
  238. FlagSet(modifiers, MODIF_ALL_UP_CASE, AllUpCase(s));
  239. return true;
  240. }
  241. // get
  242. Bool operator==(CChar8 *name) {return Equal(T, name, true);} // force case-sensitive comparison
  243. Bool operator==(CChar *name) {return Equal(T, name, true);} // force case-sensitive comparison
  244. VAR_TYPE varType() {return var_type ;}
  245. ACCESS_LEVEL accessLevel() {return access_level;}
  246. Str typeName();
  247. Str fileName(); // full name used for writing C++ files
  248. Str cppName();
  249. Str fullCppName();
  250. Str shortName(); // 'cppName' without the "operator" part for the operators
  251. Str funcDefinition (Int highlight);
  252. Str definition ();
  253. Str comments ();
  254. Str commentsCode();
  255. Symbol* Parent (); // return symbol's parent ignoring any transparent symbols (such as FUNC_LIST or TRANSPARENT class), which allows to return CLASS as parent for FUNC
  256. Symbol* rootClass ();
  257. Symbol* Class ();
  258. Symbol* Namespace ();
  259. Symbol* func ();
  260. Symbol* rootFunc ();
  261. Symbol* firstNonTransparent();
  262. Bool contains (Symbol *symbol);
  263. Token* getToken();
  264. Bool insideFunc (); // if is inside another function, sample : void func() { void inside1(){} struct str{void inside2(){}} }
  265. Bool insideClass ();
  266. Bool insideTemplateClass();
  267. ACCESS_LEVEL highestAccess();
  268. Bool fullyStatic();
  269. Bool partiallyStatic();
  270. Bool isNativeFunc ();
  271. Bool isGlobal ();
  272. Bool isVar ();
  273. Bool isFunc ();
  274. Bool isClassNonStaticMember();
  275. Bool isClassNonStaticFunc ();
  276. Bool isGlobalFunc ();
  277. Bool isGlobalAndStatic ();
  278. Bool isGlobalOrStatic ();
  279. Bool isTemplateClass ();
  280. Bool isTemplateFunc ();
  281. Bool isInlineFunc ();
  282. Bool isAbstractClass ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class is abstract
  283. Bool isVirtualClass ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class is virtual
  284. Bool isVirtualFunc ( Memc<Modif> *templates=null ); // check if a function is virtual
  285. Bool hasVirtualDestructor ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class has a virtual destructor
  286. Bool hasVirtualFunc (Symbol &func, Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class has a virtual function identical to 'func'
  287. Bool hasConstructor ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class has or should have constructor
  288. Bool hasDestructor ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // check if a class has or should have destructor
  289. Bool hasResult ( Memc<Modif> *templates=null, Modif *value=null ); // check if a function has result (return value) which is not 'void' (can be everything else, including 'void*')
  290. Bool fullyPublic (); // if this symbol and all of its parents are public
  291. Int templateClasses ();
  292. Int baseOffset (Int base_index , Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // get raw offset of the 'base_index' base class from the start of the object (this should support also the case when pointing after all bases, to return the offset of all bases)
  293. Int memberOffset (Symbol *member , Bool *found, Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // get raw offset of the 'member' member from the start of the object (this should support alse the case when 'member' is not a child of the class, to return the size of the whole class)
  294. Int rawSize (Bool ref_as_ptr_size, Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest()));
  295. Int firstMemberSize ( Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest())); // get size of first member in the class (or size of this if it's a var)
  296. Int realParams (); // return 0 for operator++(Int), operator--(Int) and "params.elms()" for everything else
  297. Bool sameFunc (Symbol &f); // compares return values and parameters only (ignores parents)
  298. Bool sameSymbol(Symbol &s); // if it's the same symbol (or a FUNC function identical to the 's' FUNC)
  299. Bool constDefineInHeader(); // if define const in header
  300. Bool fromPartialMacro (); // if was created from a macro, and only from its part
  301. Bool hasBase (Symbol *Class , Memc<Modif> *templates=null, RecTest &rt=ConstCast(RecTest()));
  302. Bool hasNonPrivateBase(Symbol *Class , Memc<Modif> *templates=null, Bool allow_self=true, Bool test_private=false, RecTest &rt=ConstCast(RecTest()));
  303. Bool hasPrivateBase (Symbol *Class , Memc<Modif> *templates=null, Bool test_private=false, RecTest &rt=ConstCast(RecTest()));
  304. Bool hasNonPublicBase (Symbol *Class , Memc<Modif> *templates=null, Bool test_access =false, RecTest &rt=ConstCast(RecTest()));
  305. Bool isMemberOf (Symbol *symbol, Memc<Symbol::Modif> &symbol_templates, Symbol *caller, Bool instance, Bool ctor_init, Bool allow_self, Bool allow_bases);
  306. Bool canBeAccessedFrom(Symbol *path , Symbol *caller, Bool precise_parent, Memc<SymbolPtr> &usings);
  307. // operations
  308. void adjustIndex (Memc<Token> &tokens, Int &i);
  309. void adjustIndexes(Memc<Token> &tokens );
  310. void addDependency (Modif &symbol);
  311. void addDependencyIfNested(Symbol *symbol);
  312. void clearBody(); // set token parents of the wholy body of the function to the function itself (to remove any references from symbols created inside the function)
  313. };
  314. /******************************************************************************/
  315. STRUCT(SymbolDecl , SymbolPtr) // symbol forward declaration (used only for classes)
  316. //{
  317. SymbolDecl& set(C SymbolPtr &parent, Symbol::TYPE type, Int token_index, Source *source)
  318. {
  319. if(!T->valid) // allow modifying only once
  320. {
  321. T->clear();
  322. T->parent =parent;
  323. T->type =type ;
  324. T->var_type =((type==Symbol::ENUM || type==Symbol::ENUM_ELM) ? VAR_ENUM : VAR_NONE);
  325. T->level =(parent ? parent->level+1 : 0);
  326. T->token_index=token_index;
  327. T->source =source;
  328. FlagSet(T->modifiers, Symbol::MODIF_DATA_TYPE , type==Symbol::CLASS || type==Symbol::ENUM || type==Symbol::TYPEDEF || type==Symbol::TYPENAME);
  329. FlagSet(T->modifiers, Symbol::MODIF_FOLLOW_BY_SPACE , type==Symbol::ENUM);
  330. FlagSet(T->modifiers, Symbol::MODIF_SKIP_SUGGESTIONS, T->isFunc() || type==Symbol::SPACE || type==Symbol::LABEL);
  331. FlagSet(T->modifiers, Symbol::MODIF_TRANSPARENT , type==Symbol::FUNC_LIST);
  332. }
  333. return T;
  334. }
  335. SymbolDecl& require(C Str &name)
  336. {
  337. super::require(name);
  338. T->valid_decl++;
  339. return T;
  340. }
  341. ~SymbolDecl()
  342. {
  343. if(T())
  344. {
  345. T->valid_decl--;
  346. if(!T->valid_decl && !T->valid)
  347. {
  348. T->clear();
  349. }
  350. }
  351. }
  352. SymbolDecl() {}
  353. NO_COPY_CONSTRUCTOR(SymbolDecl);
  354. };
  355. /******************************************************************************/
  356. STRUCT(SymbolDef , SymbolPtr) // symbol definition (pointer to symbol which also acts as the creator of the symbol, by holding a 'valid' ref-count)
  357. //{
  358. SymbolDef& set(C SymbolPtr &parent, Symbol::TYPE type, Int token_index, Source *source)
  359. {
  360. if(T->valid==1) // allow modifying only once
  361. {
  362. T->clear();
  363. T->parent =parent;
  364. T->type =type ;
  365. T->var_type =((type==Symbol::ENUM || type==Symbol::ENUM_ELM) ? VAR_ENUM : VAR_NONE);
  366. T->level =(parent ? parent->level+1 : 0);
  367. T->token_index=token_index;
  368. T->source =source;
  369. FlagSet(T->modifiers, Symbol::MODIF_DATA_TYPE , type==Symbol::CLASS || type==Symbol::ENUM || type==Symbol::TYPEDEF || type==Symbol::TYPENAME);
  370. FlagSet(T->modifiers, Symbol::MODIF_FOLLOW_BY_SPACE , type==Symbol::ENUM);
  371. FlagSet(T->modifiers, Symbol::MODIF_SKIP_SUGGESTIONS, T->isFunc() || type==Symbol::SPACE || type==Symbol::LABEL);
  372. FlagSet(T->modifiers, Symbol::MODIF_TRANSPARENT , type==Symbol::FUNC_LIST);
  373. }
  374. return T;
  375. }
  376. SymbolDef& require(C Str &name)
  377. {
  378. super::require(name);
  379. T->valid++;
  380. return T;
  381. }
  382. ~SymbolDef()
  383. {
  384. if(T())
  385. {
  386. T->valid--;
  387. if(!T->valid)
  388. {
  389. if(T->isFunc())
  390. {
  391. SymbolPtr func_list; if(func_list.find(GetPath(T->full_name)))REPA(func_list->funcs)if(func_list->funcs[i]==T())func_list->funcs.remove(i);
  392. }
  393. T->clear();
  394. }
  395. }
  396. }
  397. SymbolDef() {}
  398. NO_COPY_CONSTRUCTOR(SymbolDef);
  399. };
  400. /******************************************************************************/
  401. Str SymbolToPath (C Str &s);
  402. Str PathToSymbol(C Str &s);
  403. Str SymbolGetBase (C Str &s);
  404. Str SymbolGetPath (C Str &s);
  405. Str NamelessName(Symbol *parent);
  406. Symbol* GetFinalSymbol(Symbol *symbol, Memc<Symbol::Modif> *templates=null);
  407. SymbolPtr FindChild (C Str &name, Symbol *parent, Memc<Symbol::Modif> *parent_templates=null, Bool allow_base=true, Bool allow_self=true, RecTest &rt=ConstCast(RecTest()));
  408. SymbolPtr FindSymbol(C Str &name, Symbol *parent);
  409. SymbolPtr FindSymbol(C Str &name, Symbol *parent, Memc<SymbolPtr> &usings);
  410. void AddBaseTemplates(Memc<Symbol::Modif> &templates, Symbol &Class, RecTest &rt=ConstCast(RecTest()));
  411. /******************************************************************************/
  412. } // namespace
  413. #endif
  414. /******************************************************************************/