示例#1
0
        private void CompileNextFieldDefinition(LexList theLexList, Type varType)
        {
            string varId = theLexList.GetIdentifier("Expected the name of the field here.");

            MostRecentNameAdded = varId;
            theLexList.CheckStr(";", "Expected a ; here");
            if (MadeFieldsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field already defined.");
            }
            if (CompileMethodsDict.ContainsKey(varId))
            {
                theLexList.ThrowException("This field name already used as a method name.");
            }
            MadeFieldsDict.Add(varId, new MadeField()
            {
                VarName = varId, VarType = varType, Index = MadeFieldsDict.Count
            });
            FieldInfo fi = ClassType.GetField("Fields", BindingFlags.Public | BindingFlags.Instance);

            if (fi == null)
            {
                theLexList.ThrowException("Can only add fields to a class that has a 'List<Object> Fields' field.");
            }
            if (fi.FieldType != typeof(List <object>))
            {
                theLexList.ThrowException("Can only add fields to a class where its Fields field is of type List<object>.");
            }
            theLexList.Next();
        }
示例#2
0
        // Syntax:
        // Member  = '.' StaticMember .
        public ExpState ParseMember(Type theClass, LexList list, BindingFlags flags, bool implicitDot)
        {
            if (!implicitDot)
            {
                list.CheckStrAndAdvance(".", "Expected a dot followed by a static member name here.");
            }
            LexToken token = list.CurrentToken();
            string   name  = list.GetIdentifier("Expected the name of a static member here.");

            FieldInfo fi = theClass.GetField(name, flags);

            if (fi != null)
            {
                return(new ExpState(fi));
            }

            list.Prev();
            return(null);
        }
示例#3
0
        // Syntax:
        // Type               =  TypeNonArray [ TypeArrayPart ] .
        // TypeNonArray       =  TypeIdAndGenerics *( '.' TypeIdAndGenerics ) .
        // TypeIdAndGenerics  =  TypeIdentifier [ Generics ] .
        // Generics           =  '<' Type *( ',' Type ) '>' .
        // TypeArrayPart      =  '[' ']' *( '[' ']' ) .

        public Type Parse(LexList list, bool typeOnly, bool arrayIndexActualsAllowed, out bool pendingCloseAngle, BindingFlags visibility)
        {
            string id         = "";
            Type   returnType = null;
            int    checkPoint = list.Index;

            pendingCloseAngle = false;

            while (true)
            {
                if (list.Kind == LexKind.Type)
                {
                    returnType = list.CurrentToken().ActualObject as Type;
                    list.Next();
                    return(returnType);
                }
                if (list.Kind != LexKind.Identifier)
                {
                    if (typeOnly)
                    {
                        list.ThrowException("Unable to convert this to a type.");
                    }
                    return(returnType);
                }
                if (id != "")
                {
                    id += ".";
                }
                id += list.GetIdentifier();
                Type ty = null;
                if (list.Str != "<" || !IsGenericSpec(list))
                {
                    ty = FindTypeFromDottedIds(returnType, id, visibility);
                }
                if (ty != null)
                {
                    id         = "";
                    returnType = ty;
                    checkPoint = list.Index;
                    if (list.Kind == LexKind.End)
                    {
                        return(returnType);
                    }
                    if (list.Str != ".")
                    {
                        return(ParseArrayTypeModifier(list, returnType, arrayIndexActualsAllowed));
                    }
                }
                else if (ty == null && list.Str == "<" && IsGenericSpec(list))
                {
                    // The test for the GenericSpec is needed to separate out comparision '<' or shift '<' from generic brackets.
                    int    save  = list.Index;
                    Type[] types = ParseGenericTypeModifier(list, out pendingCloseAngle, visibility);
                    id += "`" + types.Length.ToString();
                    ty  = FindTypeFromDottedIds(returnType, id, visibility);
                    if (ty != null)
                    {
                        ty = ty.MakeGenericType(types.ToArray());
                    }
                    if (ty == null)
                    {
                        if (typeOnly)
                        {
                            list[save].ThrowException("Unable to resolve generic type.", list);
                        }
                        list.Index = checkPoint;
                        return(returnType);
                    }
                    return(ParseArrayTypeModifier(list, ty, arrayIndexActualsAllowed));
                }
                else
                {
                    if (list.Str != ".")
                    {
                        if (typeOnly)
                        {
                            list.Prev(); list.ThrowException("Unable to convert this to a type.");
                        }
                        list.Index = checkPoint;
                        return(returnType);
                    }
                }
                list.Next(); // skips over the '.'
            }
        }