public void Initialize(ClassTypeDeclerationNode self)
        {
            if (Ancestor != null)
            {
                throw new InvalidOperationException("This class has already been initialized once");
            }

            IScope scope = self.FindFirstScope();

            if (self.BaseTypes.Count() > 1)
            {
                throw new NotImplementedException("Not supporting multiple inheritance in any form, yet!");
            }
            else if (self.BaseTypes.Count() == 1)
            {
                //Bug? parrent class declared later in method?
                TypeInformation baseInformation = scope.FindSymbol(self.BaseTypes[0].Value).Single();
                if (baseInformation.NeedsABetterNameType == NeedsABetterNameType.Class)
                {
                    Ancestor = baseInformation.Type;
                }
                else
                {
                    throw new Exception("Derives from something not a type"); //TODO: Err msg
                }
            }
            else
            {
                Ancestor = CrawlSimpleType.Ting;
            }


            List <KeyValuePair <string, TypeInformation[]> > members =
                self
                .Body
                .Scope
                .LocalSymbols()
                .Select(name =>
                        new KeyValuePair <string, TypeInformation[]>(
                            name,
                            self.Body.Scope.FindSymbol(name)
                            )
                        )
                .ToList();

            _scope = new ConcurrentDictionary <string, TypeInformation[]>(members);
        }
        protected override CrawlSyntaxNode VisitBlock(BlockNode block)
        {
            string                 ns       = block.FindNameSpace()?.Module ?? "";
            BlockScope             scope    = new BlockScope();
            List <CrawlSyntaxNode> children = new List <CrawlSyntaxNode>();

            foreach (CrawlSyntaxNode child in block)
            {
                CrawlSyntaxNode          afterVisit = Visit(child);
                ClassTypeDeclerationNode asClass    = afterVisit as ClassTypeDeclerationNode;
                if (asClass != null)
                {
                    CrawlConstructedType type = scope.AddClass(asClass, ns);
                    children.Add(asClass.WithClassType(type));
                }
                else
                {
                    children.Add(afterVisit);
                }
            }

            return(block.Update(block.Interval, children, scope));
        }
Ejemplo n.º 3
0
        public CrawlConstructedType AddClass(ClassTypeDeclerationNode node, string ns)
        {
            DeclaringScope declaringScope = DeclaringScope.MethodLike;

            if (node.Parent is ClassTypeDeclerationNode || node.Parent is TranslationUnitNode)
            {
                declaringScope = DeclaringScope.ClassLike; //Workingish, parrent == TranslationUnit probably going to require a little special handling
            }

            string name = node.Identifier.Value;
            CrawlConstructedType type = new CrawlConstructedType(name, ns);
            TypeInformation      info = new TypeInformation(type, node.ProtectionLevel, node.Interval.a, declaringScope, NeedsABetterNameType.Class);

            //Update contents. If not existing add a new array (line 2)
            //Otherwise, linq to append to array
            _scopeDictionary.AddOrUpdate(
                name,
                new[] { info },
                (s, informations) => informations.Concat(info.AsSingleIEnumerable()).ToArray()
                );
            _classes.Add(type);
            return(type);
        }
        protected override void VisitClassTypeDecleration(ClassTypeDeclerationNode node)
        {
            node.ClassType.Initialize(node);

            base.VisitClassTypeDecleration(node);
        }
 protected override CrawlSyntaxNode VisitClassTypeDecleration(ClassTypeDeclerationNode classTypeDecleration)
 {
     return(base.VisitClassTypeDecleration(classTypeDecleration));
 }