compiler/libec Improvements to conversion from AST->Type class, and to outputting...
[sdk] / ide / src / designer / findParams.ec
1 import "ide"
2
3 //extern Class thisClass;
4 extern Class insideClass;
5 extern Type instanceType;
6 extern char * instanceName;
7 extern Expression paramsInsideExp;
8 extern int paramsID;
9 extern Type functionType;
10
11 static bool insideParams;
12 static Class currentClass;
13 static bool isAfterEqual;
14 static bool allocedDummyExp;
15
16 static bool InsideIncl(Location loc, int line, int charPos)
17 {
18    /*
19    return (loc.start.line < line || (loc.start.line == line && loc.start.charPos <= charPos)) && 
20           (loc.end.line > line || (loc.end.line == line && loc.end.charPos >= charPos));
21           */
22    return !loc.start.included && (loc.start.line < line || (loc.start.line == line && loc.start.charPos <= charPos)) && 
23           (loc.end.line > line || (loc.end.line == line && loc.end.charPos >= charPos));
24 }
25
26 static bool Inside(Location loc, int line, int charPos)
27 {
28    return !loc.start.included && (loc.start.line < line || (loc.start.line == line && loc.start.charPos < charPos)) && 
29           (loc.end.line > line || (loc.end.line == line && loc.end.charPos > charPos));
30 }
31
32 static bool InsideEndIncl(Location loc, int line, int charPos)
33 {
34    return !loc.start.included && (loc.start.line < line || (loc.start.line == line && loc.start.charPos < charPos)) && 
35           (loc.end.line > line || (loc.end.line == line && loc.end.charPos >= charPos));
36 }
37
38 Identifier FindParamsIdentifier(Identifier id, int line, int charPos)
39 {
40    //if(id.loc.end.line == line && id.loc.end.charPos == charPos)
41    //if(InsideIncl(&id.loc.end.line == line && id.loc.end.charPos == charPos)
42    return id;
43    return null;
44 }
45
46 Identifier FindParamsExpression(Expression exp, int line, int charPos)
47 {
48    Identifier idResult = null;
49    Expression oldExp = paramsInsideExp;
50
51    paramsInsideExp = exp;
52    switch(exp.type)
53    {
54       case newExp:
55          if(InsideIncl(&exp._new.size.loc, line, charPos))
56          {
57             idResult = FindParamsExpression(exp._new.size, line, charPos);
58             if(idResult) return idResult;
59          }
60          break;
61       case renewExp:
62          if(InsideIncl(&exp._renew.exp.loc, line, charPos))
63          {
64             idResult = FindParamsExpression(exp._renew.exp, line, charPos);
65             if(idResult) return idResult;
66          }
67          if(InsideIncl(&exp._renew.size.loc, line, charPos))
68          {
69             idResult = FindParamsExpression(exp._renew.size, line, charPos);
70             if(idResult) return idResult;
71          }
72          break;
73       case identifierExp:
74       case constantExp:
75          idResult = FindParamsIdentifier(exp.identifier, line, charPos);
76          if(idResult) return idResult;
77          //return (void *)-1;
78          break;
79       case instanceExp:
80          if(InsideIncl(&exp.instance.loc, line, charPos))
81          {
82             idResult = FindParamsInstance(exp.instance, line, charPos);
83             if(idResult) return idResult;
84          }
85          break;
86       case stringExp:
87          break;
88       case opExp:
89          if(exp.op.exp1)
90          {
91             if(InsideIncl(&exp.op.exp1.loc, line, charPos))
92             {
93                idResult = FindParamsExpression(exp.op.exp1, line, charPos);
94                if(idResult) return idResult;
95             }
96          }
97          if(exp.op.exp2)
98          {
99             // Changed this here, assuming this was changed first in findCtx and not needed here...
100             // Bug when "a = atoi()" parameters popup dissappear when on the a of atoi
101             if(InsideIncl(&exp.op.exp2.loc, line, charPos))
102             //if(InsideEndIncl(&exp.op.exp2.loc, line, charPos))
103             {
104                idResult = FindParamsExpression(exp.op.exp2, line, charPos);
105                if(idResult) return idResult;
106             }
107             paramsInsideExp = exp.op.exp2;
108          }
109          break;
110       case bracketsExp:
111       {
112          Expression expression;
113          
114          for(expression = exp.list->first; expression; expression = expression.next)
115          {
116             if(InsideIncl(&expression.loc, line, charPos))
117             {
118                idResult = FindParamsExpression(expression, line, charPos);
119                if(idResult) return idResult;
120             }
121          }
122          break;
123       }
124       case indexExp:
125       {
126          Expression expression;
127          if(InsideIncl(&exp.index.exp.loc, line, charPos))
128          {
129             idResult = FindParamsExpression(exp.index.exp, line, charPos);
130             if(idResult) return idResult;
131          }
132          
133          for(expression = exp.index.index->first; expression; expression = expression.next)
134          {
135             if(InsideIncl(&expression.loc, line, charPos))
136             {
137                idResult = FindParamsExpression(expression, line, charPos);
138                if(idResult) return idResult;
139             }
140          }
141          break;
142       }
143       case callExp:
144       {
145          int arg;
146          Type type = exp.call.exp.expType;
147
148          if(InsideIncl(&exp.call.exp.loc, line, charPos))
149          {
150             idResult = FindParamsExpression(exp.call.exp, line, charPos);
151             // Check for type here?
152             if(!functionType && !instanceType)
153             {
154                functionType = type;
155                if(paramsInsideExp == exp.call.exp) 
156                   paramsInsideExp = exp;
157             }
158             if(idResult) return idResult;
159          }
160          
161          if(exp.call.argLoc.start.line > line || (line == exp.call.argLoc.start.line && exp.call.argLoc.start.charPos >= charPos))
162             arg = -1;
163          else 
164             arg = 0;
165
166          if(exp.call.arguments)
167          {
168             Expression expression;
169
170             for(expression = exp.call.arguments->first; expression; expression = expression.next)
171             {
172                if(InsideIncl(&expression.loc, line, charPos) || (expression.loc.end.line > line || (line == expression.loc.end.line && expression.loc.end.charPos > charPos)))
173                {
174                   idResult = FindParamsExpression(expression, line, charPos);
175                   insideParams = true;
176                   // TOCHECK: Verify && vs || priority here
177                   if((functionType && paramsID != -1) || instanceType)
178                      return (void *)-1;
179                   break;
180                }
181                if(expression.next)
182                   arg++;
183             }
184
185             if(exp.call.argLoc.end.line < line || (line == exp.call.argLoc.end.line && exp.call.argLoc.end.charPos <= charPos))
186                arg = -1;
187             else if(arg > -1)
188                insideParams = true;
189
190             if(type && (type.kind == functionType || type.kind == methodType))
191             {
192                int c;
193                Type param;
194
195                paramsInsideExp = exp;
196                functionType = type;
197                paramsID = arg;
198
199                for(param = type.params.first, c = 0; c<arg && param; c++, param = (param.kind == ellipsisType ? param : param.next));
200                if(!param) paramsID = -1;
201             }
202             return (void *)-1;
203          }
204          break;
205       }
206       case memberExp:
207          if(InsideIncl(&exp.member.exp.loc, line, charPos))
208          {
209             idResult = FindParamsExpression(exp.member.exp, line, charPos);
210             if(idResult) return idResult;
211          }
212          break;
213       case pointerExp:
214          if(InsideIncl(&exp.member.exp.loc, line, charPos))
215          {
216             idResult = FindParamsExpression(exp.member.exp, line, charPos);
217             if(idResult) return idResult;
218          }
219          break;
220       case typeSizeExp:
221          break;
222       case castExp:
223          if(InsideIncl(&exp.cast.exp.loc, line, charPos))
224          {
225             idResult = FindParamsExpression(exp.cast.exp, line, charPos);
226             if(idResult) return idResult;
227          }
228          break;
229       case conditionExp:
230          if(Inside(&exp.cond.cond.loc, line, charPos))
231          {
232             idResult = FindParamsExpression(exp.cond.cond, line, charPos);
233             if(idResult) return idResult;
234          }
235
236          {
237             Expression expression;
238             for(expression = exp.cond.exp->first; expression; expression = expression.next)
239             {
240                if(InsideIncl(&expression.loc, line, charPos))
241                {
242                   idResult = FindParamsExpression(expression, line, charPos);
243                   if(idResult) return idResult;
244                }
245             }
246          }
247          if(InsideIncl(&exp.cond.elseExp.loc, line, charPos))
248          {
249             idResult = FindParamsExpression(exp.cond.elseExp, line, charPos);
250             if(idResult) return idResult;
251          }
252          break;
253    }
254    paramsInsideExp = oldExp;
255    return null;
256 }
257
258 static Identifier FindParamsStatement(Statement stmt, int line, int charPos)
259 {
260    Identifier idResult;
261
262    switch(stmt.type)
263    {
264       case labeledStmt:
265          if(InsideIncl(&stmt.labeled.stmt.loc, line, charPos))
266             return FindParamsStatement(stmt.labeled.stmt, line, charPos);
267          break;
268       case caseStmt:
269          if(stmt.caseStmt.exp)
270          {
271             if(InsideIncl(&stmt.caseStmt.exp.loc, line, charPos))
272                return FindParamsExpression(stmt.caseStmt.exp, line, charPos);
273          }
274
275          if(stmt.caseStmt.stmt)
276          {
277             if(InsideIncl(&stmt.caseStmt.stmt.loc, line, charPos))
278                return FindParamsStatement(stmt.caseStmt.stmt, line, charPos);
279          }
280          break;
281       case badDeclarationStmt:
282       {
283          Declaration decl = stmt.decl;
284          if(InsideIncl(&decl.loc, line, charPos))
285          {
286             idResult = FindParamsDeclaration(decl, line, charPos);
287             if(idResult) return idResult;
288          }
289          break;
290       }
291       case compoundStmt:
292       {
293          if(!stmt.compound.isSwitch)
294             SetCurrentContext(stmt.compound.context);
295          if(stmt.compound.declarations)
296          {
297             Declaration decl;
298             for(decl = stmt.compound.declarations->first; decl; decl = decl.next)
299             {
300                if(InsideIncl(&decl.loc, line, charPos))
301                {
302                   idResult = FindParamsDeclaration(decl, line, charPos);
303                   if(idResult) return idResult;
304                }
305             }
306          }
307          if(stmt.compound.statements)
308          {
309             Statement statement;
310             for(statement = stmt.compound.statements->first; statement; statement = statement.next)
311             {
312                if(InsideIncl(&statement.loc, line, charPos))
313                {
314                   idResult = FindParamsStatement(statement, line, charPos);
315                   if(idResult) return idResult;
316                }
317             }
318          }
319          return (void *)-1;
320          //curContext = stmt.compound.context.parent;
321          //break;
322       }
323       case expressionStmt:
324       {
325          if(stmt.expressions)
326          {
327             Expression exp;
328             for(exp = stmt.expressions->first; exp; exp = exp.next)
329             {
330                if(InsideIncl(&exp.loc, line, charPos))
331                {
332                   idResult = FindParamsExpression(exp, line, charPos);
333                   if(idResult) return idResult;
334                }
335             }
336          }
337          break;
338       }
339       case ifStmt:
340       {
341          Expression exp;
342          for(exp = stmt.ifStmt.exp->first; exp; exp = exp.next)
343          {
344             if(InsideIncl(&exp.loc, line, charPos))
345             {
346                idResult = FindParamsExpression(exp, line, charPos);
347                if(idResult) return idResult;
348             }
349          }
350          if(stmt.ifStmt.stmt)
351          {
352             if(InsideIncl(&stmt.ifStmt.stmt.loc, line, charPos))
353             {
354                idResult = FindParamsStatement(stmt.ifStmt.stmt, line, charPos);
355                if(idResult) return idResult;
356             }
357          }
358          if(stmt.ifStmt.elseStmt)
359          {
360             if(InsideIncl(&stmt.ifStmt.elseStmt.loc, line, charPos))
361                return FindParamsStatement(stmt.ifStmt.elseStmt, line, charPos);
362          }
363          break;
364       }
365       case switchStmt:
366       {
367          Expression exp;
368          for(exp = stmt.switchStmt.exp->first; exp; exp = exp.next)
369          {
370             if(InsideIncl(&exp.loc, line, charPos))
371             {
372                idResult = FindParamsExpression(exp, line, charPos);
373                if(idResult) return idResult;
374             }
375          }
376          if(stmt.switchStmt.stmt && InsideIncl(&stmt.switchStmt.stmt.loc, line, charPos))
377             return FindParamsStatement(stmt.switchStmt.stmt, line, charPos);
378          break;
379       }
380       case whileStmt:
381       {
382          if(stmt.whileStmt.exp)
383          {
384             Expression exp;
385             for(exp = stmt.whileStmt.exp->first; exp; exp = exp.next)
386             {
387                if(InsideIncl(&exp.loc, line, charPos))
388                {
389                   idResult = FindParamsExpression(exp, line, charPos);
390                   if(idResult) return idResult;
391                }
392             }
393          }
394          if(stmt.whileStmt.stmt && InsideIncl(&stmt.whileStmt.stmt.loc, line, charPos))
395             return FindParamsStatement(stmt.whileStmt.stmt, line, charPos);
396          break;
397       }
398       case doWhileStmt:
399       {
400          Expression exp;
401
402          if(stmt.doWhile.stmt && InsideIncl(&stmt.doWhile.stmt.loc, line, charPos))
403          {
404             idResult = FindParamsStatement(stmt.doWhile.stmt, line, charPos);
405             if(idResult) return idResult;
406          }
407
408          if(stmt.doWhile.exp)
409          {
410             for(exp = stmt.doWhile.exp->first; exp; exp = exp.next)
411             {
412                if(InsideIncl(&exp.loc, line, charPos))
413                {
414                   idResult = FindParamsExpression(exp, line, charPos);
415                   if(idResult) return idResult;
416                }
417             }
418          }
419          break;
420       }
421       case forStmt:
422       {
423          Expression exp;
424
425          if(stmt.forStmt.init && InsideIncl(&stmt.forStmt.init.loc, line, charPos))
426          {
427             idResult = FindParamsStatement(stmt.forStmt.init, line, charPos);
428             if(idResult) return idResult;
429          }
430          
431          if(stmt.forStmt.check && InsideIncl(&stmt.forStmt.check.loc, line, charPos))
432          {
433             idResult = FindParamsStatement(stmt.forStmt.check, line, charPos);
434             if(idResult) return idResult;
435          }
436          
437          if(stmt.forStmt.increment)
438          {
439             for(exp = stmt.forStmt.increment->first; exp; exp = exp.next)
440             {
441                if(InsideIncl(&exp.loc, line, charPos))
442                {
443                   idResult = FindParamsExpression(exp, line, charPos);
444                   if(idResult) return idResult;
445                }
446             }
447          }
448
449          if(stmt.forStmt.stmt)
450             return FindParamsStatement(stmt.forStmt.stmt, line, charPos);
451          break;
452       }
453       case gotoStmt:
454          break;
455       case continueStmt:
456          break;
457       case breakStmt:
458          break;
459       case returnStmt:
460          if(stmt.expressions)
461          {
462             Expression exp;
463             
464             for(exp = stmt.expressions->first; exp; exp = exp.next)
465             {
466                if(InsideIncl(&exp.loc, line, charPos))
467                {
468                   idResult = FindParamsExpression(exp, line, charPos);
469                   if(idResult) return idResult;
470                }
471             }
472          }
473          break;
474       case fireWatchersStmt:
475       case stopWatchingStmt:
476       {
477          Identifier _watch;
478          if(stmt._watch.watcher && InsideIncl(&stmt._watch.watcher.loc, line, charPos))
479          {
480             idResult = FindParamsExpression(stmt._watch.watcher, line, charPos);
481             if(idResult) return idResult;
482          }
483          if(stmt._watch.object && InsideIncl(&stmt._watch.object.loc, line, charPos))
484          {
485             idResult = FindParamsExpression(stmt._watch.object, line, charPos);
486             if(idResult) return idResult;
487          }
488          if(stmt._watch.watches)
489          {
490             for(_watch = stmt._watch.watches->first; _watch; _watch = _watch.next)
491             {
492                if(InsideIncl(&_watch.loc, line, charPos))
493                {
494                   idResult = FindParamsIdentifier(_watch, line, charPos);
495                   if(idResult) return idResult;
496                }
497             }
498          }
499          break;
500       }
501       case watchStmt:
502       {
503          PropertyWatch _watch;
504          if(stmt._watch.watcher && InsideIncl(&stmt._watch.watcher.loc, line, charPos))
505          {
506             idResult = FindParamsExpression(stmt._watch.watcher, line, charPos);
507             if(idResult) return idResult;
508          }
509          if(stmt._watch.object && InsideIncl(&stmt._watch.object.loc, line, charPos))
510          {
511             idResult = FindParamsExpression(stmt._watch.object, line, charPos);
512             if(idResult) return idResult;
513          }
514          if(stmt._watch.watches)
515          {
516             for(_watch = stmt._watch.watches->first; _watch; _watch = _watch.next)
517             {
518                if(_watch.compound && InsideIncl(&_watch.compound.loc, line, charPos))
519                {
520                   idResult = FindParamsStatement(_watch.compound, line, charPos);
521                   if(idResult) return idResult;
522                }
523             }
524          }
525          break;
526       }
527    }
528    return null;
529 }
530
531 static Identifier FindParamsInitializer(Initializer initializer, int line, int charPos)
532 {
533    switch(initializer.type)
534    {
535       case listInitializer:
536       {
537          Initializer init;
538          Identifier idResult;
539          
540          for(init = initializer.list->first; init; init = init.next)
541          {
542             if(InsideIncl(&init.loc, line, charPos))
543             {
544                idResult = FindParamsInitializer(init, line, charPos);
545                if(idResult) return idResult;
546             }
547          }
548          break;
549       }
550       case expInitializer:
551          if(InsideIncl(&initializer.exp.loc, line, charPos))
552             return FindParamsExpression(initializer.exp, line, charPos);
553
554          {
555             paramsInsideExp = initializer.exp;
556             return (void *)-1;
557          }
558          break;
559    }
560    return null;
561 }
562
563 static Identifier FindParamsInitDeclarator(InitDeclarator decl, int line, int charPos)
564 {
565    if(decl.initializer && InsideIncl(&decl.initializer.loc, line, charPos))
566       return FindParamsInitializer(decl.initializer, line, charPos);
567    return null;
568 }
569
570 static Identifier FindParamsSpecifier(Specifier spec, int line, int charPos)
571 {
572    Identifier idResult;
573    switch(spec.type)
574    {
575       case enumSpecifier:
576       case structSpecifier:
577       case unionSpecifier:
578       {
579          if(spec.definitions)
580          {
581             ClassDef def;
582             for(def = spec.definitions->first; def; def = def.next)
583             {
584                // TODO: Should use FindParamsClassDef here right?
585
586                //if(def.type == ClassDefDeclaration && def.decl && def.decl.type == DeclarationStruct)
587                //   ProcessDeclaration(def.decl);
588                switch(def.type)
589                {
590                   case declarationClassDef:
591                      if(InsideIncl(&def.decl.loc, line, charPos))
592                      {
593                         idResult = FindParamsDeclaration(def.decl, line, charPos);
594                         if(idResult)
595                            return idResult;
596                      }
597                      break;
598                   case defaultPropertiesClassDef:
599                   {
600                      MemberInit init;
601                      for(init = def.defProperties->first; init; init = init.next)
602                      {
603                         if(InsideIncl(&init.realLoc, line, charPos))
604                         {
605                            Class oldThisClass = GetThisClass();
606                            Context oldTopContext = GetTopContext();
607                            SetThisClass(currentClass);
608                            idResult = FindParamsMemberInit(init, line, charPos);
609                            if(idResult)
610                               return idResult;
611                            SetThisClass(oldThisClass);
612                         }
613                      }
614                      break;
615                   }
616                   case functionClassDef:
617                      if(InsideIncl(&def.function.loc, line, charPos))
618                      {
619                         idResult = FindParamsClassFunction(def.function, line, charPos);
620
621                         if(idResult)
622                            return idResult;
623                      }
624                      break;
625                   case propertyClassDef:
626                      if(def.propertyDef)
627                      {
628                         if(InsideIncl(&def.propertyDef.loc, line, charPos))
629                         {
630                            idResult = FindParamsProperty(def.propertyDef, line, charPos);
631                            if(idResult)
632                               return idResult;
633                         }
634                      }
635                      break;
636                   case propertyWatchClassDef:
637                      if(def.propertyWatch && def.propertyWatch.compound && InsideIncl(&def.propertyWatch.compound.loc, line, charPos))
638                      {
639                         Class oldThisClass = GetThisClass();
640                         Context oldTopContext = GetTopContext();
641                         SetThisClass(currentClass);
642                         idResult = FindParamsStatement(def.propertyWatch.compound, line, charPos);
643                         if(idResult) return idResult;
644                         SetThisClass(oldThisClass);
645                      }
646                      break;
647                }
648             }
649          }
650          break;
651       }
652    }
653    return null;
654 }
655
656 static Identifier FindParamsDeclaration(Declaration decl, int line, int charPos)
657 {
658    Identifier idResult;
659    
660    switch(decl.type)
661    {
662       case structDeclaration:
663       {
664          Specifier spec;
665          if(decl.specifiers)
666          {
667             for(spec = decl.specifiers->first; spec; spec = spec.next)
668             {
669                if(InsideIncl(&spec.loc, line, charPos))
670                {
671                   idResult = FindParamsSpecifier(spec, line, charPos);
672                   if(idResult) return idResult;
673                }
674             }
675          }
676          break;
677       }
678       case initDeclaration:
679       {
680          InitDeclarator d;
681          // Need to loop through specifiers to look for :: completion
682          if(decl.specifiers)
683          {
684             Specifier s;
685
686             for(s = decl.specifiers->first; s; s = s.next)
687             {
688                if(InsideIncl(&s.loc, line, charPos))
689                {
690                   idResult = FindParamsSpecifier(s, line, charPos);
691                   if(idResult) return idResult;
692                }
693             }
694          }
695
696          if(decl.declarators && decl.declarators->first)
697          {
698             for(d = decl.declarators->first; d; d = d.next)
699             {
700                if(InsideIncl(&d.loc, line, charPos))
701                {
702                   idResult = FindParamsInitDeclarator(d, line, charPos);
703                   if(idResult) return idResult;
704                }
705             }   
706          }
707          break;
708       }
709       case instDeclaration:
710          if(InsideIncl(&decl.inst.loc, line, charPos))
711             return FindParamsInstance(decl.inst, line, charPos);
712          break;
713    }
714    return null;
715 }
716
717 static Identifier FindParamsFunction(FunctionDefinition func, int line, int charPos)
718 {
719    if(func.body && Inside(&func.body.loc, line, charPos))
720    {
721       Identifier idResult;
722       
723       Identifier id = GetDeclId(func.declarator);
724       Symbol symbol = func.declarator.symbol;
725       Type type = symbol.type;
726       Class oldThisClass = GetThisClass();
727       Context oldTopContext = GetTopContext();
728
729       idResult = FindParamsStatement(func.body, line, charPos);
730       if(idResult)
731          return idResult;
732
733       SetThisClass(oldThisClass);
734       SetTopContext(oldTopContext);
735    }
736    return null;
737 }
738
739 static Identifier FindParamsMemberInit(MemberInit init, int line, int charPos)
740 {
741    Identifier idResult;
742    if(init.initializer && InsideIncl(&init.initializer.loc, line, charPos))
743    {
744       idResult = FindParamsInitializer(init.initializer, line, charPos);
745       if(idResult)
746       {
747          if(init.identifiers && init.identifiers->first)
748             isAfterEqual = true;
749          return idResult;
750       }
751    }
752    if(init.identifiers && init.identifiers->first && InsideIncl(&((Identifier)init.identifiers->first).loc, line, charPos))
753    {
754       idResult = FindParamsIdentifier(init.identifiers->first, line, charPos);
755       if(idResult)
756          return idResult;
757    }
758    if(init.initializer && Inside(&init.initializer.loc, line, charPos))
759    {
760       if(init.identifiers && init.identifiers->first)
761          isAfterEqual = true;
762
763       if(init.initializer.type == expInitializer)
764       {
765          paramsInsideExp = init.initializer.exp;
766          return (void *)-1;
767       }
768    }
769    return null;
770 }
771
772 static Identifier FindParamsInstance(Instantiation inst, int line, int charPos)
773 {
774    Identifier idResult = null;
775    Class oldThisClass = GetThisClass();
776    Symbol sym = inst._class ? FindClass(inst._class.name) : null;
777    bool insideSomething = false;
778    bool insideBrackets;
779    Method method = null;
780
781    Class curClass = null;
782    DataMember curMember = null;
783    DataMember dataMember = null;
784    DataMember subMemberStack[256];
785    int subMemberStackPos = 0;
786
787    if(sym)
788       SetThisClass(sym.registered);
789
790    insideBrackets = !(inst.insideLoc.start.line > line || (line == inst.insideLoc.start.line && inst.insideLoc.start.charPos > charPos));
791    if(insideBrackets)
792    {
793       // Start with first member
794       eClass_FindNextMember(GetThisClass(), &curClass, &curMember, subMemberStack, &subMemberStackPos);
795       dataMember = curMember;
796    }
797
798    if(inst.members)
799    {
800       MembersInit init;
801       MemberInit memberInit;
802       for(init = inst.members->first; init; init = init.next)
803       {
804          if(init.loc.start.line > line || (line == init.loc.start.line && init.loc.start.charPos > charPos))
805             break;
806
807          if(init.type == dataMembersInit && init.dataMembers && insideBrackets && sym)
808          {
809             for(memberInit = init.dataMembers->first; memberInit; memberInit = memberInit.next)
810             {
811                isAfterEqual = false;
812
813                if(memberInit.identifiers && memberInit.identifiers->first)
814                {
815                   DataMember _subMemberStack[256];
816                   int _subMemberStackPos = 0;
817                   DataMember thisMember = eClass_FindDataMember(GetThisClass(), ((Identifier)memberInit.identifiers->first).string, GetPrivateModule(), _subMemberStack, &_subMemberStackPos);
818                   if(!thisMember)
819                   {
820                      // WARNING: Brackets needed until precomp fix
821                      thisMember = (DataMember)eClass_FindProperty(GetThisClass(), ((Identifier)memberInit.identifiers->first).string, GetPrivateModule());
822                   }
823                   if(thisMember)
824                   {
825                      method = null;
826                      dataMember = thisMember;
827                      if(thisMember.memberAccess == publicAccess)
828                      {
829                         curMember = thisMember;
830                         curClass = thisMember._class;
831                         memcpy(subMemberStack, _subMemberStack, sizeof(DataMember) * _subMemberStackPos);
832                         subMemberStackPos = _subMemberStackPos;
833                      }
834                   }
835                   else
836                      method = eClass_FindMethod(GetThisClass(), ((Identifier)memberInit.identifiers->first).string, GetPrivateModule());
837                }
838
839                if(!idResult && InsideIncl(&memberInit.realLoc, line, charPos))
840                   idResult = FindParamsMemberInit(memberInit, line, charPos);
841
842                if(InsideIncl(&memberInit.realLoc, line, charPos) || (memberInit.realLoc.end.line > line || (line == memberInit.realLoc.end.line && memberInit.realLoc.end.charPos > charPos)))
843                {
844                   if(memberInit.identifiers && memberInit.identifiers->first && InsideIncl(&memberInit.loc, line, charPos) && !dataMember)
845                      insideBrackets = false;
846                   break;
847                }
848                else if((!memberInit.identifiers || !memberInit.identifiers->first || curMember) && (memberInit.next || !Inside(&init.loc, line, charPos)))
849                {
850                   method = null;
851                   eClass_FindNextMember(GetThisClass(), &curClass, &curMember, subMemberStack, &subMemberStackPos);
852                   dataMember = curMember;
853                }
854             }
855          }
856
857          if(InsideIncl(&init.loc, line, charPos))
858          {
859             if(Inside(&init.loc, line, charPos))
860                if(init.type == methodMembersInit)
861                   insideSomething = true;
862
863             if(init.type == methodMembersInit && Inside(&init.function.loc, line, charPos))
864             {
865                idResult = FindParamsClassFunction(init.function, line, charPos);
866             }
867
868             if(Inside(&init.loc, line, charPos))
869                break;
870          }
871
872          if((init.loc.end.line > line || (line == init.loc.end.line && init.loc.end.charPos > charPos)))
873             break;
874       }
875    }
876    if(!insideParams && sym && sym.registered && InsideIncl(&inst.insideLoc, line, charPos) && insideBrackets && !insideSomething)
877    {
878       if(dataMember && !method) 
879       {
880          if(!dataMember.dataType)
881             dataMember.dataType = ProcessTypeString(dataMember.dataTypeString, false);
882          paramsInsideExp = MkExpDummy();
883          allocedDummyExp = true;
884          paramsInsideExp.destType = dataMember.dataType;
885          if(paramsInsideExp.destType) paramsInsideExp.destType.refCount++;
886
887          functionType = null;
888          instanceType = paramsInsideExp.destType;
889          instanceName = dataMember.name;
890          insideParams = true;
891       }
892    }
893
894    if(!insideParams && sym && sym.registered && InsideIncl(&inst.insideLoc, line, charPos) && !insideSomething && insideBrackets)
895    {
896       if(method)
897       {
898          paramsInsideExp = MkExpDummy();
899          allocedDummyExp = true;
900          paramsInsideExp.destType = method.dataType;
901          if(paramsInsideExp.destType) paramsInsideExp.destType.refCount++;
902
903          functionType = null;
904          instanceType = paramsInsideExp.destType;
905          instanceName = method.name;
906       }
907       insideParams = true;
908    }
909
910    if(sym && !insideSomething && InsideIncl(&inst.insideLoc, line, charPos))
911    {
912       if(!isAfterEqual && !insideClass)
913          insideClass = sym.registered;
914
915       if(isAfterEqual && currentClass)
916          SetThisClass(currentClass);
917
918       return idResult ? idResult : (void *) -1;
919    }
920
921    if(idResult)
922       return idResult;
923
924    SetThisClass(oldThisClass);
925
926    return null;
927 }
928
929 static Identifier FindParamsClassFunction(ClassFunction func, int line, int charPos)
930 {
931    if(func.body && Inside(&func.body.loc, line, charPos))
932    {
933       Identifier idResult;
934       
935       Identifier id = GetDeclId(func.declarator);
936       Symbol symbol = func.declarator ? func.declarator.symbol : null;
937       Type type = symbol ? symbol.type : null;
938       Class oldThisClass = GetThisClass();
939       Context oldTopContext = GetTopContext();
940       SetThisClass((type && type.thisClass) ? type.thisClass.registered : currentClass);
941
942       idResult = FindParamsStatement(func.body, line, charPos);
943       if(idResult)
944          return idResult;
945
946       SetThisClass(oldThisClass);
947       SetTopContext(oldTopContext);
948    }
949    return null;
950 }
951
952 static Identifier FindParamsProperty(PropertyDef def, int line, int charPos)
953 {
954    Identifier result;
955    if(def.getStmt && Inside(&def.getStmt.loc, line, charPos))
956    {
957       Class oldThisClass = GetThisClass();
958       Context oldTopContext = GetTopContext();
959       SetThisClass(currentClass);
960       result = FindParamsStatement(def.getStmt, line, charPos);
961       if(result) return result;
962       SetThisClass(oldThisClass);
963    }
964    if(def.setStmt && Inside(&def.setStmt.loc, line, charPos))
965    {
966       Class oldThisClass = GetThisClass();
967       Context oldTopContext = GetTopContext();
968       SetThisClass(currentClass);
969       result = FindParamsStatement(def.setStmt, line, charPos);
970       if(result) return result;
971       SetThisClass(oldThisClass);
972    }
973    return null;
974 }
975
976 static Identifier FindParamsClassDef(ClassDef def, int line, int charPos)
977 {
978    Identifier idResult;
979    switch(def.type)
980    {
981       case declarationClassDef:
982          if(Inside(&def.decl.loc, line, charPos))
983          {
984             idResult = FindParamsDeclaration(def.decl, line, charPos);
985             if(idResult)
986                return idResult;
987          }
988          break;
989       case defaultPropertiesClassDef:
990       {
991          MemberInit init;
992          for(init = def.defProperties->first; init; init = init.next)
993          {
994             if(InsideIncl(&init.realLoc, line, charPos))
995             {
996                Class oldThisClass = GetThisClass();
997                Context oldTopContext = GetTopContext();
998                SetThisClass(currentClass);
999                idResult = FindParamsMemberInit(init, line, charPos);
1000                if(idResult)
1001                   return idResult;
1002                SetThisClass(oldThisClass);
1003             }
1004          }
1005          break;
1006       }
1007       case functionClassDef:
1008          if(Inside(&def.function.loc, line, charPos))
1009          {
1010             idResult = FindParamsClassFunction(def.function, line, charPos);
1011             if(idResult)
1012                return idResult;
1013          }
1014          break;
1015       case propertyClassDef:
1016          if(def.propertyDef)
1017          {
1018             if(Inside(&def.propertyDef.loc, line, charPos))
1019             {
1020                idResult = FindParamsProperty(def.propertyDef, line, charPos);
1021                if(idResult)
1022                   return idResult;
1023             }
1024          }
1025          break;
1026       case propertyWatchClassDef:
1027          if(def.propertyWatch && def.propertyWatch.compound && Inside(&def.propertyWatch.compound.loc, line, charPos))
1028          {
1029             Class oldThisClass = GetThisClass();
1030             Context oldTopContext = GetTopContext();
1031             SetThisClass(currentClass);
1032             idResult = FindParamsStatement(def.propertyWatch.compound, line, charPos);
1033             if(idResult) return idResult;
1034             SetThisClass(oldThisClass);
1035          }
1036          break;
1037    }
1038    return null;
1039 }
1040
1041 static Identifier FindParamsClass(ClassDefinition _class, int line, int charPos)
1042 {
1043    Identifier idResult;
1044    bool insideSomething = false;
1045    if(_class.definitions)
1046    {
1047       ClassDef def;
1048       for(def = _class.definitions->first; def; def = def.next)
1049       {
1050          if(def.type == defaultPropertiesClassDef ? InsideIncl(&def.loc, line, charPos) : Inside(&def.loc, line, charPos) )
1051          {
1052             if(def.type != defaultPropertiesClassDef)
1053                insideSomething = true;
1054
1055             idResult = FindParamsClassDef(def, line, charPos);
1056             if(idResult)
1057                return idResult;
1058          }
1059       }
1060    }
1061    if(!insideSomething)
1062    {
1063       insideClass = _class.symbol.registered;
1064       return (void *)-1;
1065    }
1066    return null;
1067 }
1068
1069 Identifier FindParamsTree(OldList ast, int line, int charPos)
1070 {
1071    Identifier idResult;
1072    External external;
1073
1074    if(allocedDummyExp)
1075    {
1076       FreeExpression(paramsInsideExp);
1077       allocedDummyExp = false;
1078    }
1079
1080    insideClass = null;
1081    paramsInsideExp = null;
1082    SetThisClass(null);
1083    paramsID = -1;
1084    functionType = null;
1085    instanceType = null;
1086    instanceName = null;
1087    insideParams = false;
1088    isAfterEqual = false;
1089
1090    if(ast != null)
1091    {
1092       for(external = ast.first; external; external = external.next)
1093       {
1094          switch(external.type)
1095          {
1096             case functionExternal: 
1097                if(Inside(&external.loc, line, charPos))
1098                {
1099                   idResult = FindParamsFunction(external.function, line, charPos);
1100                   if(idResult)
1101                      return (idResult == (void *)-1) ? null : idResult;
1102                }
1103                break;
1104             case declarationExternal: 
1105                if(InsideIncl(&external.loc, line, charPos))
1106                {
1107                   idResult = FindParamsDeclaration(external.declaration, line, charPos);
1108                   if(idResult)
1109                      return (idResult == (void *)-1) ? null : idResult;
1110                }
1111                break;
1112             case classExternal:
1113                if(Inside(&external._class.loc, line, charPos))
1114                {
1115                   currentClass = external._class.symbol.registered;
1116                   idResult = FindParamsClass(external._class, line, charPos);
1117                   currentClass = null;
1118                   if(idResult)
1119                      return (idResult == (void *)-1) ? null : idResult;
1120                }
1121                break;
1122          }
1123       }
1124    }
1125    return null;
1126 }
1127
1128 void FindParams_Terminate()
1129 {
1130    if(allocedDummyExp)
1131    {
1132       FreeExpression(paramsInsideExp);
1133       allocedDummyExp = false;
1134    }
1135 }