Esempio n. 1
0
 public override void LoadType(CClass type)
 {
     if (declared[0] != null)
     {
         declared[0].LoadType(type);
     }
 }
 public override bool canConvertTo(CClass klass)
 {
     if (klass.Name == "progid:scripting.dictionary")
     {
         return(true);
     }
     return(base.canConvertTo(klass));
 }
Esempio n. 3
0
 public virtual void incAccessCount(CClass currentclass, CFunction currentfunction)
 {
     if (assignCount == 0)
     {
         accessedBeforeUsed = true;
     }
     accessCount++;
 }
Esempio n. 4
0
 public CClassConst(CClass declaringClass, CConst myConst)
     : base(myConst.Token, myConst.Name.Value, "const", 1, false)
 {
     this.declaringClass = declaringClass;
     this.myConst        = myConst;
     Declared[0]         = myConst;
     myConst.ClassConst  = this;
 }
Esempio n. 5
0
        public CConstantExpression(CToken tok)
            : base(tok)
        {
            m_value = tok;
            CClass type = null;

            switch (tok.TokenType)
            {
            case TokenTypes.number:
                int i;
                if (Int32.TryParse(tok.Value, out i) || tok.Value.StartsWith("0x"))
                {
                    type = BuiltIns.Int32;
                }
                else
                {
                    type = BuiltIns.Double;
                }
                break;

            case TokenTypes.str:
                type = BuiltIns.String;
                break;

            case TokenTypes.character:
                type = BuiltIns.Character;
                break;

            case TokenTypes.pound:
                type = BuiltIns.Date;
                break;

            case TokenTypes.keyword:
                if (tok.Value == "true")
                {
                    type = BuiltIns.Boolean;
                }
                else if (tok.Value == "false")
                {
                    type = BuiltIns.Boolean;
                }
                else if (tok.Value == "nothing")
                {
                    type = BuiltIns.Nothing;
                }
                else if (tok.Value == "dbnull")
                {
                    type = BuiltIns.DbNull;
                }
                break;
            }
            if (type != null)
            {
                base.LoadType(type);
            }
        }
Esempio n. 6
0
 internal void AddClass(string p, CClass type)
 {
     if (classes.ContainsKey(p))
     {
         CClass[] rg = new CClass[] { type, classes[p] };
         duplicateClasses.Add(rg);
     }
     classes[p] = type;
     classesList.Add(type);
 }
Esempio n. 7
0
 protected override bool canUnionConvert(CClass klass)
 {
     foreach (CTypeRef tref in types)
     {
         if (tref.ActualType == null || !tref.ActualType.canConvertTo(klass))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 8
0
        public override bool canConvertTo(CClass klass)
        {
            CFunctionType target = klass as CFunctionType;

            if (target == null)
            {
                return(base.canConvertTo(klass));
            }

            UpdateName();
            target.UpdateName();

            return(Name == target.Name);
        }
Esempio n. 9
0
        public CClass FindClass(CToken name, bool searchImports)
        {
            CClass result = null;

            CFile file = null;

            if (name.Filename != null)
            {
                fileMap.TryGetValue(name.Filename, out file);
            }

            // first look to see if the type has been renamed
            CToken newName;

            if (file != null && file.ClassNameAliases.TryGetValue(name.RawValue, out newName))
            {
                name = newName;
            }

            // Try to find the class the normal way
            if (result == null)
            {
                result = InternalFindClass(name.RawValue, name.Value, searchImports);
            }

            // Look in the namespace mapping
            if (result == null && file != null)
            {
                foreach (var prefix in file.NameSpaceResolutionPrefixes)
                {
                    result = InternalFindClass(
                        prefix.RawValue + "." + name.RawValue,
                        prefix.Value + "." + name.Value,
                        searchImports);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
        internal CStatementBlock StartInitialize(CFunction containingFunction, CFile containingFile, CTypeRef tref, CArgumentList args)
        {
            if (lambdaFunction != null)
            {
                throw new InvalidOperationException("Lambdas can only be initalized once");
            }

            CClass @class = null;
            string extra  = "";

            if (containingFunction != null)
            {
                @class = containingFunction.Class;
                extra += containingFunction.RawName;
            }

            lambdaFunction =
                new CLambdaFunction(Token, containingFunction, containingFile, "Lambda_" + extra + "_" + lambdaId, tref, args);
            base.LoadType(lambdaType = new CFunctionType(Token, lambdaFunction, false));

            lambdaFunction.Class = @class;

            return(lambdaFunction.Statements);
        }
Esempio n. 11
0
 public virtual bool canAssign(CClass currentclass, CFunction currentfunction)
 {
     return(currentfunction == this);
 }
Esempio n. 12
0
 public void incAccessCount(CClass currentclass, CFunction currentfunction)
 {
     accesses++;
 }
Esempio n. 13
0
 public virtual void incAssignmentCount(CClass currentclass, CFunction currentfunction)
 {
     assignCount++;
 }
Esempio n. 14
0
 public CTypeRef(CNode owner, CClass type)
     : this(owner)
 {
     InternalLoad(type);
 }
Esempio n. 15
0
 internal void InternalLoad(CClass type)
 {
     ActualType = type;
 }
Esempio n. 16
0
 public virtual void Add(CClass type)
 {
     Add(new CTypeRef(this, type));
 }
Esempio n. 17
0
        public override void ConvertToArray(CClass type, int count)
        {
            base.ConvertToArray(type, count);

            EnsureDiminsionInitializerIsValid();
        }
Esempio n. 18
0
        public virtual String UpdateMembers(IVisitor checker)
        {
            if (types.Count == 0)
            {
                return("Empty enum type used");
            }

            bool isObject = true;

            for (int i = 0; i < types.Count; i++)
            {
                CTypeRef otype = types[i];
                if (!otype.Resolved)
                {
                    CClass ntype = CProgram.Global.FindClass(otype.TypeName);
                    if (ntype == null)
                    {
                        return("Cannot find type " + otype.TypeName.RawValue);
                    }
                    otype.InternalLoad(ntype);
                }
                types[i] = otype;
                types[i].ActualType.Accept(checker);
                isObject = isObject && otype.ActualType.IsObject;
            }
            IsObject = isObject;

            base.ClearMembers();
            Scope.Clear();

            foreach (CMember member in types[0].ActualType.InheritedMemberIterator)
            {
                bool found;
                if (member is CMemberOverload)
                {
                    found = false;
                }
                else// Unions can only access public members
                {
                    found = member.Visibility == TokenTypes.visPublic;
                }


                IEnumerator <CTypeRef> it = types.GetEnumerator();
                it.MoveNext();
                while (found && it.MoveNext())
                {
                    CClass  type     = it.Current.ActualType;
                    CMember luMember = type.LookupMember(member.Name);
                    if (luMember == null)
                    {
                        found = false;
                    }
                    else if (luMember.MemberType != member.MemberType)
                    {
                        // one's a method, the other's a field, or etc...
                        found = false;
                    }
                    else if (luMember.Visibility != TokenTypes.visPublic)
                    {
                        found = false;
                    }
                    else
                    {
                        switch (luMember.MemberType)
                        {
                        case "method":
                            CMethod metho   = (CMethod)member;
                            CMethod luMetho = (CMethod)luMember;
                            // already checked return type, let's try the parameters
                            if (metho.Function.Arguments.Count != luMetho.Function.Arguments.Count)
                            {
                                found = false;
                            }
                            break;

                        case "property":
                            found = UnionProperty((CProperty)member, (CProperty)luMember);
                            // dur
                            break;

                        case "field":
                            // already checked return type, nothing left to check
                            break;

                        case "override":
                            found = false;    // dur
                            break;
                        }
                    }
                }
                if (found)
                {
                    CMember fmember;
                    switch (member.MemberType)
                    {
                    case "method":
                        fmember = new CMethod((CMethod)member, true);
                        break;

                    case "property":
                        fmember = new CProperty((CProperty)member, true);
                        break;

                    case "field":
                        fmember = new CField((CField)member, true);
                        break;

                    case "override":
                        fmember = new CMemberOverload((CMemberOverload)member, true);
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                    SetMember(member.Name, fmember);
                    Scope.add(fmember);
                }
            }

            bool hasDefault = true;

            DefaultMember = null;
            foreach (CTypeRef _class in types)
            {
                var memberBase = ((CClass)types[0]).DefaultMember;
                var member     = _class.ActualType.DefaultMember;
                if (memberBase == null ||
                    member == null ||
                    !UnionProperty((CProperty)memberBase, (CProperty)member))
                {
                    hasDefault = false;
                    break;
                }
            }
            if (hasDefault)
            {
                DefaultMember = ((CClass)types[0]).DefaultMember;
            }

            return(null);
        }
Esempio n. 19
0
 public virtual void LoadType(CClass type)
 {
     this.type.InternalLoad(type);
 }
Esempio n. 20
0
 public CTypeRef(CNode owner)
 {
     this.owner = owner;
     name       = null;
     type       = null;
 }
Esempio n. 21
0
 public void incAssignmentCount(CClass currentclass, CFunction currentfunction)
 {
     throw new Exception("Const variable is readonly");
 }
Esempio n. 22
0
 public void add(CClass type)
 {
     add(type.Name, type);
 }
Esempio n. 23
0
 public virtual void ConvertToArray(CClass type, int count)
 {
     base.LoadType(type);
 }
Esempio n. 24
0
 public CMemberOverload(CMemberOverload field, bool isUnionMember)
     : base(field.Token, field.Name, "override", 0, isUnionMember)
 {
     this.owner = field.DeclaringClass;
 }
Esempio n. 25
0
 public CMemberOverload(CToken tok, CClass owner, string name)
     : base(tok, name, "override", 0, false)
 {
     this.owner = owner;
 }
Esempio n. 26
0
 public bool canAssign(CClass currentclass, CFunction currentfunction)
 {
     return(false);
 }
Esempio n. 27
0
        public override void LoadType(CClass type)
        {
            base.LoadType(type);

            EnsureDiminsionInitializerIsValid();
        }