예제 #1
0
        public static TypeDecl EnsureTypeWithoutNameInTemplate(string[] tokens, ref int index)
        {
            int      oldIndex = index;
            TypeDecl type     = null;

            try
            {
                type = EnsureTypeWithoutName(tokens, ref index);
            }
            catch (ArgumentException)
            {
                index = oldIndex;
            }

            if (CppParser.Token(tokens, ref index, ">") || CppParser.Token(tokens, ref index, ","))
            {
                index--;
            }
            else
            {
                index = oldIndex;
                CppParser.SkipUntilInTemplate(tokens, ref index, ">", ",");
                index--;

                type = new ConstantTypeDecl
                {
                    Value = tokens
                            .Skip(oldIndex)
                            .Take(index - oldIndex)
                            .Aggregate((a, b) => a + " " + b),
                };
            }
            return(type);
        }
예제 #2
0
        public SourceNamedTypeSymbol(SourceFileSymbol file, TypeDecl syntax)
        {
            Contract.ThrowIfNull(file);

            _syntax = syntax;
            _file   = file;
        }
예제 #3
0
        public static bool ParseType(string[] tokens, ref int index, out TypeDecl decl, out string name)
        {
            decl = null;
            name = null;
            TypeDecl miniType = null;

            if (ParseMiniType(tokens, ref index, out miniType))
            {
                CallingConvention callingConvention = CallingConvention.Default;
                TypeDecl          continuationDecl  = null;
                Action <TypeDecl> continuation      = null;
                ParseTypeContinue(tokens, ref index, out callingConvention, out continuationDecl, out continuation, out name);
                if (callingConvention != CallingConvention.Default)
                {
                    throw new ArgumentException("Failed to parse.");
                }
                if (continuationDecl != null)
                {
                    continuation(miniType);
                    decl = continuationDecl;
                }
                else
                {
                    decl = miniType;
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
 void CheckTypeDecl(TypeDecl type)
 {
     Assert.IsTrue(type.Name.HasValue);
     Assert.IsTrue(type is AnonymousTypeDecl || type.Span.Contains(type.Name.Span));
     Assert.IsTrue(type.Span.Contains(type.HeadingSpan));
     foreach (var member in type.Members)
     {
         Assert.IsTrue(type.Span.Contains(member.Span));
     }
     Assert.IsTrue(type is AnonymousTypeDecl || type.HeadingSpan.Contains(type.Name.Span));
     foreach (var implements in type.ImplementsList)
     {
         Assert.IsTrue(type.HeadingSpan.Contains(implements.Span));
         Assert.IsTrue(type.Span.Contains(implements.Span));
     }
     if (type.Members.Count > 0)
     {
         Assert.IsTrue(type.HeadingSpan.End <= type.Members.Min(a => a.Span.Start));
     }
     if (type.ImplementsList.Length > 0)
     {
         Assert.IsTrue(type.Name.Span.End <= type.ImplementsList.Min(a => a.Span.Start));
     }
     if (type.BaseClass != null)
     {
         Assert.IsTrue(type.Span.Contains(type.BaseClass.Span));
         Assert.IsTrue(type.HeadingSpan.Contains(type.BaseClass.Span));
         Assert.IsTrue(type.Name.Span.End <= type.BaseClass.Span.Start);
     }
 }
예제 #5
0
 /// <inheritdoc />
 public override void VisitTypeDecl(TypeDecl x)
 {
     // As a type, we consider class and interface too
     if ((x.AttributeTarget & PhpAttributeTargets.Types) != 0)
     {
         // The type can be declared inside method body of other class
         // In that case, traversing the tree of subclass or subinterface is not necessary
         if (!isInsideDeclaration)
         {
             var previousValue = isInsideDeclaration;
             try
             {
                 isInsideDeclaration = true;
                 currentReferences.Clear();
                 base.VisitTypeDecl(x);
             }
             finally
             {
                 isInsideDeclaration = previousValue;
             }
         }
     }
     else
     {
         base.VisitTypeDecl(x);
     }
 }
예제 #6
0
 public override void VisitTypeDecl(TypeDecl x)
 {
     using (new ScopeHelper(this, x))
     {
         base.VisitTypeDecl(x);
     }
 }
예제 #7
0
 /// <summary>
 /// Visit type members.
 /// </summary>
 /// <param name="x"></param>
 virtual public void VisitTypeDecl(TypeDecl x)
 {
     VisitElement(x.PHPDoc);
     VisitElement(x.BaseClass as TypeRef);
     VisitList(x.ImplementsList);
     VisitList(x.Members);
 }
        /// <summary>
        /// Generate python classes from declaration.
        /// </summary>
        public static string Build(TypeDecl decl)
        {
            // Determine if we are inside datacentric package
            // based on module name. This affects the imports
            // and namespace use.
            bool insideDc = PyExtensions.GetPackage(decl) == "datacentric";

            // If not generating for DataCentric package, use dc. namespace
            // in front of datacentric types, otherwise use no prefix
            string dcNamespacePrefix = insideDc ? "" : "dc.";

            var writer = new CodeWriter();

            writer.AppendLine("from abc import ABC");

            string keyImport = insideDc
                ? "from datacentric.storage.key import Key"
                : "import datacentric as dc";

            writer.AppendLine(keyImport);

            writer.AppendNewLineWithoutIndent();
            writer.AppendNewLineWithoutIndent();

            writer.AppendLine($"class {decl.Name}Key({dcNamespacePrefix}Key, ABC):");
            writer.PushIndent();
            writer.AppendLines(CommentHelper.PyComment(decl.Comment));
            writer.AppendLine("pass");
            writer.PopIndent();

            return(writer.ToString());
        }
예제 #9
0
 private SourceTypeSymbol(SourceFileSymbol file, TypeDecl syntax, NamedTypeSymbol baseType, ImmutableArray <NamedTypeSymbol> ifacesType, int version)
     : this(file, syntax)
 {
     _lazyBaseType       = baseType;
     _lazyInterfacesType = ifacesType;
     _version            = version;
 }
예제 #10
0
            bool TryAddPrivateSetter(out SyntaxNode newRoot)
            {
                if (TypeDecl.IsKind(SyntaxKind.ClassDeclaration) &&
                    PropertySymbol.DeclaredAccessibility != Accessibility.Private &&
                    !PropertySymbol.IsOverride &&
                    PropertySymbol.GetMethod != null &&
                    PropertySymbol.SetMethod == null &&
                    PropertyDecl.Initializer == null &&
                    IsAuto(PropertyDecl, PropertySymbol)
                    )
                {
                    var accessor =
                        SyntaxFactory.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration)
                        .WithModifiers(
                            SyntaxFactory.TokenList(
                                SyntaxFactory.Token(SyntaxKind.PrivateKeyword)
                                ))
                        .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken));
                    newRoot =
                        Root.ReplaceNode(
                            PropertyDecl,
                            PropertyDecl
                            .AddAccessorListAccessors(accessor)
                            );
                    return(true);
                }

                newRoot = default(SyntaxNode);
                return(false);
            }
예제 #11
0
 public override void VisitTypeDecl(TypeDecl x)
 {
     if (x.IsConditional)
     {
         Add(x);
     }
     // ignored
 }
예제 #12
0
        public override bool IsSealed => true;  // traits cannot be extended

        public SourceTraitTypeSymbol(SourceFileSymbol file, TypeDecl syntax)
            : base(file, syntax)
        {
            Debug.Assert(syntax.MemberAttributes.IsTrait());
            Debug.Assert(syntax.BaseClass == null); // not expecting trait can extend another class

            _typeParameters = ImmutableArray.Create <TypeParameterSymbol>(new AnonymousTypeParameterSymbol(this, 0, "TSelf", hasReferenceTypeConstraint: true));
        }
예제 #13
0
        public AstPrinterNode Visit(TypeDecl node)
        {
            var printer = new AstPrinterNode(node.ToString());

            printer.AddChild(node.Ident.Accept(this));
            printer.AddChild(node.IdentType.Accept(this));
            return(printer);
        }
예제 #14
0
            public override bool Equals(object obj)
            {
                TypeDecl other = obj as TypeDecl;

                if (other == null)
                {
                    return(false);
                }
                return(Name.Equals(other.Name) && Length == other.Length);
            }
예제 #15
0
        public SourceTypeSymbol(SourceFileSymbol file, TypeDecl syntax)
        {
            Contract.ThrowIfNull(file);

            _syntax = syntax;
            _file   = file;

            //
            _staticsContainer = new SynthesizedStaticFieldsHolder(this);
        }
예제 #16
0
        public override void VisitTypeDecl(TypeDecl x)
        {
            var declarelazy = x.IsConditional || PostponeDeclaration();

            if (declarelazy)
            {
                Add(x);
            }
            // ignored
        }
예제 #17
0
        public static TypeDecl EnsureType(string[] tokens, ref int index, out string name)
        {
            TypeDecl decl = null;

            if (!ParseType(tokens, ref index, out decl, out name))
            {
                throw new ArgumentException("Failed to parse.");
            }
            return(decl);
        }
예제 #18
0
 public override void VisitTypeDecl(TypeDecl x)
 {
     // TODO - base class and interfaces are not visited, they are converted to qualified name
     VisitElement((TypeRef)x.BaseClass);
     foreach (var item in x.ImplementsList)
     {
         VisitElement((TypeRef)item);
     }
     base.VisitTypeDecl(x);
 }
예제 #19
0
        /// <summary>
        /// Adds a type to the correct place in the inheritance trees.
        /// </summary>
        /// <param name="types">The types.</param>
        /// <param name="inheritanceTrees">The inheritance trees.</param>
        /// <param name="newType">The new type.</param>
        private static void AddToInheritanceTrees(IEnumerable <TypeDecl> types,
                                                  List <TypeDeclWrapper> inheritanceTrees, TypeDecl newType)
        {
            var      baseClassName = newType.BaseClassName.Value.QualifiedName.Name.Value;
            TypeDecl baseClass     = null;

            foreach (var type in types)
            {
                if (type.Name.Value.Equals(baseClassName, StringComparison.Ordinal))
                {
                    baseClass = type;
                    break;
                }
            }

            var message = string.Format(CultureInfo.InvariantCulture,
                                        "The base type \"{0}\" for \"{1}\" is not available in the source",
                                        baseClassName, newType.Name.Value);

            Trace.WriteIf(baseClass == null, message);

            var baseTypeWrapper     = FindDTypeWrapper(inheritanceTrees, baseClass);
            var existingTypeWrapper = FindDTypeWrapper(inheritanceTrees, newType);

            if (baseTypeWrapper == null && existingTypeWrapper == null)
            {
                if (baseClass != null)
                {
                    baseTypeWrapper = new TypeDeclWrapper(baseClass);
                    baseTypeWrapper.Children.Add(new TypeDeclWrapper(newType));
                    inheritanceTrees.Add(baseTypeWrapper);
                }
                else
                {
                    inheritanceTrees.Add(new TypeDeclWrapper(newType));
                }
            }
            else if (baseTypeWrapper != null && existingTypeWrapper == null)
            {
                baseTypeWrapper.Children.Add(new TypeDeclWrapper(newType));
            }
            else if (baseTypeWrapper == null && existingTypeWrapper != null)
            {
                Debug.Assert(inheritanceTrees.Contains(existingTypeWrapper));

                baseTypeWrapper = new TypeDeclWrapper(baseClass);
                baseTypeWrapper.Children.Add(existingTypeWrapper);
                inheritanceTrees.Remove(existingTypeWrapper);
                inheritanceTrees.Add(baseTypeWrapper);
            }
            else
            {
                Debug.Fail("Unsupported state");
            }
        }
예제 #20
0
 /// <summary>
 /// Inspects a type declaration even during parsing
 /// </summary>
 /// <param name="parser">Parser currently analyzing the source code</param>
 /// <param name="decl">Current type declaration</param>
 public void TypeDeclarationReduced(Parser /*!*/ parser, TypeDecl /*!*/ decl)
 {
     foreach (var method in decl.Members)
     {
         if (method is MethodDecl)
         {
             functions[method] = this.Ast;
         }
     }
     compilationUnit.TypeDeclarationReduced(parser, decl);
 }
예제 #21
0
 /// <summary>
 /// Gets full qualified name of the type declaration.
 /// </summary>
 /// <param name="type">Type, cannot be <c>null</c>.</param>
 /// <returns>Qualified name of the type.</returns>
 public static QualifiedName MakeQualifiedName(this TypeDecl type)
 {
     if (type is AnonymousTypeDecl)
     {
         return(((AnonymousTypeDecl)type).GetAnonymousTypeQualifiedName());
     }
     else
     {
         return(type.QualifiedName);
     }
 }
예제 #22
0
            public override void VisitTypeDecl(TypeDecl x)
            {
                VisitSpecificElementProlog();

                SerializeToken(nameof(x.Name), x.Name.ToString(), x.Name.Span);
                SerializeToken(nameof(x.BaseClass), x.BaseClass?.ClassName.ToString(), x.BaseClass?.Span);
                SerializeToken(nameof(x.MemberAttributes), x.MemberAttributes.ToString(), x.HeadingSpan);
                SerializeTokenList(nameof(x.ImplementsList), x.ImplementsList, impl => impl.ClassName.ToString(), impl => impl.Span);
                SerializeToken(nameof(x.IsConditional), x.IsConditional.ToString(), null);

                base.VisitTypeDecl(x);
            }
예제 #23
0
        /// <inheritdoc />
        public override void VisitTypeDecl(TypeDecl x)
        {
            // Declaration of classes and interfaces too is non-standard construct
            if (((x.AttributeTarget & PhpAttributeTargets.Types) != 0) &&
                isInsideSubroutine)
            {
                // All classes and interfaces declared inside a function
                occurrenceNodes.Enqueue(x);
            }

            base.VisitTypeDecl(x);
        }
예제 #24
0
        public override void VisitTypeDecl(TypeDecl x)
        {
            using (new ScopeHelper(this, x))
            {
                // final class|interface|trait [NAME] extends ... implements ... { MEMBERS }
                _composer.ConsumeModifiers(x, x.MemberAttributes);
                if ((x.MemberAttributes & PhpMemberAttributes.Interface) != 0)
                {
                    ConsumeToken(Tokens.T_INTERFACE, "interface");
                }
                else if ((x.MemberAttributes & PhpMemberAttributes.Trait) != 0)
                {
                    ConsumeToken(Tokens.T_TRAIT, "trait");
                }
                else
                {
                    ConsumeToken(Tokens.T_CLASS, "class");
                }

                if (x.Name.HasValue)
                {
                    ConsumeToken(Tokens.T_STRING, x.Name.Name.Value, x.Name.Span.Start);
                }

                if (x.BaseClass != null)
                {
                    // extends
                    ConsumeToken(Tokens.T_EXTENDS, "extends");
                    VisitElement((TypeRef)x.BaseClass);
                }

                if (x.ImplementsList != null && x.ImplementsList.Length != 0)
                {
                    // implements|extends
                    if ((x.MemberAttributes & PhpMemberAttributes.Interface) == 0)
                    {
                        ConsumeToken(Tokens.T_IMPLEMENTS);
                    }
                    else
                    {
                        ConsumeToken(Tokens.T_EXTENDS);
                    }

                    VisitElementList(x.ImplementsList, VisitNamedTypeRef, Tokens.T_COMMA, ",");
                }


                ConsumeToken(Tokens.T_LBRACE, "{", x.BodySpan.Start);
                VisitList(x.Members);
                ConsumeToken(Tokens.T_RBRACE, "}", x.BodySpan.End - 1);
            }
        }
        public override void VisitTypeDecl(TypeDecl x)
        {
            var bound = _binder.BindWholeStatement(x).SingleBoundElement();

            if (DeclareConditionally(x))
            {
                _current.Add(bound);
            }
            else
            {
                AddUnconditionalDeclaration(bound);
            }
        }
예제 #26
0
파일: Clang.cs 프로젝트: thfabian/Bifrost
            /// <summary>
            /// Visit a namespace declaration
            /// </summary>
            private void VisitTypeDecl(TypeDecl typeDecl, TraversalData traversalData)
            {
                if (typeDecl.Kind == CXCursorKind.CXCursor_ClassDecl || typeDecl.Kind == CXCursorKind.CXCursor_StructDecl)
                {
                    traversalData.AddClass(typeDecl.Name);
                }

                Visit(typeDecl.CursorChildren, traversalData);

                if (typeDecl.Kind == CXCursorKind.CXCursor_ClassDecl || typeDecl.Kind == CXCursorKind.CXCursor_StructDecl)
                {
                    traversalData.RemoveClass();
                }
            }
예제 #27
0
 private void Fix(TypeDecl decl)
 {
     if (decl.ReferencingOverloadKeys != null)
     {
         for (int i = 0; i < decl.ReferencingOverloadKeys.Count; i++)
         {
             var key = FixKey(decl.ReferencingOverloadKeys[i], this.SymbolFileMapping);
             if (key != null)
             {
                 decl.ReferencingOverloadKeys[i] = key;
             }
         }
     }
 }
예제 #28
0
            public override void VisitTypeDecl(TypeDecl x)
            {
                var type = new SourceTypeSymbol(_currentFile, x);

                x.SetProperty(type);    // remember bound function symbol

                _tables._declaredtypes.Add(type);

                if (!x.IsConditional)
                {
                    _tables._types.Add(x.MakeQualifiedName(), type);
                }

                //
                base.VisitTypeDecl(x);
            }
예제 #29
0
        ///// <summary>
        ///// Process eval expression - if the eval was produced by the TypeDecl, we process the original TypeDecl.
        ///// </summary>
        //public override void VisitEvalEx(EvalEx x)
        //{
        //    TypeDecl typeDecl;

        //    if (x.Annotations.TryGet<TypeDecl>(out typeDecl))
        //    {
        //        docResolver.VisitTypeDecl(typeDecl);
        //        VisitTypeDecl(typeDecl);
        //    }

        //    base.VisitEvalEx(x);
        //}

        /// <summary>
        /// Generate type declaration
        /// </summary>
        public CodeTypeDeclaration GenerateTypeDecl(PHPDocBlock cmt, TypeDecl x)
        {
            CodeTypeDeclaration cls = new CodeTypeDeclaration(MakeCSharpName(x.Name.Value));

            var summary = cmt.Summary;

            if (!string.IsNullOrEmpty(summary))
            {
                cls.Comments.Add(new CodeCommentStatement("<summary>\n " + summary + "\n </summary>", true));
            }

            cls.IsInterface = true;
            cls.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(DuckTypeAttribute))));

            return(cls);
        }
예제 #30
0
        public override void VisitTypeDecl(TypeDecl x)
        {
            var bound = _binder.BindWholeStatement(x).SingleBoundElement();

            if (DeclareConditionally(x))
            {
                _current.Add(bound);
            }
            else
            {
                // just simplifies the resulting semantic graph,
                // simple types are listed at the very beginning

                AddUnconditionalDeclaration(bound);
            }
        }
예제 #31
0
            public override void VisitTypeDecl(TypeDecl x)
            {
                var type = new SourceTypeSymbol(_currentFile, x);

                x.SetProperty(type);    // remember bound function symbol

                _tables._declaredtypes.Add(type);

                if (!x.IsConditional)
                {
                    _tables._types.Add(x.MakeQualifiedName(), type);
                }

                //
                base.VisitTypeDecl(x);
            }
예제 #32
0
 public ElementDecl(TypeDecl type, NameInfo nameInfo)
 {
     Type = type;
     NameInfo = nameInfo;
 }
예제 #33
0
 public StructDecl(TypeDecl type, ElementDecl[] elements)
 {
     Type = type;
     Elements = elements;
 }
예제 #34
0
 public TypeInfo(string name, TypeInfo parent, TypeDecl decl)
 {
     Name = name;
         Parent = parent;
         typedecl = decl;//para saber si es una de las decl del enum
 }
예제 #35
0
        public SourceTypeSymbol(SourceFileSymbol file, TypeDecl syntax)
        {
            Contract.ThrowIfNull(file);

            _syntax = syntax;
            _file = file;

            //
            _staticsContainer = new SynthesizedStaticFieldsHolder(this);
        }
예제 #36
0
        /// <summary>
        /// Create naming context in context of given type declaration.
        /// </summary>
        public static NamingContext GetNamingContext(TypeDecl/*!*/type)
        {
            Contract.ThrowIfNull(type);

            return GetNamingContext(type.ContainingNamespace, type.ContainingSourceUnit);
        }
예제 #37
0
        public void Init(BinaryReader reader, bool swap)
        {
            Stream stream = reader.BaseStream;

            // SDNA
            byte[] code = reader.ReadBytes(8);
            string codes = ASCIIEncoding.ASCII.GetString(code);

            // NAME
            if (!codes.Equals("SDNANAME"))
            {
                throw new InvalidDataException();
            }
            int dataLen = reader.ReadInt32();
            _names = new NameInfo[dataLen];
            for (int i = 0; i < dataLen; i++)
            {
                List<byte> name = new List<byte>();
                byte ch = reader.ReadByte();
                while (ch != 0)
                {
                    name.Add(ch);
                    ch = reader.ReadByte();
                }

                _names[i] = new NameInfo(ASCIIEncoding.ASCII.GetString(name.ToArray()));
            }
            stream.Position = (stream.Position + 3) & ~3;

            // TYPE
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("TYPE"))
            {
                throw new InvalidDataException();
            }
            dataLen = reader.ReadInt32();
            _types = new TypeDecl[dataLen];
            for (int i = 0; i < dataLen; i++)
            {
                List<byte> name = new List<byte>();
                byte ch = reader.ReadByte();
                while (ch != 0)
                {
                    name.Add(ch);
                    ch = reader.ReadByte();
                }
                string type = ASCIIEncoding.ASCII.GetString(name.ToArray());
                _types[i] = new TypeDecl(type);
            }
            stream.Position = (stream.Position + 3) & ~3;

            // TLEN
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("TLEN"))
            {
                throw new InvalidDataException();
            }
            for (int i = 0; i < _types.Length; i++)
            {
                _types[i].Length = reader.ReadInt16();
            }
            stream.Position = (stream.Position + 3) & ~3;

            // STRC
            code = reader.ReadBytes(4);
            codes = ASCIIEncoding.ASCII.GetString(code);
            if (!codes.Equals("STRC"))
            {
                throw new InvalidDataException();
            }
            dataLen = reader.ReadInt32();
            _structs = new StructDecl[dataLen];
            long shtPtr = stream.Position;
            for (int i = 0; i < dataLen; i++)
            {
                StructDecl structDecl = new StructDecl();
                _structs[i] = structDecl;
                if (swap)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    short typeNr = reader.ReadInt16();
                    structDecl.Type = _types[typeNr];
                    structDecl.Type.Struct = structDecl;
                    int numElements = reader.ReadInt16();
                    structDecl.Elements = new ElementDecl[numElements];
                    for (int j = 0; j < numElements; j++)
                    {
                        typeNr = reader.ReadInt16();
                        short nameNr = reader.ReadInt16();
                        structDecl.Elements[j] = new ElementDecl(_types[typeNr], _names[nameNr]);
                    }
                }
            }

            // build reverse lookups
            _structReverse = new Dictionary<string, int>(_structs.Length);
            for (int i = 0; i < _structs.Length; i++)
            {
                StructDecl s = _structs[i];
                if (_ptrLen == 0 && s.Type.Name.Equals("ListBase"))
                {
                    _ptrLen = s.Type.Length / 2;
                }
                _structReverse.Add(s.Type.Name, i);
            }
        }
예제 #38
0
 public ElementDecl(TypeDecl type, NameInfo name)
 {
     Type = type;
     Name = name;
 }