Example #1
0
 public override void Visit(NamespaceDefinition theNamespace)
 {
     mOutput.WriteLine("namespace {0}", theNamespace.Name);
     mOutput.WriteLine("{{");
     mOutput.Indent();
     {
         base.Visit(theNamespace);
     }
     mOutput.Unindent();
     mOutput.WriteLine("}}");
 }
Example #2
0
        public virtual void Visit(NamespaceDefinition theNamespace)
        {
            foreach (var xSubNamespace in theNamespace.Namespaces)
            {
                Visit(xSubNamespace);
            }

            foreach (var xClass in theNamespace.Classes)
            {
                Visit(xClass);
            }
        }
Example #3
0
 public override void Visit(NamespaceDefinition theNamespace)
 {
     var xParentNamespace = mNamespaces.Peek();
     var xNamespace = new MCM.NestedUnitNamespace
     {
         Name = mHostEnvironment.NameTable.GetNameFor(theNamespace.Name),
         Unit = mAssembly,
         ContainingUnitNamespace = xParentNamespace
     };
     xParentNamespace.Members.Add(xNamespace);
     mNamespaces.Push(xNamespace);
     try
     {
         base.Visit(theNamespace);
     }
     finally
     {
         mNamespaces.Pop();
     }
 }
Example #4
0
 /// <summary>
 /// Gets the namespace definition instance belonging to the specified <paramref name="name"/>, which may include dots. these dots will then be resolved
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public NamespaceDefinition GetNamespaceDefinition(string name)
 {
     string[] xParts = name.Split('.');
     var xCurrentNamespace = this;
     for (int i = 0; i < xParts.Length; i++)
     {
         var xPart = xParts[i];
         var xNewNamespace = (from item in xCurrentNamespace.Namespaces
                              where item.Name.Equals(xPart)
                              select item).SingleOrDefault();
         if (xNewNamespace == null)
         {
             xNewNamespace = new NamespaceDefinition();
             xNewNamespace.Name = xPart;
             xNewNamespace.ParentContainer = xCurrentNamespace;
             xCurrentNamespace.Namespaces.Add(xNewNamespace);
         }
         xCurrentNamespace = xNewNamespace;
     }
     return xCurrentNamespace;
 }
 private static void MergeNamespace(NamespaceDefinition target, NamespaceDefinition source)
 {
     source.MergedInto = target;
     foreach (var xSourceClass in source.Classes)
     {
         foreach (var xTargetClass in target.Classes)
         {
             if (xSourceClass.Name == xTargetClass.Name)
             {
                 // todo: add support for partial classes
                 throw new Exception("Class already exists!");
             }
         }
         target.Classes.Add(xSourceClass);
         xSourceClass.Container = target;
     }
     foreach (var xSourceNamespace in source.Namespaces)
     {
         NamespaceDefinition xFoundNamespace = null;
         foreach (var xTargetNamespace in target.Namespaces)
         {
             if (xTargetNamespace.Name == xSourceNamespace.Name)
             {
                 xFoundNamespace = xTargetNamespace;
                 break;
             }
         }
         if (xFoundNamespace == null)
         {
             target.Namespaces.Add(xSourceNamespace);
             xSourceNamespace.ParentContainer = target;
         }
         else
         {
             MergeNamespace(xFoundNamespace, xSourceNamespace);
         }
     }
 }
Example #6
0
 private void ParseNamespace(NamespaceDefinition namespaceParent)
 {
     Move();
     if (mToken.TagValue != Tag.Identifier)
     {
         Error("Identifier expected");
     }
     var xId = (Word)mToken;
     var xName = ReadFullIdentifier(true);
     var xNamespace = namespaceParent.GetNamespaceDefinition(xName);
     mParsingContexts.Push(xNamespace);
     try
     {
         Match('{');
         while (!IsMatch('}'))
         {
             #region namespace contents
             switch (mToken.TagValue)
             {
                 case Tag.Identifier:
                     {
                         var xWord = (Word)mToken;
                         switch (mKeywords.IndexOf(xWord.Value))
                         {
                             case Keywords.Class_Idx:
                                 ParseClass(xNamespace);
                                 break;
                             case Keywords.Namespace_Idx:
                                 ParseNamespace(xNamespace);
                                 break;
                             default:
                                 throw new Exception("Keyword '" + xWord.Value + "' unexpected!");
                         }
                         break;
                     }
                 default:
                     Error("Syntax Error, token not expected: " + mToken.ToString());
                     break;
             }
             #endregion
         }
         Move(); // } char was found, otherwise the while loop wouldn't have been exited
     }
     finally
     {
         mParsingContexts.Pop();
     }
 }