Пример #1
0
 public static void DumpMappingName(this MappedNode target, int indent)
 {
     if (target.MappingName.IsNullOrEmpty())
     {
         return;
     }
     WriteLine(indent, "MappingName: " + target.MappingName);
 }
Пример #2
0
 internal void MapParsedNode(MappedNode node)
 {
     if (node.Type == MappedNodeType.TypeDefiniton)
     {
         types.Add((MappedTypeDefinition)node);
     }
     MapNode(RecordingStage.Parsed, node);
 }
Пример #3
0
        private void TokensForNode(MappedNode node, Action <MappedToken> action)
        {
            var startIndex = IndexOfBufferPoint(node.TextSpan.iStartLine, node.TextSpan.iStartIndex);
            var endIndex   = IndexOfBufferPoint(node.TextSpan.iEndLine, node.TextSpan.iEndIndex);

            for (var i = Lookup(startIndex); i < tokenMap.Count && tokenMap[i].Index + tokenMap[i].Length <= endIndex; i++)
            {
                action(tokenMap[i]);
            }
        }
Пример #4
0
        private void ProcessMappingName(MappedNode node, string mappingName, ValidationRule rule)
        {
            if (mappingName.IsNullOrEmpty())
            {
                return;
            }

            mappingName = context.NameBuilder.ApplyNamingRules(mappingName);

            context.Validator.ValidateName(mappingName, rule);

            if (Comparer.Equals(node.MappingName, mappingName))
            {
                BuildLog.Warning(Strings.ExplicitMappingNameSettingIsRedundantTheSameNameXWillBeGeneratedAutomatically, node.MappingName);
            }
            else
            {
                node.MappingName = mappingName;
            }
        }
Пример #5
0
        protected override void ResolveImpl(MappedToken token)
        {
            try
            {
                var type = TypeSystemServices.GetType(Node);
                if (type is Error)
                {
                    return;
                }

                format = Formats.BooType;
                var prefix = "struct ";
                if (type.IsClass)
                {
                    prefix = "class ";
                }
                if (type.IsInterface)
                {
                    prefix = "interface ";
                }
                if (type.IsEnum)
                {
                    prefix = "enumeration ";
                }
                quickInfoTip = prefix + type.FullName;

                var internalType = type as AbstractInternalType;
                if (internalType != null)
                {
                    declaringNode = CompileResults.GetMappedNode(internalType.Node);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
Пример #6
0
 internal void MapNode(RecordingStage stage, MappedNode node)
 {
     TokensForNode(node, token => node.Record(stage, token));
 }
Пример #7
0
        public static KeyValuePair <IEnumerable <LinkModel>, string> StartBestFs(IEnumerable <MappedNode> mapedEnumerable, string keyFrom, string keyTo)
        {
            var result = new List <LinkModel>();

            var queue = new PriorityQueue <string> {
                { 0, keyFrom }
            };

            var dataDict  = new Dictionary <string, UniversalGraphNodeData>();
            var mapedList = mapedEnumerable.ToList();

            foreach (var mappedNode in mapedList)
            {
                dataDict.Add(mappedNode.Node.Key, new UniversalGraphNodeData {
                    Node = mappedNode
                });
            }

            dataDict[keyFrom].IsVisited = true;

            MappedNode nextMaped = null;
            var        isOk      = false;

            while (queue.Count != 0)
            {                           // пока очередь не пуста
                var node = queue.Pop(); // извлечь первый элемент в очереди

                nextMaped = dataDict[node].Node;

                if (node == keyTo)
                {
                    isOk = true;
                    break;                      // проверить, не ¤вл¤етс¤ ли текущий узел целевым
                }


                foreach (var link in nextMaped.Links)
                {    // все преемники текущего узла, ...
                    var to = link.GetTo(node);
                    if (dataDict[to].IsVisited == false)
                    {                        // ... которые ещЄ не были посещены ...
                        var cost = int.Parse(link.Text) * -1;
                        queue.Add(cost, to); // ... добавить в конец очереди...
                        // ... и пометить как посещЄнные
                        dataDict[to].ParentMappedNode = nextMaped;
                        dataDict[to].ParentLink       = link;
                    }
                }
                dataDict[node].IsVisited = true;
            }

            if (isOk && nextMaped != null)
            {
                //result.Add(dataDict[nextMaped.Node.Key].ParentLink);
                while (dataDict[nextMaped.Node.Key].ParentLink != null)
                {
                    result.Add(dataDict[nextMaped.Node.Key].ParentLink);       //и дописываем к пути
                    //пока существует предыдуща¤ вершина
                    nextMaped = dataDict[nextMaped.Node.Key].ParentMappedNode; //переходим в неЄ
                }
            }

            return(new KeyValuePair <IEnumerable <LinkModel>, string>(result, UniversalGraphNodeData.GetVector(dataDict, keyTo)));
        }
        protected override void ResolveImpl(MappedToken token)
        {
            switch (Node.NodeType)
            {
            case NodeType.SelfLiteralExpression:
                var classDefinition = Node;
                while (classDefinition.ParentNode != null)
                {
                    if (classDefinition.NodeType != NodeType.ClassDefinition)
                    {
                        classDefinition = classDefinition.ParentNode;
                    }
                    else
                    {
                        varType = TypeSystemServices.GetType(classDefinition);
                        break;
                    }
                }
                break;

            case NodeType.MemberReferenceExpression:
            case NodeType.ReferenceExpression:
                var     expression = (ReferenceExpression)Node;
                IEntity entity;
                try
                {
                    entity = TypeSystemServices.GetEntity(expression);
                }
                catch
                {
                    break;
                }
                var prefix = "";
                if (entity is InternalParameter)
                {
                    prefix          = "(parameter) ";
                    varType         = TypeSystemServices.GetType(expression);
                    declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter);
                }
                if (entity is InternalLocal)
                {
                    prefix          = "(local variable) ";
                    varType         = ((InternalLocal)entity).Type;
                    declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local);
                }
                if (entity is InternalField)
                {
                    varType         = TypeSystemServices.GetType(Node);
                    declaringType   = ((InternalField)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field);
                }
                if (entity is InternalMethod)
                {
                    declaringType   = ((InternalMethod)entity).DeclaringType;
                    declarationNode = CompileResults.GetMappedNode(((InternalMethod)entity).Method);
                    if (entity is InternalConstructor)
                    {
                        varType = ((InternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((InternalMethod)entity).ReturnType;
                    }
                }
                if (entity is InternalProperty)
                {
                    declaringType   = ((InternalProperty)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property);
                }
                if (entity is InternalEvent)
                {
                    declaringType   = ((InternalEvent)entity).DeclaringType;
                    varType         = TypeSystemServices.GetType(Node);
                    declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event);
                }
                if (entity is ExternalType)
                {
                    varType         = ((ExternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                }
                if (entity is AbstractInternalType)
                {
                    varType         = ((AbstractInternalType)entity).Type;
                    format          = Formats.BooType;
                    isTypeReference = true;
                    declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition);
                }
                if (entity is ExternalField)
                {
                    varType       = TypeSystemServices.GetType(Node);
                    declaringType = ((ExternalField)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(((ExternalField)entity).Field);
                }
                if (entity is ExternalMethod)
                {
                    declaringType = ((ExternalMethod)entity).DeclaringType;
//                        declarationNode = CompileResults.GetMappedNode(declaration);
                    if (entity is ExternalConstructor)
                    {
                        varType = ((ExternalConstructor)entity).DeclaringType;
                    }
                    else
                    {
                        varType = ((ExternalMethod)entity).ReturnType;
                    }
                }
                if (entity is ExternalProperty)
                {
                    declaringType = ((ExternalProperty)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalProperty)entity).Property);
                }
                if (entity is ExternalEvent)
                {
                    declaringType = ((ExternalEvent)entity).DeclaringType;
                    varType       = TypeSystemServices.GetType(Node);
//                        declarationNode = CompileResults.GetMappedNode(((ExternalEvent)entity).Event);
                }
                if (expression.ExpressionType != null)
                {
                    if (declaringType != null)
                    {
                        prefix += declaringType.FullName + '.';
                    }
                    quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName;
                }
                break;

            default:
                break;
            }
        }
Пример #9
0
 private static int GetEurastick(MappedNode from, MappedNode to)
 {
     return((int)Math.Sqrt(Math.Pow(from.Node.Location.X - to.Node.Location.X, 2) +
                           Math.Pow(from.Node.Location.Y - to.Node.Location.Y, 2)));
 }
Пример #10
0
        //NOT WORKING
        public static KeyValuePair <IEnumerable <LinkModel>, string> StartAStar(IEnumerable <MappedNode> mapedEnumerable, string keyFrom, string keyTo)
        {
            var result = new List <LinkModel>();

            var queue = new PriorityQueue <string> {
                { 0, keyFrom }
            };

            var dataDict  = new Dictionary <string, UniversalGraphNodeData>();
            var mapedList = mapedEnumerable.ToList();

            foreach (var mappedNode in mapedList)
            {
                dataDict.Add(mappedNode.Node.Key, new UniversalGraphNodeData {
                    Node = mappedNode
                });
            }
            var toMapped = dataDict[keyTo].Node;

            dataDict[keyFrom].IsVisited = true;

            MappedNode nextMaped = null;
            var        isOk      = false;

            while (queue.Count != 0)
            {                               // пока очередь не пуста
                var nodeName = queue.Pop(); // извлечь первый элемент в очереди
                nextMaped = dataDict[nodeName].Node;

                if (nodeName == keyTo)
                {
                    isOk = true;
                    break;                      // проверить, не является ли текущий узел целевым
                }

                foreach (var link in nextMaped.Links)
                {    // все преемники текущего узла, ...
                    var to = link.GetTo(nodeName);

                    if (dataDict[to].IsVisited == false)
                    {
                        var toNodeCost   = int.Parse(link.Text);
                        var selfCost     = dataDict[nodeName].Cost;
                        var newTotalCost = toNodeCost + selfCost + GetEurastick(dataDict[nodeName].Node, toMapped);

                        if (dataDict[to].Cost == -1)
                        {
                            queue.Add(newTotalCost * -1, to);
                            dataDict[to].Cost = newTotalCost;
                        }
                        else if (dataDict[to].Cost > newTotalCost)
                        {
                            queue.Remove(dataDict[to].Cost * -1);
                            dataDict[to].Cost = newTotalCost;
                            queue.Add(newTotalCost * -1, to);
                        }
                        else
                        {
                            continue;
                        }

                        dataDict[to].ParentMappedNode = nextMaped;
                        dataDict[to].ParentLink       = link;
                    }
                }
                dataDict[nodeName].IsVisited = true;
            }

            if (isOk && nextMaped != null)
            {
                //result.Add(dataDict[nextMaped.Node.Key].ParentLink);
                while (dataDict[nextMaped.Node.Key].ParentLink != null)
                {
                    result.Add(dataDict[nextMaped.Node.Key].ParentLink);       //и дописываем к пути
                    //пока существует предыдущая вершина
                    nextMaped = dataDict[nextMaped.Node.Key].ParentMappedNode; //переходим в неё
                }
            }

            return(new KeyValuePair <IEnumerable <LinkModel>, string>(result, UniversalGraphNodeData.GetVector(dataDict, keyTo)));
        }
        protected override void ResolveImpl(MappedToken token)
        {
            switch (Node.NodeType)
            {
                case NodeType.SelfLiteralExpression:
                    var classDefinition = Node;
                    while (classDefinition.ParentNode != null)
                        if (classDefinition.NodeType != NodeType.ClassDefinition)
                            classDefinition = classDefinition.ParentNode;
                        else
                        {
                            varType = TypeSystemServices.GetType(classDefinition);
                            break;
                        }
                    break;

                case NodeType.MemberReferenceExpression:
                case NodeType.ReferenceExpression:
                    var expression = (ReferenceExpression)Node;
                    IEntity entity;
                    try
                    {
                        entity = TypeSystemServices.GetEntity(expression);
                    }
                    catch
                    {
                        break;
                    }
                    var prefix = "";
                    if (entity is InternalParameter)
                    {
                        prefix = "(parameter) ";
                        varType = TypeSystemServices.GetType(expression);
                        declarationNode = CompileResults.GetMappedNode(((InternalParameter)entity).Parameter);
                    }
                    if (entity is InternalLocal)
                    {
                        prefix = "(local variable) ";
                        varType = ((InternalLocal)entity).Type;
                        declarationNode = CompileResults.GetMappedNode(((InternalLocal)entity).Local);
                    }
                    if (entity is InternalField)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalField)entity).Field);
                    }
                    if (entity is InternalMethod)
                    {
                        var declaration = ((InternalMethod)entity).Method;
                        declarationNode = CompileResults.GetMappedNode(declaration);
                        if (entity is InternalConstructor)
                            varType = ((InternalConstructor) entity).DeclaringType;
                        else
                            varType = TypeSystemServices.GetType(declaration.ReturnType);
                    }
                    if (entity is InternalProperty)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalProperty)entity).Property);
                    }
                    if (entity is InternalEvent)
                    {
                        varType = TypeSystemServices.GetType(Node);
                        declarationNode = CompileResults.GetMappedNode(((InternalEvent)entity).Event);
                    }
                    if (entity is ExternalType)
                    {
                        varType = ((ExternalType)entity).Type;
                        format = Formats.BooType;
                        isTypeReference = true;
                    }
                    if (entity is AbstractInternalType)
                    {
                        varType = ((AbstractInternalType)entity).Type;
                        format = Formats.BooType;
                        isTypeReference = true;
                        declarationNode = CompileResults.GetMappedNode(((AbstractInternalType)entity).TypeDefinition);
                    }
                    if (expression.ExpressionType != null)
                        quickInfoTip = prefix + expression.Name + " as " + expression.ExpressionType.FullName;
                    break;
                default:
                    break;
            }
        }
Пример #12
0
        protected override void ResolveImpl(MappedToken token)
        {
            try
            {
                var type = TypeSystemServices.GetType(Node);
                if (type is Error)
                    return;

                format = Formats.BooType;
                var prefix = "struct ";
                if (type.IsClass)
                    prefix = "class ";
                if (type.IsInterface)
                    prefix = "interface ";
                if (type.IsEnum)
                    prefix = "enumeration ";
                quickInfoTip = prefix + type.FullName;

                var internalType = type as AbstractInternalType;
                if (internalType != null)
                    declaringNode = CompileResults.GetMappedNode(internalType.Node);

            }
            catch (Exception)
            {
                return;
            }
        }