예제 #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 Method(string name, ReturnType type, Modifier m, IRegion region, IRegion bodyRegion)
 {
     FullyQualifiedName = name;
     returnType = type;
     this.region     = region;
     this.bodyRegion = bodyRegion;
     modifiers = (ModifierEnum)m;
 }
예제 #3
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;
 }
예제 #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 ArrayList IsAsResolve(string expression, int caretLine, int caretColumn, string fileName, string fileContent)
        {
            ArrayList result = new ArrayList ();
            this.caretLine = caretLine;
            this.caretColumn = caretColumn;

            IParseInformation parseInfo = parserContext.GetParseInformation (fileName);
            ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fcu = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
            if (fcu == null)
                return null;
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser ();
            Lexer l = new Lexer (new StringReader (expression));
            Expression expr = p.ParseExpression(l);
            if (expr == null)
                return null;

            lookupTableVisitor = new LookupTableVisitor ();
            lookupTableVisitor.Visit (fcu, null);

            TypeVisitor typeVisitor = new TypeVisitor (this);

            CSharpVisitor csharpVisitor = new CSharpVisitor ();
            cu = (ICompilationUnit)csharpVisitor.Visit (fcu, null);
            if (cu != null) {
                callingClass = GetInnermostClass ();
            }

            IReturnType type = expr.AcceptVisitor (typeVisitor, null) as IReturnType;
            if (type == null || type.PointerNestingLevel != 0) {
                fcu = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
                lookupTableVisitor.Visit (fcu, null);
                cu = (ICompilationUnit)csharpVisitor.Visit (fcu, 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");

            IClass returnClass = SearchType (type.FullyQualifiedName, cu);
            //			IClass returnClass = parserContext.SearchType (type.FullyQualifiedName, null, cu);
            if (returnClass == null)
                return null;

            foreach (IClass iclass in parserContext.GetClassInheritanceTree (returnClass)) {
                if (!result.Contains (iclass))
                    result.Add (iclass);
            }
            return result;
        }
예제 #7
0
 public Parameter(string name, ReturnType type)
 {
     this.name = name;
     returnType = type;
 }
예제 #8
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;
 }
예제 #9
0
        public override object Visit(IndexerExpression indexerExpression, object data)
        {
            //Console.WriteLine("TypeVisiting IndexerExpression");
            IReturnType type = (IReturnType)indexerExpression.TargetObject.AcceptVisitor(this, data);
            //Console.WriteLine("Type is " + type.FullyQualifiedName);
            if (type == null) {
                return null;
            }
            if (type.ArrayDimensions == null || type.ArrayDimensions.Length == 0) {
                //Console.WriteLine("No Array, checking indexer");
                // 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) {
                //Console.WriteLine("Number of indices do not match the Array dimension");
                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);
        }
예제 #10
0
 public override object Visit(StackAllocExpression stackAllocExpression, object data)
 {
     ReturnType returnType = new ReturnType(stackAllocExpression.Type);
     ++returnType.PointerNestingLevel;
     return returnType;
 }
예제 #11
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;
        }
 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;
 }
예제 #13
0
        public IReturnType internalResolve(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;
            }
            this.caretLine     = caretLineNumber;
            this.caretColumn   = caretColumn;

            IParseInformation parseInfo = parserContext.GetParseInformation(fileName);
            ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit;
            if (fileCompilationUnit == null) {
            //				ICSharpCode.SharpRefactory.Parser.Parser fileParser = new ICSharpCode.SharpRefactory.Parser.Parser();
            //				fileParser.Parse(new Lexer(new StringReader(fileContent)));
                Console.WriteLine("Warning: no parse information!");
                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;
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.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
            */
            ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.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);

            CSharpVisitor cSharpVisitor = new CSharpVisitor();
            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 = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag
                    as ICSharpCode.SharpRefactory.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);
            return type;
        }
        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 (ICSharpCode.SharpRefactory.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;
        }
        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;
        }
        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;
        }
        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;
        }
        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;
        }