Beispiel #1
0
        public Function CreateSetter(CodeString Declaration, CodeString ValueName, CodeString Code,
                                     IdentifierAccess Access = IdentifierAccess.Public)
        {
            var PChildren = Property.Children.Length;
            var Children  = new Identifier[PChildren + 1];

            Children[0]         = GlobalContainer.CommonIds.Void;
            Children[PChildren] = new FunctionParameter(this, ValueName, Property.TypeOfSelf);

            for (var i = 1; i < PChildren; i++)
            {
                Children[i] = Property.Children[i];
            }

            var Type = new TypeOfFunction(this, DefaultCallConv, Children);
            var Ret  = CreateFunctionForAccessor("set", Declaration, Type, Access);

            if (Ret == null || !CreateScopeForAccessor(Ret, Code))
            {
                return(null);
            }

            Setter = Ret;
            return(Ret);
        }
Beispiel #2
0
        public AccessModifier(CodeString Code, IdentifierAccess Access)
            : base(Code)
        {
            this.Access = Access;

            if (Access == IdentifierAccess.Unknown)
            {
                throw new ArgumentOutOfRangeException("Access");
            }
        }
Beispiel #3
0
        public static bool GetIdAccess(IdContainer Container, ref CodeString Code, out IdentifierAccess Ret)
        {
            var Mods = Recognize(Container, ref Code);

            if (Mods == null)
            {
                Ret = IdentifierAccess.Unknown;
                return(false);
            }

            return(GetIdAccess(Container.State, Mods, out Ret));
        }
Beispiel #4
0
        public Word Visit(IdentifierAccess identifierAccess)
        {
            var result = identifierAccess.IdentifierNode.Accept(this);

            if (IsError(result))
            {
                return(result);
            }
            var idValue = ((MyString)result).StringValue;

            return(new IdentifierSegment(idValue));
        }
        private IdentifierAccess CreateIdentifier(string text)
        {
            if (_identifiers.Contains(text))
            {
                return _identifiers[text];
            }
            else
            {
                var identifier = new IdentifierAccess(text);

                _identifiers.Add(identifier);

                return identifier;
            }
        }
Beispiel #6
0
        private IdentifierAccess CreateIdentifier(string text)
        {
            if (_identifiers.Contains(text))
            {
                return(_identifiers[text]);
            }
            else
            {
                var identifier = new IdentifierAccess(text);

                _identifiers.Add(identifier);

                return(identifier);
            }
        }
Beispiel #7
0
        public Function CreateGetter(CodeString Declaration, CodeString Code, IdentifierAccess Access = IdentifierAccess.Public)
        {
            var Children = new Identifier[Property.Children.Length];

            for (var i = 0; i < Property.Children.Length; i++)
            {
                Children[i] = Property.Children[i];
            }

            var Type = new TypeOfFunction(this, DefaultCallConv, Children);
            var Ret  = CreateFunctionForAccessor("get", Declaration, Type, Access);

            if (Ret == null || !CreateScopeForAccessor(Ret, Code))
            {
                return(null);
            }

            Getter = Ret;
            return(Ret);
        }
Beispiel #8
0
        public static bool GetIdAccess(CompilerState State, List <Modifier> Mods, out IdentifierAccess Ret)
        {
            var RetValue = true;

            Ret = IdentifierAccess.Unknown;

            for (var i = 0; i < Mods.Count; i++)
            {
                var Mod = Mods[i] as AccessModifier;
                if (Mod == null)
                {
                    State.Messages.Add(MessageId.NotExpected, Mods[i].Code);
                    RetValue = false;
                    continue;
                }

                Ret = Mod.Access;
            }

            return(RetValue);
        }
Beispiel #9
0
        Function CreateFunctionForAccessor(string Name, CodeString Declaration, TypeOfFunction Type, IdentifierAccess Access)
        {
            if (Identifiers.IsLessRestrictive(Access, Property.Access))
            {
                State.Messages.Add(MessageId.PropertyAccessLevel, Name);
                return(null);
            }

            Function Ret;

            if (!(Parent is StructuredScope) || (Property.Flags & IdentifierFlags.Static) != 0)
            {
                Ret = new Function(this, new CodeString(Name), Type, null);
            }
            else
            {
                Ret = new MemberFunction(this, new CodeString(Name), Type, null);
            }

            Ret.Flags       = Property.Flags;
            Ret.Access      = Access;
            Ret.Declaration = Declaration;
            return(Ret);
        }
Beispiel #10
0
 public virtual IAstNode IdentifierAccess(IdentifierAccess identifierAccess)
 {
     return(identifierAccess);
 }
Beispiel #11
0
        public IExpression IdentifierAccess(IdentifierAccess identifierAccess)
        {
            // First try variables.

            var identifiers = _resolver.DynamicExpression.ParseResult.Identifiers;

            for (int i = 0; i < _resolver.IdentifierTypes.Length; i++)
            {
                if (
                    _resolver.IdentifierTypes[i] != null &&
                    _resolver.IdentifiersEqual(identifiers[i].Name, identifierAccess.Name)
                    )
                {
                    return(VariableAccess(_resolver.IdentifierIndexes[i], _resolver.IdentifierTypes[i]));
                }
            }

            // Next, we go through the owner type.

            if (_resolver.OwnerType != null)
            {
                var result = Resolve(new VariableAccess(_resolver.OwnerType, 0), identifierAccess.Name);

                if (result == null)
                {
                    result = Resolve(new TypeAccess(_resolver.OwnerType), identifierAccess.Name);
                }

                if (result != null)
                {
                    return(result);
                }
            }

            // Next, imports. Namespaces have precedence.

            foreach (var import in _resolver.Imports)
            {
                if (
                    import.Namespace != null &&
                    _resolver.IdentifiersEqual(import.Namespace, identifierAccess.Name)
                    )
                {
                    if (import.Type != null)
                    {
                        return(new TypeAccess(import.Type));
                    }
                    else
                    {
                        return(new ImportAccess(import));
                    }
                }
            }

            // Next, members of the imports.

            foreach (var import in _resolver.Imports)
            {
                if (import.Namespace == null)
                {
                    var result = Resolve(new TypeAccess(import.Type), identifierAccess.Name);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            // Last, see whether the identifier is a built in type.

            var type = TypeUtil.GetBuiltInType(identifierAccess.Name, _resolver.DynamicExpression.Language);

            if (type != null)
            {
                return(new TypeAccess(type));
            }

            throw new ExpressionsException(
                      String.Format("Unresolved identifier '{0}'", identifierAccess.Name),
                      ExpressionsExceptionType.UndefinedName
                      );
        }