void case_26() #line 568 "cs-parser.jay" { report.Error (1514, lexer.Location, "Unexpected symbol `{0}', expecting `.' or `{{'", GetSymbolName (yyToken)); var name = (MemberName) yyVals[0+yyTop]; var ns = new NamespaceContainer (name, current_namespace); lbag.AddLocation (ns, GetLocation (yyVals[-1+yyTop])); current_namespace.AddTypeContainer (ns); }
void case_23() #line 526 "cs-parser.jay" { Attributes attrs = (Attributes) yyVals[-2+yyTop]; var name = (MemberName) yyVals[0+yyTop]; if (attrs != null) { bool valid_global_attrs = true; if ((current_namespace.DeclarationFound || current_namespace != file)) { valid_global_attrs = false; } else { foreach (var a in attrs.Attrs) { if (a.ExplicitTarget == "assembly" || a.ExplicitTarget == "module") continue; valid_global_attrs = false; break; } } if (!valid_global_attrs) report.Error (1671, name.Location, "A namespace declaration cannot have modifiers or attributes"); } module.AddAttributes (attrs, current_namespace); var ns = new NamespaceContainer (name, current_namespace); current_namespace.AddTypeContainer (ns); current_container = current_namespace = ns; }
void case_25() #line 559 "cs-parser.jay" { if (yyVals[0+yyTop] != null) lbag.AddLocation (current_container, GetLocation (yyVals[-9+yyTop]), GetLocation (yyVals[-6+yyTop]), GetLocation (yyVals[-1+yyTop]), GetLocation (yyVals[0+yyTop])); else lbag.AddLocation (current_container, GetLocation (yyVals[-9+yyTop]), GetLocation (yyVals[-6+yyTop]), GetLocation (yyVals[-1+yyTop])); current_container = current_namespace = current_namespace.Parent; }
public override void Visit(NamespaceContainer ns) { NamespaceDeclaration nDecl = null; var loc = LocationsBag.GetLocations(ns); if (ns.NS != null && !string.IsNullOrEmpty(ns.NS.Name)) { nDecl = new NamespaceDeclaration(); if (loc != null) { nDecl.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.NamespaceKeyword), Roles.NamespaceKeyword); } nDecl.AddChild(ConvertNamespaceName(ns.RealMemberName), NamespaceDeclaration.NamespaceNameRole); if (loc != null && loc.Count > 1) { nDecl.AddChild(new CSharpTokenNode(Convert(loc [1]), Roles.LBrace), Roles.LBrace); } AddToNamespace(nDecl); namespaceStack.Push(nDecl); } if (ns.Usings != null) { foreach (var us in ns.Usings) { us.Accept(this); } } if (ns.Containers != null) { foreach (var container in ns.Containers) { container.Accept(this); } } if (nDecl != null) { AddAttributeSection(nDecl, ns.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole); if (loc != null && loc.Count > 2) nDecl.AddChild(new CSharpTokenNode(Convert(loc [2]), Roles.RBrace), Roles.RBrace); if (loc != null && loc.Count > 3) nDecl.AddChild(new CSharpTokenNode(Convert(loc [3]), Roles.Semicolon), Roles.Semicolon); namespaceStack.Pop(); } }
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session) { this.file = file; current_container = current_namespace = file; this.module = file.Module; this.compiler = file.Compiler; this.settings = compiler.Settings; this.report = report; lang_version = settings.Version; yacc_verbose_flag = settings.VerboseParserFlag; doc_support = settings.DocumentationFile != null; lexer = new Tokenizer (reader, file, session, report); oob_stack = new Stack<object> (); lbag = session.LocationsBag; use_global_stacks = session.UseJayGlobalArrays; parameters_bucket = session.ParametersStack; }
public override void Define (NamespaceContainer ctx) { // // The namespace-or-type-name of a using-alias-directive is resolved as if // the immediately containing compilation unit or namespace body had no // using-directives. A using-alias-directive may however be affected // by extern-alias-directives in the immediately containing compilation // unit or namespace body // // We achieve that by introducing alias-context which redirect any local // namespace or type resolve calls to parent namespace // resolved = NamespaceExpression.ResolveAsTypeOrNamespace (new AliasContext (ctx), false); }
public NamespaceContainer (MemberName name, NamespaceContainer parent) : base (parent, name, null, MemberKind.Namespace) { this.RealMemberName = name; this.Parent = parent; this.ns = parent.NS.AddNamespace (name); containers = new List<TypeContainer> (); }
public override void Define (NamespaceContainer ctx) { var ns = ctx.Module.GetRootNamespace (Alias.Value); if (ns == null) { ctx.Module.Compiler.Report.Error (430, Location, "The extern alias `{0}' was not specified in -reference option", Alias.Value); return; } resolved = new NamespaceExpression (ns, Location); }
public AliasContext (NamespaceContainer ns) { this.ns = ns; }
public virtual void Define (NamespaceContainer ctx) { resolved = expr.ResolveAsTypeOrNamespace (ctx, false); }
public override void Define (NamespaceContainer ctx) { base.Define (ctx); if (resolved == null) return; var ns = resolved as NamespaceExpression; if (ns != null) { var compiler = ctx.Module.Compiler; compiler.Report.Error (7007, Location, "A 'using static' directive can only be applied to types but `{0}' denotes a namespace. Consider using a `using' directive instead", ns.GetSignatureForError ()); return; } // TODO: Need to move it to post_process_using_aliases //ObsoleteAttribute obsolete_attr = resolved.Type.GetAttributeObsolete (); //if (obsolete_attr != null) { // AttributeTester.Report_ObsoleteMessage (obsolete_attr, resolved.GetSignatureForError (), Location, ctx.Compiler.Report); //} }
public override void Define (NamespaceContainer ctx) { base.Define (ctx); var ns = resolved as NamespaceExpression; if (ns != null) return; if (resolved != null) { var compiler = ctx.Module.Compiler; var type = resolved.Type; compiler.Report.SymbolRelatedToPreviousError (type); compiler.Report.Error (138, Location, "A `using' directive can only be applied to namespaces but `{0}' denotes a type. Consider using a `using static' instead", type.GetSignatureForError ()); } }
public virtual void Visit (NamespaceContainer ns) { }
public override void Visit(NamespaceContainer ns) { NamespaceDeclaration nDecl = null; var loc = LocationsBag.GetLocations(ns); // <invalid> is caused by the parser - see Bug 12383 - [AST] Non existing namespaces generated if (ns.NS != null && !string.IsNullOrEmpty(ns.NS.Name) && !ns.NS.Name.EndsWith("<invalid>", StringComparison.Ordinal)) { nDecl = new NamespaceDeclaration(); if (loc != null) { nDecl.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.NamespaceKeyword), Roles.NamespaceKeyword); } nDecl.AddChild(ConvertNamespaceName(ns.RealMemberName), NamespaceDeclaration.NamespaceNameRole); if (loc != null && loc.Count > 1) { nDecl.AddChild(new CSharpTokenNode(Convert(loc [1]), Roles.LBrace), Roles.LBrace); } AddToNamespace(nDecl); namespaceStack.Push(nDecl); } if (ns.Usings != null) { foreach (var us in ns.Usings) { us.Accept(this); } } if (ns.Containers != null) { foreach (var container in ns.Containers) { container.Accept(this); } } if (nDecl != null) { AddAttributeSection(nDecl, ns.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole); if (loc != null && loc.Count > 2) nDecl.AddChild(new CSharpTokenNode(Convert(loc [2]), Roles.RBrace), Roles.RBrace); if (loc != null && loc.Count > 3) nDecl.AddChild(new CSharpTokenNode(Convert(loc [3]), Roles.Semicolon), Roles.Semicolon); namespaceStack.Pop(); } }