Example #1
0
 public string GetFullName(TypeDeclaration typeDeclaration)
 {
     if (typeDeclaration.Parent is NamespaceDeclaration)
     {
         NamespaceDeclaration namespaceDeclaration = (NamespaceDeclaration)typeDeclaration.Parent;
         return(namespaceDeclaration.Name + "." + typeDeclaration.Name);
     }
     else if (typeDeclaration.Parent is TypeDeclaration)
     {
         TypeDeclaration parentType = (TypeDeclaration)typeDeclaration.Parent;
         return(GetFullName(parentType) + '$' + typeDeclaration.Name);
     }
     else if (typeDeclaration.Parent is ClassDeclarationStatement)
     {
         ClassDeclarationStatement cd = (ClassDeclarationStatement)typeDeclaration.Parent;
         INode  parentMember          = cd.Parent.Parent;
         string memberName;
         if (parentMember is MethodDeclaration)
         {
             memberName = ((MethodDeclaration)parentMember).Name;
         }
         else
         {
             memberName = ((ConstructorDeclaration)parentMember).Name;
         }
         TypeDeclaration parentType = (TypeDeclaration)parentMember.Parent;
         return(GetFullName(parentType) + "." + memberName + "." + typeDeclaration.Name);
     }
     return(null);
 }
Example #2
0
        private Statement classDeclaration()
        {
            String name = consume(TokenType.WORD).getText();
            ClassDeclarationStatement classDeclaration = new ClassDeclarationStatement(name);

            consume(TokenType.LBRACE);
            do
            {
                if (match(TokenType.DEF))
                {
                    classDeclaration.addMethod(functionDefine());
                }
                else
                {
                    Expression fieldDeclaration = null;     // FIXME
                    if (fieldDeclaration != null)
                    {
                        classDeclaration.addField(fieldDeclaration);
                    }
                    else
                    {
                        throw new Exception("Class can contain only assignments and function declarations");
                    }
                }
            } while (!match(TokenType.RBRACE));
            return(classDeclaration);
        }
Example #3
0
        private ExecuteResult ExecuteStatement(ClassDeclarationStatement statement)
        {
            var          name  = statement.Name;
            IClassObject super = null;

            if (statement.Super != null)
            {
                super = this.EvaluateExpression(statement.Super) as IClassObject;
                if (super == null)
                {
                    throw new RuntimeException(statement.Super.LinePragma,
                                               ExceptionResource.TypeExpected);
                }
            }
            try
            {
                IClassObject value = ObjectCreator.CreateClass(this, name, super, statement.Members);
                Memory.DecalreClass(this, name, value);
            }
            catch (RuntimeException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new RuntimeException(statement.LinePragma, ex.Message, ex);
            }
            return(ExecuteResult.Next);
        }
 private void HoistingExecuteStatement(ClassDeclarationStatement statement)
 {
     var name = statement.Name;
     try
     {
         Memory.HoistingDecalreClass(this, name);
     }
     catch (RuntimeException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new RuntimeException(statement.LinePragma, ex.Message, ex);
     }
 }
Example #5
0
        bool ParseClassDeclarationStatement(out ClassDeclarationStatement classDeclarationStatement)
        {
            classDeclarationStatement = new ClassDeclarationStatement();

            if (tokenReader.Expect(LexKind.Keyword))
            {
                if (tokenReader.Expect(LexKind.Identifier, 1))
                {
                    if (tokenReader.Peek().Value == "class" && tokenReader.Expect(LexKind.BraceOpen, 2))
                    {
                        classDeclarationStatement = new ClassDeclarationStatement()
                        {
                            Name = tokenReader.Peek(1).Value
                        };

                        tokenReader.Skip(3);
                        classDeclarationStatement.Body = ParseStatements();
                        return(true);
                    }
                }
            }

            return(false);
        }
Example #6
0
 public override object VisitClassDeclarationStatement(ClassDeclarationStatement classDeclarationStatement, object data)
 {
     classDeclarationStatement.Type.Parent = classDeclarationStatement;
     return(base.VisitClassDeclarationStatement(classDeclarationStatement, data));
 }
Example #7
0
 public override object VisitClassDeclarationStatement(ClassDeclarationStatement classDeclarationStatement, object data)
 {
     classDeclarationStatement.Type.Parent = classDeclarationStatement;
     return base.VisitClassDeclarationStatement(classDeclarationStatement, data);
 }