示例#1
0
 public void Visit(FunctionExpression expression)
 {
     throw new NotImplementedException();
 }
 public void Visit(FunctionExpression expression)
 {
     throw new NotImplementedException();
 }
示例#3
0
        /// <summary>
        /// Visits a function expression
        /// </summary>
        /// <param name="expression">The expression</param>
        /// <exception cref="ArgumentNullException">Thrown when the input parameter is null</exception>
        public void Visit(FunctionExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            expression.Expression.Accept(this);
            object param = result;

            if (expression.FunctionName == "sizeof")
            {
                string customTypeName;
                long   symbolValue;
                if (param is string)
                {
                    if ((context.TryResolveCustomType((string)param, out customTypeName) &&
                         !DatatypeInfoProvider.IsPredefinedDatatype(customTypeName)) ||
                        param.ToString().StartsWith("enum") ||
                        param.ToString().StartsWith("struct") ||
                        param.ToString().StartsWith("union"))
                    {
                        result = "sizeof(" + param.ToString() + ")";
                    }
                    else
                    {
                        result = DatatypeInfoProvider.GetRpcDatatypeLength((string)param);
                    }
                }
                else if (context.TryResolveSymbol(expression.Text, out symbolValue))
                {
                    Type   value    = param.GetType();
                    string typeName = String.Empty;
                    switch (value.ToString())
                    {
                    case "System.Char":
                        typeName = "char";
                        break;

                    case "System.Byte":
                        typeName = "byte";
                        break;

                    case "System.Int16":
                        typeName = "short";
                        break;

                    case "System.Int32":
                        typeName = "int";
                        break;

                    case "System.Boolean":
                        typeName = "boolean";
                        break;

                    default:
                        break;
                    }

                    result = DatatypeInfoProvider.GetRpcDatatypeLength(typeName);
                }
                if (result is long &&
                    (long)result <= 0)
                {
                    throw new ExpressionEvaluatorException(
                              String.Format("cannot get the datatype length for the datatype '{0}'", param));
                }
            }
        }
        /// <summary>
        /// Visits a function expression
        /// </summary>
        /// <param name="expression">The expression</param>
        /// <exception cref="ArgumentNullException">Thrown when the input parameter is null</exception>        
        public void Visit(FunctionExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            expression.Expression.Accept(this);
            object param = result;
            if (expression.FunctionName == "sizeof")
            {
                string customTypeName;
                int symbolValue;
                if (param is string)
                {
                    if ((context.TryResolveCustomType((string)param, out customTypeName)
                        && !DatatypeInfoProvider.IsPredefinedDatatype(customTypeName))
                        || param.ToString().StartsWith("enum")
                        || param.ToString().StartsWith("struct")
                        || param.ToString().StartsWith("union"))
                    {
                        result = "sizeof(" + param.ToString() + ")";
                    }
                    else
                    {
                        result = DatatypeInfoProvider.GetRpcDatatypeLength((string)param);
                    }
                }
                else if (context.TryResolveSymbol(expression.Text, out symbolValue))
                {
                    Type value = param.GetType();
                    string typeName = String.Empty;
                    switch (value.ToString())
                    {
                        case "System.Char":
                            typeName = "char";
                            break;
                        case "System.Byte":
                            typeName = "byte";
                            break;
                        case "System.Int16":
                            typeName = "short";
                            break;
                        case "System.Int32":
                            typeName = "int";
                            break;
                        case "System.Boolean":
                            typeName = "boolean";
                            break;
                        default:
                            break;
                    }

                    result = DatatypeInfoProvider.GetRpcDatatypeLength(typeName);
                }
                if (result is int
                    && (int)result <= 0)
                {
                    throw new ExpressionEvaluatorException(
                        String.Format("cannot get the datatype length for the datatype '{0}'", param));
                }
            }
        }