Beispiel #1
0
        //public override bool Equals(object obj) {
        //	throw new InvalidProgramException("INTERNAL ERROR: Attempt to use type before it has been evaluated. (Equals)");
        //}

        public override ITypeDef Resolve(ExecContext context, ref bool error)
        {
            if (name == "void")
            {
                return(IntrinsicTypeDefs.VOID);
            }

            ITypeDef def = context.GetTypeByName(name);

            if (null == def)
            {
                context.engine.LogCompileError(ParseErrorType.TypeNotFound, "Type '" + name + "' not found.");
                error = true;
                return(null);
            }

            if (null == _templateTypes)
            {
                if (_isConst && !def.IsConst())
                {
                    return(def.Clone(true));
                }
                return(def);
            }

            // If we have template types, then we must be a TypeDef_Class.

            List <ITypeDef> genericTypes = new List <ITypeDef>();

            for (int ii = 0; ii < _templateTypes.Count; ++ii)
            {
                genericTypes.Add(_templateTypes[ii].Resolve(context, ref error));
            }

            if (error)
            {
                return(null);
            }


            //TypeDef_Class result = new TypeDef_Class(name, genericTypes, _isConst);
            TypeDef_Class result = TypeFactory.GetTypeDef_Class(name, genericTypes, _isConst);

            if (null == context.RegisterIfUnregisteredTemplate(result))
            {
                error = true;
            }
            return(result);
        }
Beispiel #2
0
        public static ITypeDef GetConstVersion(ITypeDef original)
        {
            if (original.IsConst())
            {
                return(original);
            }

            string constName = original.GetName() + " const";

            if (_typeRegistry.ContainsKey(constName))
            {
                return(_typeRegistry[constName]);
            }

            ITypeDef result = original.Clone(true);

            _typeRegistry.Add(constName, result);
            return(result);
        }
Beispiel #3
0
        public PebbleEnum(ExecContext context, string _enumName, ITypeDef valueTypeIn)
        {
            enumName  = _enumName;
            valueType = valueTypeIn;

            // Apparently need to register non-const first.
            ITypeDef nonConstEnumType = TypeFactory.GetTypeDef_Enum(_enumName, false);

            enumType  = (TypeDef_Enum)TypeFactory.GetConstVersion(nonConstEnumType);
            _classDef = new ClassDef_Enum(this, _enumName, enumType);
            context.RegisterClass(_classDef);

            _classDef.childAllocator = () => {
                return(new ClassValue_Enum());
            };
            _classDef.Initialize();


            //don't think this is needed _classDef.AddMemberLiteral("enumName", IntrinsicTypeDefs.CONST_STRING, _enumName, false);
            _classDef.AddMember("name", IntrinsicTypeDefs.CONST_STRING);
            _classDef.AddMember("value", valueType.Clone(true), null, false, true);

            {
                FunctionValue_Host.EvaluateDelegate eval = (_context, args, thisScope) => {
                    ClassValue cv = thisScope as ClassValue;
                    return(enumName + "::" + cv.Get(mrName).value);
                };
                FunctionValue newValue = new FunctionValue_Host(IntrinsicTypeDefs.STRING, new ArgList {
                }, eval, false, _classDef.typeDef);
                _classDef.AddMemberLiteral("ThisToString", newValue.valType, newValue, false);
            }

            _classDef.FinalizeClass(context);

            if (mrName.isInvalid)
            {
                mrName  = _classDef.GetMemberRef(null, "name", ClassDef.SEARCH.NORMAL);
                mrValue = _classDef.GetMemberRef(null, "value", ClassDef.SEARCH.NORMAL);
            }
        }