Ejemplo n.º 1
0
 /// <summary>
 /// Initialize
 /// </summary>
 public LFunctionType(string name)
 {
     this.Name = name;
     this.FullName = name;
     this.TypeVal = TypeConstants.Function;
     this.Parent = null;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Expects the objects type to be of the supplied type.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="result"></param>
 /// <param name="lType"></param>
 public static void ExpectType(AstNode node, object result, LType lType)
 {
     if(!(result is LObject) || ((LObject)result).Type != lType)
     {
         throw new LangException("Runtime Error", "Expected type " + lType.Name,
            node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Registers methods on a specific type if no existing methods implementation are already
 /// registered for the type.
 /// </summary>
 /// <param name="type">The datatype for which the methods implementation are applicable</param>
 /// <param name="methods">The method implementations</param>
 public void RegisterIfNotPresent(LType type, ITypeMethods methods)
 {
     if (!_typeToMethods.ContainsKey(type))
     {
         _typeToMethods[type] = methods;
         methods.OnRegistered();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type">The type</param>
 /// <param name="fullName">The fullname of the type</param>
 /// <param name="name">The short name of the type</param>
 public static void RegisterAlias(LType type, string fullName, string name)
 {
     _types[fullName] = type;
     if (type.IsSystemType)
     {
         _sysBasicTypes[name] = type;
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Registers methods on a specific type if no existing methods implementation are already
 /// registered for the type.
 /// </summary>
 /// <param name="type">The datatype for which the methods implementation are applicable</param>
 /// <param name="methods">The method implementations</param>
 public void RegisterIfNotPresent(LType type, ITypeMethods methods)
 {
     if (!_typeToMethods.ContainsKey(type))
     {
         _typeToMethods[type] = methods;
         methods.OnRegistered();
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Expects the objects type to be of the supplied type.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="result"></param>
 /// <param name="lType"></param>
 public static void NotNullType(AstNode node, object obj, string nullMessage, LType lType)
 {
     if (obj == null || obj == LObjects.Null)
     {
         throw new LangException("Runtime Error", nullMessage,
             node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos);
     }
     if (!(obj is LObject) || ((LObject)obj).Type != lType)
     {
         throw new LangException("Runtime Error", "Expected type " + lType.Name,
            node.Ref.ScriptName, node.Ref.Line, node.Ref.CharPos);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the type in the host language that represents the same type in fluentscript.
        /// </summary>
        /// <param name="ltype">The LType in fluentscript.</param>
        /// <returns></returns>
        public static Type ConvertToHostLangType(LType ltype)
        {
            if (ltype == LTypes.Bool) return typeof(bool);
            if (ltype == LTypes.Date) return typeof(DateTime);
            if (ltype == LTypes.Number) return typeof(int);
            if (ltype == LTypes.Number) return typeof(double);
            if (ltype == LTypes.String) return typeof(string);
            if (ltype == LTypes.Time) return typeof(TimeSpan);
            if (ltype == LTypes.Array) return typeof(IList);
            if (ltype == LTypes.Map) return typeof(IDictionary);
            if (ltype == LTypes.Null) return typeof(Nullable);

            return typeof (object);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Is match with the type supplied and the 
 /// </summary>
 /// <param name="type"></param>
 /// <param name="obj1"></param>
 /// <param name="obj2"></param>
 /// <returns></returns>
 private static bool IsTypeMatch(LType type, LObject obj1, LObject obj2)
 {
     if (obj1.Type == type && obj2.Type == type)
         return true;
     return false;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Get the methods implementation for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public ITypeMethods Get(LType type)
 {
     return(_typeToMethods[type]);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Register methods on a specific type.
 /// </summary>
 /// <param name="type">The datatype for which the methods implementation are applicable</param>
 /// <param name="methods">The method implementations</param>
 public void Register(LType type, ITypeMethods methods)
 {
     _typeToMethods[type] = methods;
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Register methods on a specific type.
 /// </summary>
 /// <param name="type">The datatype for which the methods implementation are applicable</param>
 /// <param name="methods">The method implementations</param>
 public void Register(LType type, ITypeMethods methods)
 {
     _typeToMethods[type] = methods;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Get the methods implementation for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public ITypeMethods Get(LType type)
 {
     return _typeToMethods[type];
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Whether or not there are methods for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public bool Contains(LType type)
 {
     return _typeToMethods.ContainsKey(type);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type"></param>
 public static void Register(LType type)
 {
     RegisterAlias(type, type.FullName, type.Name);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Whether or not there are methods for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public bool Contains(LType type)
 {
     return(_typeToMethods.ContainsKey(type));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type">The type</param>
 /// <param name="fullName">The fullname of the type</param>
 /// <param name="name">The short name of the type</param>
 public static void RegisterAlias(LType type, string fullName, string name)
 {
     _types[fullName] = type;
     if (type.IsSystemType)
         _sysBasicTypes[name] = type;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type"></param>
 public static void Register(LType type)
 {
     RegisterAlias(type, type.FullName, type.Name);
 }