Exemplo n.º 1
0
		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> ();

			var topParent = this;
			while (topParent.Parent != null) {
				topParent = topParent.Parent;
			}
			compSourceFile = topParent as CompilationSourceFile;
		}
			public override void Visit(NamespaceContainer nspace)
			{
				NamespaceDeclaration nDecl = null;
				var loc = LocationsBag.GetLocations(nspace);
				
				if (nspace.NS != null && !string.IsNullOrEmpty(nspace.NS.Name)) {
					nDecl = new NamespaceDeclaration ();
					if (loc != null) {
						nDecl.AddChild(new CSharpTokenNode (Convert(loc [0]), Roles.NamespaceKeyword), Roles.NamespaceKeyword);
					}
					ConvertNamespaceName(nspace.RealMemberName, nDecl);
					if (loc != null && loc.Count > 1) {
						nDecl.AddChild(new CSharpTokenNode (Convert(loc [1]), Roles.LBrace), Roles.LBrace);
					}
					AddToNamespace(nDecl);
					namespaceStack.Push(nDecl);
				}
				
				if (nspace.Usings != null) {
					foreach (var us in nspace.Usings) {
						us.Accept(this);
					}
				}
				
				if (nspace.Containers != null) {
					foreach (var container in nspace.Containers) {
						container.Accept(this);
					}
				}
				
				if (nDecl != null) {
					AddAttributeSection(nDecl, nspace.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 ();
				}
			}
Exemplo n.º 3
0
			public AliasContext (NamespaceContainer ns)
			{
				this.ns = ns;
			}
Exemplo n.º 4
0
		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));
		}
Exemplo n.º 5
0
		public override void Define (NamespaceContainer ctx)
		{
			resolved = ctx.Module.GetRootNamespace (Alias.Value);
			if (resolved == null) {
				ctx.Module.Compiler.Report.Error (430, Location,
					"The extern alias `{0}' was not specified in -reference option",
					Alias.Value);
			}
		}
Exemplo n.º 6
0
		public override void Define (NamespaceContainer ctx)
		{
			resolved = NamespaceExpression.ResolveAsTypeOrNamespace (ctx);
			if (resolved != null) {
				resolvedType = resolved.ResolveAsType (ctx);
		}
	}
Exemplo n.º 7
0
		public virtual void Visit (NamespaceContainer ns)
		{
		}
Exemplo n.º 8
0
		public virtual void Define (NamespaceContainer ctx)
		{
			resolved = expr.ResolveAsTypeOrNamespace (ctx);
			var ns = resolved as Namespace;
			if (ns == null) {
				if (resolved != null) {
					ctx.Module.Compiler.Report.SymbolRelatedToPreviousError (resolved.Type);
					ctx.Module.Compiler.Report.Error (138, Location,
						"`{0}' is a type not a namespace. A using namespace directive can only be applied to namespaces",
						GetSignatureForError ());
				}
			}
		}
Exemplo n.º 9
0
void case_23()
#line 533 "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;
	  }
Exemplo n.º 10
0
void case_24()
#line 542 "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);
	  }
Exemplo n.º 11
0
void case_21()
#line 500 "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;
	  }
Exemplo n.º 12
0
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);
	oob_stack = new Stack<object> ();
	lbag = session.LocationsBag;
	use_global_stacks = session.UseJayGlobalArrays;
	parameters_bucket = session.ParametersStack;
}
Exemplo n.º 13
0
void case_37()
#line 695 "ps-parser.jay"
{
	    /* Close the private package namespace (if it's active)*/
	  	if (current_namespace == private_namespace) {
	  		if (private_namespace.Containers.Count > 0) {
		  		prev_namespace.AddTypeContainer(private_namespace);
				var priv_un = new UsingNamespace (
					private_namespace.NS.MakeTypeNameExpression(GetLocation(yyVals[-10+yyTop])), GetLocation (yyVals[-10+yyTop]));
				prev_namespace.AddUsing(priv_un, true);
			}
			current_container = current_namespace = prev_namespace.Parent;
			prev_namespace = private_namespace = null; 
	  	}
	  
/*	  	lbag.AddLocation (current_container, GetLocation ($2), GetLocation ($6), GetLocation ($11));*/
	  }
Exemplo n.º 14
0
void case_36()
#line 681 "ps-parser.jay"
{
	  	lbag.AddLocation (current_container, GetLocation (yyVals[-7+yyTop]), GetLocation (yyVals[-3+yyTop]), GetLocation (yyVals[-1+yyTop]));
	  
	  	if (current_namespace.Parent != null && current_namespace.Parent.Parent == null) { /* Is this the top level package?*/
			var ns = new NamespaceContainer (new MemberName("__" + file.FileName.Replace(".","_")), current_namespace);
			prev_namespace = current_namespace;
			current_container = private_namespace = current_namespace = ns;
	    } else {
			current_container = current_namespace = current_namespace.Parent;
		}
		
		lexer.parsing_modifiers = false;
	  }
Exemplo n.º 15
0
void case_34()
#line 629 "ps-parser.jay"
{
		Attributes attrs = (Attributes) yyVals[-3+yyTop];
		var name = yyVals[0+yyTop] as MemberName;
		if (name == null) {
			name = new MemberName(RootNs);
		}
		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);
		
	    /* Close the private package namespace (if it's active)*/
	  	if (current_namespace == private_namespace) {
	  		if (private_namespace.Containers.Count > 0) {
		  		prev_namespace.AddTypeContainer(private_namespace);
				var priv_un = new UsingNamespace (
					private_namespace.NS.MakeTypeNameExpression(GetLocation(yyVals[-3+yyTop])), GetLocation (yyVals[-3+yyTop]));
				prev_namespace.AddUsing(priv_un, true);
			}
			current_container = current_namespace = prev_namespace.Parent;
			prev_namespace = private_namespace = null; 
	  	}
		
		var ns = new NamespaceContainer (name, current_namespace);
		current_namespace.AddTypeContainer (ns);
		current_container = current_namespace = ns;
		var un = new UsingNamespace (new SimpleName (RootNs, GetLocation (yyVals[-3+yyTop])), GetLocation (yyVals[-3+yyTop]));
		current_namespace.AddUsing(un, true);
	  }