Example #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;
            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();
                        }
                    }
                }
            }
        }