Exemple #1
0
        public override void Bind(IntermediateBuilder context)
        {
            if (_method == null)
            {
                foreach (var p in _parameters)
                {
                    p.Bind(context);
                }

                _thisPtr?.Bind(context);

                if (_resolver != null)
                {
                    _resolver.SetOwner(Owner);
                    _resolver.Bind(context);
                    _staticCall = _resolver.IsStatic;
                    if (!_staticCall)
                    {
                        _thisPtr = _resolver.GetReferencedFieldOrProperty();
                    }
                }

                CodeType type;
                if (_staticCall)
                {
                    type = _resolver.Type;
                }
                else if (_thisPtr == null)
                {
                    if (!_baseAccess)
                    {
                        type = new InterUserType(Owner.Owner);
                    }
                    else
                    {
                        type = UserType.ToUserType(Owner.Owner.BaseType);
                    }
                }
                else
                {
                    if (!_baseAccess)
                    {
                        type = _thisPtr.Type;
                    }
                    else
                    {
                        type = UserType.ToUserType(_thisPtr.Type).GetBaseType();
                    }
                }

                CodeType searchType;

                if (ThisPointerTypeOverride != null)
                {
                    searchType = ThisPointerTypeOverride;
                }
                else if (ThisPointerTypeNameOverride != TypeName.Unknown)
                {
                    searchType = context.ResolveType(ThisPointerTypeNameOverride);
                }
                else
                {
                    searchType = type;
                }

                _method = context.FindClosestFunction(_targetName, searchType, _parameters);
            }

            _return = _method.ReturnType;

            for (int i = 0; i < _parameters.Length; i++)
            {
                if (_parameters[i].Type.CanAssignTo(_method.Arguments[i].StoredType) == AssignType.CanAssign)
                {
                    continue;
                }

                _parameters[i] = new ConvertedValue(_parameters[i], _method.Arguments[i].StoredType, Owner);
                _parameters[i].Bind(context);
            }

            _valueType = _thisPtr != null &&
                         ((_thisPtr.Type is UserType &&
                           (_thisPtr.Type as UserType).ValueType) ||
                          _thisPtr.IsSymbol() && _thisPtr.Type is BasicType);

            if (_thisPtr == null)
            {
                return;
            }
            if (_thisPtr.Type is UserType && (_thisPtr.Type as UserType).ValueType)
            {
                _valueType = true;
            }
            if (_method.IsInstance && !_thisPtr.IsSymbol() && _thisPtr.Type is BasicType)
            {
                if (_thisPtr.ToSymbol() == null)
                {
                    _valueType = true;
                    LocalSymbol l = new LocalSymbol("locl" + Owner.Locals.Count, _thisPtr.Type, Owner.Locals.Count);
                    Owner.Locals.Add(l);
                    _symbolConversion = new InterCopy(l, _thisPtr);
                    _symbolConversion.SetOwner(Owner);
                    _symbolConversion.Bind(context);
                    _thisPtr = l;
                }
                else
                {
                    _thisPtr = _thisPtr.ToSymbol();
                }
            }
        }