示例#1
0
            public void Callback(Node node)
            {
                if (node is ITypedNode)
                {
                    ITypedNode theNode = node as ITypedNode;
                    theNode.Type = mapper.Map(theNode.Type);
                }
                if (node is ManageField)
                {
                    ManageField theNode = node as ManageField;
                    theNode.Field = mapper.Map(theNode.Field);
                }
                if (node is MethodBodyBlock)
                {
                    MethodBodyBlock body = node as MethodBodyBlock;
                    foreach (Variable var in body.Variables)
                    {
                        var.Type = mapper.Map(var.Type);
                    }
                    body.ReturnType = mapper.Map(body.ReturnType);
                }
                if (node is CallMethod)
                {
                    CallMethod     call = node as CallMethod;
                    ResidualMethod id   = Specialization.GetResidualMethod(call);
                    if (id != null)
                    {
                        MethodBodyBlock mbb = mapper.Holder[id];
                        node.Options["HasPseudoParameter"] = mapper.HasPseudoParameter(mbb);
                        call.MethodWithParams = new MethodInfoExtention(mapper.Map(mbb), call.IsVirtCall, mapper.Map(GetParamTypes(mbb, id.IsConstructor)));
                    }
                    else
                    {
                        call.MethodWithParams = mapper.Map(call.MethodWithParams);
                    }
                }
                if (node is NewObject)
                {
                    NewObject      newObj = node as NewObject;
                    ResidualMethod id     = Specialization.GetResidualMethod(node);
                    if (id != null)
                    {
                        MethodBodyBlock mbb = mapper.Holder[id];
                        newObj.CtorWithParams = new MethodInfoExtention(mapper.Map(mbb), false, mapper.Map(GetParamTypes(mbb, id.IsConstructor)));
                        node.Options["HasPseudoParameter"] = mapper.HasPseudoParameter(mbb);
                    }
                    else
                    {
                        newObj.CtorWithParams = mapper.Map(newObj.CtorWithParams);
                    }
                }
                if (node is CreateDelegate)
                {
                    CreateDelegate crDel = node as CreateDelegate;
                    //Andrew TODO: Map this node...
                }

                // Graph should be verified AFTER the metadata is resolved
            }
示例#2
0
        //TODO move this method to DataDefinition
        private DataType GetTypeDefinition(SymbolTable table, Node symbol)
        {
            var data = symbol as DataDefinition;

            if (data != null)
            {
                var dataCondition = data as DataCondition;
                if (dataCondition != null)
                {
                    return(dataCondition.CodeElement().DataType);
                }

                DataDescriptionEntry entry;
                if (data.CodeElement is DataDescriptionEntry)
                {
                    entry = (DataDescriptionEntry)data.CodeElement;
                }
                else
                if (data.CodeElement is DataRedefinesEntry)
                {
                    var redefines = (DataRedefinesEntry)data.CodeElement;
                    var node      = GetSymbol(table, redefines.RedefinesDataName);
                    if (node is DataDescription)
                    {
                        entry = (DataDescriptionEntry)node.CodeElement;
                    }
                    else
                    {
                        entry = GetDataDescriptionEntry(table, redefines);
                    }
                }
                else
                {
                    throw new NotImplementedException(data.CodeElement.GetType().Name);
                }
                if (entry == null)
                {
                    return(null);
                }
                if (entry.UserDefinedDataType == null)
                {
                    return(entry.DataType);                                          //not a custom type
                }
            }
            ITypedNode typed = symbol as ITypedNode;

            if (typed == null)
            {
                return(null);                  // symbol untyped
            }
            var types = table.GetTypes(typed);

            if (types.Count != 1)
            {
                return(null);                     // symbol type not found or ambiguous
            }
            return(types[0].DataType);
        }
示例#3
0
        public IList <TypeDefinition> GetTypes(ITypedNode symbol)
        {
            var types = new List <TypeDefinition>();
            var list  = GetType(symbol.DataType.Name);

            foreach (var type in list)
            {
                types.Add(type);
            }
            return(types);
        }
示例#4
0
        public override void OnInspectorGUI()
        {
            Node myTarget = (Node)target;

            EditorGUI.BeginChangeCheck();

            if (myTarget is INodeCollection || NameEditable)
            {
                EditorGUIExtension.SimpleBox("", 5, "", delegate()
                {
                    myTarget.Name = EditorGUILayout.TextField("Name", myTarget.Name);
                });
            }
            else if (myTarget is ITypedNode)
            {
                ITypedNode t = (ITypedNode)myTarget;
                EditorGUIExtension.SimpleBox("", 5, "", delegate()
                {
                    if (_typePopup == null)
                    {
                        int index           = 0;
                        List <string> names = new List <string>();
                        for (int cnt = 0; cnt < t.AllowedTypes.Count; cnt++)
                        {
                            if (t.Type == t.AllowedTypes[cnt])
                            {
                                index = cnt;
                            }
                            names.Add(TypeUtils.GetPrettyName(t.AllowedTypes[cnt]));
                        }
                        _typePopup = new SmartPopup(names, index);
                    }

                    if (_typePopup.Draw("Value Type"))
                    {
                        t.Type = t.AllowedTypes[_typePopup.Index];
                    }
                });
            }

            EditorGUILayout.Space();

            onGUI();

            if (EditorGUI.EndChangeCheck())
            {
                myTarget.HasChanges = true;
            }
        }
示例#5
0
 /// <summary>
 /// Gets a node's type as a string
 /// </summary>
 /// <param name="typedNode">The node to get the type of</param>
 /// <returns>A string describing the type of the node</returns>
 private static string GetTypeString(ITypedNode typedNode)
 {
     return($"Type: {(typedNode.Type is null ? "not set" : typedNode.Type.ToString())}");
 }
示例#6
0
        //TODO move this method to DataDefinition
        /// <summary>
        /// Allows to get DataType of a DataDefinition Node
        /// </summary>
        /// <param name="node"></param>
        /// <param name="symbol"></param>
        /// <param name="isReadDictionary"></param>
        /// <returns></returns>
        private static DataDefinition GetDataDefinitionType(Node node, Node symbol, bool isReadDictionary)
        {
            var data = symbol as DataDefinition;

            if (data != null)
            {
                var dataCondition = data as DataCondition;
                if (dataCondition != null)
                {
                    return(new GeneratedDefinition(dataCondition.CodeElement().DataType.Name,
                                                   dataCondition.CodeElement().DataType));
                }

                DataDescriptionEntry entry;
                var descriptionEntry = data.CodeElement as DataDescriptionEntry;
                if (descriptionEntry != null)
                {
                    entry = descriptionEntry;
                }
                else if (data.CodeElement as DataRedefinesEntry != null)
                {
                    var redefines = (DataRedefinesEntry)data.CodeElement;
                    var searchedDataDefinition = node.GetDataDefinitionForQualifiedName(redefines.RedefinesDataName.URI, isReadDictionary);
                    if (searchedDataDefinition as DataDescription != null)
                    {
                        entry = (DataDescriptionEntry)searchedDataDefinition.CodeElement;
                    }
                    else
                    {
                        entry = GetDataDescriptionEntry(node, redefines, isReadDictionary);
                    }
                }
                else if (data is IndexDefinition)
                {
                    entry = null;
                }
                else
                {
                    throw new NotImplementedException(data.CodeElement.GetType().Name);
                }

                if (entry == null)
                {
                    return(null);
                }

                if (entry.UserDefinedDataType == null)
                {
                    return(new GeneratedDefinition(entry.DataType.Name, entry.DataType));
                }
            }
            ITypedNode typed = symbol as ITypedNode;

            if (typed == null)
            {
                return(null);               // symbol untyped
            }
            if (data?.TypeDefinition != null)
            {
                return(data.TypeDefinition);
            }

            var types = node.SymbolTable.GetType(typed);

            // return null if symbol type not found or ambiguous
            return(types.Count != 1 ? null : types[0]);
        }
示例#7
0
 public IList <TypeDefinition> GetType(ITypedNode symbol)
 {
     return(GetType(symbol.DataType));
 }
        private void WriteTypedNode(ITypedNode typedNode, StringBuilder result, bool edition, PrefixModules prefixModule,
            bool allowObservable)
        {
            if (typedNode.IsDictionary)
            {
                result.Append("{ [key: string]: ");
            }

            WriteType(typedNode.Type, result, edition, prefixModule, allowObservable);

            if (typedNode.IsCollection)
            {
                result.Append("[]");
            }

            if (typedNode.IsDictionary)
            {
                result.Append(" }");
            }
        }
示例#9
0
 /// <summary>
 /// Gets a node's type as a string
 /// </summary>
 /// <param name="typedNode">The node to get the type of</param>
 /// <returns>A string describing the type of the node</returns>
 private static string GetTypeString(ITypedNode typedNode)
 {
     return($"Type: {(typedNode.Type is null ? "Type "+ typedNode.Position + " is not set or not found" : typedNode.Type.ToString())}");
 }
示例#10
0
 public AssigmentStatement(VariableReference Reference, ITypedNode Assigment)
 {
     reference = Reference;
     assigment = Assigment;
 }
示例#11
0
        private void FillType(ITypedNode typedNode, Type parameterType, AssemblyNode assembly, Type[] parents, string version)
        {
            if (Nullable.GetUnderlyingType(parameterType) == null && parameterType.GetTypeInfo().IsGenericType)
            {
                if (parameterType.ImplementsInterface(typeof(IDictionary<,>)))
                {
                    typedNode.IsDictionary = true;
                    parameterType = parameterType.GenericTypeArguments[1];
                }
                else if (parameterType.ImplementsInterface(typeof(IEnumerable<>)))
                {
                    typedNode.IsCollection = true;
                    parameterType = parameterType.GenericTypeArguments[0];
                }
            }

            if (parameterType.IsArray)
            {
                typedNode.IsCollection = true;
                parameterType = parameterType.GetElementType();
            }

            typedNode.Type = ReadType(parameterType, assembly, parents, version);
        }