Esempio n. 1
0
        public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
        {
            var ci       = m_ClassInfoStack.Peek();
            var localSym = m_Model.GetDeclaredSymbol(node) as ILocalSymbol;

            if (null != localSym && localSym.HasConstantValue)
            {
                if (null != node.Initializer)
                {
                    CodeBuilder.AppendFormat("{0}local({1}); {2}", GetIndentString(), node.Identifier.Text, node.Identifier.Text);
                }
                else
                {
                    CodeBuilder.AppendFormat("{0}local({1})", GetIndentString(), node.Identifier.Text);
                }
                CodeBuilder.Append(" = ");
                OutputConstValue(localSym.ConstantValue, localSym);
                CodeBuilder.AppendLine(";");
                return;
            }
            bool       dslToObject = false;
            IOperation oper        = null;

            if (null != node.Initializer)
            {
                oper = m_Model.GetOperationEx(node.Initializer.Value);
                if (null != localSym && null != localSym.Type && null != oper && null != oper.Type)
                {
                    dslToObject = InvocationInfo.IsDslToObject(localSym.Type, oper.Type);
                }
            }
            VisitLocalVariableDeclarator(ci, node, dslToObject);
            if (null != node.Initializer)
            {
                var rightSymbolInfo = m_Model.GetSymbolInfoEx(node.Initializer.Value);
                var rightSym        = rightSymbolInfo.Symbol;
                if (null != oper && null != oper.Type && oper.Type.IsValueType && !dslToObject && !SymbolTable.IsBasicType(oper.Type) && !CsDslTranslater.IsImplementationOfSys(oper.Type, "IEnumerator"))
                {
                    if (null != rightSym && (rightSym.Kind == SymbolKind.Method || rightSym.Kind == SymbolKind.Property || rightSym.Kind == SymbolKind.Field || rightSym.Kind == SymbolKind.Local) && SymbolTable.Instance.IsCs2DslSymbol(rightSym))
                    {
                        MarkNeedFuncInfo();
                        if (SymbolTable.Instance.IsCs2DslSymbol(oper.Type))
                        {
                            CodeBuilder.AppendFormat("{0}{1} = wrapstruct({2}, {3});", GetIndentString(), node.Identifier.Text, node.Identifier.Text, ClassInfo.GetFullName(oper.Type));
                            CodeBuilder.AppendLine();
                        }
                        else
                        {
                            string ns = ClassInfo.GetNamespaces(oper.Type);
                            if (ns != "System")
                            {
                                CodeBuilder.AppendFormat("{0}{1} = wrapexternstruct({2}, {3});", GetIndentString(), node.Identifier.Text, node.Identifier.Text, ClassInfo.GetFullName(oper.Type));
                                CodeBuilder.AppendLine();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public override void VisitVariableDeclarator(VariableDeclaratorSyntax node)
        {
            var ci       = m_ClassInfoStack.Peek();
            var localSym = m_Model.GetDeclaredSymbol(node) as ILocalSymbol;

            if (null != localSym && localSym.HasConstantValue)
            {
                if (null != node.Initializer)
                {
                    CodeBuilder.AppendFormat("{0}local({1}); {2}", GetIndentString(), node.Identifier.Text, node.Identifier.Text);
                }
                else
                {
                    CodeBuilder.AppendFormat("{0}local({1})", GetIndentString(), node.Identifier.Text);
                }
                CodeBuilder.Append(" = ");
                OutputConstValue(localSym.ConstantValue, localSym);
                CodeBuilder.AppendLine(";");
                return;
            }
            bool        dslToObject = false;
            ITypeSymbol type        = null;

            if (null != node.Initializer)
            {
                type = m_Model.GetTypeInfoEx(node.Initializer.Value).Type;
                if (null != localSym && null != localSym.Type && null != type)
                {
                    dslToObject = InvocationInfo.IsDslToObject(localSym.Type, type);
                }
            }
            VisitLocalVariableDeclarator(ci, node, dslToObject);
            if (null != node.Initializer)
            {
                var valSyntax = node.Initializer.Value;
                var rightType = m_Model.GetTypeInfoEx(valSyntax).Type;
                var rightOper = m_Model.GetOperationEx(valSyntax);
                if (null == rightType && null != rightOper)
                {
                    rightType = rightOper.Type;
                }
                ;
                bool needWrapStruct = NeedWrapStruct(valSyntax, rightType, rightOper, dslToObject);
                if (needWrapStruct)
                {
                    MarkNeedFuncInfo();
                    if (SymbolTable.Instance.IsCs2DslSymbol(type))
                    {
                        CodeBuilder.AppendFormat("{0}{1} = wrapstruct({2}, {3});", GetIndentString(), node.Identifier.Text, node.Identifier.Text, ClassInfo.GetFullName(type));
                        CodeBuilder.AppendLine();
                    }
                    else
                    {
                        string ns = ClassInfo.GetNamespaces(type);
                        if (ns != "System")
                        {
                            CodeBuilder.AppendFormat("{0}{1} = wrapexternstruct({2}, {3});", GetIndentString(), node.Identifier.Text, node.Identifier.Text, ClassInfo.GetFullName(type));
                            CodeBuilder.AppendLine();
                        }
                    }
                }
            }
        }