Exemple #1
0
        public Diagnostic[] GetDiagnostics()
        {
            var res = _diagnostics.ToArray();

            _diagnostics.ClearAndTruncate();
            return(res);
        }
Exemple #2
0
        internal void EnsureClientTypeVersion()
        {
            if (ClientTypeVersion != 0)
            {
                return;
            }
            EnsureKnownLastPersistedVersion();
            var props  = _clientType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var fields = new StructList <TableFieldInfo>();

            fields.Reserve((uint)props.Length);
            foreach (var pi in props)
            {
                if (pi.GetCustomAttributes(typeof(NotStoredAttribute), true).Length != 0)
                {
                    continue;
                }
                if (pi.GetIndexParameters().Length != 0)
                {
                    continue;
                }
                fields.Add(TableFieldInfo.Build(Name, pi, _tableInfoResolver.FieldHandlerFactory, FieldHandlerOptions.None));
            }
            var tvi = new TableVersionInfo(fields.ToArray());

            if (LastPersistedVersion == 0)
            {
                _tableVersions.TryAdd(1, tvi);
                ClientTypeVersion = 1;
            }
            else
            {
                var last = _tableVersions.GetOrAdd(LastPersistedVersion, (ver, tableInfo) => tableInfo._tableInfoResolver.LoadTableVersionInfo(tableInfo._id, ver, tableInfo.Name), this);
                if (TableVersionInfo.Equal(last, tvi))
                {
                    _tableVersions[LastPersistedVersion] = tvi; // tvi was build from real types and not loaded so it is more exact
                    ClientTypeVersion = LastPersistedVersion;
                }
                else
                {
                    _tableVersions.TryAdd(LastPersistedVersion + 1, tvi);
                    ClientTypeVersion = LastPersistedVersion + 1;
                }
            }
        }
Exemple #3
0
        public TypeInf(Type type, IFieldHandlerFactory fieldHandlerFactory)
        {
            OriginalType = type;
            _name        = type.Name;
            var methodInfs   = new StructList <MethodInf>();
            var propertyInfs = new StructList <PropertyInf>();

            if (type.IsSubclassOf(typeof(Delegate)))
            {
                var method = type.GetMethod(nameof(Action.Invoke));
                if (IsMethodSupported(method, fieldHandlerFactory))
                {
                    methodInfs.Add(new MethodInf(method, fieldHandlerFactory));
                }
            }
            else
            {
                var methods = type.GetMethods();
                foreach (var method in methods)
                {
                    var methodBase = method.GetBaseDefinition();
                    if (methodBase.DeclaringType == typeof(object))
                    {
                        continue;
                    }
                    if (methodBase.GetBaseDefinition().DeclaringType == typeof(IDisposable))
                    {
                        continue;
                    }
                    if (!methodBase.IsPublic)
                    {
                        continue;
                    }
                    if (!IsMethodSupported(method, fieldHandlerFactory))
                    {
                        continue;
                    }
                    methodInfs.Add(new MethodInf(method, fieldHandlerFactory));
                }
                var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                foreach (var property in properties)
                {
                    if (!property.CanRead || !property.CanWrite)
                    {
                        continue;
                    }
                    if (property.GetCustomAttributes(typeof(NotStoredAttribute), true).Length != 0)
                    {
                        continue;
                    }
                    if (property.GetIndexParameters().Length != 0)
                    {
                        continue;
                    }
                    if (property.GetGetMethod() == null)
                    {
                        continue;
                    }
                    if (property.GetSetMethod() == null)
                    {
                        continue;
                    }
                    if (!fieldHandlerFactory.TypeSupported(property.PropertyType))
                    {
                        continue;
                    }
                    propertyInfs.Add(new PropertyInf(property, fieldHandlerFactory));
                }
            }
            _methodInfs   = methodInfs.ToArray();
            _propertyInfs = propertyInfs.ToArray();
        }
Exemple #4
0
        private bool ParseDeclaration(ref ASTNode node)
        {
            AttributeNode             attrNode   = null;
            LightList <AttributeNode> attributes = LightList <AttributeNode> .Get();

            while (ParseAttribute(ref attrNode))
            {
                attributes.Add(attrNode);
                if (tokenStream.Current != ExpressionTokenType.ArrayAccessOpen)
                {
                    break;
                }
            }

            if (attributes.size == 0)
            {
                LightList <AttributeNode> .Release(ref attributes);
            }

            if (tokenStream.Current != ExpressionTokenType.Identifier)
            {
                return(false);
            }

            // modifiers? -> returnType -> name -> signature -> openBrace * closeBrace

            tokenStream.Save();

            bool isStatic = false;

            if (tokenStream.Current == "static")
            {
                isStatic = true;
                tokenStream.Advance();
            }

            ExpressionParser            parser    = new ExpressionParser(tokenStream);
            StructList <LambdaArgument> signature = null;
            TypeLookup typeLookup = default;

            if (!parser.ParseTypePath(ref typeLookup))
            {
                goto fail;
            }

            tokenStream.Set(parser.GetTokenPosition());
            parser.Release(false);

            if (tokenStream.Current != ExpressionTokenType.Identifier)
            {
                goto fail;
            }

            string name = tokenStream.Current.value;

            tokenStream.Advance();

            // if semi colon then we have a field!
            if (tokenStream.Current == ExpressionTokenType.SemiColon)
            {
                tokenStream.Advance();
                node = new FieldNode()
                {
                    name       = name,
                    isStatic   = isStatic,
                    attributes = attributes,
                    typeLookup = typeLookup
                };
                return(true);
            }

            if (tokenStream.Current != ExpressionTokenType.ParenOpen)
            {
                goto fail;
            }

            signature = StructList <LambdaArgument> .Get();

            if (tokenStream.NextTokenIs(ExpressionTokenType.ParenClose))
            {
                tokenStream.Advance(2);
            }
            else
            {
                int matchingIndex = tokenStream.FindMatchingIndex(ExpressionTokenType.ParenOpen, ExpressionTokenType.ParenClose);

                if (matchingIndex == -1)
                {
                    goto fail;
                }

                TokenStream subStream = tokenStream.AdvanceAndReturnSubStream(matchingIndex);
                subStream.Advance();
                tokenStream.Advance();
                if (!ExpressionParser.ParseSignature(subStream, signature))
                {
                    goto fail;
                }

                for (int i = 0; i < signature.size; i++)
                {
                    if (signature.array[i].type == null)
                    {
                        throw new ParseException($"When defining a method you must specify a type for all arguments. Found identifier {signature.array[i].identifier} but no type was given.");
                    }
                }
            }

            if (tokenStream.Current != ExpressionTokenType.ExpressionOpen)
            {
                goto fail;
            }

            BlockNode block = ParseBlock();

            node = new MethodNode()
            {
                body             = block,
                returnTypeLookup = typeLookup,
                attributes       = attributes,
                name             = name,
                isStatic         = isStatic,
                signatureList    = signature != null?signature.ToArray() : s_EmptySignature
            };

            StructList <LambdaArgument> .Release(ref signature);

            parser.Release(false);

            return(true);

fail:
            {
                tokenStream.Restore();
                parser.Release(false);
                typeLookup.Release();
                signature?.Release();
                return(false);
            }
        }