Пример #1
0
 public Field(ReturnType type, string fullyQualifiedName, Modifier m, IRegion region)
 {
     this.returnType = type;
     this.FullyQualifiedName = fullyQualifiedName;
     this.region = region;
     modifiers = (ModifierEnum)m;
 }
Пример #2
0
 public Indexer(ReturnType type, ParameterCollection parameters, Modifier m, IRegion region, IRegion bodyRegion)
 {
     returnType      = type;
     this.parameters = parameters;
     this.region     = region;
     this.bodyRegion = bodyRegion;
     modifiers = (ModifierEnum)m;
 }
Пример #3
0
		public Event(string name, ReturnType type, Modifier m, IRegion region, IRegion bodyRegion)
		{
			FullyQualifiedName = name;
			returnType         = type;
			this.region        = region;
			this.bodyRegion    = bodyRegion;
			modifiers          = (ModifierEnum)m;
		}
Пример #4
0
		public Property(string fullyQualifiedName, ReturnType type, Modifier m, IRegion region, IRegion bodyRegion)
		{
			this.FullyQualifiedName = fullyQualifiedName;
			returnType = type;
			this.region = region;
			this.bodyRegion = bodyRegion;
			modifiers = (ModifierEnum)m;
		}
Пример #5
0
 public override object Visit(InvocationExpression invocationExpression, object data)
 {
     if (invocationExpression.TargetObject is FieldReferenceExpression) {
         FieldReferenceExpression field = (FieldReferenceExpression)invocationExpression.TargetObject;
         IReturnType type = field.TargetObject.AcceptVisitor(this, data) as IReturnType;
         ArrayList methods = resolver.SearchMethod(type, field.FieldName);
         resolver.ShowStatic = false;
         if (methods.Count <= 0) {
             return null;
         }
         // TODO: Find the right method
         return ((IMethod)methods[0]).ReturnType;
     } else if (invocationExpression.TargetObject is IdentifierExpression) {
         string id = ((IdentifierExpression)invocationExpression.TargetObject).Identifier;
         if (resolver.CallingClass == null) {
             return null;
         }
         IReturnType type = new ReturnType(resolver.CallingClass.FullyQualifiedName);
         ArrayList methods = resolver.SearchMethod(type, id);
         resolver.ShowStatic = false;
         if (methods.Count <= 0) {
             return null;
         }
         // TODO: Find the right method
         return ((IMethod)methods[0]).ReturnType;
     }
     // invocationExpression is delegate call
     IReturnType t = invocationExpression.AcceptChildren(this, data) as IReturnType;
     if (t == null) {
         return null;
     }
     IClass c = resolver.SearchType(t.FullyQualifiedName, resolver.CompilationUnit);
     if (c.ClassType == ClassType.Delegate) {
         ArrayList methods = resolver.SearchMethod(t, "invoke");
         if (methods.Count <= 0) {
             return null;
         }
         return ((IMethod)methods[0]).ReturnType;
     }
     return null;
 }
Пример #6
0
        public override object Visit(IndexerExpression indexerExpression, object data)
        {
            IReturnType type = (IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, data);
            if (type == null) {
                return null;
            }
            if (type.ArrayDimensions == null || type.ArrayDimensions.Length == 0) {
                // check if ther is an indexer
                if (indexerExpression.TargetObject is ThisReferenceExpression) {
                    if (resolver.CallingClass == null) {
                        return null;
                    }
                    type = new ReturnType(resolver.CallingClass.FullyQualifiedName);
                }
                ArrayList indexer = resolver.SearchIndexer(type);
                if (indexer.Count == 0) {
                    return null;
                }
                // TODO: get the right indexer
                return ((IIndexer)indexer[0]).ReturnType;
            }

            // TODO: what is a[0] if a is pointer to array or array of pointer ?
            if (type.ArrayDimensions[type.ArrayDimensions.Length - 1] != indexerExpression.Indices.Count) {
                return null;
            }
            int[] newArray = new int[type.ArrayDimensions.Length - 1];
            Array.Copy(type.ArrayDimensions, 0, newArray, 0, type.ArrayDimensions.Length - 1);
            return new ReturnType(type.Name, newArray, type.PointerNestingLevel);
        }
Пример #7
0
 public override object Visit(StackAllocExpression stackAllocExpression, object data)
 {
     ReturnType returnType = new ReturnType(stackAllocExpression.Type);
     ++returnType.PointerNestingLevel;
     return returnType;
 }
Пример #8
0
		public override object Visit(AST.ConstructorDeclaration constructorDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(constructorDeclaration.StartLocation, constructorDeclaration.EndLocation);
			DefaultRegion bodyRegion = GetRegion(constructorDeclaration.EndLocation, constructorDeclaration.Body != null ? constructorDeclaration.Body.EndLocation : new Point(-1, -1));
			
			Class c       = (Class)currentClass.Peek();
			
			Constructor constructor = new Constructor(constructorDeclaration.Modifier, region, bodyRegion);
			ParameterCollection parameters = new ParameterCollection();
			if (constructorDeclaration.Parameters != null) {
				foreach (AST.ParameterDeclarationExpression par in constructorDeclaration.Parameters) {
					ReturnType parType = new ReturnType(par.TypeReference);
					Parameter p = new Parameter(par.ParameterName, parType);
					parameters.Add(p);
				}
			}
			constructor.Parameters = parameters;
			c.Methods.Add(constructor);
			return null;
		}
Пример #9
0
		ReturnType SearchVariable(string name)
		{
//			Console.WriteLine("Searching Variable");
//			
//			Console.WriteLine("LookUpTable has {0} entries", lookupTableVisitor.variables.Count);
//			Console.WriteLine("Listing Variables:");
			IDictionaryEnumerator enumerator = lookupTableVisitor.variables.GetEnumerator();
			while (enumerator.MoveNext()) {
				Console.WriteLine(enumerator.Key);
			}
//			Console.WriteLine("end listing");
			ArrayList variables = (ArrayList)lookupTableVisitor.variables[name];
			if (variables == null || variables.Count <= 0) {
//				Console.WriteLine(name + " not in LookUpTable");
				return null;
			}
			
			ReturnType found = null;
			foreach (LocalLookupVariable v in variables) {
//				Console.WriteLine("Position: ({0}/{1})", v.StartPos, v.EndPos);
				if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos)) {
					found = new ReturnType(v.TypeRef);
//					Console.WriteLine("Variable found");
					break;
				}
			}
			if (found == null) {
//				Console.WriteLine("No Variable found");
				return null;
			}
			return found;
		}
Пример #10
0
 public Parameter(string name, ReturnType type)
 {
     this.name = name;
     returnType = type;
 }
Пример #11
0
		public override object Visit(AST.IndexerDeclaration indexerDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(indexerDeclaration.StartLocation, indexerDeclaration.EndLocation);
			DefaultRegion bodyRegion = GetRegion(indexerDeclaration.BodyStart,     indexerDeclaration.BodyEnd);
			ParameterCollection parameters = new ParameterCollection();
			Indexer i = new Indexer(new ReturnType(indexerDeclaration.TypeReference), parameters, indexerDeclaration.Modifier, region, bodyRegion);
			if (indexerDeclaration.Parameters != null) {
				foreach (AST.ParameterDeclarationExpression par in indexerDeclaration.Parameters) {
					ReturnType parType = new ReturnType(par.TypeReference);
					Parameter p = new Parameter(par.ParameterName, parType);
					parameters.Add(p);
				}
			}
			Class c = (Class)currentClass.Peek();
			c.Indexer.Add(i);
			return null;
		}
Пример #12
0
		public override object Visit(AST.EventDeclaration eventDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation);
			DefaultRegion bodyRegion = GetRegion(eventDeclaration.BodyStart,     eventDeclaration.BodyEnd);
			ReturnType type = new ReturnType(eventDeclaration.TypeReference);
			Class c = (Class)currentClass.Peek();
			Event e = null;
			
			if (eventDeclaration.VariableDeclarators != null) {
				foreach (JRefactory.Parser.AST.VariableDeclaration varDecl in eventDeclaration.VariableDeclarators) {
					e = new Event(varDecl.Name, type, eventDeclaration.Modifier, region, bodyRegion);
					c.Events.Add(e);
				}
			} else {
				e = new Event(eventDeclaration.Name, type, eventDeclaration.Modifier, region, bodyRegion);
				c.Events.Add(e);
			}
			return null;
		}
Пример #13
0
		public override object Visit(AST.PropertyDeclaration propertyDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation);
			DefaultRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart,     propertyDeclaration.BodyEnd);
			
			ReturnType type = new ReturnType(propertyDeclaration.TypeReference);
			Class c = (Class)currentClass.Peek();
			
			Property property = new Property(propertyDeclaration.Name, type, propertyDeclaration.Modifier, region, bodyRegion);
			c.Properties.Add(property);
			return null;
		}
Пример #14
0
		public override object Visit(AST.FieldDeclaration fieldDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(fieldDeclaration.StartLocation, fieldDeclaration.EndLocation);
			Class c = (Class)currentClass.Peek();
			ReturnType type = null;
			if (fieldDeclaration.TypeReference == null) {
				Debug.Assert(c.ClassType == ClassType.Enum);
			} else {
				type = new ReturnType(fieldDeclaration.TypeReference);
			}
			if (currentClass.Count > 0) {
				foreach (AST.VariableDeclaration field in fieldDeclaration.Fields) {
					Field f = new Field(type, field.Name, fieldDeclaration.Modifier, region);
					
					c.Fields.Add(f);
				}
			}
			return null;
		}
Пример #15
0
 public override object Visit(ArrayCreateExpression arrayCreateExpression, object data)
 {
     ReturnType type = new ReturnType(arrayCreateExpression.CreateType);
     if (arrayCreateExpression.Parameters != null && arrayCreateExpression.Parameters.Count > 0) {
         int[] newRank = new int[arrayCreateExpression.Rank.Length + 1];
         newRank[0] = arrayCreateExpression.Parameters.Count - 1;
         Array.Copy(type.ArrayDimensions, 0, newRank, 1, type.ArrayDimensions.Length);
         type.ArrayDimensions = newRank;
     }
     return type;
 }
Пример #16
0
		public ResolveResult Resolve(IParserContext parserService, string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent)
		{
			Console.WriteLine("Start Resolving");
			if (expression == null) {
				return null;
			}
			expression = expression.TrimStart(null);
			if (expression == "") {
				return null;
			}
			if (expression.StartsWith("using ")) {
				// expression[expression.Length - 1] != '.'
				// the period that causes this Resove() is not part of the expression
				if (expression[expression.Length - 1] == '.') {
					return null;
				}
				int i;
				for (i = expression.Length - 1; i >= 0; --i) {
					if (!(Char.IsLetterOrDigit(expression[i]) || expression[i] == '_' || expression[i] == '.')) {
						break;
					}
				}
				// no Identifier before the period
				if (i == expression.Length - 1) {
					return null;
				}
				string t = expression.Substring(i + 1);
//				Console.WriteLine("in Using Statement");
				string[] namespaces = parserService.GetNamespaceList(t);
				if (namespaces == null || namespaces.Length <= 0) {
					return null;
				}
				return new ResolveResult(namespaces);
			}
			
			Console.WriteLine("Not in Using");
			this.caretLine     = caretLineNumber;
			this.caretColumn   = caretColumn;
			
			this.parserService = parserService;
			IParseInformation parseInfo = parserService.GetParseInformation(fileName);
			JRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as JRefactory.Parser.AST.CompilationUnit;
			if (fileCompilationUnit == null) {
//				JRefactory.Parser.Parser fileParser = new JRefactory.Parser.Parser();
//				fileParser.Parse(new Lexer(new StringReader(fileContent)));
				Console.WriteLine("!Warning: no parseinformation!");
				return null;
			}
			/*
			//// try to find last expression in original string, it could be like " if (act!=null) act"
			//// in this case only "act" should be parsed as expression  
			!!is so!! don't change things that work
			Expression expr=null;	// tentative expression
			Lexer l=null;
			JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
			while (expression.Length > 0) {
				l = new Lexer(new StringReader(expression));
				expr = p.ParseExpression(l);
				if (l.LookAhead.val != "" && expression.LastIndexOf(l.LookAhead.val) >= 0) {
					if (expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Length > 0) 
						expression=expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Trim();
					else {
						expression=l.LookAhead.val.Trim();
						l=new Lexer(new StringReader(expression));
						expr=p.ParseExpression(l);
						break;
					}
				} else {
					if (l.Token.val!="" || expr!=null) break;
				}
			}
			//// here last subexpression should be fixed in expr
			if it should be changed in expressionfinder don't fix it here
			*/
			JRefactory.Parser.Parser p = new JRefactory.Parser.Parser();
			Lexer l = new Lexer(new StringReader(expression));
			Expression expr = p.ParseExpression(l);
			if (expr == null) {
				return null;
			}
			lookupTableVisitor = new LookupTableVisitor();
			lookupTableVisitor.Visit(fileCompilationUnit, null);
			
			TypeVisitor typeVisitor = new TypeVisitor(this);
			
			JavaVisitor cSharpVisitor = new JavaVisitor();
			cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
			if (cu != null) {
				callingClass = GetInnermostClass();
				//Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name);
			}
			//Console.WriteLine("expression = " + expr.ToString());
			IReturnType type = expr.AcceptVisitor(typeVisitor, null) as IReturnType;
			//Console.WriteLine("type visited");
			if (type == null || type.PointerNestingLevel != 0) {
//				Console.WriteLine("Type == null || type.PointerNestingLevel != 0");
				if (type != null) {
					//Console.WriteLine("PointerNestingLevel is " + type.PointerNestingLevel);
				} else {
					//Console.WriteLine("Type == null");
				}
				//// when type is null might be file needs to be reparsed - some vars were lost
				fileCompilationUnit=parserService.ParseFile(fileName, fileContent).MostRecentCompilationUnit.Tag 
					as JRefactory.Parser.AST.CompilationUnit;
				lookupTableVisitor.Visit(fileCompilationUnit,null);
				cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null);
				if (cu != null) {
					callingClass = GetInnermostClass();
				}
				type=expr.AcceptVisitor(typeVisitor,null) as IReturnType;
				if (type==null)	return null;
			}
			if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) {
				type = new ReturnType("System.Array");
			}
			Console.WriteLine("Here: Type is " + type.FullyQualifiedName);
			IClass returnClass = SearchType(type.FullyQualifiedName, cu);
			if (returnClass == null) {
				// Try if type is Namespace:
				string n = SearchNamespace(type.FullyQualifiedName, cu);
				if (n == null) {
					return null;
				}
				ArrayList content = parserService.GetNamespaceContents(n);
				ArrayList classes = new ArrayList();
				for (int i = 0; i < content.Count; ++i) {
					if (content[i] is IClass) {
						classes.Add((IClass)content[i]);
					}
				}
				string[] namespaces = parserService.GetNamespaceList(n);
				return new ResolveResult(namespaces, classes);
			}
			Console.WriteLine("Returning Result!");
			return new ResolveResult(returnClass, ListMembers(new ArrayList(), returnClass));
		}
Пример #17
0
		public override object Visit(AST.MethodDeclaration methodDeclaration, object data)
		{
			DefaultRegion region     = GetRegion(methodDeclaration.StartLocation, methodDeclaration.EndLocation);
			DefaultRegion bodyRegion = GetRegion(methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : new Point(-1, -1));
//			Console.WriteLine(region + " --- " + bodyRegion);
			ReturnType type = new ReturnType(methodDeclaration.TypeReference);
			Class c       = (Class)currentClass.Peek();
			
			Method method = new Method(String.Concat(methodDeclaration.Name), type, methodDeclaration.Modifier, region, bodyRegion);
			ParameterCollection parameters = new ParameterCollection();
			if (methodDeclaration.Parameters != null) {
				foreach (AST.ParameterDeclarationExpression par in methodDeclaration.Parameters) {
					ReturnType parType = new ReturnType(par.TypeReference);
					Parameter p = new Parameter(par.ParameterName, parType);
					parameters.Add(p);
				}
			}
			method.Parameters = parameters;
			c.Methods.Add(method);
			return null;
		}