Beispiel #1
0
        private static void FormatValue(object v, StringBuilder sb)
        {
            if (v == null)
            {
                sb.Append("<null>");
            }
            else if (v is IDictionary dic)
            {
                sb.Append("[");
                bool first = true;
                foreach (DictionaryEntry pair in dic)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(";");
                    }

                    FormatValue(pair.Key, sb);
                    sb.Append("=>");
                    FormatValue(pair.Value, sb);
                }
                sb.Append("]");
            }
            else if (v is Row row)
            {
                sb.Append(row.ToString());
            }
            else if ((!TypePrimitive.IsSimple(v.GetType())) && v is IEnumerable ien)
            {
                sb.Append("[");
                bool first = true;
                foreach (object cv in ien)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        sb.Append(";");
                    }

                    FormatValue(cv, sb);
                }
                sb.Append("]");
            }
            else
            {
                sb.Append(v.ToString());
            }
        }
Beispiel #2
0
        private int GetBitWidth(SchemaElement schema)
        {
            int bitWidth = TypePrimitive.GetBitWidth(schema.ElementType);

            if (bitWidth == 0)
            {
                throw new ParquetException($"cannot find bit width for type '{schema.ElementType}'");
            }

            return(bitWidth);
        }
        private ILanguageExpression translate_Expression_Function_Cast(TypePrimitive targetType, ParseTreeNode node)
        {
            if (node.ChildNodes.Count != 1)
            {
                return
                    (CompilationLog.RaiseGeneratorError <ILanguageExpression>(
                         "Expecting a single expression as input to the type cast operation", node));
            }

            var expr = translate_Expression_Function_Inputs_1(node.ChildNodes[0]);

            return(BasicExpressionGenerator.Generate_TypeCast(targetType, targetType, expr));
        }
Beispiel #4
0
        /// <summary>
        /// Search for a built-in type in the root global scope's general role dictionary
        /// </summary>
        /// <param name="typeName">The name of the built-in type</param>
        /// <param name="builtinType">The returned LanguageType object</param>
        /// <returns>True if the builtin type is found</returns>
        public bool LookupTypePrimitive(string typeName, out TypePrimitive builtinType)
        {
            builtinType = null;
            LanguageSymbol symbol;

            if (!RootAst.RootScope.LookupSymbol(typeName, RootAst.TypePrimitiveRoleName, out symbol))
            {
                return(false);
            }

            builtinType = symbol as TypePrimitive;

            return(ReferenceEquals(builtinType, null) == false);
        }
        public override string TargetTypeName(TypePrimitive itemType)
        {
            if (itemType.IsBoolean())
            {
                return("bool");
            }

            if (itemType.IsInteger())
            {
                return("int");
            }

            if (itemType.IsScalar())
            {
                return(CodeGenerator.ScalarTypeName);
            }

            return(@"/*<Unknown type>*/");
        }
Beispiel #6
0
        //private static readonly Regex LlVarOnlyRegex = new Regex(@"^\b" + LlVarNamePrefix + @"[0-9A-F][0-9A-F][0-9A-F][0-9A-F]\b$", RegexOptions.ECMAScript);


        /// <summary>
        /// Low level processing requires the use of MathematicaScalar primitive values only. This method extracts
        /// the a primitive value of the given type as a MathematicaScalar primitive value.
        /// </summary>
        /// <param name="langType"></param>
        /// <returns></returns>
        public static ValuePrimitive <MathematicaScalar> GetDefaultScalarValue(this TypePrimitive langType)
        {
            MathematicaScalar scalar;

            if (langType.IsNumber())
            {
                scalar = MathematicaScalar.Create(SymbolicUtils.Cas, 0);
            }

            else if (langType.IsBoolean())
            {
                scalar = MathematicaScalar.Create(SymbolicUtils.Cas, "False");
            }

            else
            {
                throw new InvalidOperationException();
            }

            return(ValuePrimitive <MathematicaScalar> .Create(langType, scalar));
        }
 private void Reset()
 {
     _Type = TypePrimitive.Barrier;
 }
Beispiel #8
0
 public static ValuePrimitive <T> Create(TypePrimitive valueType, T value)
 {
     return(new ValuePrimitive <T>(valueType, value));
 }
Beispiel #9
0
        protected ValuePrimitive(TypePrimitive valueType, T value)
        {
            ValuePrimitiveType = valueType;

            Value = value;
        }
Beispiel #10
0
 /// <summary>
 /// Gets the target language type name equivalent to the given GMacDSL primitive type
 /// </summary>
 /// <param name="itemType"></param>
 /// <returns></returns>
 public abstract string TargetTypeName(TypePrimitive itemType);
 public override string TargetTypeName(TypePrimitive itemType)
 {
     return(itemType.SymbolAccessName);
 }