Ejemplo n.º 1
0
 public int AddField(Name name, Type fieldType, Grammar.ASTNodeDeclStructField astNode)
 {
     var fieldIndex = this.fieldTypes.Count;
     this.fieldTypes.Add(fieldType);
     this.fieldNames.Add(name, fieldIndex);
     this.fieldASTNodes.Add(astNode);
     return fieldIndex;
 }
Ejemplo n.º 2
0
        public int CreateFunct(Name name)
        {
            var decl = new DeclFunct();
            this.declFuncts.Add(decl);

            var declRef = new DeclReference
            {
                kind = DeclReference.Kind.Funct,
                index = this.declFuncts.Count - 1
            };

            this.declTree.Add(name, declRef);
            return this.declFuncts.Count - 1;
        }
Ejemplo n.º 3
0
        public int CreateStruct(Name name, Grammar.ASTNodeDeclStruct declASTNode)
        {
            var decl = new DeclStruct();
            decl.declASTNode = declASTNode;
            this.declStructs.Add(decl);

            var declRef = new DeclReference
            {
                kind = DeclReference.Kind.Struct,
                index = this.declStructs.Count - 1
            };

            this.declTree.Add(name, declRef);
            return this.declStructs.Count - 1;
        }
Ejemplo n.º 4
0
        public int CreatePrimitiveStruct(Name name)
        {
            var decl = new DeclStruct();
            decl.primitive = true;
            decl.declASTNode = null;
            this.declStructs.Add(decl);

            var declRef = new DeclReference
            {
                kind = DeclReference.Kind.Struct,
                index = this.declStructs.Count - 1
            };

            this.declTree.Add(name, declRef);
            return this.declStructs.Count - 1;
        }
Ejemplo n.º 5
0
        public List<DeclReference> GetDeclsWithUseDirectives(Name name, bool isAbsolutePath, IList<UseDirective> useDirectives)
        {
            DeclReference decl;
            var foundDecls = new List<DeclReference>();

            if (!isAbsolutePath && useDirectives != null)
            {
                foreach (var directive in useDirectives)
                {
                    var useAllDirective = directive as UseDirectiveAll;
                    if (useAllDirective != null)
                    {
                        if (this.declTree.FindByName(useAllDirective.name.Concatenate(name), out decl))
                            foundDecls.Add(decl);
                    }
                    else
                        throw new NotImplementedException();
                }
            }

            if (this.declTree.FindByName(name, out decl))
                foundDecls.Add(decl);

            return foundDecls;
        }
Ejemplo n.º 6
0
 public bool ValidateSingleDecl(List<DeclReference> decls, Name origName, Diagnostics.Span span)
 {
     if (decls.Count == 0)
     {
         this.AddMessage(
             Diagnostics.MessageKind.Error,
             Diagnostics.MessageCode.Unknown,
             "unknown '" + origName.GetString() + "'",
             span);
         return false;
     }
     else if (decls.Count > 1)
     {
         this.AddMessage(
             Diagnostics.MessageKind.Error,
             Diagnostics.MessageCode.AmbiguousDeclaration,
             "ambiguous '" + origName.GetString() + "' between " +
             "'" + this.GetDeclName(decls[0]).GetString() + "'" +
             (decls.Count == 2 ? " and " : ", ") +
             "'" + this.GetDeclName(decls[1]).GetString() + "'" +
             (decls.Count > 2 ? ", and other " + (decls.Count - 2) : ""),
             span);
         return false;
     }
     else
         return true;
 }
Ejemplo n.º 7
0
        public bool ValidateAsType(DeclReference decl, Name origName, Diagnostics.Span span)
        {
            if (decl.kind != Core.Session.DeclReference.Kind.Struct)
            {
                this.AddMessage(
                    Diagnostics.MessageKind.Error,
                    Diagnostics.MessageCode.WrongDeclarationKind,
                    "'" + this.GetDeclName(decl).GetString() + "' is not a type",
                    span);
                return false;
            }

            return true;
        }
Ejemplo n.º 8
0
        public bool TryGetDecl(Name name, out int index)
        {
            index = -1;

            DeclReference decl;
            if (!this.declTree.FindByName(name, out decl))
                return false;

            index = decl.index;
            return true;
        }