コード例 #1
0
ファイル: SecondPass.cs プロジェクト: goric/cflat
        public override void VisitSubClassDefinition(ASTSubClassDefinition n)
        {
            var parent = (ClassDescriptor)_scopeMgr.Find(n.Parent, p => p is ClassDescriptor);

            //need to restore the parent class's scope so that inheritance can pass semantic analysis
            _scopeMgr.RestoreScope(parent.Scope);

            _currentClass = new TypeClass(n.Name, parent);
            var classScope = _scopeMgr.PushScope(string.Format("subclass {0}", _currentClass.ClassName));

            _currentClass.Descriptor = (ClassDescriptor)_scopeMgr.Find(n.Name, p => p is ClassDescriptor);

            var declarationType = CheckSubTree(n.Declarations);

            n.Type = _currentClass;

            CheckNecessaryFunctions(n);

            _currentClass.Descriptor.Scope = _currentClass.Scope = classScope;

            AddCtorIfNone(classScope, n.Name);

            //pop the sub class scope and the parent class
            _scopeMgr.PopScope();
            _scopeMgr.PopScope();
        }
コード例 #2
0
ファイル: SecondPass.cs プロジェクト: goric/cflat
        //finds any 'necessary' methods in the parent class and makes sure that this subclass implements them
        private void CheckNecessaryFunctions(ASTSubClassDefinition n)
        {
            var parent = (ClassDescriptor)_scopeMgr.Find(n.Parent, p => p is ClassDescriptor);

            foreach (var method in parent.Methods)
            {
                if (method.Modifiers.Contains(NECESSARY_MODIFIER, StringComparer.InvariantCultureIgnoreCase))
                {
                    if (!_scopeMgr.CurrentScope.HasSymbol(method.Name))
                    {
                        ReportError(n.Location, "Class '{0}' does not implement method '{1}', marked necessary by superclass '{2}'", n.Name, method.Name, n.Parent);
                    }
                }
            }
        }
コード例 #3
0
ファイル: FirstPass.cs プロジェクト: goric/cflat
        /// <summary>
        /// Visit subclass node, adding appropriate descriptors to the current scope
        /// </summary>
        /// <param name="n"></param>
        public override void VisitSubClassDefinition(ASTSubClassDefinition n)
        {
            CheckForGlobalScope(n.Name, n.Location);

            ClassDescriptor prnt = (ClassDescriptor)_scopeMgr.GetType(n.Parent);

            TypeClass cls = new TypeClass(n.Name, prnt);

            _currentClass = cls;

            //prnt should be null if it's not a type or isn't found.. check for error, then check the actual type
            if (prnt == null || !prnt.IsType)
            {
                ReportError(n.Location, "Could not find base type '{0}' for type '{1}'.", n.Parent, n.Name);
            }
            if (!cls.IsClass)
            {
                ReportError(n.Location, "Could not find base type '{0}' for type '{1}'.", n.Parent, n.Name);
            }
            n.Descriptor = _scopeMgr.AddClass(cls.ClassName, cls, prnt);
            n.Type       = cls;
        }
コード例 #4
0
ファイル: ClassPass.cs プロジェクト: goric/cflat
 public override void VisitSubClassDefinition(ASTSubClassDefinition n)
 {
     _mgr.AddSubClass(n);
 }
コード例 #5
0
 public override void VisitSubClassDefinition(ASTSubClassDefinition n)
 {
     throw new NotImplementedException("Inheritance is not yet finished");
 }
コード例 #6
0
ファイル: ThirdPass.cs プロジェクト: goric/cflat
 /// <summary>
 /// Same as visiting a regular Class definition.
 /// </summary>
 /// <param name="n"></param>
 public override void VisitSubClassDefinition(ASTSubClassDefinition n)
 {
     VisitClassBody(n.Type as TypeClass, n.Declarations);
 }
コード例 #7
0
 public override void VisitSubClassDefinition(ASTSubClassDefinition n)
 {
     _currentType = n.Name;
     n.Declarations.Visit(this);
 }
コード例 #8
0
ファイル: TypeBuilderInfo.cs プロジェクト: goric/cflat
 public TypeBuilderInfo(ASTSubClassDefinition n, ModuleBuilder module, TypeBuilderInfo parent)
 {
     Builder = module.DefineType(n.Name, TypeAttributes.Public, parent.Builder);
     Init();
 }
コード例 #9
0
        public void AddSubClass(ASTSubClassDefinition n)
        {
            var parent = TypeBuilderMap[n.Parent];

            TypeBuilderMap.Add(n.Name, new TypeBuilderInfo(n, Module, parent));
        }