Пример #1
0
        public override void OnAttribute(Boo.Lang.Ast.Attribute attribute, ref Boo.Lang.Ast.Attribute resultingNode)
        {
            // Neste primeiro passo tentamos apenas
            // resolver ast attributes.
            // Um passo posterior (resoluo de nomes e tipos) ir
            // assegurar que todos os nomes tenham sido resolvidos e colocar
            // mensagens de erro de acordo
            IBinding binding = ResolveQualifiedName(attribute, attribute.Name);

            if (null == binding)
            {
                binding = ResolveQualifiedName(attribute, BuildAttributeName(attribute.Name));
            }

            if (null != binding)
            {
                if (BindingType.Ambiguous == binding.BindingType)
                {
                    Errors.AmbiguousName(attribute, attribute.Name, ((AmbiguousBinding)binding).Bindings);
                }
                else
                {
                    if (BindingType.TypeReference != binding.BindingType)
                    {
                        Errors.NameNotType(attribute, attribute.Name);
                    }
                    else
                    {
                        ITypeBinding attributeType = ((ITypedBinding)binding).BoundType;
                        if (IsAstAttribute(attributeType))
                        {
                            ExternalTypeBinding externalType = attributeType as ExternalTypeBinding;
                            if (null == externalType)
                            {
                                Errors.AstAttributeMustBeExternal(attribute, attributeType);
                            }
                            else
                            {
                                ScheduleAttributeApplication(attribute, externalType.Type);

                                // remove it from parent
                                resultingNode = null;
                            }
                        }
                        else
                        {
                            if (!IsSystemAttribute(attributeType))
                            {
                                Errors.TypeNotAttribute(attribute, attributeType.FullName);
                            }
                            else
                            {
                                // remember the attribute's type
                                BindingManager.Bind(attribute, attributeType);
                            }
                        }
                    }
                }
            }
        }
        protected TypeReference CreateBoundTypeReference(ITypeBinding binding)
        {
            TypeReference typeReference = new TypeReference(binding.FullName);

            BindingManager.Bind(typeReference, BindingManager.ToTypeReference(binding));
            return(typeReference);
        }
Пример #3
0
 private void UpdateTypeBinding(string typeName, ITypeBinding typeBinding)
 {
     if (typeBinding != null)
     {
         _typeBindings[typeName] = typeBinding;
         AddNativeTypeBinding(typeBinding.Type, typeName);
     }
 }
Пример #4
0
        public void RegisterType(INamedType namedType, ITypeBinding typeBinding = null)
        {
            if (namedType == null)
            {
                throw new ArgumentNullException(nameof(namedType));
            }

            _schemaContext.Types.RegisterType(namedType, typeBinding);
        }
Пример #5
0
        public ITypeBinding ToTypeBinding(TypeDefinition typeDefinition)
        {
            ITypeBinding binding = (ITypeBinding)_bindingCache[typeDefinition];

            if (null == binding)
            {
                Cache(typeDefinition, binding = new InternalTypeBinding(this, typeDefinition));
            }
            return(binding);
        }
Пример #6
0
        public bool IsAssignableFrom(ITypeBinding other)
        {
            ExternalTypeBinding external = other as ExternalTypeBinding;

            if (null == external)
            {
                return(other.IsSubclassOf(this));
            }
            return(_type.IsAssignableFrom(external._type));
        }
Пример #7
0
        public bool IsSubclassOf(ITypeBinding other)
        {
            ExternalTypeBinding external = other as ExternalTypeBinding;

            if (null == external)
            {
                throw new NotImplementedException(other.ToString());
            }
            return(_type.IsSubclassOf(external._type));
        }
Пример #8
0
        public ITypedBinding ToTypeReference(ITypeBinding type)
        {
            ITypedBinding cached = (ITypedBinding)_referenceCache[type];

            if (null == cached)
            {
                cached = new TypeReferenceBinding(type);
                _referenceCache[type] = cached;
            }
            return(cached);
        }
Пример #9
0
 public override bool IsSubclassOf(ITypeBinding type)
 {
     foreach (TypeReference baseTypeReference in _typeDefinition.BaseTypes)
     {
         ITypeBinding baseType = _bindingManager.GetBoundType(baseTypeReference);
         if (type == baseType || baseType.IsSubclassOf(type))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #10
0
        public void RegisterType(INamedType namedType, ITypeBinding typeBinding)
        {
            if (namedType == null)
            {
                throw new ArgumentNullException(nameof(namedType));
            }

            if (!_sealed)
            {
                TryUpdateNamedType(namedType);
                UpdateTypeBinding(namedType.Name, typeBinding);
            }
        }
Пример #11
0
        public void RegisterType(INamedType namedType, ITypeBinding typeBinding = null)
        {
            if (namedType == null)
            {
                throw new ArgumentNullException(nameof(namedType));
            }

            if (!_namedTypes.ContainsKey(namedType.Name))
            {
                _namedTypes[namedType.Name] = namedType;
            }

            if (typeBinding != null)
            {
                _typeBindings[namedType.Name] = typeBinding;
            }
        }
Пример #12
0
        public override void Run()
        {
            _astAttributeBaseClass    = BindingManager.ToTypeBinding(typeof(AstAttribute));
            _systemAttributeBaseClass = BindingManager.ToTypeBinding(typeof(System.Attribute));

            int step = 0;

            while (step < CompilerParameters.MaxAttributeSteps)
            {
                Switch(CompileUnit);
                if (0 == _tasks.Count)
                {
                    // Colocar informao de tracing aqui...
                    break;
                }
                _tasks.Flush();
                ++step;
            }
        }
Пример #13
0
 public ParameterBinding(ParameterDeclaration parameter, ITypeBinding type)
 {
     _parameter = parameter;
     _type      = type;
     _index     = -1;
 }
Пример #14
0
 bool IsSystemAttribute(ITypeBinding type)
 {
     return(type.IsSubclassOf(_systemAttributeBaseClass));
 }
Пример #15
0
        /// <summary>
        /// Scan properties and add column definition.
        /// </summary>
        private void AddColumns()
        {
            List <string> primaryKeyProps = null;
            Dictionary <Type, List <IDbColumnBinding> > foreignKeyFields = null;
            List <string> uniqueKeyProps = null;

            columns = new TypeBinding <IDbColumnBinding, DbColumnAttribute>(TemplateType,
                                                                            (p, a) => DbColumnBinding.CreateInstance(Setup, p, a, this));

            foreach (var col in columns.BindingList)
            {
                var keyConstraint = col.KeyConstraint;

                if (keyConstraint == DbKeyConstraint.PrimaryKey || keyConstraint == DbKeyConstraint.PrimaryForeignKey)
                {
                    (primaryKeyProps = primaryKeyProps ?? new List <string>()).Add(col.PropertyName);
                }

                if (keyConstraint == DbKeyConstraint.UniqueKey)
                {
                    (uniqueKeyProps = uniqueKeyProps ?? new List <string>()).Add(col.PropertyName);
                }

                if (keyConstraint == DbKeyConstraint.ForeignKey || keyConstraint == DbKeyConstraint.PrimaryForeignKey)
                {
                    foreignKeyFields = foreignKeyFields ?? new Dictionary <Type, List <IDbColumnBinding> >();
                    if (!foreignKeyFields.TryGetValue(col.PrimaryTableTemplate, out List <IDbColumnBinding> list))
                    {
                        list = new List <IDbColumnBinding>();
                        foreignKeyFields.Add(col.PrimaryTableTemplate, list);
                    }
                    list.Add(col);
                }
            }

            if (primaryKeyProps != null)
            {
                if (PrimaryKey != null)
                {
                    throw new ArgumentException($"Multiple primary key definition in table [{TableName}]");
                }

                PrimaryKey = new DbTablePrimaryKeyAttribute(primaryKeyProps.ToArray());
            }

            if (PrimaryKey?.PropertyNames.Length == 1)
            {
                SingleColumnPrimaryKey = this.FindColumn(primaryKeyProps[0]);
            }

            if (uniqueKeyProps != null)
            {
                uniqueKeys.Add(new DbTableUniqueKeyAttribute(uniqueKeyProps.ToArray()));
            }

            if (uniqueKeys?.Count == 1 && uniqueKeys[0].PropertyNames.Length == 1)
            {
                SingleColumnUniqueKey = this.FindColumn(uniqueKeys[0].PropertyNames[0]);
            }

            if (foreignKeyFields != null)
            {
                foreach (var item in foreignKeyFields)
                {
                    foreach (var rel in item.Value)
                    {
                        var attr = new DbTableForeignKeyAttribute(item.Key, rel.PropertyName);
                        foreignKeys.Add(attr);
                    }
                }
            }
        }
Пример #16
0
 bool IsAstAttribute(ITypeBinding type)
 {
     return(type.IsSubclassOf(_astAttributeBaseClass));
 }
Пример #17
0
 void Cache(object key, ITypeBinding binding)
 {
     _bindingCache[key] = binding;
 }
Пример #18
0
 public virtual bool IsSubclassOf(ITypeBinding other)
 {
     return(false);
 }
Пример #19
0
 public virtual bool IsAssignableFrom(ITypeBinding other)
 {
     return(false);
 }
Пример #20
0
 public LocalBinding(Local local, ITypeBinding typeInfo)
 {
     _local    = local;
     _typeInfo = typeInfo;
 }
Пример #21
0
        // From class Starcounter.Db. Added CultureInfo.InvariantCulture and NumberFormatInfo.InvariantInfo.
        internal static String CreateObjectString(ITypeBinding typeBind, IObjectView currentObj)
        {
            IPropertyBinding propBind = null;
            String result = FieldSeparator;
            for (Int32 i = 0; i < typeBind.PropertyCount; i++)
            {
                propBind = typeBind.GetPropertyBinding(i);
                switch (propBind.TypeCode)
                {
                    case DbTypeCode.Binary:
                        Nullable<Binary> binValue = currentObj.GetBinary(i);
                        if (binValue == null)
                            result += Db.NullString;
                        else
                            result += BinaryToHex(binValue.Value);
                        break;

                    case DbTypeCode.Boolean:
                        Nullable<Boolean> blnValue = currentObj.GetBoolean(i);
                        if (blnValue == null)
                            result += Db.NullString;
                        else
                            result += blnValue.Value.ToString();
                        break;

                    case DbTypeCode.Byte:
                        Nullable<Byte> byteValue = currentObj.GetByte(i);
                        if (byteValue == null)
                            result += Db.NullString;
                        else
                            result += byteValue.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.DateTime:
                        Nullable<DateTime> dtmValue = currentObj.GetDateTime(i);
                        if (dtmValue == null)
                            result += Db.NullString;
                        else
                            result += dtmValue.Value.ToString("u", DateTimeFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Decimal:
                        Nullable<Decimal> decValue = currentObj.GetDecimal(i);
                        if (decValue == null)
                            result += Db.NullString;
                        else
                            result += decValue.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Double:
                        Nullable<Double> dblValue = currentObj.GetDouble(i);
                        if (dblValue == null)
                            result += Db.NullString;
                        else
                            result += dblValue.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Int16:
                        Nullable<Int16> int16Value = currentObj.GetInt16(i);
                        if (int16Value == null)
                            result += Db.NullString;
                        else
                            result += int16Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Int32:
                        Nullable<Int32> int32Value = currentObj.GetInt32(i);
                        if (int32Value == null)
                            result += Db.NullString;
                        else
                            result += int32Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Int64:
                        Nullable<Int64> int64Value = currentObj.GetInt64(i);
                        if (int64Value == null)
                            result += Db.NullString;
                        else
                            result += int64Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Object:
                        IObjectView objValue = currentObj.GetObject(i);
                        if (objValue == null)
                            result += Db.NullString;
                        else
                        {
                            if (objValue is IObjectProxy)
                                //result += DbHelper.GetObjectID(objValue as Entity).ToString();
                                result += Utilities.GetObjectIdString(objValue);
                            else
                                result += objValue.ToString();
                        }
                        break;

                    case DbTypeCode.SByte:
                        Nullable<SByte> sbyteValue = currentObj.GetSByte(i);
                        if (sbyteValue == null)
                            result += Db.NullString;
                        else
                            result += sbyteValue.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.Single:
                        Nullable<Single> sngValue = currentObj.GetSingle(i);
                        if (sngValue == null)
                            result += Db.NullString;
                        else
                            result += sngValue.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.String:
                        String strValue = currentObj.GetString(i);
                        if (strValue == null)
                            result += Db.NullString;
                        else
                            result += strValue;
                        break;

                    case DbTypeCode.UInt16:
                        Nullable<UInt16> uint16Value = currentObj.GetUInt16(i);
                        if (uint16Value == null)
                            result += Db.NullString;
                        else
                            result += uint16Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.UInt32:
                        Nullable<UInt32> uint32Value = currentObj.GetUInt32(i);
                        if (uint32Value == null)
                            result += Db.NullString;
                        else
                            result += uint32Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    case DbTypeCode.UInt64:
                        Nullable<UInt64> uint64Value = currentObj.GetUInt64(i);
                        if (uint64Value == null)
                            result += Db.NullString.ToString(NumberFormatInfo.InvariantInfo);
                        else
                            result += uint64Value.Value.ToString(NumberFormatInfo.InvariantInfo);
                        break;

                    default:
                        throw new Exception("Incorrect TypeCode: " + propBind.TypeCode);
                }
                result += FieldSeparator;
            }
            return result;
        }
Пример #22
0
 public TypeReferenceBinding(ITypeBinding type)
 {
     _type = type;
 }