예제 #1
0
파일: Compiler.cs 프로젝트: Szune/EGScript
        public void Visit(ASTClassDefinition _class)
        {
            var name     = _class.Name;
            var baseName = _class.Base;

            Class newClass;

            if (baseName.Length == 0)
            {
                newClass = ObjectFactory.Class(name);
            }
            else
            {
                var baseClass = _environment.FindClass(baseName);
                if (baseClass == null)
                {
                    throw new CompilerException($"Base class '{name}' has not been defined.");
                }

                newClass = ObjectFactory.Class(name, baseClass);
            }

            _environment.AddClass(newClass);
            var memberDefinitions = _class.MemberDefinitions;

            for (int i = 0; i < memberDefinitions.Count; i++)
            {
                memberDefinitions[i].Accept(this, newClass);
            }
        }