Exemple #1
0
 public override void ResolveTypesForSignatures(ParserContext context)
 {
     this.ResolvedReturnType = this.DoTypeLookup(this.ReturnType, context);
     this.ResolvedArgTypes   = this.ArgTypes
                               .Select(t => this.DoTypeLookup(t, context))
                               .Select(t => t.IsEnum ? ResolvedType.CreateEnumField(t) : t)
                               .ToArray();
 }
Exemple #2
0
        private void ResolveCustomFieldReference()
        {
            string fieldName = this.Name.Value;

            if (this.RootValue.ResolvedType.IsEnum)
            {
                if (!this.RootValue.ResolvedType.HasEnumField(fieldName))
                {
                    throw new ParserException(this.Name, this.RootValue.ResolvedType.ToString() + " doesn't have a field called " + fieldName + ".");
                }
                this.ResolvedType = ResolvedType.CreateEnumField(this.RootValue.ResolvedType);
            }
            else
            {
                ClassLikeDefinition rootType = (ClassLikeDefinition)this.RootValue.ResolvedType.CustomType;
                TopLevelEntity      member   = rootType.GetMember(fieldName).FirstOrDefault();
                if (member == null)
                {
                    throw new ParserException(this.Name, "Not implemented or not found.");                 // could be a framework field.
                }
                if (member is PropertyDefinition)
                {
                    this.Property     = (PropertyDefinition)member;
                    this.ResolvedType = this.Property.ResolvedType;
                }
                else if (member is FieldDefinition)
                {
                    this.Field        = (FieldDefinition)member;
                    this.ResolvedType = this.Field.ResolvedType;
                }
                else
                {
                    throw new ParserException(this.FirstToken, "Not implemented");
                }
            }
        }
Exemple #3
0
        private void ResolveFrameworkMethodReference(ResolvedType[] argTypes)
        {
            ResolvedType resolvedType = this.RootValue.ResolvedType;

            if (resolvedType.IsEnum)
            {
                if (resolvedType.FrameworkClass != null)
                {
                    if (!resolvedType.HasEnumField(this.Name.Value))
                    {
                        throw new ParserException(
                                  this.Name,
                                  resolvedType.ToString() + " doesn't have a field called " + this.Name.Value);
                    }
                    this.ResolvedType = ResolvedType.CreateEnumField(resolvedType);
                }
                else
                {
                    throw new NotImplementedException();
                }
                return;
            }
            string className  = resolvedType.FrameworkClass;
            string methodName = this.Name.Value;

            this.Type = MethodRefType.FRAMEWORK_METHOD;
            switch (className + ":" + methodName)
            {
            case "System.Collections.Generic.HashSet:Contains":
            case "System.Collections.Generic.ISet:Contains":
                ResolvedType itemType = resolvedType.Generics[0];
                this.ResolvedType = ResolvedType.CreateFunction(ResolvedType.Bool(), new ResolvedType[] { itemType });
                return;

            case "System.Collections.Generic.Dictionary:Keys":
            case "System.Collections.Generic.IDictionary:Keys":
                ResolvedType keyType = resolvedType.Generics[0];
                this.ResolvedType = ResolvedType.CreateEnumerableType(keyType);
                return;

            case "System.Collections.Generic.Dictionary:Values":
            case "System.Collections.Generic.IDictionary:Values":
                ResolvedType valueType = resolvedType.Generics[1];
                this.ResolvedType = ResolvedType.CreateEnumerableType(valueType);
                return;

            case "CommonUtil.Collections.Pair:First":
                this.ResolvedType = resolvedType.Generics[0];
                break;

            case "CommonUtil.Collections.Pair:Second":
                this.ResolvedType = resolvedType.Generics[1];
                break;

            case "CommonUtil.DateTime.Time:UnixTimeNow":
            case "System.Collections.Generic.HashSet:Count":
            case "System.Collections.Generic.Dictionary:Count":
            case "System.Collections.Generic.IDictionary:Count":
                this.ResolvedType = ResolvedType.Int();
                return;

            default:
                throw new ParserException(this.FirstToken, "Not implemented --> " + className + ":" + methodName);
            }
        }