示例#1
0
 /// <summary>
 /// Initialize
 /// </summary>
 public LFunctionType(string name)
 {
     this.Name = name;
     this.FullName = name;
     this.TypeVal = TypeConstants.Function;
     this.Parent = null;
 }
示例#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);
     }
 }
示例#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();
     }
 }
 /// <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;
     }
 }
 /// <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();
     }
 }
示例#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);
     }
 }
示例#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);
        }
示例#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;
 }
示例#9
0
 /// <summary>
 /// Get the methods implementation for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public ITypeMethods Get(LType type)
 {
     return(_typeToMethods[type]);
 }
示例#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;
 }
示例#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;
 }
示例#12
0
 /// <summary>
 /// Get the methods implementation for the supplied type.
 /// </summary>
 /// <param name="type"></param>
 public ITypeMethods Get(LType type)
 {
     return _typeToMethods[type];
 }
示例#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);
 }
示例#14
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type"></param>
 public static void Register(LType type)
 {
     RegisterAlias(type, type.FullName, type.Name);
 }
示例#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));
 }
示例#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;
 }
示例#17
0
 /// <summary>
 /// Register the type
 /// </summary>
 /// <param name="type"></param>
 public static void Register(LType type)
 {
     RegisterAlias(type, type.FullName, type.Name);
 }