From 59fa5c27b64d0fc660e2fc53cf913d5de691cbd9 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sat, 15 Dec 2012 23:35:36 +0100 Subject: [PATCH 01/46] Added support for new compiler when loading objj files in the browsers --- Objective-J/Executable.js | 30 +- Objective-J/FileExecutable.js | 12 +- Objective-J/Includes.js | 2 + Objective-J/ObjJCompiler.js | 4178 +++++++++++++++++++++++++++++++++ Objective-J/Parser.js | 382 +++ 5 files changed, 4597 insertions(+), 7 deletions(-) create mode 100644 Objective-J/ObjJCompiler.js create mode 100644 Objective-J/Parser.js diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 55d4d05ec..ea38196e6 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -26,15 +26,17 @@ var ExecutableUnloadedFileDependencies = 0, ExecutableLoadedFileDependencies = 2, AnonymousExecutableCount = 0; -function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction) +function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction, /*ObjJCompiler*/aCompiler) { if (arguments.length === 0) return this; this._code = aCode; - this._function = aFunction || NULL; + this._function = aFunction || null; this._URL = makeAbsoluteURL(aURL || new CFURL("(Anonymous" + (AnonymousExecutableCount++) + ")")); + this._compiler = aCompiler || null; + this._fileDependencies = fileDependencies; if (fileDependencies.length) @@ -48,7 +50,8 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String if (this._function) return; - this.setCode(aCode); + if (!aCompiler) + this.setCode(aCode); } exports.Executable = Executable; @@ -135,6 +138,27 @@ Executable.prototype.execute = function() #if EXECUTION_LOGGING CPLog("EXECUTION: " + this.URL()); #endif + + if (this._compiler) + { + var fileDependencies = this.fileDependencies(), + index = 0, + count = fileDependencies.length; + + for (; index < count; ++index) + { + var fileDependency = fileDependencies[index], + isQuoted = fileDependency.isLocal(), + URL = fileDependency.URL(); + + CPLog("Execute FileDependant: " + URL); + objj_executeFile(URL, isQuoted); + } + + CPLog("Compile Pass 2: " + this.URL()); + this.setCode(this._compiler.compilePass2()); + } + var oldContextBundle = CONTEXT_BUNDLE; // FIXME: Should we have stored this? diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 2dda22f1a..4e5f59f1e 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -41,13 +41,17 @@ function FileExecutable(/*CFURL|String*/ aURL) if (fileContents.match(/^@STATIC;/)) executable = decompile(fileContents, aURL); - else if (extension === "j" || !extension) - executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); - + else if (extension === "j" || !extension) { +// console.log("Compile: " + aURL); +// if (!aURL || aURL.toString().indexOf("Boplats/Office/Applications") === -1) +// executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); +// else + executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); + } else executable = new Executable(fileContents, [], aURL); - Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function]); + Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler]); this._hasExecuted = NO; } diff --git a/Objective-J/Includes.js b/Objective-J/Includes.js index b2cc26fb2..f133c41bc 100644 --- a/Objective-J/Includes.js +++ b/Objective-J/Includes.js @@ -43,6 +43,8 @@ #include "CFBundle.js" #include "StaticResource.js" #include "Preprocessor.js" +#include "Parser.js" +#include "ObjJCompiler.js" #include "FileDependency.js" #include "Executable.js" #include "FileExecutable.js" diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js new file mode 100644 index 000000000..5506ba990 --- /dev/null +++ b/Objective-J/ObjJCompiler.js @@ -0,0 +1,4178 @@ +/* + * ObjJCompiler.js + * Objective-J + * + * Created by Martin Carlberg. + * Copyright 2012, Martin Carlberg. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +//function FileDependency(/*CFURL*/ aURL, /*BOOL*/ isLocal) +/*{ + this._URL = aURL; + this._isLocal = isLocal; +}*/ + +//var FileDependency = {}; // Dummy declaration !!!!!!! REMOVE!!!!!!!! +var ObjJCompiler = { }; + +//(function(global, exports, module) +//{ + +/* function IS_NOT_EMPTY(buffer) {return buffer.atoms.length !== 0;} + + function CONCAT(buffer, atom) + { + if (buffer) + buffer.atoms[buffer.atoms.length] = atom; + } +*/ +/*function StringBuffer() +{ + this.atoms = []; +} + +StringBuffer.prototype.toString = function() +{ + return this.atoms.join(""); +}*/ + +//exports.compile = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +/*{ + return new ObjJCompiler(aString, aURL, flags); +}*/ + +exports.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + return new ObjJCompiler(aString, aURL, flags, 2).executable(); +} + +exports.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + return new ObjJCompiler(aString, aURL, flags, 2).IMBuffer(); +} + +exports.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + return new ObjJCompiler(aString, aURL, flags, 1).executable(); +} + +/*exports.eval = function(aString) +{ + return eval(exports.compile(aString).JSBuffer()); +}*/ + +var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) +{ + aString = aString.replace(/^#[^\n]+\n/, "\n"); + this._URL = new CFURL(aURL); + this._pass = pass; + // If this is pass one we should not save anything in buffers + if (pass === 1) + this._jsBuffer = null; + else + this._jsBuffer = new StringBuffer(); + this._imBuffer = null; + this._cmBuffer = null; + console.time("Parse - " + aURL); + this._tokens = exports.Parser.parse(aString); + console.timeEnd("Parse - " + aURL); + this._dependencies = []; + this._flags = flags | ObjJCompiler.Flags.IncludeDebugSymbols; + this._classDefs = {}; + console.time("Compile" + pass + " - " + aURL); + this.nodeDocument(this._tokens); + console.timeEnd("Compile" + pass + " - " + aURL); +// console.log("JS: " + this._jsBuffer); +} + +ObjJCompiler.prototype.compilePass2 = function() +{ + this._pass = 2; + this._jsBuffer = new StringBuffer(); + console.time("Compile" + this._pass + " - " + this._URL); + this.nodeDocument(this._tokens); + console.timeEnd("Compile" + this._pass + " - " + this._URL); + return this._jsBuffer; +} + +exports.ObjJCompiler = ObjJCompiler; + +ObjJCompiler.Flags = { }; + +ObjJCompiler.Flags.IncludeDebugSymbols = 1 << 0; +ObjJCompiler.Flags.IncludeTypeSignatures = 1 << 1; + +ObjJCompiler.AstNodeDocument = "#document"; +ObjJCompiler.AstNodeStart = "start"; +ObjJCompiler.AstNodeFunctionBody = "FunctionBody"; +ObjJCompiler.AstNodeSourceElements = "SourceElements"; +ObjJCompiler.AstNodeSourceElement = "SourceElement"; +ObjJCompiler.AstNodeFunctionDeclaration = "FunctionDeclaration"; +ObjJCompiler.AstNodeFunctionExpression = "FunctionExpression"; +ObjJCompiler.AstNodeFormalParameterList = "FormalParameterList"; +ObjJCompiler.AstNodeStatementList = "StatementList"; +ObjJCompiler.AstNodeStatement = "Statement"; +ObjJCompiler.AstNodeBlock = "Block"; +ObjJCompiler.AstNodeVariableStatement = "VariableStatement"; +ObjJCompiler.AstNodeEmptyStatement = "EmptyStatement"; +ObjJCompiler.AstNodeExpressionStatement = "ExpressionStatement"; +ObjJCompiler.AstNodeIfStatement = "IfStatement"; +ObjJCompiler.AstNodeIterationStatement = "IterationStatement"; +ObjJCompiler.AstNodeContinueStatement = "ContinueStatement"; +ObjJCompiler.AstNodeBreakStatement = "BreakStatement"; +ObjJCompiler.AstNodeReturnStatement = "ReturnStatement"; +ObjJCompiler.AstNodeWithStatement = "WithStatement"; +ObjJCompiler.AstNodeLabelledStatement = "LabelledStatement"; +ObjJCompiler.AstNodeSwitchStatement = "SwitchStatement"; +ObjJCompiler.AstNodeThrowStatement = "ThrowStatement"; +ObjJCompiler.AstNodeTryStatement = "TryStatement"; +ObjJCompiler.AstNodeDebuggerStatement = "DebuggerStatement"; +ObjJCompiler.AstNodeImportStatement = "ImportStatement"; +ObjJCompiler.AstNodeVariableDeclaration = "VariableDeclaration"; +ObjJCompiler.AstNodeVariableDeclarationNoIn = "VariableDeclarationNoIn"; +ObjJCompiler.AstNodeVariableDeclarationListNoIn = "VariableDeclarationListNoIn"; +ObjJCompiler.AstNodeDoWhileStatement = "DoWhileStatement"; +ObjJCompiler.AstNodeWhileStatement = "WhileStatement"; +ObjJCompiler.AstNodeForStatement = "ForStatement"; +ObjJCompiler.AstNodeForFirstExpression = "ForFirstExpression"; +ObjJCompiler.AstNodeForInStatement = "ForInStatement"; +ObjJCompiler.AstNodeForInFirstExpression = "ForInFirstExpression"; +ObjJCompiler.AstNodeEachStatement = "EachStatement"; +ObjJCompiler.AstNodeCaseBlock = "CaseBlock"; +ObjJCompiler.AstNodeCaseClauses = "CaseClauses"; +ObjJCompiler.AstNodeCaseClause = "CaseClause"; +ObjJCompiler.AstNodeDefaultClause = "DefaultClause"; +ObjJCompiler.AstNodeCatch = "Catch"; +ObjJCompiler.AstNodeFinally = "Finally"; +ObjJCompiler.AstNodeLocalFilePath = "LocalFilePath"; +ObjJCompiler.AstNodeStandardFilePath = "StandardFilePath"; +ObjJCompiler.AstNodeClassDeclarationStatement = "ClassDeclarationStatement"; +ObjJCompiler.AstNodeSuperclassDeclaration = "SuperclassDeclaration"; +ObjJCompiler.AstNodeCategoryDeclaration = "CategoryDeclaration"; +ObjJCompiler.AstNodeCompoundIvarDeclaration = "CompoundIvarDeclaration"; +ObjJCompiler.AstNodeIvarType = "IvarType"; +ObjJCompiler.AstNodeIvarTypeElement = "IvarTypeElement"; +ObjJCompiler.AstNodeIvarDeclaration = "IvarDeclaration"; +ObjJCompiler.AstNodeAccessors = "Accessors"; +ObjJCompiler.AstNodeAccessorsConfiguration = "AccessorsConfiguration"; +ObjJCompiler.AstNodeIvarPropertyName = "IvarPropertyName"; +ObjJCompiler.AstNodeIvarGetterName = "IvarGetterName"; +ObjJCompiler.AstNodeIvarSetterName = "IvarSetterName"; +ObjJCompiler.AstNodeClassBody = "ClassBody"; +ObjJCompiler.AstNodeClassElements = "ClassElements"; +ObjJCompiler.AstNodeClassElement = "ClassElement"; +ObjJCompiler.AstNodeClassMethodDeclaration = "ClassMethodDeclaration"; +ObjJCompiler.AstNodeInstanceMethodDeclaration = "InstanceMethodDeclaration"; +ObjJCompiler.AstNodeMethodSelector = "MethodSelector"; +ObjJCompiler.AstNodeUnarySelector = "UnarySelector"; +ObjJCompiler.AstNodeKeywordSelector = "KeywordSelector"; +ObjJCompiler.AstNodeKeywordDeclarator = "KeywordDeclarator"; +ObjJCompiler.AstNodeSelector = "Selector"; +ObjJCompiler.AstNodeMethodType = "MethodType"; +ObjJCompiler.AstNodeACTION = "ACTION"; +ObjJCompiler.AstNodeExpression = "Expression"; +ObjJCompiler.AstNodeExpressionNoIn = "ExpressionNoIn"; +ObjJCompiler.AstNodeAssignmentExpression = "AssignmentExpression"; +ObjJCompiler.AstNodeAssignmentExpressionNoIn = "AssignmentExpressionNoIn"; +ObjJCompiler.AstNodeAssignmentOperator = "AssignmentOperator"; +ObjJCompiler.AstNodeConditionalExpression = "ConditionalExpression"; +ObjJCompiler.AstNodeConditionalExpressionNoIn = "ConditionalExpressionNoIn"; +ObjJCompiler.AstNodeLogicalOrExpression = "LogicalOrExpression"; +ObjJCompiler.AstNodeLogicalOrExpressionNoIn = "LogicalOrExpressionNoIn"; +ObjJCompiler.AstNodeLogicalAndExpression = "LogicalAndExpression"; +ObjJCompiler.AstNodeLogicalAndExpressionNoIn = "LogicalAndExpressionNoIn"; +ObjJCompiler.AstNodeBitwiseOrExpression = "BitwiseOrExpression"; +ObjJCompiler.AstNodeBitwiseOrExpressionNoIn = "BitwiseOrExpressionNoIn"; +ObjJCompiler.AstNodeBitwiseXOrExpression = "BitwiseXOrExpression"; +ObjJCompiler.AstNodeBitwiseXOrExpressionNoIn = "BitwiseXOrExpressionNoIn"; +ObjJCompiler.AstNodeBitwiseAndExpression = "BitwiseAndExpression"; +ObjJCompiler.AstNodeBitwiseAndExpressionNoIn = "BitwiseAndExpressionNoIn"; +ObjJCompiler.AstNodeEqualityExpression = "EqualityExpression"; +ObjJCompiler.AstNodeEqualityExpressionNoIn = "EqualityExpressionNoIn"; +ObjJCompiler.AstNodeEqualityOperator = "EqualityOperator"; +ObjJCompiler.AstNodeRelationalExpression = "RelationalExpression"; +ObjJCompiler.AstNodeRelationalOperator = "RelationalOperator"; +ObjJCompiler.AstNodeRelationalExpressionNoIn = "RelationalExpressionNoIn"; +ObjJCompiler.AstNodeRelationalOperatorNoIn = "RelationalOperatorNoIn"; +ObjJCompiler.AstNodeShiftExpression = "ShiftExpression"; +ObjJCompiler.AstNodeShiftOperator = "ShiftOperator"; +ObjJCompiler.AstNodeAdditiveExpression = "AdditiveExpression"; +ObjJCompiler.AstNodeAdditiveOperator = "AdditiveOperator"; +ObjJCompiler.AstNodeMultiplicativeExpression = "MultiplicativeExpression"; +ObjJCompiler.AstNodeMultiplicativeOperator = "MultiplicativeOperator"; +ObjJCompiler.AstNodeUnaryExpression = "UnaryExpression"; +ObjJCompiler.AstNodePostfixExpression = "PostfixExpression"; +ObjJCompiler.AstNodeLeftHandSideExpression = "LeftHandSideExpression"; +ObjJCompiler.AstNodeNewExpression = "NewExpression"; +ObjJCompiler.AstNodeCallExpression = "CallExpression"; +ObjJCompiler.AstNodeMemberExpression = "MemberExpression"; +ObjJCompiler.AstNodeBracketedAccessor = "BracketedAccessor"; +ObjJCompiler.AstNodeDotAccessor = "DotAccessor"; +ObjJCompiler.AstNodeArguments = "Arguments"; +ObjJCompiler.AstNodeArgumentList = "ArgumentList"; +ObjJCompiler.AstNodePrimaryExpression = "PrimaryExpression"; +ObjJCompiler.AstNodeMessageExpression = "MessageExpression"; +ObjJCompiler.AstNodeSUPER = "SUPER"; +ObjJCompiler.AstNodeSelectorCall = "SelectorCall"; +ObjJCompiler.AstNodeKeywordSelectorCall = "KeywordSelectorCall"; +ObjJCompiler.AstNodeKeywordCall = "KeywordCall"; +ObjJCompiler.AstNodeArrayLiteral = "ArrayLiteral"; +ObjJCompiler.AstNodeElementList = "ElementList"; +ObjJCompiler.AstNodeObjectLiteral = "ObjectLiteral"; +ObjJCompiler.AstNodePropertyNameAndValueList = "PropertyNameAndValueList"; +ObjJCompiler.AstNodePropertyAssignment = "PropertyAssignment"; +ObjJCompiler.AstNodePropertyGetter = "PropertyGetter"; +ObjJCompiler.AstNodePropertySetter = "PropertySetter"; +ObjJCompiler.AstNodePropertyName = "PropertyName"; +ObjJCompiler.AstNodePropertySetParameterList = "PropertySetParameterList"; +ObjJCompiler.AstNodeLiteral = "Literal"; +ObjJCompiler.AstNodeNullLiteral = "NullLiteral"; +ObjJCompiler.AstNodeBooleanLiteral = "BooleanLiteral"; +ObjJCompiler.AstNodeNumericLiteral = "NumericLiteral"; +ObjJCompiler.AstNodeDecimalLiteral = "DecimalLiteral"; +ObjJCompiler.AstNodeDecimalIntegerLiteral = "DecimalIntegerLiteral"; +ObjJCompiler.AstNodeDecimalDigit = "DecimalDigit"; +ObjJCompiler.AstNodeExponentPart = "ExponentPart"; +ObjJCompiler.AstNodeSignedInteger = "SignedInteger"; +ObjJCompiler.AstNodeHexIntegerLiteral = "HexIntegerLiteral"; +ObjJCompiler.AstNodeHexDigit = "HexDigit"; +ObjJCompiler.AstNodeStringLiteral = "StringLiteral"; +ObjJCompiler.AstNodeDoubleStringCharacter = "DoubleStringCharacter"; +ObjJCompiler.AstNodeSingleStringCharacter = "SingleStringCharacter"; +ObjJCompiler.AstNodeLineContinuation = "LineContinuation"; +ObjJCompiler.AstNodeEscapeSequence = "EscapeSequence"; +ObjJCompiler.AstNodeCharacterEscapeSequence = "CharacterEscapeSequence"; +ObjJCompiler.AstNodeSingleEscapeCharacter = "SingleEscapeCharacter"; +ObjJCompiler.AstNodeNonEscapeCharacter = "NonEscapeCharacter"; +ObjJCompiler.AstNodeEscapeCharacter = "EscapeCharacter"; +ObjJCompiler.AstNodeHexEscapeSequence = "HexEscapeSequence"; +ObjJCompiler.AstNodeUnicodeEscapeSequence = "UnicodeEscapeSequence"; +ObjJCompiler.AstNodeRegularExpressionLiteral = "RegularExpressionLiteral"; +ObjJCompiler.AstNodeRegularExpressionBody = "RegularExpressionBody"; +ObjJCompiler.AstNodeRegularExpressionFirstChar = "RegularExpressionFirstChar"; +ObjJCompiler.AstNodeRegularExpressionChar = "RegularExpressionChar"; +ObjJCompiler.AstNodeRegularExpressionBackslashSequence = "RegularExpressionBackslashSequence"; +ObjJCompiler.AstNodeRegularExpressionNonTerminator = "RegularExpressionNonTerminator"; +ObjJCompiler.AstNodeRegularExpressionClass = "RegularExpressionClass"; +ObjJCompiler.AstNodeRegularExpressionClassChar = "RegularExpressionClassChar"; +ObjJCompiler.AstNodeRegularExpressionFlags = "RegularExpressionFlags"; +ObjJCompiler.AstNodeSelectorLiteral = "SelectorLiteral"; +ObjJCompiler.AstNodeSelectorLiteralContents = "SelectorLiteralContents"; +ObjJCompiler.AstNodeUnderline = "_"; +ObjJCompiler.AstNodeUnderlineNoLineBreak = "__"; +ObjJCompiler.AstNodeWhiteSpace = "WhiteSpace"; +ObjJCompiler.AstNodeLineTerminator = "LineTerminator"; +ObjJCompiler.AstNodeLineTerminatorSequence = "LineTerminatorSequence"; +ObjJCompiler.AstNodeComment = "Comment"; +ObjJCompiler.AstNodeMultiLineComment = "MultiLineComment"; +ObjJCompiler.AstNodeSingleLineMultiLineComment = "SingleLineMultiLineComment"; +ObjJCompiler.AstNodeSingleLineComment = "SingleLineComment"; +ObjJCompiler.AstNodeSingleLineCommentChar = "SingleLineCommentChar"; +ObjJCompiler.AstNodeEOS = "EOS"; +ObjJCompiler.AstNodeSemicolonInsertionEOS = "SemicolonInsertionEOS"; +ObjJCompiler.AstNodeEOF = "EOF"; +ObjJCompiler.AstNodeReservedWord = "ReservedWord"; +ObjJCompiler.AstNodeKeyword = "Keyword"; +ObjJCompiler.AstNodeFutureReservedWord = "FutureReservedWord"; +ObjJCompiler.AstNodeIdentifier = "Identifier"; +ObjJCompiler.AstNodeBadIdentifier = "BadIdentifier"; +ObjJCompiler.AstNodeReservedWordIdentifier = "ReservedWordIdentifier"; +ObjJCompiler.AstNodeDigitIdentifier = "DigitIdentifier"; +ObjJCompiler.AstNodeIdentifierName = "IdentifierName"; +ObjJCompiler.AstNodeIdentifierStart = "IdentifierStart"; +ObjJCompiler.AstNodeIdentifierPart = "IdentifierPart"; +ObjJCompiler.AstNodeUnicodeLetter = "UnicodeLetter"; +ObjJCompiler.AstNodeUnicodeCombiningMark = "UnicodeCombiningMark"; +ObjJCompiler.AstNodeUnicodeDigit = "UnicodeDigit"; +ObjJCompiler.AstNodeUnicodeConnectorPunctuation = "UnicodeConnectorPunctuation"; +ObjJCompiler.AstNodeZWNJ = "ZWNJ"; +ObjJCompiler.AstNodeZWJ = "ZWJ"; +ObjJCompiler.AstNodeFALSE = "FALSE"; +ObjJCompiler.AstNodeTRUE = "TRUE"; +ObjJCompiler.AstNodeNULL = "NULL"; +ObjJCompiler.AstNodeBREAK = "BREAK"; +ObjJCompiler.AstNodeCONTINUE = "CONTINUE"; +ObjJCompiler.AstNodeDEBUGGER = "DEBUGGER"; +ObjJCompiler.AstNodeIN = "IN"; +ObjJCompiler.AstNodeINSTANCEOF = "INSTANCEOF"; +ObjJCompiler.AstNodeDELETE = "DELETE"; +ObjJCompiler.AstNodeFUNCTION = "FUNCTION"; +ObjJCompiler.AstNodeNEW = "NEW"; +ObjJCompiler.AstNodeTHIS = "THIS"; +ObjJCompiler.AstNodeTYPEOF = "TYPEOF"; +ObjJCompiler.AstNodeVOID = "VOID"; +ObjJCompiler.AstNodeIF = "IF"; +ObjJCompiler.AstNodeELSE = "ELSE"; +ObjJCompiler.AstNodeDO = "DO"; +ObjJCompiler.AstNodeWHILE = "WHILE"; +ObjJCompiler.AstNodeFOR = "FOR"; +ObjJCompiler.AstNodeVAR = "VAR"; +ObjJCompiler.AstNodeRETURN = "RETURN"; +ObjJCompiler.AstNodeCASE = "CASE"; +ObjJCompiler.AstNodeDEFAULT = "DEFAULT"; +ObjJCompiler.AstNodeSWITCH = "SWITCH"; +ObjJCompiler.AstNodeTHROW = "THROW"; +ObjJCompiler.AstNodeCATCH = "CATCH"; +ObjJCompiler.AstNodeFINALLY = "FINALLY"; +ObjJCompiler.AstNodeTRY = "TRY"; +ObjJCompiler.AstNodeWITH = "WITH"; + +ObjJCompiler.prototype.assertNode = function(/*SyntaxNode*/ astNode, /*String*/ astNodeName) +{ + if (!astNode || astNode.name !== astNodeName) + { +// debugger; + throw new SyntaxError(this.error_message("Expected node " + astNodeName + " but got " + (astNode ? astNode.name : astNode), astNode)); + } +} + +ObjJCompiler.prototype.nodeDocument = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDocument); + this.nodeStart(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeStart = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeStart); + var children = astNode.children; + + this.nodeUnderline(children[0], false); + var lastUnderlineIndex = 1; + if (children.length === 3) + { + this.nodeSourceElements(children[1]); + lastUnderlineIndex++; + } + this.nodeUnderline(children[lastUnderlineIndex], false) +} + +ObjJCompiler.prototype.nodeFunctionBody = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFunctionBody); + var children = astNode.children; + + this.nodeUnderline(children[0], false); + var lastUnderlineIndex = 1; + if (children.length === 3) + { + this.nodeSourceElements(children[1]); + lastUnderlineIndex++; + } + this.nodeUnderline(children[lastUnderlineIndex], false) +} + +ObjJCompiler.prototype.nodeSourceElements = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSourceElements); + var children = astNode.children; + + this.nodeSourceElement(children[0]); + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + this.nodeSourceElement(children[i + 1]); + } +} + +ObjJCompiler.prototype.nodeSourceElement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSourceElement); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeStatement) + this.nodeStatement(child); + else if (child && child.name === ObjJCompiler.AstNodeFunctionDeclaration) + if (this._pass === 2) // Skip this if it is the first pass + this.nodeFunctionDeclaration(child); + else + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeStatement + " or " + ObjJCompiler.AstNodeFunctionDeclaration + " but got " + child, child)); +} + +ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode) +{ + // Safari can't handle function declarations of the form function [name]([arguments]) { } + // in evals. It requires them to be in the form [name] = function([arguments]) { }. So we + // need format them like that. + this.assertNode(astNode, ObjJCompiler.AstNodeFunctionDeclaration); + var children = astNode.children, + child = children[6], + offset = 0, + saveJSBuffer = this._jsBuffer; + + this._jsBuffer = null; + this.nodeFUNCTION(children[0]); + this.nodeUnderline(children[1], true); + var identifier = this.nodeIdentifier(children[2]); + this.nodeUnderline(children[3], false); + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, identifier); + CONCAT(saveJSBuffer, " = function"); + } + this._jsBuffer = saveJSBuffer; + this.nodeOpenParenthesis(children[4]); + this.nodeUnderline(children[5], false); + + if (child && child.name ===ObjJCompiler.AstNodeFormalParameterList) + { + this.nodeFormalParameterList(children[6]); + offset++; + } + this.nodeUnderline(children[6 + offset], false); + this.nodeCloseParenthesis(children[7 + offset]); + this.nodeUnderline(children[8 + offset], false); + this.nodeOpenBrace(children[9 + offset]); + this.nodeUnderline(children[10 + offset], false); + this.nodeFunctionBody(children[11 + offset]); + this.nodeUnderline(children[12 + offset], false); + this.nodeCloseBrace(children[13 + offset]); +} + +ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFunctionExpression); + var children = astNode.children, + child = children[2], + offset = 0; + + this.nodeFUNCTION(children[0]); + this.nodeUnderline(children[1], true); + if (child && child.name === ObjJCompiler.AstNodeIdentifier) + { + this.nodeIdentifier(child); + offset++; + } + this.nodeUnderline(children[2 + offset], false); + this.nodeWORD(children[3 + offset]); + this.nodeUnderline(children[4 + offset], false); + + child = children[5 + offset]; + + if (child && child.name ===ObjJCompiler.AstNodeFormalParameterList) + { + this.nodeFormalParameterList(child); + offset++; + } + this.nodeUnderline(children[5 + offset], false); + this.nodeWORD(children[6 + offset]); + this.nodeUnderline(children[7 + offset], false); + this.nodeOpenBrace(children[8 + offset]); + this.nodeUnderline(children[9 + offset], false); + this.nodeFunctionBody(children[10 + offset]); + this.nodeUnderline(children[11 + offset], false); + this.nodeCloseBrace(children[12 + offset]); +} + +ObjJCompiler.prototype.nodeFormalParameterList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFormalParameterList); + var children = astNode.children; + + this.nodeIdentifier(children[0]); + for (var i = 1; i + 3 < children.length; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeIdentifier(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeStatementList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeStatementList); + var children = astNode.children; + + this.nodeStatement(children[0]); + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + this.nodeStatement(children[i + 1]); + } +} + +ObjJCompiler.prototype.nodeStatement = function(/*SyntaxNode*/ astNode) +{ + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeBlock: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeBlock(child); + break; + case ObjJCompiler.AstNodeVariableStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeVariableStatement(child); + break; + case ObjJCompiler.AstNodeEmptyStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeEmptyStatement(child); + break; + case ObjJCompiler.AstNodeExpressionStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeExpressionStatement(child); + break; + case ObjJCompiler.AstNodeIfStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeIfStatement(child); + break; + case ObjJCompiler.AstNodeIterationStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeIterationStatement(child); + break; + case ObjJCompiler.AstNodeContinueStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeContinueStatement(child); + break; + case ObjJCompiler.AstNodeBreakStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeBreakStatement(child); + break; + case ObjJCompiler.AstNodeReturnStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeReturnStatement(child); + break; + case ObjJCompiler.AstNodeWithStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeWithStatement(child); + break; + case ObjJCompiler.AstNodeLabelledStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeLabelledStatement(child); + break; + case ObjJCompiler.AstNodeSwitchStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeSwitchStatement(child); + break; + case ObjJCompiler.AstNodeThrowStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeThrowStatement(child); + break; + case ObjJCompiler.AstNodeTryStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeTryStatement(child); + break; + case ObjJCompiler.AstNodeDebuggerStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeDebuggerStatement(child); + break; + case ObjJCompiler.AstNodeFunctionDeclaration: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeFunctionDeclaration(child); + break; + case ObjJCompiler.AstNodeFunctionExpression: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeFunctionExpression(child); + break; + case ObjJCompiler.AstNodeImportStatement: + this.nodeImportStatement(child); + break; + case ObjJCompiler.AstNodeClassDeclarationStatement: + if (this._pass === 2) // Skip this if it is the first pass + this.nodeClassDeclationStatement(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeStatement + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeBlock = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBlock); + var children = astNode.children; + + this.nodeOpenBrace(children[0]); + this.nodeUnderline(children[1], false); + var offset = 0; + if (children.length === 5) + { + this.nodeStatementList(children[2]); + offset++; + } + this.nodeUnderline(children[2 + offset], false); + this.nodeCloseBrace(children[3 + offset]); + // TODO: Handle BadBlock with missing close brace +} + +ObjJCompiler.prototype.nodeVariableStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVariableStatement); + var children = astNode.children; + + this.nodeVAR(children[0]); + this.nodeUnderline(children[1], true); + this.nodeVariableDeclaration(children[2]); + + for (var i = 3; i + 3 < children.length; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeCOMMA(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeVariableDeclaration(children[i + 3]); + } + this.nodeEOS(children[i]); +} + +ObjJCompiler.prototype.nodeVariableDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclaration); + var children = astNode.children, + identifier = this.nodeIdentifier(children[0]); + + if (children.length === 5) + { + this.nodeUnderline(children[1], false); + this.nodeEQUALS(children[2]); + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpression(children[4]); + } + + this.createLocalVariable({"identifier": identifier}); +} + +ObjJCompiler.prototype.nodeVariableDeclarationNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationNoIn); + var children = astNode.children, + identifier = this.nodeIdentifier(children[0]); + + if (children.length === 5) + { + this.nodeUnderline(children[1], false); + this.nodeEQUALS(children[2]); + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpressionNoIn(children[4]); + } + + this.createLocalVariable({"identifier": identifier}); +} + +ObjJCompiler.prototype.nodeVariableDeclarationListNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationListNoIn); + var children = astNode.children; + + this.nodeVariableDeclarationNoIn(children[0]); + + for (var i = 1; i + 3 < children.length; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeCOMMA(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeVariableDeclarationNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeEmptyStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEmptyStatement); + + this.nodeWORD(astNode.children[0]); // ";" +} + +ObjJCompiler.prototype.nodeExpressionStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeExpressionStatement); + var children = astNode.children; + + this.nodeExpression(children[0]); + this.nodeEOS(children[1]); +} + +ObjJCompiler.prototype.nodeIfStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIfStatement); + var children = astNode.children; + + this.nodeIF(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeExpression(children[4]); + this.nodeUnderline(children[5], false); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeStatement(children[8]); + + if (children.length === 13) + { + this.nodeUnderline(children[9], false); + this.nodeELSE(children[10], false); + this.nodeUnderline(children[11], true); + this.nodeStatement(children[12]); + } +} + +ObjJCompiler.prototype.nodeIterationStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIterationStatement); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeDoWhileStatement: + this.nodeDoWhileStatement(child); + break; + case ObjJCompiler.AstNodeWhileStatement: + this.nodeWhileStatement(child); + break; + case ObjJCompiler.AstNodeForStatement: + this.nodeForStatement(child); + break; + case ObjJCompiler.AstNodeForInStatement: + this.nodeForInStatement(child); + break; + case ObjJCompiler.AstNodeEachStatement: + this.nodeEachStatement(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeIterationStatement + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeDoWhileStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDoWhileStatement); + var children = astNode.children; + + this.nodeDO(children[0]); + this.nodeUnderline(children[1], true); + this.nodeStatement(children[2]); + this.nodeUnderline(children[3], true); + this.nodeWHILE(children[4]); + this.nodeUnderline(children[5], false); + this.nodeOpenParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeExpression(children[8]); + this.nodeUnderline(children[9], false); + this.nodeCloseParenthesis(children[10]); + this.nodeEOS(children[11]); +} + +ObjJCompiler.prototype.nodeWhileStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeWhileStatement); + var children = astNode.children; + + this.nodeWHILE(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeExpression(children[4]); + this.nodeUnderline(children[5], false); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeStatement(children[8]); +} + +ObjJCompiler.prototype.nodeForStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeForStatement); + var children = astNode.children, + child = children[4]; + + this.nodeFOR(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + var offset = 0; + if (!child || child.name !== ObjJCompiler.AstNodeUnderline) + { + this.nodeForFirstExpression(children[4]); + offset++; + } + this.nodeUnderline(children[4 + offset], false); + this.nodeWORD(children[5 + offset]); // ";" + this.nodeUnderline(children[6 + offset], false); + child = children[7 + offset]; + if (!child || child.name !== ObjJCompiler.AstNodeUnderline) + { + this.nodeExpression(child); + offset++; + } + this.nodeUnderline(children[7 + offset], false); + this.nodeWORD(children[8 + offset]); // ";" + this.nodeUnderline(children[9 + offset], false); + child = children[10 + offset]; + if (!child || child.name !== ObjJCompiler.AstNodeUnderline) + { + this.nodeExpression(children[10 + offset]); + offset++; + } + this.nodeUnderline(children[10 + offset], false); + this.nodeCloseParenthesis(children[11 + offset]); + this.nodeUnderline(children[12 + offset], false); + this.nodeStatement(children[13 + offset]); +} + +ObjJCompiler.prototype.nodeForFirstExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeForFirstExpression); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeVAR) + { + this.nodeVAR(child); + this.nodeUnderline(children[1], true); + this.nodeVariableDeclarationListNoIn(children[2]); + } + else + this.nodeExpressionNoIn(children[0]); +} + +ObjJCompiler.prototype.nodeForInStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeForInStatement); + var children = astNode.children; + + this.nodeFOR(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeForInFirstExpression(children[4]); + this.nodeUnderline(children[5], true); + this.nodeIN(children[6]); + this.nodeUnderline(children[7], true); + this.nodeExpression(children[8]); // ";" + this.nodeUnderline(children[9], false); + this.nodeCloseParenthesis(children[10]); + this.nodeUnderline(children[11], false); + this.nodeStatement(children[12]); +} + +ObjJCompiler.prototype.nodeForInFirstExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeForInFirstExpression); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeVAR) + { + this.nodeVAR(child); + this.nodeUnderline(children[1], true); + this.nodeVariableDeclarationNoIn(children[2]); + } + else + this.nodeLeftHandSideExpression(child); +} + +ObjJCompiler.prototype.nodeEachStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEachStatement); + var children = astNode.children; + + this.nodeEACH(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeForInFirstExpression(children[4]); + this.nodeUnderline(children[5], true); + this.nodeIN(children[6]); + this.nodeUnderline(children[7], true); + this.nodeExpression(children[8]); // ";" + this.nodeUnderline(children[9], false); + this.nodeCloseParenthesis(children[10]); + this.nodeUnderline(children[11], false); + this.nodeStatement(children[12]); +} + +ObjJCompiler.prototype.nodeContinueStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeContinueStatement); + var children = astNode.children, + child = children[2]; + + this.nodeCONTINUE(children[0]); + this.nodeUnderlineNoLineBreak(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeIdentifier) + { + this.nodeIdentifier(child); + this.nodeEOS(children[3]); + } + else + this.nodeSemicolonInsertionEOS(children[2]); +} + +ObjJCompiler.prototype.nodeBreakStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBreakStatement); + var children = astNode.children, + child = children[2]; + + this.nodeBREAK(children[0]); + this.nodeUnderlineNoLineBreak(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeIdentifier) + { + this.nodeIdentifier(child); + this.nodeEOS(children[3]); + } + else + this.nodeSemicolonInsertionEOS(children[2]); +} + +ObjJCompiler.prototype.nodeReturnStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeReturnStatement); + var children = astNode.children, + child = children[2]; + + this.nodeRETURN(children[0]); + this.nodeUnderlineNoLineBreak(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeExpression) + { + this.nodeExpression(child); + this.nodeEOS(children[3]); + } + else + this.nodeSemicolonInsertionEOS(child); +} + +ObjJCompiler.prototype.nodeWithStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeWithStatement); + var children = astNode.children; + + this.nodeWITH(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeExpression(children[4]); + this.nodeUnderline(children[5], true); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeStatement(children[8]); +} + +ObjJCompiler.prototype.nodeSwitchStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSwitchStatement); + var children = astNode.children; + + this.nodeSWITCH(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeExpression(children[4]); + this.nodeUnderline(children[5], true); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeCaseBlock(children[8]); +} + +ObjJCompiler.prototype.nodeCaseBlock = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCaseBlock); + var children = astNode.children, + child = children[2]; + + this.nodeOpenBrace(children[0]); + this.nodeUnderline(children[1], false); + var offset = 0; + if (child && child.name === ObjJCompiler.AstNodeCaseClauses) + { + this.nodeCaseClauses(child); + offset++; + } + this.nodeUnderline(children[2 + offset], false); + child = children[3 + offset]; + if (child && child.name === ObjJCompiler.AstNodeDefaultClause) + { + this.nodeDefaultClause(child); + offset++; + } + this.nodeUnderline(children[3 + offset], false); + child = children[4 + offset]; + if (child && child.name === ObjJCompiler.AstNodeCaseClauses) + { + this.nodeCaseClauses(child); + offset++; + } + this.nodeUnderline(children[4 + offset], false); + this.nodeCloseBrace(children[5 + offset]); +} + +ObjJCompiler.prototype.nodeCaseClauses = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCaseClauses); + var children = astNode.children; + + this.nodeCaseClause(children[0]); + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + this.nodeCaseClause(children[i + 1]); + } +} + +ObjJCompiler.prototype.nodeCaseClause = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCaseClause); + var children = astNode.children, + child = children[5]; + + this.nodeCASE(children[0]); + this.nodeUnderline(children[1], true); + this.nodeExpression(children[2]); + this.nodeUnderline(children[3], false); + this.nodeCOLON(children[4]); + if (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + this.nodeStatementList(children[6]); + } +} + +ObjJCompiler.prototype.nodeDefaultClause = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDefaultClause); + var children = astNode.children, + child = children[3]; + + this.nodeDEFAULT(children[0]); + this.nodeUnderline(children[1], true); + this.nodeCOLON(children[2]); + if (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + this.nodeStatementList(children[4]); + } +} + +ObjJCompiler.prototype.nodeLabelledStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLabelledStatement); + var children = astNode.children; + + this.nodeIdentifier(children[0]); + this.nodeUnderline(children[1], true); + this.nodeCOLON(children[2]); + this.nodeUnderline(children[3], false); + this.nodeStatementList(children[4]); +} + +ObjJCompiler.prototype.nodeThrowStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeThrowStatement); + var children = astNode.children, + child = children[2]; + + this.nodeTHROW(children[0]); + this.nodeUnderlineNoLineBreak(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeExpression) + { + this.nodeExpression(child); + this.nodeEOS(children[3]); + } + else + this.nodeSemicolonInsertionEOS(children[2]); +} + +ObjJCompiler.prototype.nodeTryStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTryStatement); + var children = astNode.children, + child = children[4]; + + this.nodeTRY(children[0]); + this.nodeUnderline(children[1], false); + this.nodeBlock(children[2]); + this.nodeUnderline(children[3], false); + if (child && child.name === ObjJCompiler.AstNodeCatch) + { + this.nodeCatch(child); + child = children[5]; + if (child && child.name === ObjJCompiler.AstNodeFinally) + { + this.nodeFinally(child); + } + } + else + this.nodeFinally(child); +} + +ObjJCompiler.prototype.nodeCatch = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCatch); + var children = astNode.children; + + this.nodeCATCH(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + this.nodeIdentifier(children[4]); + this.nodeUnderline(children[5], false); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeBlock(children[8]); +} + +ObjJCompiler.prototype.nodeFinally = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFinally); + var children = astNode.children; + + this.nodeFINALLY(children[0]); + this.nodeUnderline(children[1], false); + this.nodeBlock(children[2]); +} + +ObjJCompiler.prototype.nodeDebuggerStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDebuggerStatement); + var children = astNode.children; + + this.nodeDEBUGGER(children[0]); + this.nodeEOS(children[1]); +} + +ObjJCompiler.prototype.nodeImportStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeImportStatement); + var children = astNode.children, + child = children[2], + isQuoted = null, + urlString = null, + saveJSBuffer = this._jsBuffer; + + this._jsBuffer = null; + this.nodeIMPORT(children[0]); + this.nodeUnderline(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeLocalFilePath) + { + urlString = this.nodeLocalFilePath(child); + isQuoted = true; + } + else + { + urlString = this.nodeStandardFilePath(children[2]); + isQuoted = false; + } + this.nodeEOS(children[3]); + + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, "objj_executeFile(\""); + CONCAT(saveJSBuffer, urlString); + CONCAT(saveJSBuffer, isQuoted ? "\", YES);" : "\", NO);"); + } + + this._dependencies.push(new FileDependency(new CFURL(urlString), isQuoted)); + this._jsBuffer = saveJSBuffer; +} + +ObjJCompiler.prototype.nodeLocalFilePath = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLocalFilePath); + + return this.nodeStringLiteral(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeStandardFilePath = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeStandardFilePath); + var children = astNode.children, + size = children.length, + string = ""; + + this.nodeLESSTHEN(children[0]); + this.nodeUnderline(children[1], false); + for (var i = 2; i < size - 2; i++) + { + string += this.nodeWORD(children[i]); + } + this.nodeUnderline(children[size - 2], false); + this.nodeGREATERTHEN(children[size - 1]); + + return string; +} + +ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeClassDeclarationStatement); + var children = astNode.children, + child = children[4], + offset = 0, + saveJSBuffer = this._jsBuffer, // Save the javascript buffer + saveObjJBuffer = this._objJBuffer, // Save the objJ buffer + classBodyBuffer = new StringBuffer(); // Create a buffer for javascript statements and functions inside the class declaration + + // Make sure nothing is copied to the javascript buffer + this._jsBuffer = null; + // Crate an objJ buffer if we need to create accessors + this._objJBuffer = new StringBuffer(); + + this.nodeIMPLEMENTATION(children[0]); + this.nodeUnderline(children[1], true); + + var className = this.nodeIdentifier(children[2]), + superClassName = null, + classDef = null; + + this.nodeUnderline(children[3], false); + + if (child && child.name === ObjJCompiler.AstNodeSuperclassDeclaration) + { + superClassName = this.nodeSuperclassDeclaration(child); + offset++; + + if (this.getClassDef(className)) + throw new SyntaxError(this.error_message("Duplicate class " + className, children[2])); + if (!this.getClassDef(superClassName)) + throw new SyntaxError(this.error_message("Can't find superclass " + superClassName, child)); + + classDef = {"className": className, "superClassName": superClassName, "ivars": {}, "methods": {}}; + + this._classDefs[className] = classDef; + + if (saveJSBuffer) + CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(" + superClassName + ", \"" + className + "\"),\nmeta_class = the_class.isa;"); + } + else if (child && child.name === ObjJCompiler.AstNodeCategoryDeclaration) + { + this.nodeCategoryDeclaration(child); + offset++; + + classDef = this.getClassDef(className); + if (!classDef) + throw new SyntaxError(this.error_message("Class " + className + " not found ", children[2])); + + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, "{\nvar the_class = objj_getClass(\"" + className + "\")\n"); + CONCAT(saveJSBuffer, "if(!the_class) throw new SyntaxError(\"*** Could not find definition for class \\\"" + className + "\\\"\");\n"); + CONCAT(saveJSBuffer, "var meta_class = the_class.isa;"); + } + } + + this._currentSuperClass = "objj_getClass(\"" + className + "\").super_class"; + this._currentSuperMetaClass = "objj_getMetaClass(\"" + className + "\").super_class"; + + this.nodeUnderline(children[4 + offset], false); + this._imBuffer = new StringBuffer(); + this._cmBuffer = new StringBuffer(); + this._classBodyBuffer = new StringBuffer(); + child = children[5 + offset]; + + if (!child || child.name !== ObjJCompiler.AstNodeUnderline) + { + this.nodeOpenBrace(child); + offset++; + var firstIvarDeclaration = true, + ivars = classDef.ivars, + hasAccessors = false; + + child = children[6 + offset]; + + while (child && child.name === ObjJCompiler.AstNodeCompoundIvarDeclaration) + { + this.nodeUnderline(children[5 + offset++], false); + + var ivarDeclaration = this.nodeCompoundIvarDeclaration(child, ivars), // This will save the declaration in ivars and return the declaration. + type = ivarDeclaration.type; + + for (var name in ivarDeclaration.ivars) + { + if (firstIvarDeclaration) + { + firstIvarDeclaration = false; + if (saveJSBuffer) + CONCAT(saveJSBuffer, "class_addIvars(the_class, ["); + } + else + if (saveJSBuffer) + CONCAT(saveJSBuffer, ", "); + + if (saveJSBuffer) + if (this._flags & ObjJCompiler.Flags.IncludeTypeSignatures) + CONCAT(saveJSBuffer, "new objj_ivar(\"" + name + "\", \"" + type + "\")"); + else + CONCAT(saveJSBuffer, "new objj_ivar(\"" + name + "\")"); + + if (!hasAccessors && ivarDeclaration.ivars[name].accessors) + hasAccessors = true; + } + + child = children[6 + ++offset]; + } + if (!firstIvarDeclaration) + if (saveJSBuffer) + CONCAT(saveJSBuffer, "]);\n"); + + this.nodeUnderline(children[5 + offset++], false); + this.nodeCloseBrace(children[5 + offset++]); + + if (hasAccessors) + { + var getterSetterBuffer = new StringBuffer(); + + // Add the class declaration to compile accessors correctly + CONCAT(getterSetterBuffer, this._objJBuffer); + CONCAT(getterSetterBuffer, "\n"); + + for (var name in ivars) + { + var ivarDecl = ivars[name], + type = ivarDecl.type, + accessors = ivarDecl.accessors; + + if (!accessors) + continue; + + var property = accessors["property"] || name, + getterName = accessors["getter"] || property, + getterCode = "- (" + (type ? type : "id") + ")" + getterName + "\n{\nreturn " + name + ";\n}\n"; + + CONCAT(getterSetterBuffer, getterCode); + + if (accessors["readonly"]) + continue; + + var setterName = accessors["setter"]; + + if (!setterName) + { + var start = property.charAt(0) == '_' ? 1 : 0; + setterName = (start ? "_" : "") + "set" + property.substr(start, 1).toUpperCase() + property.substring(start + 1) + ":"; + } + + var setterCode = "- (void)" + setterName + "(" + (type ? type : "id") + ")newValue\n{\n"; + + if (accessors["copy"]) + setterCode += "if (" + name + " !== newValue)\n" + name + " = [newValue copy];\n}\n"; + else + setterCode += name + " = newValue;\n}\n"; + + CONCAT(getterSetterBuffer, setterCode); + } + + CONCAT(getterSetterBuffer, "\n@end"); + // Remove all @accessors or we will get a recursive loop in infinity + var b = getterSetterBuffer.toString().replace(/@accessors(\(.*\))?/g, ""); + var imBuffer = exports.compileToIMBuffer(b, "getter", this._flags); + + CONCAT(this._imBuffer, imBuffer); + } + } + this.nodeUnderline(children[5 + offset], false); + this._currentClassDef = classDef; + + this._jsBuffer = classBodyBuffer; + this.nodeClassBody(children[6 + offset]); + this._currentClassDef = null; + this._jsBuffer = null; + + this.nodeUnderline(children[7 + offset], false); + this.nodeEND(children[8 + offset]); + this.nodeEOS(children[9 + offset]); + + // We must make a new class object for our class definition. + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, "objj_registerClassPair(the_class);\n"); + + if (IS_NOT_EMPTY(this._imBuffer)) + { + CONCAT(saveJSBuffer, "class_addMethods(the_class, ["); + CONCAT(saveJSBuffer, this._imBuffer); + CONCAT(saveJSBuffer, "]);\n"); + } + + if (IS_NOT_EMPTY(this._cmBuffer)) + { + CONCAT(saveJSBuffer, "class_addMethods(meta_class, ["); + CONCAT(saveJSBuffer, this._cmBuffer); + CONCAT(saveJSBuffer, "]);\n"); + } + + CONCAT(saveJSBuffer, "}"); + + // FIXME: Maybe we should add this before we add the class implementation? + // We might have variable/function declarations etc that is needed before class declaration? + // Maybe not? Needs some investigation.... + CONCAT(saveJSBuffer, this._classBodyBuffer); + } + // Restore javascript buffer + this._jsBuffer = saveJSBuffer; + // Restore objJ buffer + if (saveObjJBuffer) + CONCAT(saveObjJBuffer, this._objJBuffer); + this._objJBuffer = saveObjJBuffer; +} + +ObjJCompiler.prototype.nodeSuperclassDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSuperclassDeclaration); + var children = astNode.children; + + this.nodeCOLON(children[0]); + this.nodeUnderline(children[1], false); + return this.nodeIdentifier(children[2]); +} + +ObjJCompiler.prototype.nodeCategoryDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCategoryDeclaration); + var children = astNode.children; + + this.nodeOpenParenthesis(children[0]); + this.nodeUnderline(children[1], false); + this.nodeIdentifier(children[2]); + this.nodeUnderline(children[3], false); + this.nodeCloseParenthesis(children[4]); +} + +ObjJCompiler.prototype.nodeCompoundIvarDeclaration = function(/*SyntaxNode*/ astNode, classDefIvars) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCompoundIvarDeclaration); + var children = astNode.children, + type = this.nodeIvarType(children[0]); + + this.nodeUnderline(children[1], true); + var ivar = this.nodeIvarDeclaration(children[2]), + ivars = {}; + + ivars[ivar.identifier] = ivar; + classDefIvars[ivar.identifier] = {"type": type, "name": ivar.identifier, "accessors": ivar.accessors}; + for (var i = 3; i + 3 < children.length; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "," + this.nodeUnderline(children[i + 2], false); + ivar = this.nodeIvarDeclaration(children[i + 3]); + if (classDefIvars[ivar.identifier]) // FIXME: Must look at classes not in this file + throw new SyntaxError(this.error_message("Duplicate member " + ivar.identifier, children[i + 3])); + ivars[ivar.identifier] = ivar; + classDefIvars[ivar.identifier] = {"type": type, "name": ivar.identifier, "accessors": ivar.accessors}; + } + this.nodeEOS(children[i]); + return {"type": type, "ivars": ivars}; +} + +// This grammar is not correct. You should not be able to have multiple IvarTypeElement. +// Maybe should be one type element and one extra @outlet? Or something...... +// IvarType = +// IvarTypeElement (_ IvarTypeElement)* + +ObjJCompiler.prototype.nodeIvarType = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarType); + var children = astNode.children, + type = ""; + + var newType = this.nodeIvarTypeElement(children[0]); + // Maybe we should return the outlet information and save it along the ivars for the class.... + if (newType !== "@outlet") + type = newType; + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + newType = this.nodeIvarTypeElement(children[i + 1]); + // Maybe we should return the outlet information and save it along the ivars for the class.... + if (newType !== "@outlet") + type += " " + newType; + } + + return type; +} + +ObjJCompiler.prototype.nodeIvarTypeElement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarTypeElement); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeIdentifierName) + return this.nodeIdentifierName(child); + else + return this.nodeOUTLET(child); +} + +ObjJCompiler.prototype.nodeIvarDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarDeclaration); + var children = astNode.children, + child = children[2], + ivar = {}; + + ivar.identifier = this.nodeIdentifier(children[0]); + this.nodeUnderline(children[1], false); + + if (child && child.name === ObjJCompiler.AstNodeAccessors) + ivar.accessors = this.nodeAccessors(child); + return ivar; +} + +ObjJCompiler.prototype.nodeAccessors = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAccessors); + var children = astNode.children, + size = children.length, + accessors = {}; + + this.nodeACCESSORS(children[0]); + if (size > 1) + { + this.nodeOpenParenthesis(children[1]); + var offset = 0, + child = children[2]; + if (child && child.name === ObjJCompiler.AstNodeAccessorsConfiguration) + { + accessors = this.nodeAccessorsConfiguration(child); + child = children[2 + ++offset] + while (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(children[2 + offset++], false); + this.nodeWORD(children[2 + offset++]); // "," + this.nodeUnderline(children[2 + offset++], false); + var moreAccessors = this.nodeAccessorsConfiguration(children[2 + offset++]); + for (var attrname in moreAccessors) // Clang takes the last if many exists so just Merge in moreAccessors + accessors[attrname] = moreAccessors[attrname]; + child = children[2 + offset]; + } + } + this.nodeCloseParenthesis(child); + } + return accessors; +} + +ObjJCompiler.prototype.nodeAccessorsConfiguration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAccessorsConfiguration); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeIvarPropertyName: + return {"property": this.nodeIvarPropertyName(child)}; + case ObjJCompiler.AstNodeIvarGetterName: + return {"getter": this.nodeIvarGetterName(child)}; + case ObjJCompiler.AstNodeIvarSetterName: + return {"setter": this.nodeIvarSetterName(child)}; + default: + this.nodeREADONLY(child); + return {"readonly": true}; + } +} + +ObjJCompiler.prototype.nodeIvarPropertyName = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarPropertyName); + var children = astNode.children; + + this.nodePROPERTY(children[0]); + this.nodeUnderline(children[1], false); + this.nodeEQUALS(children[2]); + this.nodeUnderline(children[3], false); + return this.nodeIdentifier(children[4]); +} + +ObjJCompiler.prototype.nodeIvarGetterName = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarGetterName); + var children = astNode.children; + + this.nodeGETTER(children[0]); + this.nodeUnderline(children[1], false); + this.nodeEQUALS(children[2]); + this.nodeUnderline(children[3], false); + return this.nodeIdentifier(children[4]); +} + +ObjJCompiler.prototype.nodeIvarSetterName = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIvarSetterName); + var children = astNode.children; + + this.nodeSETTER(children[0]); + this.nodeUnderline(children[1], false); + this.nodeEQUALS(children[2]); + this.nodeUnderline(children[3], false); + var setterName = this.nodeIdentifier(children[4]); + + // I think the grammar is wrong here! You should always include the colon. + // IvarSetterName = + // "setter" _ "=" _ Identifier (_ ":")? + + if (children.length > 6) + { + this.nodeUnderline(children[5], false); + setterName += this.nodeCOLON(children[6]); + } + else + { + setterName += ":"; + } + + return setterName; +} + +ObjJCompiler.prototype.nodeClassBody = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeClassBody); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeClassElements) + this.nodeClassElements(child); +} + +ObjJCompiler.prototype.nodeClassElements = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeClassElements); + var children = astNode.children; + + this.nodeClassElement(children[0]); + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + this.nodeClassElement(children[i + 1]); + } +} + +ObjJCompiler.prototype.nodeClassElement = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeClassElement); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeClassMethodDeclaration: + this.nodeClassMethodDeclaration(child); + break; + case ObjJCompiler.AstNodeInstanceMethodDeclaration: + this.nodeInstanceMethodDeclaration(child); + break; + case ObjJCompiler.AstNodeStatement: + this._jsBuffer = this._classBodyBuffer; + this.nodeStatement(child); + this._jsBuffer = null; + break; + case ObjJCompiler.AstNodeFunctionDeclaration: + this._jsBuffer = this._classBodyBuffer; + this.nodeFunctionDeclaration(child); + this._jsBuffer = null; + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeClassElement + " but got " + child, child)); + break; + } +} + +ObjJCompiler.prototype.nodeClassMethodDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeClassMethodDeclaration); + this.nodePLUS(astNode.children[0]); + this._classMethod = true; + this.genericMethodDeclaration(astNode, this._cmBuffer); +} + +ObjJCompiler.prototype.nodeInstanceMethodDeclaration = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeInstanceMethodDeclaration); + this.nodeMINUS(astNode.children[0]); + this._classMethod = false; + this.genericMethodDeclaration(astNode, this._imBuffer); +} + +ObjJCompiler.prototype.genericMethodDeclaration = function(/*SyntaxNode*/ astNode, /*StringBuffer*/ buffer) +{ + var children = astNode.children, + child = children[2], + offset = 0, + returnTypes = [null], + classDef = this._currentClassDef, + currentClassMethods = classDef ? classDef.methods : null; + + if (child && child.name === ObjJCompiler.AstNodeMethodType) + { + this.nodeUnderline(children[1 + offset++], false); + returnTypes = this.nodeMethodType(children[1 + offset++]); + } + this.nodeUnderline(children[1 + offset], false); + var methodSelector = this.nodeMethodSelector(children[2 + offset]), + selector = methodSelector.selector, + types = [returnTypes[0]]; // First type is return type? We might handle only one type? The grammar MethodType can be many types + + if (IS_NOT_EMPTY(buffer)) // Add comma separator if this is not first method in this buffer + CONCAT(buffer, ", "); + CONCAT(buffer, "new objj_method(sel_getUid(\""); + CONCAT(buffer, selector); + CONCAT(buffer, "\"), function"); + +// this._currentSelector = selector; + + if (this._flags & ObjJCompiler.Flags.IncludeDebugSymbols) + { + CONCAT(buffer, " $" + this._currentClassDef.className + "__" + selector.replace(/:/g, "_")); + } + + CONCAT(buffer, "(self, _cmd"); + + for (var identifier in methodSelector.parameters) + { + var parameter = methodSelector.parameters[identifier]; + + CONCAT(buffer, ", "); + CONCAT(buffer, parameter.identifier); + types.push(parameter.type); + } + + if (currentClassMethods) + { + var currentMethodSelector = currentClassMethods[methodSelector.selector]; + if (currentMethodSelector) + { + // Method already declared. May be a warning? + } + currentClassMethods[methodSelector.selector] = methodSelector; + this._currentMethod = methodSelector; + } + + CONCAT(buffer, ")\n{\n"); + + this.nodeUnderline(children[3 + offset], false); + + child = children[4 + offset]; + if (child && child.name !== ObjJCompiler.AstNodeUnderline) + { + this.nodeSEMICOLON(children[4 + offset++]); + } + this.nodeUnderline(children[4 + offset], false); + this.nodeOpenBrace(children[5 + offset]); + this._jsBuffer = buffer; // Now write the FunctionBody to buffer + this.nodeUnderline(children[6 + offset], false); + this.nodeFunctionBody(children[7 + offset]); + this._jsBuffer = null; // Turn back off again so nothing is written + this.nodeUnderline(children[8 + offset], false); + this.nodeCloseBrace(children[9 + offset]); + CONCAT(buffer, "}\n"); + if (this._flags & ObjJCompiler.Flags.IncludeDebugSymbols) //flags.IncludeTypeSignatures) + CONCAT(buffer, ","+JSON.stringify(types)); + CONCAT(buffer, ")"); + + this._currentMethod = null; +} + +ObjJCompiler.prototype.nodeMethodSelector = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMethodSelector); + var children = astNode.children, + child = children[0], + size = children.length; + + if (child && child.name === ObjJCompiler.AstNodeKeywordSelector) + { + var keywordSelector = this.nodeKeywordSelector(child); + if (size > 1) + { + this.nodeUnderline(children[1], false); + this.nodeCOMMA(children[2]); + this.nodeUnderline(children[3], false); + // FIXME: Handle argument list. If we need to? + this.nodeWORD(children[4]); // ... + } + return keywordSelector; + } + else + return {"selector": this.nodeUnarySelector(child)}; +} + +ObjJCompiler.prototype.nodeUnarySelector = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnarySelector); + return this.nodeSelector(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeKeywordSelector = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelector); + var children = astNode.children, + keywordDecl = this.nodeKeywordDeclarator(children[0]), + typeAndIndentifier = {"type": keywordDecl.methodType, "identifier": keywordDecl.identifier}, + keywordSelector = {"selector": keywordDecl.selector, "parameters":{}}; + + keywordSelector.parameters[keywordDecl.identifier] = typeAndIndentifier; + + for (var i = 1; i + 1 < children.length; i += 2) + { + this.nodeUnderline(children[i], false); + var nextKeywordDecl = this.nodeKeywordDeclarator(children[i + 1]); + + keywordSelector.selector += nextKeywordDecl.selector; + keywordSelector.parameters[nextKeywordDecl.identifier] = {"type": nextKeywordDecl.methodType, "identifier": nextKeywordDecl.identifier}; + } + return keywordSelector; +} + +ObjJCompiler.prototype.nodeKeywordDeclarator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeKeywordDeclarator); + var children = astNode.children, + child = children[0], + offset = 0, + selector = "", + methodType = null; + + if (child && child.name === ObjJCompiler.AstNodeSelector) + { + selector = this.nodeSelector(children[0 + offset++]); + this.nodeUnderline(children[0 + offset++], false); + } + + this.nodeCOLON(children[0 + offset]); + selector += ":"; + child = children[2 + offset]; + + if (child && child.name === ObjJCompiler.AstNodeMethodType) + { + this.nodeUnderline(children[1 + offset++], false); + // TODO: Parser allows multiple MethodType. Need to find out what to do if we get more then one + methodType = this.nodeMethodType(children[1 + offset++])[0]; + } + + this.nodeUnderline(children[1 + offset], false); + var identifier = this.nodeIdentifier(children[2 + offset]); + + return {"selector": selector, "methodType": methodType, "identifier": identifier}; +} + +ObjJCompiler.prototype.nodeSelector = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSelector); + return this.nodeIdentifierName(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMethodType); + var children = astNode.children, + child = children[2], + size = children.length, + methodTypes = []; + + this.nodeOpenParenthesis(children[0]); + this.nodeUnderline(children[1], false); + + if (child && child.name === ObjJCompiler.AstNodeACTION) + methodTypes.push(this.nodeACTION(child)); + else + methodTypes.push(this.nodeIdentifierName(child)); + + for (var i = 3; i + 1 < size - 2; i += 2) + { + this.nodeUnderline(children[i], true); + child = children[i + 1]; + if (child && child.name === ObjJCompiler.AstNodeACTION) + methodTypes.push(this.nodeACTION(child)); + else + methodTypes.push(this.nodeIdentifierName(child)); + } + + this.nodeUnderline(children[size - 2], false); + this.nodeCloseParenthesis(children[size - 1]); + return methodTypes; +} + +ObjJCompiler.prototype.nodeACTION = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeACTION); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeExpression); + var children = astNode.children, + size = children.length; + + this.nodeAssignmentExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "," + this.nodeUnderline(children[i + 2], false); + this.nodeAssignmentExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeAssignmentExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "," + this.nodeUnderline(children[i + 2], false); + this.nodeAssignmentExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeAssignmentExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpression); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeLeftHandSideExpression) + { + this.nodeLeftHandSideExpression(child); + this.nodeUnderline(children[1], false); + this.nodeAssignmentOperator(children[2]); + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpression(children[4]); + } + else + this.nodeConditionalExpression(child); +} + +ObjJCompiler.prototype.nodeAssignmentExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpressionNoIn); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeLeftHandSideExpression) + { + this.nodeLeftHandSideExpression(child); + this.nodeUnderline(children[1], false); + this.nodeAssignmentOperator(children[2]); + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpressionNoIn(children[4]); + } + else + this.nodeConditionalExpressionNoIn(child); +} + +ObjJCompiler.prototype.nodeAssignmentOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentOperator); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeConditionalExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpression); + var children = astNode.children, + child = children[1]; + + this.nodeLogicalOrExpression(children[0]); + if (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + this.nodeWORD(children[2]); // "?" + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpression(children[4]); + this.nodeUnderline(children[5], false); + this.nodeWORD(children[6]); // ":" + this.nodeUnderline(children[7], false); + this.nodeAssignmentExpression(children[8]); + } +} + +ObjJCompiler.prototype.nodeConditionalExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpressionNoIn); + var children = astNode.children, + child = children[1]; + + this.nodeLogicalOrExpressionNoIn(children[0]); + if (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + this.nodeWORD(children[2]); // "?" + this.nodeUnderline(children[3], false); + this.nodeAssignmentExpressionNoIn(children[4]); + this.nodeUnderline(children[5], false); + this.nodeWORD(children[6]); // ":" + this.nodeUnderline(children[7], false); + this.nodeAssignmentExpressionNoIn(children[8]); + } +} + +ObjJCompiler.prototype.nodeLogicalOrExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpression); + var children = astNode.children, + size = children.length; + + this.nodeLogicalAndExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "||" + this.nodeUnderline(children[i + 2], false); + this.nodeLogicalAndExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeLogicalOrExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeLogicalAndExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "||" + this.nodeUnderline(children[i + 2], false); + this.nodeLogicalAndExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeLogicalAndExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpression); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseOrExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "&&" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseOrExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeLogicalAndExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseOrExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "&&" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseOrExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseOrExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpression); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseXOrExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "|" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseXOrExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseOrExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseXOrExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "|" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseXOrExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseXOrExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpression); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseAndExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "^" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseAndExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseXOrExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeBitwiseAndExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "^" + this.nodeUnderline(children[i + 2], false); + this.nodeBitwiseAndExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseAndExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpression); + var children = astNode.children, + size = children.length; + + this.nodeEqualityExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "&" + this.nodeUnderline(children[i + 2], false); + this.nodeEqualityExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeBitwiseAndExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeEqualityExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeWORD(children[i + 1]); // "&" + this.nodeUnderline(children[i + 2], false); + this.nodeEqualityExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeEqualityExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpression); + var children = astNode.children, + size = children.length; + + this.nodeRelationalExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeEqualityOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeRelationalExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeEqualityExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeRelationalExpressionNoIn(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeEqualityOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeRelationalExpressionNoIn(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeEqualityOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEqualityOperator); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeRelationalExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpression); + var children = astNode.children, + size = children.length; + + this.nodeShiftExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeRelationalOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeShiftExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeRelationalOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperator); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeIN: + this.nodeIN(child); + break; + case ObjJCompiler.AstNodeINSTANCEOF: + this.nodeINSTANCEOF(child); + break; + default: + this.nodeWORD(child); + } +} + +ObjJCompiler.prototype.nodeRelationalExpressionNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpressionNoIn); + var children = astNode.children, + size = children.length; + + this.nodeShiftExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeRelationalOperatorNoIn(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeShiftExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeRelationalOperatorNoIn = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperatorNoIn); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeINSTANCEOF: + this.nodeINSTANCEOF(child); + break; + default: + this.nodeWORD(child); + } +} + +ObjJCompiler.prototype.nodeShiftExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeShiftExpression); + var children = astNode.children, + size = children.length; + + this.nodeAdditiveExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeShiftOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeAdditiveExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeShiftOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeShiftOperator); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeAdditiveExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveExpression); + var children = astNode.children, + size = children.length; + + this.nodeMultiplicativeExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeAdditiveOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeMultiplicativeExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeAdditiveOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveOperator); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeMultiplicativeExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeExpression); + var children = astNode.children, + size = children.length; + + this.nodeUnaryExpression(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeMultiplicativeOperator(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeUnaryExpression(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodeMultiplicativeOperator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeOperator); + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeUnaryExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnaryExpression); + var children = astNode.children, + child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodePostfixExpression: + this.nodePostfixExpression(child); + break; + case ObjJCompiler.AstNodeDELETE: + this.nodeDELETE(child); + this.nodeUnderline(children[1], true); + this.nodeUnaryExpression(children[2]); + break; + case ObjJCompiler.AstNodeVOID: + this.nodeVOID(child); + this.nodeUnderline(children[1], true); + this.nodeUnaryExpression(children[2]); + break; + case ObjJCompiler.AstNodeTYPEOF: + this.nodeTYPEOF(child); + this.nodeUnderline(children[1], true); + this.nodeUnaryExpression(children[2]); + break; + default: + this.nodeWORD(child); + this.nodeUnderline(children[1], false); + this.nodeUnaryExpression(children[2]); + } +} + +ObjJCompiler.prototype.nodePostfixExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePostfixExpression); + var children = astNode.children; + + this.nodeLeftHandSideExpression(children[0]); + + if (children.length > 1) + { + this.nodeUnderlineNoLineBreak(children[1], false); + this.nodeWORD(children[2]); // "++" or "--" + } +} + +ObjJCompiler.prototype.nodeLeftHandSideExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLeftHandSideExpression); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeCallExpression) + this.nodeCallExpression(child) + else + this.nodeNewExpression(child); +} + +ObjJCompiler.prototype.nodeNewExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNewExpression); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeMemberExpression) + this.nodeMemberExpression(child) + else + { + this.nodeNEW(child); + this.nodeUnderline(children[1], true); + this.nodeNewExpression(children[2]); + } +} + +ObjJCompiler.prototype.nodeCallExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCallExpression); + var children = astNode.children, + size = children.length; + + this.nodeMemberExpression(children[0]); + this.nodeUnderline(children[1], false); + this.nodeArguments(children[2]); + + for (var i = 3; i + 1 < size; i += 2) + { + this.nodeUnderline(children[i], false); + var child = children[i + 1], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeArguments: + this.nodeArguments(child); + break; + case ObjJCompiler.AstNodeBracketedAccessor: + this.nodeBracketedAccessor(child); + break; + case ObjJCompiler.AstNodeDotAccessor: + this.nodeDotAccessor(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeArguments + ", " + ObjJCompiler.AstNodeBracketedAccessor + " or " + ObjJCompiler.AstNodeDotAccessor + " but got " + child, child)); + } + } +} + +ObjJCompiler.prototype.nodeMemberExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMemberExpression); + var children = astNode.children, + size = children.length, + child = children[0], + name = child ? child.name : null, + offset = 1; + + switch(name) + { + case ObjJCompiler.AstNodePrimaryExpression: + this.nodePrimaryExpression(child); + break; + case ObjJCompiler.AstNodeFunctionExpression: + this.nodeFunctionExpression(child); + break; + case ObjJCompiler.AstNodeMessageExpression: + this.nodeMessageExpression(child); + break; + default: + this.nodeNEW(child); + this.nodeUnderline(children[offset++], true); + this.nodeMemberExpression(children[offset++]); + this.nodeUnderline(children[offset++], false); + this.nodeArguments(children[offset++]); + } + + for (var i = offset; i + 1 < size; i += 2) + { + this.nodeUnderline(children[i], false); + var child = children[i + 1], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeBracketedAccessor: + this.nodeBracketedAccessor(child); + break; + case ObjJCompiler.AstNodeDotAccessor: + this.nodeDotAccessor(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeBracketedAccessor + " or " + ObjJCompiler.AstNodeDotAccessor + " but got " + child, child)); + } + } +} + +ObjJCompiler.prototype.nodeBracketedAccessor = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBracketedAccessor); + var children = astNode.children; + + this.nodeOpenBracket(children[0]); + this.nodeUnderline(children[1], false); + this.nodeExpression(children[2]); + this.nodeUnderline(children[3], false); + this.nodeCloseBracket(children[4]); +} + +ObjJCompiler.prototype.nodeDotAccessor = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDotAccessor); + var children = astNode.children; + + this.nodeDOT(children[0]); + this.nodeUnderline(children[1], false); + this.nodeIdentifierName(children[2]); +} + +ObjJCompiler.prototype.nodeArguments = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeArguments); + var children = astNode.children, + child = children[2], + offset = 0; + + this.nodeOpenParenthesis(children[0]); + this.nodeUnderline(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeArgumentList) + { + this.nodeArgumentList(child); + offset++; + } + this.nodeUnderline(children[2 + offset], false); + this.nodeCloseParenthesis(children[3 + offset]); +} + +ObjJCompiler.prototype.nodeArgumentList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeArgumentList); + var children = astNode.children, + size = children.length; + + this.nodeAssignmentExpression(children[0]); + this.nodeUnderline(children[1], false); + + for (var i = 2; i + 2 < size; i += 3) + { + this.nodeCOMMA(children[i]); + this.nodeUnderline(children[i + 1], false); + this.nodeAssignmentExpression(children[i + 2]); + } +} + +ObjJCompiler.prototype.nodePrimaryExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePrimaryExpression); + var children = astNode.children, + child = children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeTHIS: + this.nodeTHIS(child); + break; + case ObjJCompiler.AstNodeIdentifier: + var saveJSBuffer = this._jsBuffer; + + this._jsBuffer = null; + var identifier = this.nodeIdentifier(child); + this._jsBuffer = saveJSBuffer; + + if (saveJSBuffer) + { + var lvar = this.getLvarForCurrentMethod(identifier), + ivar = this.getIvarForCurrentClass(identifier); + + if (ivar) + if (lvar) + 0 == 0; // Warning: Local declaration of 'identifier' hides instance variable + else + CONCAT(saveJSBuffer, "self."); + + CONCAT(saveJSBuffer, identifier); + } + break; + case ObjJCompiler.AstNodeLiteral: + this.nodeLiteral(child); + break; + case ObjJCompiler.AstNodeArrayLiteral: + this.nodeArrayLiteral(child); + break; + case ObjJCompiler.AstNodeObjectLiteral: + this.nodeObjectLiteral(child); + break; + default: + this.nodeOpenParenthesis(child); + this.nodeUnderline(children[1], false); + this.nodeExpression(children[2]); + this.nodeUnderline(children[3], false); + this.nodeCloseParenthesis(children[4]); + } +} + +ObjJCompiler.prototype.nodeMessageExpression = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMessageExpression); + var children = astNode.children, + child = children[2], + saveJSBuffer = this._jsBuffer; + + this._jsBuffer = null; + this.nodeOpenBracket(children[0]); + this.nodeUnderline(children[1], false); + if (child && child.name === ObjJCompiler.AstNodeExpression) + { + var buffer = new StringBuffer(); + + this._jsBuffer = buffer; + this.nodeExpression(child); + this._jsBuffer = null; + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, "objj_msgSend("); + CONCAT(saveJSBuffer, buffer); + } + } + else + { + this.nodeSUPER(child); + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, "objj_msgSendSuper("); + CONCAT(saveJSBuffer, "{ receiver:self, super_class:" + (this._classMethod ? this._currentSuperMetaClass : this._currentSuperClass ) + " }"); + } + } + + this.nodeUnderline(children[3], false); + var selector = this.nodeSelectorCall(children[4]); + + if (saveJSBuffer) + { + CONCAT(saveJSBuffer, ", \""); + CONCAT(saveJSBuffer, selector.selector); // FIXME: sel_getUid(selector.selector + "") ? + CONCAT(saveJSBuffer, "\""); + + if (selector.expressions) + for (var i = 0; i < selector.expressions.length; i++) + CONCAT(saveJSBuffer, ", " + selector.expressions[i]); + + CONCAT(saveJSBuffer, ")"); + } + + this.nodeUnderline(children[5], false); + this.nodeCloseBracket(children[6]); + + this._jsBuffer = saveJSBuffer; +} + +ObjJCompiler.prototype.nodeSelectorCall = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSelectorCall); + var children = astNode.children, + size = children.length, + child = children[0], + selector = {}; + + if (child && child.name === ObjJCompiler.AstNodeUnarySelector) + selector.selector = this.nodeUnarySelector(child); + else + { + selector = this.nodeKeywordSelectorCall(child); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeCOMMA(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + var buffer = new StringBuffer(); + this._jsBuffer = buffer; + this.nodeExpression(children[i + 3]); + selector.parameters.push(buffer.toString()); + this._jsBuffer = null; + } + } + return selector; +} + +ObjJCompiler.prototype.nodeKeywordSelectorCall = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelectorCall); + var children = astNode.children, + size = children.length; + + var keywordCall = this.nodeKeywordCall(children[0]), + selector = keywordCall.selector, + expressions = [keywordCall.expression]; + + for (var i = 1; i + 1 < size; i += 2) + { + this.nodeUnderline(children[i], false); + keywordCall = this.nodeKeywordCall(children[i + 1]); + selector += keywordCall.selector; + expressions.push(keywordCall.expression); + } + return {"selector": selector, "expressions": expressions}; +} + +ObjJCompiler.prototype.nodeKeywordCall = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeKeywordCall); + var children = astNode.children, + child = children[0], + offset = 0, + selector = "", + buffer = new StringBuffer(); + + if (child && child.name === ObjJCompiler.AstNodeSelector) + selector += this.nodeSelector(children[offset++]); + + this.nodeUnderline(children[offset++], false); + this.nodeCOLON(children[offset++]); + selector += ":"; + this.nodeUnderline(children[offset++], false); + this._jsBuffer = buffer; + this.nodeExpression(children[offset]); + this._jsBuffer = null; + + return {"selector": selector, "expression": buffer.toString()}; +} + +ObjJCompiler.prototype.nodeArrayLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeArrayLiteral); + var children = astNode.children; + + this.nodeOpenBracket(children[0]); + this.nodeUnderline(children[1], false); + this.nodeElementList(children[2]); + this.nodeUnderline(children[3], false); + this.nodeCloseBracket(children[4]); +} + +ObjJCompiler.prototype.nodeElementList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeElementList); + var children = astNode.children, + offset = 0; + + while (children[offset] === ",") + { + this.nodeCOMMA(children[offset++]); + this.nodeUnderline(children[offset++], false); + } + + var child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + child = children[++offset]; + if (child && child.name === ObjJCompiler.AstNodeAssignmentExpression) + this.nodeAssignmentExpression(child); + else if (child === ",") + this.nodeCOMMA(child); + + child = children[++offset]; + } +} + +ObjJCompiler.prototype.nodeObjectLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeObjectLiteral); + var children = astNode.children, + child = children[2], + offset = 2; + + this.nodeOpenBrace(children[0]); + this.nodeUnderline(children[1], false); + if (child && child.name === ObjJCompiler.AstNodePropertyNameAndValueList) + { + this.nodePropertyNameAndValueList(children[offset++]); + this.nodeUnderline(children[offset++], false); + if (children[offset] === ",") + this.nodeCOMMA(children[offset++]); + } + this.nodeUnderline(children[offset++], false); + this.nodeCloseBrace(children[offset]); +} + +ObjJCompiler.prototype.nodePropertyNameAndValueList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertyNameAndValueList); + var children = astNode.children, + size = children.length; + + this.nodePropertyAssignment(children[0]); + + for (var i = 1; i + 3 < size; i += 4) + { + this.nodeUnderline(children[i], false); + this.nodeCOMMA(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodePropertyAssignment(children[i + 3]); + } +} + +ObjJCompiler.prototype.nodePropertyAssignment = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertyAssignment); + var children = astNode.children, + child = children[4], + name = child ? child.name : null; + + this.nodePropertyName(children[0]); + this.nodeUnderline(children[1], false); + this.nodeCOLON(children[2]); + this.nodeUnderline(children[3], false); + + switch(name) + { + case ObjJCompiler.AstNodeAssignmentExpression: + this.nodeAssignmentExpression(child); + break; + case ObjJCompiler.AstNodePropertyGetter: + this.nodePropertyGetter(child); + break; + case ObjJCompiler.AstNodePropertySetter: + this.nodePropertySetter(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeAssignmentExpression + ", " + ObjJCompiler.AstNodePropertyGetter + " or " + ObjJCompiler.AstNodePropertySetter + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodePropertyGetter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); + var children = astNode.children, + child = children[4]; + + this.nodeGET(children[0]); + this.nodeUnderline(children[1], true); + this.nodePropertyName(children[2]); + this.nodeUnderline(children[3], false); + this.nodeOpenParenthesis(children[4]); + this.nodeUnderline(children[5], false); + this.nodeCloseParenthesis(children[6]); + this.nodeUnderline(children[7], false); + this.nodeOpenBrace(children[8]); + this.nodeUnderline(children[9], false); + this.nodeFunctionBody(children[10]); + this.nodeUnderline(children[11], false); + this.nodeCloseBrace(children[12]); +} + +function PropertySetter(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); + var children = astNode.children, + child = children[4]; + + this.nodeGET(children[0]); + this.nodeUnderline(children[1], true); + this.nodePropertyName(children[2]); + this.nodeUnderline(children[3], false); + this.nodeOpenParenthesis(children[4]); + this.nodeUnderline(children[5], false); + this.nodePropertySetParameterList(children[6]); + this.nodeUnderline(children[7], false); + this.nodeCloseParenthesis(children[8]); + this.nodeUnderline(children[9], false); + this.nodeOpenBrace(children[10]); + this.nodeUnderline(children[11], false); + this.nodeFunctionBody(children[12]); + this.nodeUnderline(children[13], false); + this.nodeCloseBrace(children[14]); +} + +ObjJCompiler.prototype.nodePropertyName = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertyName); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeIdentifierName: + this.nodeIdentifierName(child); + break; + case ObjJCompiler.AstNodeStringLiteral: + this.nodeStringLiteral(child); + break; + case ObjJCompiler.AstNodeNumericLiteral: + this.nodeNumericLiteral(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeIdentifierName + ", " + ObjJCompiler.AstNodeStringLiteral + " or " + ObjJCompiler.AstNodeNumericLiteral + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodePropertySetParameterList = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodePropertySetParameterList); + + this.nodeIdentifier(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLiteral); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeNullLiteral: + this.nodeNullLiteral(child); + break; + case ObjJCompiler.AstNodeBooleanLiteral: + this.nodeBooleanLiteral(child); + break; + case ObjJCompiler.AstNodeNumericLiteral: + this.nodeNumericLiteral(child); + break; + case ObjJCompiler.AstNodeStringLiteral: + this.nodeStringLiteral(child); + break; + case ObjJCompiler.AstNodeRegularExpressionLiteral: + this.nodeRegularExpressionLiteral(child); + break; + case ObjJCompiler.AstNodeSelectorLiteral: + this.nodeSelectorLiteral(child); + break; + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeLiteral + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeSelectorLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteral); + var children = astNode.children, + saveJSBuffer = this._jsBuffer, + selectorBuffer = new StringBuffer(); + + this._jsBuffer = null; + this.nodeSELECTOR(children[0]); + this.nodeUnderline(children[1], false); + this.nodeOpenParenthesis(children[2]); + this.nodeUnderline(children[3], false); + if (saveJSBuffer) + CONCAT(selectorBuffer, "sel_getUid(\""); + this._jsBuffer = selectorBuffer; + this.nodeSelectorLiteralContents(children[4]); + CONCAT(selectorBuffer, "\")"); + this._jsBuffer = null; + this.nodeUnderline(children[5], false); + this.nodeCloseParenthesis(children[6]); + this._jsBuffer = saveJSBuffer; + if (saveJSBuffer) + CONCAT(saveJSBuffer, selectorBuffer); +} + +ObjJCompiler.prototype.nodeSelectorLiteralContents = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteralContents); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeIdentifier) + this.nodeIdentifier(child); + else + { + var size = children.length, + offset = 0; + + while (offset < size) + { + child = children[offset]; + if (child && child.name === ObjJCompiler.AstNodeSelector) + this.nodeSelector(children[offset++]); + this.nodeUnderline(children[offset++], false); + this.nodeCOLON(children[offset++]); + this.nodeUnderline(children[offset++], false); + } + } +} + +ObjJCompiler.prototype.nodeNullLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNullLiteral); + + this.nodeNULL(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeBooleanLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBooleanLiteral); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeTRUE) + this.nodeTRUE(child); + else + this.nodeFALSE(child); +} + +ObjJCompiler.prototype.nodeNumericLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNumericLiteral); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeHexIntegerLiteral) + this.nodeHexIntegerLiteral(child); + else + this.nodeDecimalLiteral(child); +} + +ObjJCompiler.prototype.nodeDecimalLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDecimalLiteral); + var children = astNode.children, + offset = 0, + number = "", + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeDecimalIntegerLiteral) + { + number += this.nodeDecimalIntegerLiteral(child); + child = children[++offset]; + } + + if (child === ".") + { + number += this.nodeWORD(child); // "." + child = children[++offset]; + } + + while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) + { + number += this.nodeDecimalDigit(child); + child = children[++offset] + } + + if (child && child.name === ObjJCompiler.AstNodeExponentPart) + number += this.nodeExponentPart(child); +} + +ObjJCompiler.prototype.nodeDecimalIntegerLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDecimalIntegerLiteral); + var children = astNode.children, + offset = 1, + number = ""; + + if (children[0] === "0") + number = this.nodeWORD(children[0]); + else + { + number = this.nodeWORD(children[0]); + } + + var child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) + { + number += this.nodeDecimalDigit(child); + child = children[++offset] + } + + return number; +} + +ObjJCompiler.prototype.nodeDecimalDigit = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDecimalDigit); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeExponentPart = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeExponentPart); + var children = astNode.children; + + return this.nodeWORD(children[0]) + this.nodeSignedInteger(children[1]); +} + +ObjJCompiler.prototype.nodeSignedInteger = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSignedInteger); + var children = astNode.children, + offset = 1, + number = "", + child = children[0]; + + if (child === "+" || child === "-") + { + number = this.nodeWORD(child); + child = children[offset++]; + } + + while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) + { + number += this.nodeDecimalDigit(child); + child = children[offset++]; + } + + return number; +} + +ObjJCompiler.prototype.nodeHexIntegerLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeHexIntegerLiteral); + var children = astNode.children, + offset = 2, + hex = this.nodeWORD(children[0]); + + hex += this.nodeWORD(children[1]); + + var child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeHexDigit) + { + hex += this.nodeHexDigit(child); + child = children[++offset]; + } + + return hex; +} + +ObjJCompiler.prototype.nodeHexDigit = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeHexDigit); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeStringLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeStringLiteral); + var children = astNode.children, + offset = 0, + string = ""; + + if (children[0] === "@") + { + var saveJSBuffer = this._jsBuffer; + + this._jsBuffer = null; + this.nodeWORD(children[offset++]); + this._jsBuffer = saveJSBuffer; + this.nodeUnderline(children[offset++], false); + } + + var quoteCharacter = children[offset++], + stringCharacterFunction = null; + + this.nodeWORD(quoteCharacter); + + if (quoteCharacter === '"') + stringCharacterFunction = this.nodeDoubleStringCharacter; + else + stringCharacterFunction = this.nodeSingleStringCharacter; + + while (children[offset] !== quoteCharacter) + { + string += stringCharacterFunction.call(this, children[offset++]); + } + + this.nodeWORD(children[offset]); + + return string; +} + +ObjJCompiler.prototype.nodeDoubleStringCharacter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDoubleStringCharacter); + var children = astNode.children, + child = children[0]; + + if (child === "\\") + return this.nodeWORD(child) + this.nodeEscapeSequence(children[1]); + else if (child && child.name === ObjJCompiler.AstNodeLineContinuation) + return this.nodeLineContinuation(child); + else + return this.nodeWORD(child); +} + +ObjJCompiler.prototype.nodeSingleStringCharacter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSingleStringCharacter); + var children = astNode.children, + child = children[0]; + + if (child === "\\") + return this.nodeWORD(child) + this.nodeEscapeSequence(children[1]); + else if (child && child.name === ObjJCompiler.AstNodeLineContinuation) + return this.nodeLineContinuation(child); + else + return this.nodeWORD(child); +} + +ObjJCompiler.prototype.nodeLineContinuation = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLineContinuation); + var children = astNode.children; + + return this.nodeWORD(children[0]) + nodeLineTerminatorSequence(children[1]); +} + +ObjJCompiler.prototype.nodeEscapeSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEscapeSequence); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeCharacterEscapeSequence: + return this.nodeCharacterEscapeSequence(child); + case ObjJCompiler.AstNodeHexEscapeSequence: + return this.nodeHexEscapeSequence(child); + case ObjJCompiler.AstNodeUnicodeEscapeSequence: + return this.nodeUnicodeEscapeSequence(child); + default: + return this.nodeWORD(child); + } +} + +ObjJCompiler.prototype.nodeCharacterEscapeSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCharacterEscapeSequence); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeSingleEscapeCharacter) + return this.nodeSingleEscapeCharacter(child); + else + return this.nodeNonEscapeCharacter(child); +} + +ObjJCompiler.prototype.nodeSingleEscapeCharacter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSingleEscapeCharacter); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeNonEscapeCharacter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNonEscapeCharacter); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeHexEscapeSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeHexEscapeSequence); + var children = astNode.children; + + return children[0] + this.nodeHexDigit(children[1]) + nodeHexDigit(children[2]); +} + +ObjJCompiler.prototype.nodeUnicodeEscapeSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeEscapeSequence); + var children = astNode.children; + + return this.nodeWORD(children[0]) + this.nodeHexDigit(children[1]) + this.nodeHexDigit(children[2]) + this.nodeHexDigit(children[3]) + this.nodeHexDigit(children[4]); +} + +ObjJCompiler.prototype.nodeRegularExpressionLiteral = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionLiteral); + var children = astNode.children; + + return this.nodeWORD(children[0]) + this.nodeRegularExpressionBody(children[1]) + this.nodeWORD(children[2]) + this.nodeRegularExpressionFlags(children[3]); +} + +ObjJCompiler.prototype.nodeRegularExpressionBody = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBody); + var children = astNode.children, + regString = this.nodeRegularExpressionFirstChar(children[0]), + offset = 1, + child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeRegularExpressionChar) + { + regString += this.nodeRegularExpressionChar(child); + child = children[++offset]; + } + return regString; +} + +ObjJCompiler.prototype.nodeRegularExpressionFirstChar = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFirstChar); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeRegularExpressionNonTerminator: + return this.nodeRegularExpressionNonTerminator(child); + case ObjJCompiler.AstNodeRegularExpressionBackslashSequence: + return this.nodeRegularExpressionBackslashSequence(child); + case ObjJCompiler.AstNodeRegularExpressionClass: + return this.nodeRegularExpressionClass(child); + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeRegularExpressionNonTerminator + ", " + ObjJCompiler.AstNodeRegularExpressionBackslashSequence + " or " + ObjJCompiler.AstNodeRegularExpressionClass + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeRegularExpressionChar = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionChar); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeRegularExpressionNonTerminator: + return this.nodeRegularExpressionNonTerminator(child); + case ObjJCompiler.AstNodeRegularExpressionBackslashSequence: + return this.nodeRegularExpressionBackslashSequence(child); + case ObjJCompiler.AstNodeRegularExpressionClass: + return this.nodeRegularExpressionClass(child); + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeRegularExpressionNonTerminator + ", " + ObjJCompiler.AstNodeRegularExpressionBackslashSequence + " or " + ObjJCompiler.AstNodeRegularExpressionClass + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeRegularExpressionBackslashSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBackslashSequence); + var children = astNode.children; + + return this.nodeWORD(children[0]) + this.nodeRegularExpressionNonTerminator(children[1]); +} + +ObjJCompiler.prototype.nodeRegularExpressionNonTerminator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionNonTerminator); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeRegularExpressionClass = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClass); + var children = astNode.children, + offset = 1, + regString = this.nodeWORD(children[0]), + child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeRegularExpressionClassChar) + { + regString += this.nodeRegularExpressionClassChar(children[offset++]); + child = children[++offset]; + } + + return regString + this.nodeWORD(child); +} + +ObjJCompiler.prototype.nodeRegularExpressionClassChar = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClassChar); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeRegularExpressionNonTerminator) + return this.nodeRegularExpressionNonTerminator(child); + else + return this.nodeRegularExpressionBackslashSequence(child); +} + +ObjJCompiler.prototype.nodeRegularExpressionFlags = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFlags); + var children = astNode.children, + offset = 0, + regString = "", + child = children[offset]; + + while (child && child.name === ObjJCompiler.AstNodeIdentifierPart) + { + regString += this.nodeIdentifierPart(child); + child = children[++offset]; + } + + return regString; +} + +ObjJCompiler.prototype.nodeUnderline = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnderline); + var children = astNode.children, + size = children.length; + string = ""; + + for (var i = 0; i < size; i++) + { + var child = children[i], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeWhiteSpace: + string += this.nodeWhiteSpace(child); + break; + case ObjJCompiler.AstNodeLineTerminator: + string += this.nodeLineTerminator(child); + break; + case ObjJCompiler.AstNodeComment: + string += this.nodeComment(child); + break + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeWhiteSpace + ", " + ObjJCompiler.AstNodeLineTerminator + " or " + ObjJCompiler.AstNodeComment + " but got " + child.name, child)); + } + } + // FIXME: Do something smart with this..... +} + +ObjJCompiler.prototype.nodeUnderlineNoLineBreak = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnderlineNoLineBreak); + var children = astNode.children, + size = children.length; + string = ""; + + for (var i = 0; i < size; i++) + { + var child = children[i], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeWhiteSpace: + string += this.nodeWhiteSpace(child); + break + case ObjJCompiler.AstNodeSingleLineMultiLineComment: + string += this.nodeSingleLineMultiLineComment(child); + break + case AstSingleLineComment: + string += this.nodeSingleLineComment(child); + break + default: + throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeWhiteSpace + ", " + ObjJCompiler.AstNodeSingleLineMultiLineComment + " or " + ObjJCompiler.AstSingleLineComment + " but got " + child.name, child)); + } + } + // FIXME: Do something smart with this..... +} + +ObjJCompiler.prototype.nodeWhiteSpace = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeWhiteSpace); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeLineTerminator = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminator); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeLineTerminatorSequence = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminatorSequence); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeComment = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeComment); + var child = astNode.children[0]; + + if (child && child.name === ObjJCompiler.AstNodeMultiLineComment) + return this.nodeMultiLineComment(child); + else + return this.nodeSingleLineComment(child); +} + +ObjJCompiler.prototype.nodeMultiLineComment = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeMultiLineComment); + var children = astNode.children, + size = children.length; + string = ""; + + for (var i = 0; i < size; i++) + { + string += this.nodeWORD(children[i]); + } + + return string; +} + +ObjJCompiler.prototype.nodeSingleLineMultiLineComment = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineMultiLineComment); + var children = astNode.children, + size = children.length, + string = ""; + + for (var i = 0; i < size; i++) + { + string += this.nodeWORD(children[i]); + } + + return string; +} + +ObjJCompiler.prototype.nodeSingleLineComment = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineComment); + var children = astNode.children, + size = children.length, + string = children[0]; + + this.nodeWORD(string); + for (var i = 1; i < size; i++) + { + string += this.nodeSingleLineCommentChar(children[i]) + } + + return string; +} + +ObjJCompiler.prototype.nodeSingleLineCommentChar = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineCommentChar); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeEOS = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEOS); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeUnderline) + { + this.nodeUnderline(child, false); + this.nodeSEMICOLON(children[1]); + } + else + { + this.nodeUnderlineNoLineBreak(child, false); + child = children[1]; + + if (child && child.name === ObjJCompiler.AstNodeLineTerminatorSequence) + this.nodeLineTerminatorSequence(child); + else if (child && child.name === ObjJCompiler.AstNodeEOF) + this.nodeEOF(child); + } +} + +ObjJCompiler.prototype.nodeSemicolonInsertionEOS = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSemicolonInsertionEOS); + var children = astNode.children, + child = children[1]; + + this.nodeUnderlineNoLineBreak(children[0], false) + if (child && child.name === ObjJCompiler.AstNodeLineTerminatorSequence) + this.nodeLineTerminatorSequence(child); + else if (child && child.name === ObjJCompiler.AstNodeEOF) + this.nodeEOF(child); + else if (children.length > 1) + this.nodeSEMICOLON(child); +} + +ObjJCompiler.prototype.nodeEOF = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeEOF); +} + +ObjJCompiler.prototype.nodeIdentifier = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIdentifier); + + return this.nodeIdentifierName(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeIdentifierName = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierName); + var children = astNode.children, + size = children.length, + string = this.nodeIdentifierStart(children[0]); + + for (var i = 1; i < size; i++) + { + string += this.nodeIdentifierPart(children[i]); + } + + return string; +} + +ObjJCompiler.prototype.nodeIdentifierStart = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierStart); + var children = astNode.children, + child = children[0]; + + if (child && child.name === ObjJCompiler.AstNodeUnicodeLetter) + return this.nodeUnicodeLetter(child); + else if (child === "\\") + return this.nodeWORD(child) + nodeUnicodeEscapeSequence(children[1]); + else + return this.nodeWORD(child); +} + +ObjJCompiler.prototype.nodeIdentifierPart = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierPart); + var child = astNode.children[0], + name = child ? child.name : null; + + switch(name) + { + case ObjJCompiler.AstNodeIdentifierStart: + return this.nodeIdentifierStart(child); + case ObjJCompiler.AstNodeUnicodeCombiningMark: + return this.nodeUnicodeCombiningMark(child); + case ObjJCompiler.AstNodeUnicodeDigit: + return this.nodeUnicodeDigit(child); + case ObjJCompiler.AstNodeUnicodeConnectorPunctuation: + return this.nodeUnicodeConnectorPunctuation(child); + case ObjJCompiler.AstNodeZWNJ: + return this.nodeZWNJ(child); + case ObjJCompiler.AstNodeZWJ: + return this.nodeZWJ(child); + default: + throw new SyntaxError(this.error_message("Expected children of " + ObjJCompiler.AstNodeIdentifierPart + " but got " + child, child)); + } +} + +ObjJCompiler.prototype.nodeZWNJ = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeZWNJ); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeZWJ = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeZWJ); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeUnicodeLetter = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeLetter); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeUnicodeCombiningMark = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeCombiningMark); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeUnicodeDigit = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeDigit); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeUnicodeConnectorPunctuation = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeConnectorPunctuation); + + return this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeFALSE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFALSE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeTRUE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTRUE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeNULL = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNULL); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeBREAK = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeBREAK); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeCONTINUE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCONTINUE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeDEBUGGER = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDEBUGGER); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeIN = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIN); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeINSTANCEOF = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeINSTANCEOF); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeDELETE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDELETE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeFUNCTION = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFUNCTION); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeNEW = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeNEW); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeTHIS = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTHIS); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeTYPEOF = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTYPEOF); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeVOID = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVOID); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeIF = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeIF); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeELSE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeELSE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeDO = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDO); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeWHILE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeWHILE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeFOR = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFOR); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeVAR = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeVAR); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeRETURN = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeRETURN); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeCASE = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCASE); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeDEFAULT = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeDEFAULT); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeSWITCH = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSWITCH); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeTHROW = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTHROW); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeCATCH = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeCATCH); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeFINALLY = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeFINALLY); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeTRY = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeTRY); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeWITH = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeWITH); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeSUPER = function(/*SyntaxNode*/ astNode) +{ + this.assertNode(astNode, ObjJCompiler.AstNodeSUPER); + + this.nodeWORD(astNode.children[0]); +} + +ObjJCompiler.prototype.nodeCOMMA = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeCOLON = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeSEMICOLON = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeOpenParenthesis = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeCloseParenthesis = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeOpenBrace = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeCloseBrace = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeOpenBracket = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeCloseBracket = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeDOT = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeIMPLEMENTATION = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeEND = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeIMPORT = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeOUTLET = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeSELECTOR = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeACCESSORS = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodePROPERTY = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeGETTER = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeSETTER = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeREADONLY = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeLESSTHEN = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeGREATERTHEN = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeEQUALS = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodePLUS = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeMINUS = function(/*SyntaxNode*/ astNode) +{ + return this.nodeWORD(astNode); +} + +ObjJCompiler.prototype.nodeWORD = function(/*SyntaxNode*/ astNode) +{ +// if (typeof astNode !== "string") +// debugger; + if (this._jsBuffer) + CONCAT(this._jsBuffer, astNode); + if (this._objJBuffer) + CONCAT(this._objJBuffer, astNode); + return astNode; +} + +ObjJCompiler.prototype.getClassDef = function(/* String */ aClassName) +{ + var c = this._classDefs[aClassName]; + + if (c) return c; + + if (objj_getClass) + { + var aClass = objj_getClass(aClassName); + if (aClass) + { + var ivars = class_copyIvarList(aClass), + ivarSize = ivars.length, + myIvars = {}, + superClass = aClass.super_class; + + for (var i = 0; i < ivarSize; i++) + { + var ivar = ivars[i]; + + myIvars[ivar.name] = {"type": ivar.type, "name": ivar.name}; + } + c = {"className": aClassName, "ivars": myIvars}; + + if (superClass) + c.superClassName = superClass.name; + this._classDefs[aClassName] = c; + return c; + } + } + + return null; +// classDef = {"className": className, "superClassName": superClassName, "ivars": {}, "methods": {}}; +} + +ObjJCompiler.prototype.getIvarForCurrentClass = function(/* String */ ivarName) +{ + var c = this._currentClassDef; + + while (c) + { + var ivars = c.ivars; + if (ivars) + { + var ivarDef = ivars[ivarName]; + if (ivarDef) + return ivarDef; + } + c = this.getClassDef(c.superClassName); + } + + return null; +} + +ObjJCompiler.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) +{ + var currentMethod = this._currentMethod; + + if (currentMethod) + { + var ivars = currentMethod.lvars; + if (ivars && ivars[lvarName]) + { + return ivars[lvarName]; + } + // TODO: check the parameters in the method declaration + } + + return null; +} + +ObjJCompiler.prototype.createLocalVariable = function(/*Variable*/ variable) +{ + var currentClassMethods = this._currentMethod; + + if (currentClassMethods) + { + var lvars = currentClassMethods.lvars; + + if (!lvars) + { + lvars = {}; + currentClassMethods.lvars = lvars; + } + + if (lvars[variable.identifier]) + { + // Local variable already declared! Maybe a warning? + } + + lvars[variable.identifier] = variable; + } +} + +ObjJCompiler.prototype.executable = function() +{ + if (!this._executable) + this._executable = new Executable(this._jsBuffer ? this._jsBuffer.toString() : null, this._dependencies, this._URL, null, this); + return this._executable; +} + +ObjJCompiler.prototype.IMBuffer = function() +{ + return this._imBuffer; +} + +ObjJCompiler.prototype.JSBuffer = function() +{ + return this._jsBuffer; +} + +ObjJCompiler.prototype.error_message = function(errorMessage, astNode) +{ + return errorMessage + " "; +} +//})(window, ObjJCompiler, { exports: ObjJCompiler }); diff --git a/Objective-J/Parser.js b/Objective-J/Parser.js new file mode 100644 index 000000000..39f3aba60 --- /dev/null +++ b/Objective-J/Parser.js @@ -0,0 +1,382 @@ + +var Parser = { }; + +var compiledGrammar = {"table":[[0,"source",1],[0,"start",2],[4,3,4,3],[0,"_",5],[8,6],[6,7],[0,"SourceElements",8],[3,9,10,11],[4,12,13],[0,"WhiteSpace",14],[0,"LineTerminator",15],[0,"Comment",16],[0,"SourceElement",17],[6,18],[2,"[\\u0009\\u000B\\u000C\\u0020\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"],[2,"[\\u000A\\u000D\\u2028\\u2029]"],[3,19,20],[3,21,22],[4,3,12],[0,"MultiLineComment",23],[0,"SingleLineComment",24],[0,"Statement",25],[0,"FunctionDeclaration",26],[4,27,28,29],[4,30,31],[3,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,22,47,48,49],[4,50,3,51,3,52,3,53,3,54,3,55,3,56,3,57],[5,"/*"],[6,58],[5,"*/"],[5,"//"],[6,59],[0,"Block",60],[0,"VariableStatement",61],[0,"EmptyStatement",62],[0,"ExpressionStatement",63],[0,"IfStatement",64],[0,"IterationStatement",65],[0,"ContinueStatement",66],[0,"BreakStatement",67],[0,"ReturnStatement",68],[0,"WithStatement",69],[0,"LabelledStatement",70],[0,"SwitchStatement",71],[0,"ThrowStatement",72],[0,"TryStatement",73],[0,"DebuggerStatement",74],[0,"FunctionExpression",75],[0,"ImportStatement",76],[0,"ClassDeclarationStatement",77],[0,"FUNCTION",78],[0,"Identifier",79],[5,"("],[8,80],[5,")"],[5,"{"],[0,"FunctionBody",2],[5,"}"],[4,81,82],[0,"SingleLineCommentChar",83],[4,55,3,84,3,57],[4,85,3,86,87,88],[5,";"],[4,89,90,88],[4,91,3,52,3,90,3,54,3,21,92],[3,93,94,95,96,97],[4,98,99,100],[4,101,99,100],[4,102,99,103],[4,104,3,52,3,90,3,54,3,21],[4,51,3,105,3,21],[4,106,3,52,3,90,3,54,3,107],[4,108,99,103],[4,109,3,32,3,110],[4,111,88],[4,50,3,112,3,52,3,53,3,54,3,55,3,56,3,57],[4,113,3,114,88],[4,115,3,51,3,116,3,117,3,118,3,119,88],[4,120,121],[4,122,123],[0,"FormalParameterList",124],[9,29],[1],[4,125,82],[8,126],[0,"VAR",127],[0,"VariableDeclaration",128],[6,129],[0,"EOS",130],[9,131],[0,"Expression",132],[0,"IF",133],[8,134],[0,"DoWhileStatement",135],[0,"WhileStatement",136],[0,"ForStatement",137],[0,"ForInStatement",138],[0,"EachStatement",139],[0,"CONTINUE",140],[0,"__",141],[3,142,143],[0,"BREAK",144],[0,"RETURN",145],[3,143,146],[0,"WITH",147],[5,":"],[0,"SWITCH",148],[0,"CaseBlock",149],[0,"THROW",150],[0,"TRY",151],[3,152,153],[0,"DEBUGGER",154],[8,51],[5,"@import"],[3,155,156],[5,"@implementation"],[8,157],[8,158],[0,"ClassBody",159],[5,"@end"],[5,"function"],[9,160],[9,161],[0,"IdentifierName",162],[4,51,163],[9,10],[0,"StatementList",164],[4,165,121],[4,51,166],[4,3,167,3,86],[3,168,169,170,171],[3,55,50],[4,172,173],[4,174,121],[4,3,175,3,21],[4,176,3,21,3,177,3,52,3,90,3,54,88],[4,177,3,52,3,90,3,54,3,21],[4,178,3,52,3,179,3,62,3,180,3,62,3,180,3,54,3,21],[4,178,3,52,3,181,3,182,3,90,3,54,3,21],[4,183,3,52,3,181,3,182,3,90,3,54,3,21],[4,184,121],[6,185],[4,51,88],[0,"SemicolonInsertionEOS",186],[4,187,121],[4,188,121],[4,90,88],[4,189,121],[4,190,121],[4,55,3,191,3,192,3,191,3,57],[4,193,121],[4,194,121],[4,195,196],[0,"Finally",197],[4,198,121],[0,"LocalFilePath",199],[0,"StandardFilePath",200],[3,201,202],[4,55,203,3,57],[8,204],[0,"IdentifierPart",205],[4,206,121],[4,207,208],[6,209],[4,21,210],[5,"var"],[8,211],[5,","],[4,3,62],[4,99,212],[4,99,213],[4,99,214],[0,"AssignmentExpression",215],[6,216],[5,"if"],[0,"ELSE",217],[0,"DO",218],[0,"WHILE",219],[0,"FOR",220],[8,221],[8,90],[0,"ForInFirstExpression",222],[0,"IN",223],[5,"@each"],[5,"continue"],[3,9,224,20],[3,225,169,170,171],[5,"break"],[5,"return"],[5,"with"],[5,"switch"],[8,226],[8,227],[5,"throw"],[5,"try"],[0,"Catch",228],[8,229],[4,230,3,32],[5,"debugger"],[0,"StringLiteral",231],[4,232,3,233,3,234],[0,"SuperclassDeclaration",235],[0,"CategoryDeclaration",236],[6,237],[0,"ClassElements",238],[3,207,239,240,241,242,243],[0,"ReservedWord",244],[0,"IdentifierStart",245],[6,160],[4,3,167,3,51],[6,246],[4,3,247,248,3,172],[0,"LineTerminatorSequence",249],[10,57],[0,"EOF",250],[3,251,252],[4,3,167,3,172],[4,253,121],[4,254,121],[4,255,121],[4,256,121],[0,"ForFirstExpression",257],[3,258,259],[4,260,121],[0,"SingleLineMultiLineComment",261],[4,99,62],[0,"CaseClauses",262],[0,"DefaultClause",263],[4,264,3,52,3,51,3,54,3,32],[4,3,153],[0,"FINALLY",265],[3,266,267],[5,"<"],[6,268],[5,">"],[4,105,3,51],[4,52,3,51,3,54],[4,3,269],[4,270,271],[0,"UnicodeCombiningMark",272],[0,"UnicodeDigit",273],[0,"UnicodeConnectorPunctuation",274],[0,"ZWNJ",275],[0,"ZWJ",276],[3,277,278,279,280],[3,281,282,283],[4,3,21],[5,"="],[9,247],[3,284,285,286,287,288],[9,82],[4,258,3,289,3,172],[0,"ConditionalExpression",290],[5,"else"],[5,"do"],[5,"while"],[5,"for"],[3,291,292],[0,"LeftHandSideExpression",293],[4,85,3,294],[5,"in"],[4,27,295,29],[4,296,297],[4,298,3,105,299],[0,"CATCH",300],[4,301,121],[4,302,303,304,303],[4,305,306,305],[3,307,308],[0,"CompoundIvarDeclaration",309],[0,"ClassElement",310],[6,311],[3,312,313,314,315,316,317],[3,318,319,320,321],[2,"[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]"],[5,"\u200C"],[5,"\u200D"],[0,"Keyword",322],[0,"FutureReservedWord",323],[0,"NullLiteral",324],[0,"BooleanLiteral",325],[0,"UnicodeLetter",326],[2,"[$_]"],[4,327,328],[5,"\n"],[4,288,329],[5,"\u2028"],[5,"\u2029"],[5,"\r"],[0,"AssignmentOperator",330],[4,331,332],[0,"ExpressionNoIn",333],[4,85,3,334],[3,335,336],[0,"VariableDeclarationNoIn",337],[6,338],[0,"CaseClause",339],[6,340],[0,"DEFAULT",341],[8,342],[4,343,121],[5,"finally"],[8,344],[5,"\""],[6,345],[5,"'"],[6,346],[5,"\\>"],[4,347,82],[4,348,3,349,350,88],[3,351,352,21,22],[4,3,270],[2,"[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0900-\\u0902\\u093A\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0957\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135D-\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1BE6\\u1BE8\\u1BE9\\u1BED\\u1BEF-\\u1BF1\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFC-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26\\u0903\\u093B\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u094F\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1BE7\\u1BEA-\\u1BEC\\u1BEE\\u1BF2\\u1BF3\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"],[4,353,354],[4,355,356],[4,357,358],[4,359,360],[4,361,362],[2,"[\\u0030-\\u0039\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]"],[4,363,364],[4,357,365],[4,366,367],[3,187,368,343,184,198,369,370,254,253,301,256,120,174,371,260,372,188,190,373,193,194,374,165,375,255,189],[3,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405],[0,"NULL",406],[3,407,408],[3,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426],[5,"\\"],[0,"UnicodeEscapeSequence",427],[8,284],[3,428,429,430,431,432,433,434,435,436,437,438,439],[0,"LogicalOrExpression",440],[8,441],[4,442,443],[0,"VariableDeclarationListNoIn",444],[0,"CallExpression",445],[0,"NewExpression",446],[4,51,447],[4,81,125,82],[4,448,3,90,3,105,299],[4,3,296],[4,369,121],[4,3,126],[5,"catch"],[4,449,3],[0,"DoubleStringCharacter",450],[0,"SingleStringCharacter",451],[9,234],[0,"IvarType",452],[0,"IvarDeclaration",453],[6,454],[0,"ClassMethodDeclaration",455],[0,"InstanceMethodDeclaration",456],[5,"\uDB40"],[2,"[\\uDD00-\\uDDEF]"],[5,"\uD834"],[2,"[\\uDD67-\\uDD69\\uDD7B-\\uDD82\\uDD85-\\uDD8B\\uDDAA-\\uDDAD\\uDE42-\\uDE44\\uDD65\\uDD66\\uDD6D-\\uDD72]"],[5,"\uD804"],[2,"[\\uDC01\\uDC38-\\uDC46\\uDC80\\uDC81\\uDCB3-\\uDCB6\\uDCB9\\uDCBA\\uDC00\\uDC02\\uDC82\\uDCB0-\\uDCB2\\uDCB7\\uDCB8]"],[5,"\uD800"],[2,"[\\uDDFD]"],[5,"\uD802"],[2,"[\\uDE01-\\uDE03\\uDE05\\uDE06\\uDE0C-\\uDE0F\\uDE38-\\uDE3A\\uDE3F]"],[5,"\uD835"],[2,"[\\uDFCE-\\uDFFF]"],[2,"[\\uDC66-\\uDC6F]"],[5,"\uD801"],[2,"[\\uDCA0-\\uDCA9]"],[5,"case"],[5,"default"],[5,"delete"],[5,"instanceof"],[5,"new"],[5,"this"],[5,"typeof"],[5,"void"],[5,"abstract"],[5,"boolean"],[5,"byte"],[5,"char"],[5,"class"],[5,"const"],[5,"double"],[5,"enum"],[5,"export"],[5,"extends"],[5,"final"],[5,"float"],[5,"goto"],[5,"implements"],[5,"import"],[5,"interface"],[5,"int"],[5,"long"],[5,"native"],[5,"package"],[5,"private"],[5,"protected"],[5,"public"],[5,"short"],[5,"static"],[5,"super"],[5,"synchronized"],[5,"throws"],[5,"transient"],[5,"volatile"],[4,457,121],[0,"TRUE",458],[0,"FALSE",459],[2,"[\\u0041-\\u005A\\u00C0-\\u00D6\\u00D8-\\u00DE\\u0100\\u0102\\u0104\\u0106\\u0108\\u010A\\u010C\\u010E\\u0110\\u0112\\u0114\\u0116\\u0118\\u011A\\u011C\\u011E\\u0120\\u0122\\u0124\\u0126\\u0128\\u012A\\u012C\\u012E\\u0130\\u0132\\u0134\\u0136\\u0139\\u013B\\u013D\\u013F\\u0141\\u0143\\u0145\\u0147\\u014A\\u014C\\u014E\\u0150\\u0152\\u0154\\u0156\\u0158\\u015A\\u015C\\u015E\\u0160\\u0162\\u0164\\u0166\\u0168\\u016A\\u016C\\u016E\\u0170\\u0172\\u0174\\u0176\\u0178\\u0179\\u017B\\u017D\\u0181\\u0182\\u0184\\u0186\\u0187\\u0189-\\u018B\\u018E-\\u0191\\u0193\\u0194\\u0196-\\u0198\\u019C\\u019D\\u019F\\u01A0\\u01A2\\u01A4\\u01A6\\u01A7\\u01A9\\u01AC\\u01AE\\u01AF\\u01B1-\\u01B3\\u01B5\\u01B7\\u01B8\\u01BC\\u01C4\\u01C7\\u01CA\\u01CD\\u01CF\\u01D1\\u01D3\\u01D5\\u01D7\\u01D9\\u01DB\\u01DE\\u01E0\\u01E2\\u01E4\\u01E6\\u01E8\\u01EA\\u01EC\\u01EE\\u01F1\\u01F4\\u01F6-\\u01F8\\u01FA\\u01FC\\u01FE\\u0200\\u0202\\u0204\\u0206\\u0208\\u020A\\u020C\\u020E\\u0210\\u0212\\u0214\\u0216\\u0218\\u021A\\u021C\\u021E\\u0220\\u0222\\u0224\\u0226\\u0228\\u022A\\u022C\\u022E\\u0230\\u0232\\u023A\\u023B\\u023D\\u023E\\u0241\\u0243-\\u0246\\u0248\\u024A\\u024C\\u024E\\u0370\\u0372\\u0376\\u0386\\u0388-\\u038A\\u038C\\u038E\\u038F\\u0391-\\u03A1\\u03A3-\\u03AB\\u03CF\\u03D2-\\u03D4\\u03D8\\u03DA\\u03DC\\u03DE\\u03E0\\u03E2\\u03E4\\u03E6\\u03E8\\u03EA\\u03EC\\u03EE\\u03F4\\u03F7\\u03F9\\u03FA\\u03FD-\\u042F\\u0460\\u0462\\u0464\\u0466\\u0468\\u046A\\u046C\\u046E\\u0470\\u0472\\u0474\\u0476\\u0478\\u047A\\u047C\\u047E\\u0480\\u048A\\u048C\\u048E\\u0490\\u0492\\u0494\\u0496\\u0498\\u049A\\u049C\\u049E\\u04A0\\u04A2\\u04A4\\u04A6\\u04A8\\u04AA\\u04AC\\u04AE\\u04B0\\u04B2\\u04B4\\u04B6\\u04B8\\u04BA\\u04BC\\u04BE\\u04C0\\u04C1\\u04C3\\u04C5\\u04C7\\u04C9\\u04CB\\u04CD\\u04D0\\u04D2\\u04D4\\u04D6\\u04D8\\u04DA\\u04DC\\u04DE\\u04E0\\u04E2\\u04E4\\u04E6\\u04E8\\u04EA\\u04EC\\u04EE\\u04F0\\u04F2\\u04F4\\u04F6\\u04F8\\u04FA\\u04FC\\u04FE\\u0500\\u0502\\u0504\\u0506\\u0508\\u050A\\u050C\\u050E\\u0510\\u0512\\u0514\\u0516\\u0518\\u051A\\u051C\\u051E\\u0520\\u0522\\u0524\\u0526\\u0531-\\u0556\\u10A0-\\u10C5\\u1E00\\u1E02\\u1E04\\u1E06\\u1E08\\u1E0A\\u1E0C\\u1E0E\\u1E10\\u1E12\\u1E14\\u1E16\\u1E18\\u1E1A\\u1E1C\\u1E1E\\u1E20\\u1E22\\u1E24\\u1E26\\u1E28\\u1E2A\\u1E2C\\u1E2E\\u1E30\\u1E32\\u1E34\\u1E36\\u1E38\\u1E3A\\u1E3C\\u1E3E\\u1E40\\u1E42\\u1E44\\u1E46\\u1E48\\u1E4A\\u1E4C\\u1E4E\\u1E50\\u1E52\\u1E54\\u1E56\\u1E58\\u1E5A\\u1E5C\\u1E5E\\u1E60\\u1E62\\u1E64\\u1E66\\u1E68\\u1E6A\\u1E6C\\u1E6E\\u1E70\\u1E72\\u1E74\\u1E76\\u1E78\\u1E7A\\u1E7C\\u1E7E\\u1E80\\u1E82\\u1E84\\u1E86\\u1E88\\u1E8A\\u1E8C\\u1E8E\\u1E90\\u1E92\\u1E94\\u1E9E\\u1EA0\\u1EA2\\u1EA4\\u1EA6\\u1EA8\\u1EAA\\u1EAC\\u1EAE\\u1EB0\\u1EB2\\u1EB4\\u1EB6\\u1EB8\\u1EBA\\u1EBC\\u1EBE\\u1EC0\\u1EC2\\u1EC4\\u1EC6\\u1EC8\\u1ECA\\u1ECC\\u1ECE\\u1ED0\\u1ED2\\u1ED4\\u1ED6\\u1ED8\\u1EDA\\u1EDC\\u1EDE\\u1EE0\\u1EE2\\u1EE4\\u1EE6\\u1EE8\\u1EEA\\u1EEC\\u1EEE\\u1EF0\\u1EF2\\u1EF4\\u1EF6\\u1EF8\\u1EFA\\u1EFC\\u1EFE\\u1F08-\\u1F0F\\u1F18-\\u1F1D\\u1F28-\\u1F2F\\u1F38-\\u1F3F\\u1F48-\\u1F4D\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F68-\\u1F6F\\u1FB8-\\u1FBB\\u1FC8-\\u1FCB\\u1FD8-\\u1FDB\\u1FE8-\\u1FEC\\u1FF8-\\u1FFB\\u2102\\u2107\\u210B-\\u210D\\u2110-\\u2112\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u2130-\\u2133\\u213E\\u213F\\u2145\\u2183\\u2C00-\\u2C2E\\u2C60\\u2C62-\\u2C64\\u2C67\\u2C69\\u2C6B\\u2C6D-\\u2C70\\u2C72\\u2C75\\u2C7E-\\u2C80\\u2C82\\u2C84\\u2C86\\u2C88\\u2C8A\\u2C8C\\u2C8E\\u2C90\\u2C92\\u2C94\\u2C96\\u2C98\\u2C9A\\u2C9C\\u2C9E\\u2CA0\\u2CA2\\u2CA4\\u2CA6\\u2CA8\\u2CAA\\u2CAC\\u2CAE\\u2CB0\\u2CB2\\u2CB4\\u2CB6\\u2CB8\\u2CBA\\u2CBC\\u2CBE\\u2CC0\\u2CC2\\u2CC4\\u2CC6\\u2CC8\\u2CCA\\u2CCC\\u2CCE\\u2CD0\\u2CD2\\u2CD4\\u2CD6\\u2CD8\\u2CDA\\u2CDC\\u2CDE\\u2CE0\\u2CE2\\u2CEB\\u2CED\\uA640\\uA642\\uA644\\uA646\\uA648\\uA64A\\uA64C\\uA64E\\uA650\\uA652\\uA654\\uA656\\uA658\\uA65A\\uA65C\\uA65E\\uA660\\uA662\\uA664\\uA666\\uA668\\uA66A\\uA66C\\uA680\\uA682\\uA684\\uA686\\uA688\\uA68A\\uA68C\\uA68E\\uA690\\uA692\\uA694\\uA696\\uA722\\uA724\\uA726\\uA728\\uA72A\\uA72C\\uA72E\\uA732\\uA734\\uA736\\uA738\\uA73A\\uA73C\\uA73E\\uA740\\uA742\\uA744\\uA746\\uA748\\uA74A\\uA74C\\uA74E\\uA750\\uA752\\uA754\\uA756\\uA758\\uA75A\\uA75C\\uA75E\\uA760\\uA762\\uA764\\uA766\\uA768\\uA76A\\uA76C\\uA76E\\uA779\\uA77B\\uA77D\\uA77E\\uA780\\uA782\\uA784\\uA786\\uA78B\\uA78D\\uA790\\uA7A0\\uA7A2\\uA7A4\\uA7A6\\uA7A8\\uFF21-\\uFF3A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00DF-\\u00F6\\u00F8-\\u00FF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F-\\u0293\\u0295-\\u02AF\\u0371\\u0373\\u0377\\u037B-\\u037D\\u0390\\u03AC-\\u03CE\\u03D0\\u03D1\\u03D5-\\u03D7\\u03D9\\u03DB\\u03DD\\u03DF\\u03E1\\u03E3\\u03E5\\u03E7\\u03E9\\u03EB\\u03ED\\u03EF-\\u03F3\\u03F5\\u03F8\\u03FB\\u03FC\\u0430-\\u045F\\u0461\\u0463\\u0465\\u0467\\u0469\\u046B\\u046D\\u046F\\u0471\\u0473\\u0475\\u0477\\u0479\\u047B\\u047D\\u047F\\u0481\\u048B\\u048D\\u048F\\u0491\\u0493\\u0495\\u0497\\u0499\\u049B\\u049D\\u049F\\u04A1\\u04A3\\u04A5\\u04A7\\u04A9\\u04AB\\u04AD\\u04AF\\u04B1\\u04B3\\u04B5\\u04B7\\u04B9\\u04BB\\u04BD\\u04BF\\u04C2\\u04C4\\u04C6\\u04C8\\u04CA\\u04CC\\u04CE\\u04CF\\u04D1\\u04D3\\u04D5\\u04D7\\u04D9\\u04DB\\u04DD\\u04DF\\u04E1\\u04E3\\u04E5\\u04E7\\u04E9\\u04EB\\u04ED\\u04EF\\u04F1\\u04F3\\u04F5\\u04F7\\u04F9\\u04FB\\u04FD\\u04FF\\u0501\\u0503\\u0505\\u0507\\u0509\\u050B\\u050D\\u050F\\u0511\\u0513\\u0515\\u0517\\u0519\\u051B\\u051D\\u051F\\u0521\\u0523\\u0525\\u0527\\u0561-\\u0587\\u1D00-\\u1D2B\\u1D62-\\u1D77\\u1D79-\\u1D9A\\u1E01\\u1E03\\u1E05\\u1E07\\u1E09\\u1E0B\\u1E0D\\u1E0F\\u1E11\\u1E13\\u1E15\\u1E17\\u1E19\\u1E1B\\u1E1D\\u1E1F\\u1E21\\u1E23\\u1E25\\u1E27\\u1E29\\u1E2B\\u1E2D\\u1E2F\\u1E31\\u1E33\\u1E35\\u1E37\\u1E39\\u1E3B\\u1E3D\\u1E3F\\u1E41\\u1E43\\u1E45\\u1E47\\u1E49\\u1E4B\\u1E4D\\u1E4F\\u1E51\\u1E53\\u1E55\\u1E57\\u1E59\\u1E5B\\u1E5D\\u1E5F\\u1E61\\u1E63\\u1E65\\u1E67\\u1E69\\u1E6B\\u1E6D\\u1E6F\\u1E71\\u1E73\\u1E75\\u1E77\\u1E79\\u1E7B\\u1E7D\\u1E7F\\u1E81\\u1E83\\u1E85\\u1E87\\u1E89\\u1E8B\\u1E8D\\u1E8F\\u1E91\\u1E93\\u1E95-\\u1E9D\\u1E9F\\u1EA1\\u1EA3\\u1EA5\\u1EA7\\u1EA9\\u1EAB\\u1EAD\\u1EAF\\u1EB1\\u1EB3\\u1EB5\\u1EB7\\u1EB9\\u1EBB\\u1EBD\\u1EBF\\u1EC1\\u1EC3\\u1EC5\\u1EC7\\u1EC9\\u1ECB\\u1ECD\\u1ECF\\u1ED1\\u1ED3\\u1ED5\\u1ED7\\u1ED9\\u1EDB\\u1EDD\\u1EDF\\u1EE1\\u1EE3\\u1EE5\\u1EE7\\u1EE9\\u1EEB\\u1EED\\u1EEF\\u1EF1\\u1EF3\\u1EF5\\u1EF7\\u1EF9\\u1EFB\\u1EFD\\u1EFF-\\u1F07\\u1F10-\\u1F15\\u1F20-\\u1F27\\u1F30-\\u1F37\\u1F40-\\u1F45\\u1F50-\\u1F57\\u1F60-\\u1F67\\u1F70-\\u1F7D\\u1F80-\\u1F87\\u1F90-\\u1F97\\u1FA0-\\u1FA7\\u1FB0-\\u1FB4\\u1FB6\\u1FB7\\u1FBE\\u1FC2-\\u1FC4\\u1FC6\\u1FC7\\u1FD0-\\u1FD3\\u1FD6\\u1FD7\\u1FE0-\\u1FE7\\u1FF2-\\u1FF4\\u1FF6\\u1FF7\\u210A\\u210E\\u210F\\u2113\\u212F\\u2134\\u2139\\u213C\\u213D\\u2146-\\u2149\\u214E\\u2184\\u2C30-\\u2C5E\\u2C61\\u2C65\\u2C66\\u2C68\\u2C6A\\u2C6C\\u2C71\\u2C73\\u2C74\\u2C76-\\u2C7C\\u2C81\\u2C83\\u2C85\\u2C87\\u2C89\\u2C8B\\u2C8D\\u2C8F\\u2C91\\u2C93\\u2C95\\u2C97\\u2C99\\u2C9B\\u2C9D\\u2C9F\\u2CA1\\u2CA3\\u2CA5\\u2CA7\\u2CA9\\u2CAB\\u2CAD\\u2CAF\\u2CB1\\u2CB3\\u2CB5\\u2CB7\\u2CB9\\u2CBB\\u2CBD\\u2CBF\\u2CC1\\u2CC3\\u2CC5\\u2CC7\\u2CC9\\u2CCB\\u2CCD\\u2CCF\\u2CD1\\u2CD3\\u2CD5\\u2CD7\\u2CD9\\u2CDB\\u2CDD\\u2CDF\\u2CE1\\u2CE3\\u2CE4\\u2CEC\\u2CEE\\u2D00-\\u2D25\\uA641\\uA643\\uA645\\uA647\\uA649\\uA64B\\uA64D\\uA64F\\uA651\\uA653\\uA655\\uA657\\uA659\\uA65B\\uA65D\\uA65F\\uA661\\uA663\\uA665\\uA667\\uA669\\uA66B\\uA66D\\uA681\\uA683\\uA685\\uA687\\uA689\\uA68B\\uA68D\\uA68F\\uA691\\uA693\\uA695\\uA697\\uA723\\uA725\\uA727\\uA729\\uA72B\\uA72D\\uA72F-\\uA731\\uA733\\uA735\\uA737\\uA739\\uA73B\\uA73D\\uA73F\\uA741\\uA743\\uA745\\uA747\\uA749\\uA74B\\uA74D\\uA74F\\uA751\\uA753\\uA755\\uA757\\uA759\\uA75B\\uA75D\\uA75F\\uA761\\uA763\\uA765\\uA767\\uA769\\uA76B\\uA76D\\uA76F\\uA771-\\uA778\\uA77A\\uA77C\\uA77F\\uA781\\uA783\\uA785\\uA787\\uA78C\\uA78E\\uA791\\uA7A1\\uA7A3\\uA7A5\\uA7A7\\uA7A9\\uA7FA\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFF41-\\uFF5A\\u01C5\\u01C8\\u01CB\\u01F2\\u1F88-\\u1F8F\\u1F98-\\u1F9F\\u1FA8-\\u1FAF\\u1FBC\\u1FCC\\u1FFC\\u02B0-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0374\\u037A\\u0559\\u0640\\u06E5\\u06E6\\u07F4\\u07F5\\u07FA\\u081A\\u0824\\u0828\\u0971\\u0E46\\u0EC6\\u10FC\\u17D7\\u1843\\u1AA7\\u1C78-\\u1C7D\\u1D2C-\\u1D61\\u1D78\\u1D9B-\\u1DBF\\u2071\\u207F\\u2090-\\u209C\\u2C7D\\u2D6F\\u2E2F\\u3005\\u3031-\\u3035\\u303B\\u309D\\u309E\\u30FC-\\u30FE\\uA015\\uA4F8-\\uA4FD\\uA60C\\uA67F\\uA717-\\uA71F\\uA770\\uA788\\uA9CF\\uAA70\\uAADD\\uFF70\\uFF9E\\uFF9F\\u01BB\\u01C0-\\u01C3\\u0294\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u063F\\u0641-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u0800-\\u0815\\u0840-\\u0858\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0972-\\u0977\\u0979-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E45\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10D0-\\u10FA\\u1100-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17DC\\u1820-\\u1842\\u1844-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BC0-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C77\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u2135-\\u2138\\u2D30-\\u2D65\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3006\\u303C\\u3041-\\u3096\\u309F\\u30A1-\\u30FA\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FCB\\uA000-\\uA014\\uA016-\\uA48C\\uA4D0-\\uA4F7\\uA500-\\uA60B\\uA610-\\uA61F\\uA62A\\uA62B\\uA66E\\uA6A0-\\uA6E5\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA6F\\uAA71-\\uAA76\\uAA7A\\uAA80-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB\\uAADC\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uABC0-\\uABE2\\uAC00\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA2D\\uFA30-\\uFA6D\\uFA70-\\uFAD9\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF66-\\uFF6F\\uFF71-\\uFF9D\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u16EE-\\u16F0\\u2160-\\u2182\\u2185-\\u2188\\u3007\\u3021-\\u3029\\u3038-\\u303A\\uA6E6-\\uA6EF]"],[4,460,461],[4,462,463],[4,464,465],[4,466,467],[4,363,468],[4,357,469],[4,359,470],[4,471,472],[4,366,473],[4,474,475],[4,476,477],[4,478,479],[4,480,481],[4,482,483],[4,484,485],[4,361,486],[4,487,488],[4,489,490,490,490,490],[4,247,248],[5,"*="],[5,"/="],[5,"%="],[5,"+="],[5,"-="],[5,"<<="],[5,">>="],[5,">>>="],[5,"&="],[5,"^="],[5,"|="],[4,491,492],[4,3,493,3,172,3,105,3,172],[0,"AssignmentExpressionNoIn",494],[6,495],[4,294,496],[4,497,3,498,499],[3,497,500],[8,501],[0,"CASE",502],[5,"@"],[3,503,504,505],[3,506,504,505],[4,507,508],[4,51,3,509],[4,3,167,3,349],[4,510,511,3,512,3,513,3,55,3,56,3,57],[4,514,511,3,512,3,513,3,55,3,56,3,57],[5,"null"],[4,515,121],[4,516,121],[5,"\uD82C"],[2,"[\\uDC00\\uDC01]"],[5,"\uD808"],[2,"[\\uDC00-\\uDF6E]"],[5,"\uD869"],[2,"[\\uDED6\\uDF00]"],[5,"\uD809"],[2,"[\\uDC00-\\uDC62]"],[2,"[\\uDC00-\\uDC19\\uDC34-\\uDC4D\\uDC68-\\uDC81\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB5\\uDCD0-\\uDCE9\\uDD04\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD38\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD6C-\\uDD85\\uDDA0-\\uDDB9\\uDDD4-\\uDDED\\uDE08-\\uDE21\\uDE3C-\\uDE55\\uDE70-\\uDE89\\uDEA8-\\uDEC0\\uDEE2-\\uDEFA\\uDF1C-\\uDF34\\uDF56-\\uDF6E\\uDF90-\\uDFA8\\uDFCA\\uDC1A-\\uDC33\\uDC4E-\\uDC54\\uDC56-\\uDC67\\uDC82-\\uDC9B\\uDCB6-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDCEA-\\uDD03\\uDD1E-\\uDD37\\uDD52-\\uDD6B\\uDD86-\\uDD9F\\uDDBA-\\uDDD3\\uDDEE-\\uDE07\\uDE22-\\uDE3B\\uDE56-\\uDE6F\\uDE8A-\\uDEA5\\uDEC2-\\uDEDA\\uDEDC-\\uDEE1\\uDEFC-\\uDF14\\uDF16-\\uDF1B\\uDF36-\\uDF4E\\uDF50-\\uDF55\\uDF70-\\uDF88\\uDF8A-\\uDF8F\\uDFAA-\\uDFC2\\uDFC4-\\uDFC9\\uDFCB]"],[2,"[\\uDC03-\\uDC37\\uDC83-\\uDCAF]"],[2,"[\\uDC00-\\uDC0B\\uDC0D-\\uDC26\\uDC28-\\uDC3A\\uDC3C\\uDC3D\\uDC3F-\\uDC4D\\uDC50-\\uDC5D\\uDC80-\\uDCFA\\uDE80-\\uDE9C\\uDEA0-\\uDED0\\uDF00-\\uDF1E\\uDF30-\\uDF40\\uDF42-\\uDF49\\uDF80-\\uDF9D\\uDFA0-\\uDFC3\\uDFC8-\\uDFCF\\uDD40-\\uDD74\\uDF41\\uDF4A\\uDFD1-\\uDFD5]"],[5,"\uD80C"],[2,"[\\uDC00-\\uDFFF]"],[2,"[\\uDC00-\\uDC9D]"],[5,"\uD86E"],[2,"[\\uDC1D]"],[5,"\uD803"],[2,"[\\uDC00-\\uDC48]"],[5,"\uD840"],[2,"[\\uDC00]"],[5,"\uD87E"],[2,"[\\uDC00-\\uDE1D]"],[5,"\uD86D"],[2,"[\\uDF34\\uDF40]"],[5,"\uD81A"],[2,"[\\uDC00-\\uDE38]"],[2,"[\\uDC00-\\uDC05\\uDC08\\uDC0A-\\uDC35\\uDC37\\uDC38\\uDC3C\\uDC3F-\\uDC55\\uDD00-\\uDD15\\uDD20-\\uDD39\\uDE00\\uDE10-\\uDE13\\uDE15-\\uDE17\\uDE19-\\uDE33\\uDE60-\\uDE7C\\uDF00-\\uDF35\\uDF40-\\uDF55\\uDF60-\\uDF72]"],[5,"\uD80D"],[2,"[\\uDC00-\\uDC2E]"],[5,"u"],[0,"HexDigit",517],[0,"LogicalAndExpression",518],[6,519],[5,"?"],[3,520,521],[4,3,167,3,442],[6,522],[0,"MemberExpression",523],[0,"Arguments",524],[6,525],[4,526,3,336],[4,3,247,248,3,442],[4,368,121],[4,527,82],[4,327,528],[0,"LineContinuation",529],[4,530,82],[0,"IvarTypeElement",531],[6,532],[8,533],[5,"+"],[8,534],[0,"MethodSelector",535],[8,62],[5,"-"],[5,"true"],[5,"false"],[2,"[0-9a-fA-F]"],[4,536,537],[4,3,538,3,491],[4,258,3,289,3,442],[0,"ConditionalExpressionNoIn",539],[4,3,167,3,294],[4,540,541],[4,52,3,542,3,54],[4,3,543],[0,"NEW",544],[9,545],[0,"EscapeSequence",546],[4,327,212],[9,547],[4,548,549],[4,3,507],[0,"Accessors",550],[4,3,551],[3,552,553],[0,"BitwiseOrExpression",554],[6,555],[5,"||"],[4,556,557],[3,558,47,559,560],[6,561],[8,562],[3,498,563,564],[4,372,121],[3,565,327,10],[3,566,567,568,328],[3,569,327,10],[9,570],[3,123,571],[4,572,573],[0,"MethodType",574],[4,575,576],[0,"UnarySelector",577],[4,578,579],[4,3,580,3,536],[0,"LogicalOrExpressionNoIn",581],[8,582],[0,"PrimaryExpression",583],[0,"MessageExpression",584],[4,526,3,497,3,498],[4,3,585],[0,"ArgumentList",586],[0,"BracketedAccessor",587],[0,"DotAccessor",588],[2,"[\"]"],[0,"CharacterEscapeSequence",589],[4,590,591],[0,"HexEscapeSequence",592],[2,"[']"],[4,549,3,593],[5,"@outlet"],[5,"@accessors"],[8,594],[4,52,3,595,596,3,54],[0,"KeywordSelector",597],[8,598],[0,"Selector",123],[0,"BitwiseXOrExpression",599],[6,600],[5,"&&"],[4,601,602],[4,3,493,3,442,3,105,3,442],[3,603,51,604,605,606,607],[4,608,3,609,3,610,3,611],[3,563,564],[4,172,3,612],[4,608,3,90,3,611],[4,613,3,123],[3,614,615],[5,"0"],[9,616],[4,617,490,490],[3,533,88,167],[4,52,618,54],[3,619,123],[6,620],[4,621,622],[4,3,167,3,623],[4,624,625],[4,3,626,248,3,578],[0,"LogicalAndExpressionNoIn",627],[6,628],[0,"THIS",629],[0,"Literal",630],[0,"ArrayLiteral",631],[0,"ObjectLiteral",632],[4,52,3,90,3,54],[5,"["],[3,633,90],[0,"SelectorCall",634],[5,"]"],[6,635],[5,"."],[0,"SingleEscapeCharacter",636],[0,"NonEscapeCharacter",637],[0,"DecimalDigit",638],[5,"x"],[8,639],[0,"ACTION",640],[4,3,595],[0,"KeywordDeclarator",641],[6,642],[5,"..."],[0,"BitwiseAndExpression",643],[6,644],[5,"|"],[4,645,646],[4,3,538,3,601],[4,373,121],[3,279,280,647,199,648,649],[4,608,3,650,3,611],[4,55,3,651,3,57],[0,"SUPER",652],[3,653,553],[4,167,3,172],[2,"['\"\\\\bfnrtv]"],[4,125,654,82],[2,"[0-9]"],[4,655,656],[3,657,658],[4,659,105,511,3,51],[4,3,621],[4,660,661],[4,3,662,248,3,624],[0,"BitwiseOrExpressionNoIn",663],[6,664],[0,"NumericLiteral",665],[0,"RegularExpressionLiteral",666],[0,"SelectorLiteral",667],[0,"ElementList",668],[8,669],[4,401,121],[4,670,671],[9,672],[0,"AccessorsConfiguration",673],[6,674],[4,675,121],[4,676,121],[8,677],[0,"EqualityExpression",678],[6,679],[5,"^"],[4,680,681],[4,3,580,3,645],[4,682,683],[4,684,685,684,686],[4,687,3,52,3,688,3,54],[4,689,690,3,691],[4,692,3,693],[0,"KeywordSelectorCall",694],[6,695],[0,"EscapeCharacter",696],[3,697,698,699,700],[4,3,167,3,655],[5,"@action"],[5,"IBAction"],[4,577,3],[4,701,702],[4,3,703,248,3,660],[0,"BitwiseXOrExpressionNoIn",704],[6,705],[3,706,707],[9,207],[5,"/"],[0,"RegularExpressionBody",708],[0,"RegularExpressionFlags",208],[5,"@selector"],[0,"SelectorLiteralContents",709],[6,710],[6,711],[8,172],[0,"PropertyNameAndValueList",712],[8,167],[4,713,714],[4,3,167,3,90],[3,614,616,617,489],[0,"IvarPropertyName",715],[0,"IvarGetterName",716],[0,"IvarSetterName",717],[5,"readonly"],[0,"RelationalExpression",718],[6,719],[5,"&"],[4,720,721],[4,3,626,248,3,680],[0,"HexIntegerLiteral",722],[0,"DecimalLiteral",723],[4,724,725],[3,726,51],[4,167,3],[4,3,172,727],[4,728,729],[0,"KeywordCall",730],[6,731],[4,732,3,247,3,51],[4,733,3,247,3,51],[4,734,3,247,3,51,735],[4,736,737],[4,3,738,3,701],[0,"BitwiseAndExpressionNoIn",739],[6,740],[4,590,741,742],[4,743,744],[0,"RegularExpressionFirstChar",745],[6,746],[7,747],[7,748],[0,"PropertyAssignment",749],[6,750],[4,751,3,105,3,90],[4,3,713],[5,"property"],[5,"getter"],[5,"setter"],[8,752],[0,"ShiftExpression",753],[6,754],[0,"EqualityOperator",755],[4,756,757],[4,3,662,248,3,720],[2,"[Xx]"],[7,490],[3,758,759,760],[8,761],[3,762,763,764],[0,"RegularExpressionChar",765],[4,751,3,105,3],[4,3,167],[3,766,767,768],[4,3,167,3,728],[8,577],[4,3,105],[4,769,770],[4,3,771,3,736],[3,772,773,774,775],[0,"EqualityExpressionNoIn",776],[6,777],[4,760,613,778],[4,613,779],[0,"DecimalIntegerLiteral",780],[0,"ExponentPart",781],[4,782,783],[0,"RegularExpressionBackslashSequence",784],[0,"RegularExpressionClass",785],[3,786,763,764],[4,787,3,105,3,172],[0,"PropertyGetter",788],[0,"PropertySetter",789],[0,"AdditiveExpression",790],[6,791],[0,"RelationalOperator",792],[5,"==="],[5,"!=="],[5,"=="],[5,"!="],[4,793,794],[4,3,703,248,3,756],[6,616],[7,616],[3,590,795],[4,796,797],[9,798],[0,"RegularExpressionNonTerminator",83],[4,327,783],[4,608,799,611],[4,800,783],[0,"PropertyName",801],[4,802,3,787,3,52,3,54,3,55,3,56,3,57],[4,803,3,787,3,52,3,804,3,54,3,55,3,56,3,57],[4,805,806],[4,3,807,3,769],[3,808,809,232,234,810,182],[0,"RelationalExpressionNoIn",811],[6,812],[4,813,778],[2,"[eE]"],[0,"SignedInteger",814],[2,"[*\\u005C/[]"],[6,815],[9,816],[3,123,199,647],[5,"get"],[5,"set"],[0,"PropertySetParameterList",51],[0,"MultiplicativeExpression",817],[6,818],[0,"ShiftOperator",819],[5,"<="],[5,">="],[0,"INSTANCEOF",820],[4,736,821],[4,3,738,3,793],[2,"[1-9]"],[4,822,779],[0,"RegularExpressionClassChar",823],[2,"[\\u005C/[]"],[4,824,825],[4,3,826,3,805],[3,827,828,829],[4,371,121],[6,830],[8,831],[3,832,763],[0,"UnaryExpression",833],[6,834],[0,"AdditiveOperator",835],[5,"<<"],[5,">>"],[5,">>>"],[4,3,836,3,736],[2,"[+-]"],[4,837,783],[3,838,839,840,841,842,843,844,845,846,847],[4,3,848,3,824],[4,849,248],[0,"RelationalOperatorNoIn",850],[9,851],[0,"PostfixExpression",852],[4,853,3,824],[4,854,3,824],[4,855,3,824],[4,856,3,824],[4,857,3,824],[4,510,3,824],[4,514,3,824],[4,858,3,824],[4,859,3,824],[0,"MultiplicativeOperator",860],[3,861,862],[3,808,809,232,234,810],[2,"[\\u005C\\]]"],[4,258,863],[0,"DELETE",864],[0,"VOID",865],[0,"TYPEOF",866],[5,"++"],[5,"--"],[5,"~"],[5,"!"],[4,867,248],[4,510,868],[4,514,869],[8,870],[4,370,121],[4,375,121],[4,374,121],[3,871,684,872],[9,510],[9,514],[4,99,873],[5,"*"],[5,"%"],[3,856,857],[0,"%start",875],[4,876,877,876],[0,"%_",878],[8,879],[6,880],[0,"%SourceElements",881],[3,882,883,884],[4,885,886],[0,"%WhiteSpace",14],[0,"%LineTerminator",15],[0,"%Comment",887],[0,"%SourceElement",888],[6,889],[3,890,891],[3,892,893],[4,876,885],[0,"%MultiLineComment",23],[0,"%SingleLineComment",894],[0,"%Statement",895],[0,"%FunctionDeclaration",896],[4,30,897],[3,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,893,913,914,915],[4,916,876,917,876,52,876,918,876,54,876,55,876,919,876,57],[6,920],[0,"%Block",921],[0,"%VariableStatement",922],[0,"%EmptyStatement",62],[0,"%ExpressionStatement",923],[0,"%IfStatement",924],[0,"%IterationStatement",925],[0,"%ContinueStatement",926],[0,"%BreakStatement",927],[0,"%ReturnStatement",928],[0,"%WithStatement",929],[0,"%LabelledStatement",930],[0,"%SwitchStatement",931],[0,"%ThrowStatement",932],[0,"%TryStatement",933],[0,"%DebuggerStatement",934],[0,"%FunctionExpression",935],[0,"%ImportStatement",936],[0,"%ClassDeclarationStatement",937],[0,"%FUNCTION",938],[0,"%Identifier",939],[8,940],[0,"%FunctionBody",875],[0,"%SingleLineCommentChar",941],[12,942,943],[4,944,876,945,946,947],[4,948,949,947],[4,950,876,52,876,949,876,54,876,892,951],[3,952,953,954,955,956],[4,957,958,959],[4,960,958,959],[4,961,958,962],[4,963,876,52,876,949,876,54,876,892],[4,917,876,105,876,892],[4,964,876,52,876,949,876,54,876,965],[4,966,958,962],[4,967,876,898,876,968],[4,969,947],[4,916,876,970,876,52,876,918,876,54,876,55,876,919,876,57],[4,113,876,971,947],[4,115,876,917,876,972,876,973,876,974,876,119,947],[4,120,975],[12,976,977],[0,"%FormalParameterList",978],[4,979,82],[4,55,876,980,876,57],[11,"%BadBlock",981,"Missing ending brace"],[0,"%VAR",982],[0,"%VariableDeclaration",983],[6,984],[0,"%EOS",985],[9,986],[0,"%Expression",987],[0,"%IF",988],[8,989],[0,"%DoWhileStatement",990],[0,"%WhileStatement",991],[0,"%ForStatement",992],[0,"%ForInStatement",993],[0,"%EachStatement",994],[0,"%CONTINUE",995],[0,"%__",996],[3,997,998],[0,"%BREAK",999],[0,"%RETURN",1000],[3,998,1001],[0,"%WITH",1002],[0,"%SWITCH",1003],[0,"%CaseBlock",1004],[0,"%THROW",1005],[0,"%TRY",1006],[3,1007,1008],[0,"%DEBUGGER",1009],[8,917],[3,1010,1011],[8,1012],[8,1013],[0,"%ClassBody",1014],[9,1015],[4,1016,1017],[0,"%BadIdentifier",1018],[4,917,1019],[9,883],[8,1020],[4,55,876,980,876],[4,165,975],[4,917,1021],[4,876,167,876,945],[3,1022,1023,1024,1025],[3,55,916],[4,1026,1027],[4,174,975],[4,876,1028,876,892],[4,1029,876,892,876,1030,876,52,876,949,876,54,947],[4,1030,876,52,876,949,876,54,876,892],[4,1031,876,52,876,1032,876,62,876,1033,876,62,876,1033,876,54,876,892],[4,1031,876,52,876,1034,876,1035,876,949,876,54,876,892],[4,183,876,52,876,1034,876,1035,876,949,876,54,876,892],[4,184,975],[6,1036],[4,917,947],[0,"%SemicolonInsertionEOS",1037],[4,187,975],[4,188,975],[4,949,947],[4,189,975],[4,190,975],[4,55,876,1038,876,1039,876,1038,876,57],[4,193,975],[4,194,975],[4,1040,1041],[0,"%Finally",1042],[4,198,975],[0,"%LocalFilePath",1043],[0,"%StandardFilePath",1044],[3,1045,1046],[4,55,1047,876,57],[8,1048],[0,"%IdentifierPart",1049],[9,1050],[0,"%IdentifierName",1051],[3,1052,1053],[6,1054],[0,"%StatementList",1055],[8,1056],[4,876,62],[4,958,1057],[4,958,213],[4,958,1058],[0,"%AssignmentExpression",1059],[6,1060],[0,"%ELSE",1061],[0,"%DO",1062],[0,"%WHILE",1063],[0,"%FOR",1064],[8,1065],[8,949],[0,"%ForInFirstExpression",1066],[0,"%IN",1067],[3,882,1068,891],[3,1069,1023,1024,1025],[8,1070],[8,1071],[0,"%Catch",1072],[8,1073],[4,1074,876,898],[0,"%StringLiteral",1075],[4,232,876,233,876,234],[0,"%SuperclassDeclaration",1076],[0,"%CategoryDeclaration",1077],[6,1078],[0,"%ClassElements",1079],[3,1080,1081,1082,1083,1084,1085],[4,1086,975],[4,1080,1087],[11,"%ReservedWordIdentifier",1050,"Identifier cannot be a reserved word"],[11,"%DigitIdentifier",1088,"Identifier cannot start with a digit"],[4,876,167,876,917],[4,892,1089],[4,876,247,248,876,1026],[0,"%LineTerminatorSequence",249],[0,"%EOF",250],[3,1090,1091],[4,876,167,876,1026],[4,253,975],[4,254,975],[4,255,975],[4,256,975],[0,"%ForFirstExpression",1092],[3,1093,1094],[4,260,975],[0,"%SingleLineMultiLineComment",1095],[4,958,62],[0,"%CaseClauses",1096],[0,"%DefaultClause",1097],[4,1098,876,52,876,917,876,54,876,898],[4,876,1008],[0,"%FINALLY",1099],[3,1100,1101],[4,105,876,917],[4,52,876,917,876,54],[4,876,1102],[4,1103,1104],[0,"%IdentifierStart",1105],[0,"%UnicodeCombiningMark",272],[0,"%UnicodeDigit",273],[0,"%UnicodeConnectorPunctuation",274],[0,"%ZWNJ",275],[0,"%ZWJ",276],[0,"%ReservedWord",1106],[6,1015],[4,1082,1107],[6,1108],[4,1093,876,1109,876,1026],[0,"%ConditionalExpression",1110],[3,1111,1112],[0,"%LeftHandSideExpression",1113],[4,944,876,1114],[4,27,1115,29],[4,1116,1117],[4,1118,876,105,1119],[0,"%CATCH",1120],[4,301,975],[4,1121,303,1122,303],[4,305,1123,305],[0,"%CompoundIvarDeclaration",1124],[0,"%ClassElement",1125],[6,1126],[3,1127,282,1128],[3,1129,1130,1131,1132],[7,1015],[4,876,892],[0,"%AssignmentOperator",330],[4,1133,1134],[0,"%ExpressionNoIn",1135],[4,944,876,1136],[3,1137,1138],[0,"%VariableDeclarationNoIn",1139],[6,1140],[0,"%CaseClause",1141],[6,1142],[0,"%DEFAULT",1143],[8,1144],[4,343,975],[8,1145],[6,1146],[6,1147],[4,1148,876,1149,1150,947],[3,1151,1152,892,893],[4,876,1103],[0,"%UnicodeLetter",326],[4,327,1153],[0,"%Keyword",322],[0,"%FutureReservedWord",323],[0,"%NullLiteral",1154],[0,"%BooleanLiteral",1155],[0,"%LogicalOrExpression",1156],[8,1157],[4,1158,1159],[0,"%VariableDeclarationListNoIn",1160],[0,"%CallExpression",1161],[0,"%NewExpression",1162],[4,917,1163],[4,81,979,82],[4,1164,876,949,876,105,1119],[4,876,1116],[4,369,975],[4,876,1020],[4,449,876],[0,"%DoubleStringCharacter",1165],[0,"%SingleStringCharacter",1166],[0,"%IvarType",1167],[0,"%IvarDeclaration",1168],[6,1169],[0,"%ClassMethodDeclaration",1170],[0,"%InstanceMethodDeclaration",1171],[0,"%UnicodeEscapeSequence",1172],[0,"%NULL",1173],[3,1174,1175],[4,1176,1177],[4,876,493,876,1026,876,105,876,1026],[0,"%AssignmentExpressionNoIn",1178],[6,1179],[4,1114,1180],[4,1181,876,1182,1183],[3,1181,1184],[8,1185],[0,"%CASE",1186],[3,1187,1188,1189],[3,1190,1188,1189],[4,1191,1192],[4,917,876,1193],[4,876,167,876,1149],[4,510,1194,876,1195,876,513,876,55,876,919,876,57],[4,514,1194,876,1195,876,513,876,55,876,919,876,57],[4,489,1196,1196,1196,1196],[4,457,975],[0,"%TRUE",1197],[0,"%FALSE",1198],[0,"%LogicalAndExpression",1199],[6,1200],[3,1201,1202],[4,876,167,876,1158],[6,1203],[0,"%MemberExpression",1204],[0,"%Arguments",1205],[6,1206],[4,1207,876,1138],[4,876,247,248,876,1158],[4,368,975],[4,1208,82],[4,327,1209],[0,"%LineContinuation",1210],[4,1211,82],[0,"%IvarTypeElement",1212],[6,1213],[8,1214],[8,1215],[0,"%MethodSelector",1216],[0,"%HexDigit",517],[4,515,975],[4,516,975],[4,1217,1218],[4,876,538,876,1176],[4,1093,876,1109,876,1158],[0,"%ConditionalExpressionNoIn",1219],[4,876,167,876,1114],[4,1220,1221],[4,52,876,1222,876,54],[4,876,1223],[0,"%NEW",1224],[9,1225],[0,"%EscapeSequence",1226],[4,327,1057],[9,1227],[4,1228,1229],[4,876,1191],[0,"%Accessors",1230],[4,876,1231],[3,1232,1233],[0,"%BitwiseOrExpression",1234],[6,1235],[4,1236,1237],[3,1238,913,1239,1240],[6,1241],[8,1242],[3,1182,1243,1244],[4,372,975],[3,565,327,883],[3,1245,1246,1247,1153],[3,569,327,883],[9,1248],[3,1017,571],[4,572,1249],[0,"%MethodType",1250],[4,1251,1252],[0,"%UnarySelector",1253],[4,1254,1255],[4,876,580,876,1217],[0,"%LogicalOrExpressionNoIn",1256],[8,1257],[0,"%PrimaryExpression",1258],[0,"%MessageExpression",1259],[4,1207,876,1181,876,1182],[4,876,1260],[0,"%ArgumentList",1261],[0,"%BracketedAccessor",1262],[0,"%DotAccessor",1263],[0,"%CharacterEscapeSequence",1264],[4,590,1265],[0,"%HexEscapeSequence",1266],[4,1229,876,1267],[8,1268],[4,52,876,1269,1270,876,54],[0,"%KeywordSelector",1271],[8,1272],[0,"%Selector",1017],[0,"%BitwiseXOrExpression",1273],[6,1274],[4,1275,1276],[4,876,493,876,1158,876,105,876,1158],[3,1277,917,1278,1279,1280,1281],[4,608,876,1282,876,1283,876,611],[3,1243,1244],[4,1026,876,1284],[4,608,876,949,876,611],[4,613,876,1017],[3,1285,1286],[9,1287],[4,617,1196,1196],[3,1214,947,167],[4,52,1288,54],[3,1289,1017],[6,1290],[4,1291,1292],[4,876,167,876,623],[4,1293,1294],[4,876,626,248,876,1254],[0,"%LogicalAndExpressionNoIn",1295],[6,1296],[0,"%THIS",1297],[0,"%Literal",1298],[0,"%ArrayLiteral",1299],[0,"%ObjectLiteral",1300],[4,52,876,949,876,54],[3,1301,949],[0,"%SelectorCall",1302],[6,1303],[0,"%SingleEscapeCharacter",636],[0,"%NonEscapeCharacter",1304],[0,"%DecimalDigit",638],[8,1305],[0,"%ACTION",1306],[4,876,1269],[0,"%KeywordDeclarator",1307],[6,1308],[0,"%BitwiseAndExpression",1309],[6,1310],[4,1311,1312],[4,876,538,876,1275],[4,373,975],[3,1131,1132,1313,1043,1314,1315],[4,608,876,1316,876,611],[4,55,876,1317,876,57],[0,"%SUPER",1318],[3,1319,1233],[4,167,876,1026],[4,979,1320,82],[4,1321,1322],[3,1323,1324],[4,1325,105,1194,876,917],[4,876,1291],[4,1326,1327],[4,876,662,248,876,1293],[0,"%BitwiseOrExpressionNoIn",1328],[6,1329],[0,"%NumericLiteral",1330],[0,"%RegularExpressionLiteral",1331],[0,"%SelectorLiteral",1332],[0,"%ElementList",1333],[8,1334],[4,401,975],[4,1335,1336],[9,1337],[0,"%AccessorsConfiguration",1338],[6,1339],[4,675,975],[4,676,975],[8,1340],[0,"%EqualityExpression",1341],[6,1342],[4,1343,1344],[4,876,580,876,1311],[4,1345,1346],[4,684,1347,684,1348],[4,687,876,52,876,1349,876,54],[4,1350,1351,876,1352],[4,1353,876,693],[0,"%KeywordSelectorCall",1354],[6,1355],[0,"%EscapeCharacter",1356],[3,1357,1358,1359,700],[4,876,167,876,1321],[4,1253,876],[4,1360,1361],[4,876,703,248,876,1326],[0,"%BitwiseXOrExpressionNoIn",1362],[6,1363],[3,1364,1365],[9,1080],[0,"%RegularExpressionBody",1366],[0,"%RegularExpressionFlags",1087],[0,"%SelectorLiteralContents",1367],[6,1368],[6,1369],[8,1026],[0,"%PropertyNameAndValueList",1370],[4,1371,1372],[4,876,167,876,949],[3,1285,1287,617,489],[0,"%IvarPropertyName",1373],[0,"%IvarGetterName",1374],[0,"%IvarSetterName",1375],[0,"%RelationalExpression",1376],[6,1377],[4,1378,1379],[4,876,626,248,876,1343],[0,"%HexIntegerLiteral",1380],[0,"%DecimalLiteral",1381],[4,1382,1383],[3,1384,917],[4,167,876],[4,876,1026,1385],[4,1386,1387],[0,"%KeywordCall",1388],[6,1389],[4,732,876,247,876,917],[4,733,876,247,876,917],[4,734,876,247,876,917,1390],[4,1391,1392],[4,876,1393,876,1360],[0,"%BitwiseAndExpressionNoIn",1394],[6,1395],[4,590,741,1396],[4,1397,1398],[0,"%RegularExpressionFirstChar",1399],[6,1400],[7,1401],[7,1402],[0,"%PropertyAssignment",1403],[6,1404],[4,1405,876,105,876,949],[4,876,1371],[8,1406],[0,"%ShiftExpression",1407],[6,1408],[0,"%EqualityOperator",755],[4,1409,1410],[4,876,662,248,876,1378],[7,1196],[3,1411,1412,1413],[8,1414],[3,1415,1416,1417],[0,"%RegularExpressionChar",1418],[4,1405,876,105,876],[4,876,167],[3,1419,1420,1421],[4,876,167,876,1386],[8,1253],[4,876,105],[4,1422,1423],[4,876,1424,876,1391],[0,"%EqualityExpressionNoIn",1425],[6,1426],[4,1413,613,1427],[4,613,1428],[0,"%DecimalIntegerLiteral",1429],[0,"%ExponentPart",1430],[4,782,1431],[0,"%RegularExpressionBackslashSequence",1432],[0,"%RegularExpressionClass",1433],[3,1434,1416,1417],[4,1435,876,105,876,1026],[0,"%PropertyGetter",1436],[0,"%PropertySetter",1437],[0,"%AdditiveExpression",1438],[6,1439],[0,"%RelationalOperator",1440],[4,1441,1442],[4,876,703,248,876,1409],[6,1287],[7,1287],[3,590,1443],[4,796,1444],[0,"%RegularExpressionNonTerminator",941],[4,327,1431],[4,608,1445,611],[4,800,1431],[0,"%PropertyName",1446],[4,802,876,1435,876,52,876,54,876,55,876,919,876,57],[4,803,876,1435,876,52,876,1447,876,54,876,55,876,919,876,57],[4,1448,1449],[4,876,1450,876,1422],[3,808,809,232,234,1451,1035],[0,"%RelationalExpressionNoIn",1452],[6,1453],[4,813,1427],[0,"%SignedInteger",1454],[6,1455],[3,1017,1043,1313],[0,"%PropertySetParameterList",917],[0,"%MultiplicativeExpression",1456],[6,1457],[0,"%ShiftOperator",819],[0,"%INSTANCEOF",1458],[4,1391,1459],[4,876,1393,876,1441],[4,822,1428],[0,"%RegularExpressionClassChar",1460],[4,1461,1462],[4,876,1463,876,1448],[4,371,975],[6,1464],[3,1465,1416],[0,"%UnaryExpression",1466],[6,1467],[0,"%AdditiveOperator",835],[4,876,1468,876,1391],[4,837,1431],[3,1469,1470,1471,1472,1473,1474,1475,1476,1477,1478],[4,876,1479,876,1461],[0,"%RelationalOperatorNoIn",1480],[0,"%PostfixExpression",1481],[4,1482,876,1461],[4,1483,876,1461],[4,1484,876,1461],[4,856,876,1461],[4,857,876,1461],[4,510,876,1461],[4,514,876,1461],[4,858,876,1461],[4,859,876,1461],[0,"%MultiplicativeOperator",860],[3,808,809,232,234,1451],[4,1093,1485],[0,"%DELETE",1486],[0,"%VOID",1487],[0,"%TYPEOF",1488],[8,1489],[4,370,975],[4,375,975],[4,374,975],[4,958,873]],"nameToUID":{"start":1,"_":3,"SourceElements":6,"WhiteSpace":9,"LineTerminator":10,"Comment":11,"SourceElement":12,"MultiLineComment":19,"SingleLineComment":20,"Statement":21,"FunctionDeclaration":22,"Block":32,"VariableStatement":33,"EmptyStatement":34,"ExpressionStatement":35,"IfStatement":36,"IterationStatement":37,"ContinueStatement":38,"BreakStatement":39,"ReturnStatement":40,"WithStatement":41,"LabelledStatement":42,"SwitchStatement":43,"ThrowStatement":44,"TryStatement":45,"DebuggerStatement":46,"FunctionExpression":47,"ImportStatement":48,"ClassDeclarationStatement":49,"FUNCTION":50,"Identifier":51,"FunctionBody":56,"SingleLineCommentChar":59,"FormalParameterList":80,"VAR":85,"VariableDeclaration":86,"EOS":88,"Expression":90,"IF":91,"DoWhileStatement":93,"WhileStatement":94,"ForStatement":95,"ForInStatement":96,"EachStatement":97,"CONTINUE":98,"__":99,"BREAK":101,"RETURN":102,"WITH":104,"SWITCH":106,"CaseBlock":107,"THROW":108,"TRY":109,"DEBUGGER":111,"ClassBody":118,"IdentifierName":123,"StatementList":126,"SemicolonInsertionEOS":143,"Finally":153,"LocalFilePath":155,"StandardFilePath":156,"IdentifierPart":160,"AssignmentExpression":172,"ELSE":175,"DO":176,"WHILE":177,"FOR":178,"ForInFirstExpression":181,"IN":182,"Catch":195,"StringLiteral":199,"SuperclassDeclaration":201,"CategoryDeclaration":202,"ClassElements":204,"ReservedWord":206,"IdentifierStart":207,"LineTerminatorSequence":212,"EOF":214,"ForFirstExpression":221,"SingleLineMultiLineComment":224,"CaseClauses":226,"DefaultClause":227,"FINALLY":230,"UnicodeCombiningMark":239,"UnicodeDigit":240,"UnicodeConnectorPunctuation":241,"ZWNJ":242,"ZWJ":243,"ConditionalExpression":252,"LeftHandSideExpression":258,"CATCH":264,"CompoundIvarDeclaration":269,"ClassElement":270,"Keyword":277,"FutureReservedWord":278,"NullLiteral":279,"BooleanLiteral":280,"UnicodeLetter":281,"AssignmentOperator":289,"ExpressionNoIn":291,"VariableDeclarationNoIn":294,"CaseClause":296,"DEFAULT":298,"NULL":324,"UnicodeEscapeSequence":328,"LogicalOrExpression":331,"VariableDeclarationListNoIn":334,"CallExpression":335,"NewExpression":336,"DoubleStringCharacter":345,"SingleStringCharacter":346,"IvarType":348,"IvarDeclaration":349,"ClassMethodDeclaration":351,"InstanceMethodDeclaration":352,"TRUE":407,"FALSE":408,"AssignmentExpressionNoIn":442,"CASE":448,"HexDigit":490,"LogicalAndExpression":491,"MemberExpression":497,"Arguments":498,"LineContinuation":505,"IvarTypeElement":507,"MethodSelector":512,"ConditionalExpressionNoIn":521,"NEW":526,"EscapeSequence":528,"Accessors":533,"BitwiseOrExpression":536,"MethodType":551,"UnarySelector":553,"LogicalOrExpressionNoIn":556,"PrimaryExpression":558,"MessageExpression":559,"ArgumentList":562,"BracketedAccessor":563,"DotAccessor":564,"CharacterEscapeSequence":566,"HexEscapeSequence":568,"KeywordSelector":575,"Selector":577,"BitwiseXOrExpression":578,"LogicalAndExpressionNoIn":601,"THIS":603,"Literal":604,"ArrayLiteral":605,"ObjectLiteral":606,"SelectorCall":610,"SingleEscapeCharacter":614,"NonEscapeCharacter":615,"DecimalDigit":616,"ACTION":619,"KeywordDeclarator":621,"BitwiseAndExpression":624,"SUPER":633,"BitwiseOrExpressionNoIn":645,"NumericLiteral":647,"RegularExpressionLiteral":648,"SelectorLiteral":649,"ElementList":650,"AccessorsConfiguration":655,"EqualityExpression":660,"KeywordSelectorCall":670,"EscapeCharacter":672,"BitwiseXOrExpressionNoIn":680,"RegularExpressionBody":685,"RegularExpressionFlags":686,"SelectorLiteralContents":688,"PropertyNameAndValueList":692,"IvarPropertyName":697,"IvarGetterName":698,"IvarSetterName":699,"RelationalExpression":701,"HexIntegerLiteral":706,"DecimalLiteral":707,"KeywordCall":713,"BitwiseAndExpressionNoIn":720,"RegularExpressionFirstChar":724,"PropertyAssignment":728,"ShiftExpression":736,"EqualityOperator":738,"RegularExpressionChar":746,"EqualityExpressionNoIn":756,"DecimalIntegerLiteral":760,"ExponentPart":761,"RegularExpressionBackslashSequence":763,"RegularExpressionClass":764,"PropertyGetter":767,"PropertySetter":768,"AdditiveExpression":769,"RelationalOperator":771,"RegularExpressionNonTerminator":783,"PropertyName":787,"RelationalExpressionNoIn":793,"SignedInteger":797,"PropertySetParameterList":804,"MultiplicativeExpression":805,"ShiftOperator":807,"INSTANCEOF":810,"RegularExpressionClassChar":815,"UnaryExpression":824,"AdditiveOperator":826,"RelationalOperatorNoIn":836,"PostfixExpression":838,"MultiplicativeOperator":848,"DELETE":853,"VOID":854,"TYPEOF":855,"%start":874,"%_":876,"%SourceElements":879,"%WhiteSpace":882,"%LineTerminator":883,"%Comment":884,"%SourceElement":885,"%MultiLineComment":890,"%SingleLineComment":891,"%Statement":892,"%FunctionDeclaration":893,"%Block":898,"%VariableStatement":899,"%EmptyStatement":900,"%ExpressionStatement":901,"%IfStatement":902,"%IterationStatement":903,"%ContinueStatement":904,"%BreakStatement":905,"%ReturnStatement":906,"%WithStatement":907,"%LabelledStatement":908,"%SwitchStatement":909,"%ThrowStatement":910,"%TryStatement":911,"%DebuggerStatement":912,"%FunctionExpression":913,"%ImportStatement":914,"%ClassDeclarationStatement":915,"%FUNCTION":916,"%Identifier":917,"%FunctionBody":919,"%SingleLineCommentChar":920,"%FormalParameterList":940,"%BadBlock":943,"%VAR":944,"%VariableDeclaration":945,"%EOS":947,"%Expression":949,"%IF":950,"%DoWhileStatement":952,"%WhileStatement":953,"%ForStatement":954,"%ForInStatement":955,"%EachStatement":956,"%CONTINUE":957,"%__":958,"%BREAK":960,"%RETURN":961,"%WITH":963,"%SWITCH":964,"%CaseBlock":965,"%THROW":966,"%TRY":967,"%DEBUGGER":969,"%ClassBody":974,"%BadIdentifier":977,"%SemicolonInsertionEOS":998,"%Finally":1008,"%LocalFilePath":1010,"%StandardFilePath":1011,"%IdentifierPart":1015,"%IdentifierName":1017,"%StatementList":1020,"%AssignmentExpression":1026,"%ELSE":1028,"%DO":1029,"%WHILE":1030,"%FOR":1031,"%ForInFirstExpression":1034,"%IN":1035,"%Catch":1040,"%StringLiteral":1043,"%SuperclassDeclaration":1045,"%CategoryDeclaration":1046,"%ClassElements":1048,"%ReservedWordIdentifier":1052,"%DigitIdentifier":1053,"%LineTerminatorSequence":1057,"%EOF":1058,"%ForFirstExpression":1065,"%SingleLineMultiLineComment":1068,"%CaseClauses":1070,"%DefaultClause":1071,"%FINALLY":1074,"%IdentifierStart":1080,"%UnicodeCombiningMark":1081,"%UnicodeDigit":1082,"%UnicodeConnectorPunctuation":1083,"%ZWNJ":1084,"%ZWJ":1085,"%ReservedWord":1086,"%ConditionalExpression":1091,"%LeftHandSideExpression":1093,"%CATCH":1098,"%CompoundIvarDeclaration":1102,"%ClassElement":1103,"%AssignmentOperator":1109,"%ExpressionNoIn":1111,"%VariableDeclarationNoIn":1114,"%CaseClause":1116,"%DEFAULT":1118,"%UnicodeLetter":1127,"%Keyword":1129,"%FutureReservedWord":1130,"%NullLiteral":1131,"%BooleanLiteral":1132,"%LogicalOrExpression":1133,"%VariableDeclarationListNoIn":1136,"%CallExpression":1137,"%NewExpression":1138,"%DoubleStringCharacter":1146,"%SingleStringCharacter":1147,"%IvarType":1148,"%IvarDeclaration":1149,"%ClassMethodDeclaration":1151,"%InstanceMethodDeclaration":1152,"%UnicodeEscapeSequence":1153,"%NULL":1154,"%AssignmentExpressionNoIn":1158,"%CASE":1164,"%TRUE":1174,"%FALSE":1175,"%LogicalAndExpression":1176,"%MemberExpression":1181,"%Arguments":1182,"%LineContinuation":1189,"%IvarTypeElement":1191,"%MethodSelector":1195,"%HexDigit":1196,"%ConditionalExpressionNoIn":1202,"%NEW":1207,"%EscapeSequence":1209,"%Accessors":1214,"%BitwiseOrExpression":1217,"%MethodType":1231,"%UnarySelector":1233,"%LogicalOrExpressionNoIn":1236,"%PrimaryExpression":1238,"%MessageExpression":1239,"%ArgumentList":1242,"%BracketedAccessor":1243,"%DotAccessor":1244,"%CharacterEscapeSequence":1245,"%HexEscapeSequence":1247,"%KeywordSelector":1251,"%Selector":1253,"%BitwiseXOrExpression":1254,"%LogicalAndExpressionNoIn":1275,"%THIS":1277,"%Literal":1278,"%ArrayLiteral":1279,"%ObjectLiteral":1280,"%SelectorCall":1283,"%SingleEscapeCharacter":1285,"%NonEscapeCharacter":1286,"%DecimalDigit":1287,"%ACTION":1289,"%KeywordDeclarator":1291,"%BitwiseAndExpression":1293,"%SUPER":1301,"%BitwiseOrExpressionNoIn":1311,"%NumericLiteral":1313,"%RegularExpressionLiteral":1314,"%SelectorLiteral":1315,"%ElementList":1316,"%AccessorsConfiguration":1321,"%EqualityExpression":1326,"%KeywordSelectorCall":1335,"%EscapeCharacter":1337,"%BitwiseXOrExpressionNoIn":1343,"%RegularExpressionBody":1347,"%RegularExpressionFlags":1348,"%SelectorLiteralContents":1349,"%PropertyNameAndValueList":1353,"%IvarPropertyName":1357,"%IvarGetterName":1358,"%IvarSetterName":1359,"%RelationalExpression":1360,"%HexIntegerLiteral":1364,"%DecimalLiteral":1365,"%KeywordCall":1371,"%BitwiseAndExpressionNoIn":1378,"%RegularExpressionFirstChar":1382,"%PropertyAssignment":1386,"%ShiftExpression":1391,"%EqualityOperator":1393,"%RegularExpressionChar":1400,"%EqualityExpressionNoIn":1409,"%DecimalIntegerLiteral":1413,"%ExponentPart":1414,"%RegularExpressionBackslashSequence":1416,"%RegularExpressionClass":1417,"%PropertyGetter":1420,"%PropertySetter":1421,"%AdditiveExpression":1422,"%RelationalOperator":1424,"%RegularExpressionNonTerminator":1431,"%PropertyName":1435,"%RelationalExpressionNoIn":1441,"%SignedInteger":1444,"%PropertySetParameterList":1447,"%MultiplicativeExpression":1448,"%ShiftOperator":1450,"%INSTANCEOF":1451,"%RegularExpressionClassChar":1455,"%UnaryExpression":1461,"%AdditiveOperator":1463,"%RelationalOperatorNoIn":1468,"%PostfixExpression":1469,"%MultiplicativeOperator":1479,"%DELETE":1482,"%VOID":1483,"%TYPEOF":1484}}; + + +//function Parser(/*String | CompiledGrammar*/ aGrammar) +/*{ + if (typeof aGrammar.valueOf() === "string") + this.compiledGrammar = new (require("./compiledgrammar"))(aGrammar); + else + this.compiledGrammar = aGrammar; + + return this; +}*/ + +//exports.Parser = Parser; + +var Parser = function(/*CompiledGrammar*/ aGrammar) +{ + this.compiledGrammar = aGrammar; +} + +//Parser.compiledGrammar = compiledGrammar; + +Parser.prototype.parse = function(input) +{ + return parse(this.compiledGrammar, input); +} + +var NAME = 0, + DOT = 1, + CHARACTER_CLASS = 2, + ORDERED_CHOICE = 3, + SEQUENCE = 4, + STRING_LITERAL = 5, + ZERO_OR_MORE = 6, + ONE_OR_MORE = 7, + OPTIONAL = 8, + NEGATIVE_LOOK_AHEAD = 9, + POSITIVE_LOOK_AHEAD = 10, + ERROR_NAME = 11, + ERROR_CHOICE = 12; + +function parse(aCompiledGrammar, input, name) +{ + var node = new SyntaxNode("#document", input, 0, 0), + table = aCompiledGrammar.table, + nameToUID = aCompiledGrammar.nameToUID; + + name = name || "start"; + + // This is a stupid check. + if (aCompiledGrammar.nameToUID["EOF"] !== undefined) + table[0] = [SEQUENCE, nameToUID[name], nameToUID["EOF"]]; + + if (!evaluate(new context(input, table), node, table, 0)) + { + // This is a stupid check. + if (aCompiledGrammar.nameToUID["EOF"] !== undefined) + table[0] = [SEQUENCE, nameToUID["%" + name], nameToUID["EOF"]]; + + node.children.length = 0; + + evaluate(new context(input, table), node, table, 0); + + node.traverse( + { + traverseTextNodes:false, + enteredNode:function(node) + { + if (node.error) + console.log(node.message() + "\n"); + } + }); + } + + return node; +} + +exports.parse = parse; + +function context(input, table) +{ + this.position = 0; + this.input = input; + this.memos = []; + for (var i=0;i input_length) + { + memos[uid] = false; + return false; + } + + var index = 0; + + for (; index < string_length; ++context.position, ++index) + if (context.input.charCodeAt(context.position) !== string.charCodeAt(index)) + { + context.position -= index; + memos[uid] = false; + return false; + } + +// memos[uid] = string; + if (parent) + parent.children.push(string); + + return true; + case DOT: + if (context.position < input_length) + { + if (parent) + parent.children.push(context.input.charAt(context.position)); + ++context.position; + return true; + } + memos[uid] = false; + return false; + case POSITIVE_LOOK_AHEAD: + case NEGATIVE_LOOK_AHEAD: + var position = context.position, + result = evaluate(context, null, rules, rule[1]) === (type === POSITIVE_LOOK_AHEAD); + context.position = position; + memos[uid] = result; + + return result; + + case ZERO_OR_MORE: + var child, + position = context.position, + childCount = parent && parent.children.length; + + while (evaluate(context, parent, rules, rule[1])) + { + position = context.position, + childCount = parent && parent.children.length; + } + + context.position = position; + if (parent) + parent.children.length = childCount; + + return true; + + case ONE_OR_MORE: + var position = context.position, + childCount = parent && parent.children.length; + if (!evaluate(context, parent, rules, rule[1])) + { + memos[uid] = false; + context.position = position; + if (parent) + parent.children.length = childCount; + return false; + } + position = context.position, + childCount = parent && parent.children.length; + while (evaluate(context, parent, rules, rule[1])) + { + position = context.position; + childCount = parent && parent.children.length; + } + context.position = position; + if (parent) + parent.children.length = childCount; + return true; + + case OPTIONAL: + var position = context.position, + childCount = parent && parent.children.length; + + if (!evaluate(context, parent, rules, rule[1])) + { + context.position = position; + + if (parent) + parent.children.length = childCount; + } + + return true; + } +} + +function SyntaxNode(/*String*/ aName, /*String*/ aSource, /*Number*/ aLocation, /*Number*/ aLength, /*String*/anErrorMessage) +{ + this.name = aName; + this.source = aSource; + this.range = { location:aLocation, length:aLength }; + this.children = []; + + if (anErrorMessage) + this.error = anErrorMessage; +} + +SyntaxNode.prototype.message = function() +{ + var source = this.source, + lineNumber = 1, + index = 0, + start = 0, + length = source.length, + range = this.range; + + for (; index < range.location; ++index) + if (source.charAt(index) === '\n') + { + ++lineNumber; + start = index + 1; + } + + for (; index < length; ++index) + if (source.charAt(index) === '\n') + break; + + var line = source.substring(start, index); + message = line + "\n"; + + message += (new Array(this.range.location - start + 1)).join(" "); + message += (new Array(Math.min(range.length, line.length) + 1)).join("^") + "\n"; + message += "ERROR line " + lineNumber + ": " + this.error; + + return message; +} + +SyntaxNode.prototype.toString = function(/*String*/ spaces) +{ + if (!spaces) + spaces = ""; + + var string = spaces + this.name + " <" + this.innerText() + "> ", + children = this.children, + index = 0, + count = children.length; + + for (; index < count; ++index) + { + var child = children[index]; + + if (typeof child === "string") + string += "\n" + spaces + "\t" + child; + + else + string += "\n" + children[index].toString(spaces + '\t'); + } + + return string; +} + +SyntaxNode.prototype.innerText = function() +{ + var range = this.range; + + return this.source.substr(range.location, range.length); +} + +SyntaxNode.prototype.traverse = function(walker) +{ + if (!walker.enteredNode || walker.enteredNode(this) !== false) + { + var children = this.children, + index = 0, + count = children && children.length; + + for (; index < count; ++index) + { + var child = children[index]; + + if (typeof child !== "string") + child.traverse(walker); + + else if (walker.traversesTextNodes) + { + walker.enteredNode(child); + walker.exitedNode(child); + } + } + } + + if (walker.exitedNode) + walker.exitedNode(this); +} + + +exports.Parser = new Parser(compiledGrammar); + From c297e926f980d9e67355766869f696f5fdae6b86 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sun, 16 Dec 2012 17:38:47 +0100 Subject: [PATCH 02/46] Compiler now works with jake and can compiler the whole Cappuccino framework. A lot of test cases still fail --- AppKit/CPAccordionView.j | 2 +- AppKit/CPApplication.j | 2 +- AppKit/CPButton.j | 4 +- AppKit/CPCollectionView.j | 2 +- AppKit/CPControl.j | 2 +- AppKit/CPDocument.j | 6 +- AppKit/CPDocumentController.j | 2 +- AppKit/CPKeyValueBinding.j | 2 +- AppKit/CPMenu/CPMenu.j | 2 +- AppKit/CPMenuItem/_CPMenuItemView.j | 2 +- AppKit/CPPasteboard.j | 2 +- AppKit/CPRuleEditor/CPRuleEditor.j | 8 +- .../CPRuleEditor/_CPPredicateEditorRowNode.j | 2 +- AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j | 2 + AppKit/CPSegmentedControl.j | 2 +- AppKit/CPStepper.j | 6 +- AppKit/CPTableColumn.j | 1 + AppKit/CPTableView.j | 2 +- AppKit/CPTheme.j | 1 + AppKit/CPTokenField.j | 2 +- AppKit/CPToolbarItem.j | 4 +- AppKit/CPUserDefaultsController.j | 2 +- AppKit/CPView.j | 2 +- AppKit/CPViewController.j | 2 +- AppKit/CPWindow/CPWindow.j | 7 +- AppKit/Cib/_CPCibObjectData.j | 2 +- AppKit/CoreAnimation/CAMediaTimingFunction.j | 2 +- AppKit/Platform/CPPlatformWindow.j | 2 +- AppKit/Platform/DOM/CPDOMWindowLayer.j | 2 +- AppKit/Themes/BlendKit/BKThemeDescriptor.j | 3 + AppKit/_CPAutocompleteMenu.j | 1 + AppKit/_CPPopUpList.j | 1 + Foundation/CPArray+KVO.j | 2 +- Foundation/CPArray/CPArray.j | 2 +- Foundation/CPCountedSet.j | 2 +- Foundation/CPDateFormatter.j | 6 +- Foundation/CPDictionary.j | 51 ++++---- Foundation/CPException.j | 2 + Foundation/CPLog.j | 1 + Foundation/CPNumberFormatter.j | 6 +- Foundation/CPObject.j | 4 +- Foundation/CPPredicate/CPExpression.j | 16 +-- Foundation/CPPredicate/CPPredicate.j | 6 +- Foundation/CPPredicate/_CPKeyPathExpression.j | 1 + Foundation/CPProxy.j | 3 +- Foundation/CPSet+KVO.j | 2 +- Foundation/CPSet/CPMutableSet.j | 2 +- Foundation/CPSet/CPSet.j | 2 +- Foundation/CPURLConnection.j | 4 +- Foundation/CPValueTransformer.j | 13 +- Foundation/Foundation.j | 2 + Foundation/_CPCollectionKVCOperators.j | 2 + Objective-J/CFBundle.js | 9 ++ Objective-J/CFHTTPRequest.js | 30 +++++ Objective-J/CommonJS/lib/objective-j.js | 5 +- .../lib/objective-j/jake/bundletask.js | 41 +++++- Objective-J/Executable.js | 71 +++++++--- Objective-J/FileExecutable.js | 12 +- Objective-J/ObjJCompiler.js | 121 ++++++++++++++---- Objective-J/Parser.js | 2 +- Objective-J/Runtime.js | 21 +++ Objective-J/StaticResource.js | 48 ++++++- Tests/AppKit/CPApplicationTest.j | 1 + Tests/AppKit/CPArrayControllerTest.j | 3 +- Tests/AppKit/CPOutlineViewTest.j | 6 +- Tests/AppKit/CPPredicateEditorTest.j | 4 +- Tests/AppKit/CPSearchFieldTest.j | 2 + Tests/AppKit/CPWindowTest.j | 1 + Tests/Foundation/CPArrayPerformanceTest.j | 2 +- Tests/Foundation/CPDataTest.j | 2 +- Tests/Manual/ArrayController1/AppController.j | 2 +- .../Manual/CPOutlineViewTest/AppController.j | 4 +- .../AppController+WebPolicyDelegate.m | 4 +- Tools/nib2cib/NSExpression.j | 7 + 74 files changed, 443 insertions(+), 168 deletions(-) diff --git a/AppKit/CPAccordionView.j b/AppKit/CPAccordionView.j index c4a6e6e49..669cad8b2 100644 --- a/AppKit/CPAccordionView.j +++ b/AppKit/CPAccordionView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPApplication.j b/AppKit/CPApplication.j index 8743ecee4..0dd71baf6 100644 --- a/AppKit/CPApplication.j +++ b/AppKit/CPApplication.j @@ -406,7 +406,7 @@ CPRunContinuesResponse = -1002; } -- (void)_documentController:(NSDocumentController *)docController didCloseAll:(BOOL)didCloseAll context:(Object)info +- (void)_documentController:(CPDocumentController)docController didCloseAll:(BOOL)didCloseAll context:(Object)info { // callback method for terminate: if (didCloseAll) diff --git a/AppKit/CPButton.j b/AppKit/CPButton.j index b70039120..1e1cd3446 100644 --- a/AppKit/CPButton.j +++ b/AppKit/CPButton.j @@ -989,5 +989,5 @@ var CPButtonImageKey = @"CPButtonImageKey", @end -@import "CPCheckBox.j" -@import "CPRadio.j" +//@import "CPCheckBox.j" +//@import "CPRadio.j" diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index e1c934f4c..588161cc9 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index cae59c446..c060bd74a 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -22,7 +22,7 @@ #import "../Foundation/Ref.h" -@import "../Foundation/CPFormatter.j" +@import @import "CPFont.j" @import "CPShadow.j" @import "CPView.j" diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 3922efe26..4e8bdf3e7 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -21,7 +21,7 @@ */ @import -@import +@import @import "CPApplication.j" @import "CPResponder.j" @@ -142,7 +142,7 @@ var CPDocumentUntitledCount = 0; @param anError not used @return the initialized document */ -- (id)initWithType:(CPString)aType error:({CPError})anError +- (id)initWithType:(CPString)aType error:(/*{*/CPError/*}*/)anError { self = [self init]; @@ -211,7 +211,7 @@ var CPDocumentUntitledCount = 0; @throws CPUnsupportedMethodException if this method hasn't been overridden by the subclass @return the document data */ -- (CPData)dataOfType:(CPString)aType error:({CPError})anError +- (CPData)dataOfType:(CPString)aType error:(/*{*/CPError/*}*/)anError { [CPException raise:CPUnsupportedMethodException reason:"dataOfType:error: must be overridden by the document subclass."]; diff --git a/AppKit/CPDocumentController.j b/AppKit/CPDocumentController.j index 8d731d2d5..96c9c3484 100644 --- a/AppKit/CPDocumentController.j +++ b/AppKit/CPDocumentController.j @@ -124,7 +124,7 @@ var CPSharedDocumentController = nil; @param anError not used @return the created document */ -- (CPDocument)makeUntitledDocumentOfType:(CPString)aType error:({CPError})anError +- (CPDocument)makeUntitledDocumentOfType:(CPString)aType error:(/*{*/CPError/*}*/)anError { return [[[self documentClassForType:aType] alloc] initWithType:aType error:anError]; } diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 450de2152..90f5a624c 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -24,7 +24,7 @@ */ @import -@import +@import @import @import diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 2d4bf62fe..20f98508e 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPMenuItem/_CPMenuItemView.j b/AppKit/CPMenuItem/_CPMenuItemView.j index e29c93a2d..288755717 100644 --- a/AppKit/CPMenuItem/_CPMenuItemView.j +++ b/AppKit/CPMenuItem/_CPMenuItemView.j @@ -1,5 +1,5 @@ -@import +@import "CPControl.j" @import "_CPMenuItemSeparatorView.j" @import "_CPMenuItemStandardView.j" diff --git a/AppKit/CPPasteboard.j b/AppKit/CPPasteboard.j index 5a898ead0..ebcfe36fb 100644 --- a/AppKit/CPPasteboard.j +++ b/AppKit/CPPasteboard.j @@ -21,7 +21,7 @@ */ @import -@import +@import @import @import diff --git a/AppKit/CPRuleEditor/CPRuleEditor.j b/AppKit/CPRuleEditor/CPRuleEditor.j index 9f30eb120..1b7c05c7c 100644 --- a/AppKit/CPRuleEditor/CPRuleEditor.j +++ b/AppKit/CPRuleEditor/CPRuleEditor.j @@ -20,13 +20,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import -@import -@import @import -@import +@import @import @import +@import "CPTextField.j" +@import "CPViewAnimation.j" +@import "CPView.j" @import "_CPRuleEditorViewSliceRow.j" @import "_CPRuleEditorLocalizer.j" diff --git a/AppKit/CPRuleEditor/_CPPredicateEditorRowNode.j b/AppKit/CPRuleEditor/_CPPredicateEditorRowNode.j index 4226d0e1c..f66c6a21f 100644 --- a/AppKit/CPRuleEditor/_CPPredicateEditorRowNode.j +++ b/AppKit/CPRuleEditor/_CPPredicateEditorRowNode.j @@ -3,7 +3,7 @@ * Copyright (c) 2011 Pear, Inc. All rights reserved. */ -@class _CPPredicateEditorTree; +//@class _CPPredicateEditorTree; @implementation _CPPredicateEditorRowNode : CPObject { _CPPredicateEditorTree tree @accessors; diff --git a/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j b/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j index e11febcc5..b5b92ea8f 100644 --- a/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j +++ b/AppKit/CPRuleEditor/_CPRuleEditorLocalizer.j @@ -77,3 +77,5 @@ var LocalizerStringsRegex = new RegExp("\"(.+)\"\\s*=\\s*\"(.+)\"\\s*;\\s*(//.+) return aString; } + +@end diff --git a/AppKit/CPSegmentedControl.j b/AppKit/CPSegmentedControl.j index 0399cf050..b85d28eaf 100644 --- a/AppKit/CPSegmentedControl.j +++ b/AppKit/CPSegmentedControl.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import "CPControl.j" diff --git a/AppKit/CPStepper.j b/AppKit/CPStepper.j index 76c7a3c9d..fd7370bfc 100644 --- a/AppKit/CPStepper.j +++ b/AppKit/CPStepper.j @@ -20,9 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import -@import -@import +@import "CPControl.j" +@import "CPButton.j" +@import "CPTextField.j" diff --git a/AppKit/CPTableColumn.j b/AppKit/CPTableColumn.j index 335da30eb..2ba2de937 100644 --- a/AppKit/CPTableColumn.j +++ b/AppKit/CPTableColumn.j @@ -27,6 +27,7 @@ @import @import "CPTableHeaderView.j" +@import "CPKeyValueBinding.j" CPTableColumnNoResizing = 0; diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 49a08a7d3..7b08b408f 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import "CGGradient.j" diff --git a/AppKit/CPTheme.j b/AppKit/CPTheme.j index 09e689ff9..e5fd49d85 100644 --- a/AppKit/CPTheme.j +++ b/AppKit/CPTheme.j @@ -21,6 +21,7 @@ */ @import +@import @import @import diff --git a/AppKit/CPTokenField.j b/AppKit/CPTokenField.j index e333e3a59..b94bc390c 100755 --- a/AppKit/CPTokenField.j +++ b/AppKit/CPTokenField.j @@ -948,7 +948,7 @@ var CPScrollDestinationNone = 0, [self interpretKeyEvents:[anEvent]]; [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; -}} +} - (void)keyUp:(CPEvent)anEvent { diff --git a/AppKit/CPToolbarItem.j b/AppKit/CPToolbarItem.j index 6c6478a0f..4f6f23a25 100644 --- a/AppKit/CPToolbarItem.j +++ b/AppKit/CPToolbarItem.j @@ -655,8 +655,8 @@ var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey", @end -@import "_CPToolbarFlexibleSpaceItem.j" +/*@import "_CPToolbarFlexibleSpaceItem.j" @import "_CPToolbarShowColorsItem.j" @import "_CPToolbarSeparatorItem.j" @import "_CPToolbarSpaceItem.j" - +*/ diff --git a/AppKit/CPUserDefaultsController.j b/AppKit/CPUserDefaultsController.j index 6aa98fe7f..4decd0ec3 100644 --- a/AppKit/CPUserDefaultsController.j +++ b/AppKit/CPUserDefaultsController.j @@ -25,7 +25,7 @@ @import -@import +@import "CPController.j" var SharedUserDefaultsController = nil; diff --git a/AppKit/CPView.j b/AppKit/CPView.j index a1b1d42ba..ba0753e26 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index f6268b4dc..f140716e8 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import "CPApplication.j" @import "CPCib.j" diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index ffd7de7e6..98f3441de 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -29,6 +29,9 @@ @import "CPPlatformWindow.j" @import "CPResponder.j" @import "CPScreen.j" +#if PLATFORM(BROWSER) +@import "CPPlatformWindow+DOM.j" +#endif /* @@ -3334,7 +3337,7 @@ CPPanelWindowShadowStyle = 2; CPCustomWindowShadowStyle = 3; -@import "_CPWindowView.j" +/*@import "_CPWindowView.j" @import "_CPStandardWindowView.j" @import "_CPDocModalWindowView.j" @import "_CPToolTipWindowView.j" @@ -3343,4 +3346,4 @@ CPCustomWindowShadowStyle = 3; @import "_CPBorderlessBridgeWindowView.j" @import "_CPAttachedWindowView.j" @import "CPDragServer.j" -@import "CPView.j" +@import "CPView.j"*/ diff --git a/AppKit/Cib/_CPCibObjectData.j b/AppKit/Cib/_CPCibObjectData.j index 2d1eecf95..87d079ec8 100644 --- a/AppKit/Cib/_CPCibObjectData.j +++ b/AppKit/Cib/_CPCibObjectData.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import diff --git a/AppKit/CoreAnimation/CAMediaTimingFunction.j b/AppKit/CoreAnimation/CAMediaTimingFunction.j index 62d20f194..80c891d79 100644 --- a/AppKit/CoreAnimation/CAMediaTimingFunction.j +++ b/AppKit/CoreAnimation/CAMediaTimingFunction.j @@ -75,7 +75,7 @@ var CAMediaNamedTimingFunctions = nil; return self; } -- (void)getControlPointAtIndex:(unsigned)anIndex values:(float[2])reference +- (void)getControlPointAtIndex:(unsigned)anIndex values:(float/*[2]*/)reference { if (anIndex == 0) { diff --git a/AppKit/Platform/CPPlatformWindow.j b/AppKit/Platform/CPPlatformWindow.j index 28a356be1..6a1188fe2 100644 --- a/AppKit/Platform/CPPlatformWindow.j +++ b/AppKit/Platform/CPPlatformWindow.j @@ -278,5 +278,5 @@ var PrimaryPlatformWindow = NULL; @end #if PLATFORM(BROWSER) -@import "CPPlatformWindow+DOM.j" +//@import "CPPlatformWindow+DOM.j" #endif diff --git a/AppKit/Platform/DOM/CPDOMWindowLayer.j b/AppKit/Platform/DOM/CPDOMWindowLayer.j index a919dcff6..5b8a0fa73 100644 --- a/AppKit/Platform/DOM/CPDOMWindowLayer.j +++ b/AppKit/Platform/DOM/CPDOMWindowLayer.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import diff --git a/AppKit/Themes/BlendKit/BKThemeDescriptor.j b/AppKit/Themes/BlendKit/BKThemeDescriptor.j index 0fbe4477c..86e56ecf9 100644 --- a/AppKit/Themes/BlendKit/BKThemeDescriptor.j +++ b/AppKit/Themes/BlendKit/BKThemeDescriptor.j @@ -21,6 +21,9 @@ */ @import +@import +@import +@import var ItemSizes = { }, diff --git a/AppKit/_CPAutocompleteMenu.j b/AppKit/_CPAutocompleteMenu.j index 2aaafd81f..59a8bef3a 100644 --- a/AppKit/_CPAutocompleteMenu.j +++ b/AppKit/_CPAutocompleteMenu.j @@ -23,6 +23,7 @@ @import @import "CPTextField.j" +@import "CPTableView.j" @import "_CPMenuWindow.j" // TODO Make themable. diff --git a/AppKit/_CPPopUpList.j b/AppKit/_CPPopUpList.j index 10f66136f..fd6cfa920 100644 --- a/AppKit/_CPPopUpList.j +++ b/AppKit/_CPPopUpList.j @@ -21,6 +21,7 @@ */ @import "CPTableView.j" +@import "CPPanel.j" @import "_CPPopUpListDataSource.j" diff --git a/Foundation/CPArray+KVO.j b/Foundation/CPArray+KVO.j index fc65294ef..a5b52bf9c 100644 --- a/Foundation/CPArray+KVO.j +++ b/Foundation/CPArray+KVO.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPArray.j" +@import "_CPJavaScriptArray.j" @import "CPNull.j" @import "_CPCollectionKVCOperators.j" diff --git a/Foundation/CPArray/CPArray.j b/Foundation/CPArray/CPArray.j index d835196ad..2f38e3faf 100755 --- a/Foundation/CPArray/CPArray.j +++ b/Foundation/CPArray/CPArray.j @@ -1015,4 +1015,4 @@ var _CPSharedPlaceholderArray = nil; @end -@import "_CPJavaScriptArray.j" +//@import "_CPJavaScriptArray.j" diff --git a/Foundation/CPCountedSet.j b/Foundation/CPCountedSet.j index cb5c13953..034714b08 100644 --- a/Foundation/CPCountedSet.j +++ b/Foundation/CPCountedSet.j @@ -21,7 +21,7 @@ */ @import "CPObject.j" -@import "CPSet.j" +@import "_CPConcreteMutableSet.j" /*! @class CPCountedSet diff --git a/Foundation/CPDateFormatter.j b/Foundation/CPDateFormatter.j index 2e52fa725..0dd9d4062 100644 --- a/Foundation/CPDateFormatter.j +++ b/Foundation/CPDateFormatter.j @@ -22,9 +22,9 @@ #import "Ref.h" -@import -@import -@import +@import "CPDate.j" +@import "CPString.j" +@import "CPFormatter.j" CPDateFormatterNoStyle = 0; CPDateFormatterShortStyle = 1; diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index e63313c75..05933558a 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPArray.j" +@import "_CPJavaScriptArray.j" @import "CPEnumerator.j" @import "CPException.j" @import "CPNull.j" @@ -322,7 +322,7 @@ */ - (int)count { - return _count; + return self._count; } /*! @@ -330,7 +330,7 @@ */ - (CPArray)allKeys { - return [_keys copy]; + return [self._keys copy]; } /*! @@ -338,11 +338,12 @@ */ - (CPArray)allValues { - var index = _keys.length, + var keys = self._keys, + index = keys.length, values = []; while (index--) - values.push(self.valueForKey(_keys[index])); + values.push(self.valueForKey(keys[index])); return values; } @@ -357,7 +358,8 @@ */ - (CPArray)allKeysForObject:(id)anObject { - var count = _keys.length, + var keys = self._keys, + count = keys.length, index = 0, matchingKeys = [], key = nil, @@ -365,8 +367,8 @@ for (; index < count; ++index) { - key = _keys[index]; - value = _buckets[key]; + key = keys[index]; + value = self._buckets[key]; if (value.isa && anObject && anObject.isa && [value respondsToSelector:@selector(isEqual:)] && [value isEqual:anObject]) matchingKeys.push(key); @@ -384,16 +386,18 @@ - (CPArray)keysOfEntriesWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id key, id obj, @ref BOOL stop)*/)predicate { + var keys = self._keys; + if (options & CPEnumerationReverse) { - var index = [_keys count] - 1, + var index = [keys count] - 1, stop = -1, increment = -1; } else { var index = 0, - stop = [_keys count], + stop = [keys count], increment = 1; } @@ -405,8 +409,8 @@ for (; index !== stop; index += increment) { - key = _keys[index]; - value = _buckets[key]; + key = keys[index]; + value = self._buckets[key]; if (predicate(key, value, stopRef)) matchingKeys.push(key); @@ -447,7 +451,7 @@ */ - (CPEnumerator)keyEnumerator { - return [_keys objectEnumerator]; + return [self._keys objectEnumerator]; } /*! @@ -471,12 +475,13 @@ if (count !== [aDictionary count]) return NO; - var index = count; + var index = count, + keys = self._keys; while (index--) { - var currentKey = _keys[index], - lhsObject = _buckets[currentKey], + var currentKey = keys[index], + lhsObject = self._buckets[currentKey], rhsObject = aDictionary._buckets[currentKey]; if (lhsObject === rhsObject) @@ -532,7 +537,7 @@ */ - (id)objectForKey:(id)aKey { - var object = _buckets[aKey]; + var object = self._buckets[aKey]; return (object === undefined) ? nil : object; } @@ -634,9 +639,9 @@ - (CPString)description { var string = "@{\n", - keys = _keys, + keys = self._keys, index = 0, - count = _count; + count = self._count; for (; index < count; ++index) { @@ -658,11 +663,13 @@ - (void)enumerateKeysAndObjectsUsingBlock:(Function /*(id aKey, id anObject, @ref BOOL stop)*/)aFunction { var shouldStop = NO, - shouldStopRef = AT_REF(shouldStop); + shouldStopRef = AT_REF(shouldStop), + keys = self._keys, + count = self._count; - for (var index = 0; index < _count; index++) + for (var index = 0; index < count; index++) { - var key = _keys[index], + var key = keys[index], value = valueForKey(key); aFunction(key, value, shouldStopRef); diff --git a/Foundation/CPException.j b/Foundation/CPException.j index 48594cdb4..8b0d99342 100755 --- a/Foundation/CPException.j +++ b/Foundation/CPException.j @@ -46,6 +46,8 @@ if (input == nil) @implementation CPException : CPObject { id _userInfo; + CPString name; + CPString message; } /* diff --git a/Foundation/CPLog.j b/Foundation/CPLog.j index 26e5e5839..4a5b7a38f 100644 --- a/Foundation/CPLog.j +++ b/Foundation/CPLog.j @@ -1 +1,2 @@ // placeholder. moved to Objective-J/CPLog.js +1; // Dummy row! To fool when reading from gcc who removes all comments and whitespaces and makes this file empty. Empty file == no file -> Error diff --git a/Foundation/CPNumberFormatter.j b/Foundation/CPNumberFormatter.j index ec6a5b177..bcede4ff9 100644 --- a/Foundation/CPNumberFormatter.j +++ b/Foundation/CPNumberFormatter.j @@ -22,9 +22,9 @@ #import "Ref.h" -@import -@import -@import +@import "CPString.j" +@import "CPFormatter.j" +@import "CPDecimalNumber.j" #define UPDATE_NUMBER_HANDLER_IF_NECESSARY() if (!_numberHandler) \ _numberHandler = [CPDecimalNumberHandler decimalNumberHandlerWithRoundingMode:_roundingMode scale:_maximumFractionDigits raiseOnExactness:NO raiseOnOverflow:NO raiseOnUnderflow:NO raiseOnDivideByZero:YES]; diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 5590a2048..583638f32 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -154,7 +154,7 @@ CPLog(@"Got some class: %@", inst); */ + (Class)superclass { - return super_class; + return self.super_class; } /*! @@ -484,7 +484,7 @@ CPLog(@"Got some class: %@", inst); if (typeof self._UID === "undefined") self._UID = objj_generateObjectUID(); - return _UID + ""; + return self._UID + ""; } /*! diff --git a/Foundation/CPPredicate/CPExpression.j b/Foundation/CPPredicate/CPExpression.j index ffccea30e..5a9561cb7 100644 --- a/Foundation/CPPredicate/CPExpression.j +++ b/Foundation/CPPredicate/CPExpression.j @@ -387,11 +387,11 @@ CPMinusSetExpressionType = 9; @end -@import "_CPConstantValueExpression.j" -@import "_CPSelfExpression.j" -@import "_CPVariableExpression.j" -@import "_CPKeyPathExpression.j" -@import "_CPFunctionExpression.j" -@import "_CPAggregateExpression.j" -@import "_CPSetExpression.j" -@import "_CPSubqueryExpression.j" +//@import "_CPConstantValueExpression.j" +//@import "_CPSelfExpression.j" +//@import "_CPVariableExpression.j" +//@import "_CPKeyPathExpression.j" +//@import "_CPFunctionExpression.j" +//@import "_CPAggregateExpression.j" +//@import "_CPSetExpression.j" +//@import "_CPSubqueryExpression.j" diff --git a/Foundation/CPPredicate/CPPredicate.j b/Foundation/CPPredicate/CPPredicate.j index 36c5b2002..3a97a1a1c 100644 --- a/Foundation/CPPredicate/CPPredicate.j +++ b/Foundation/CPPredicate/CPPredicate.j @@ -970,6 +970,6 @@ var CPRaiseParseError = function CPRaiseParseError(aScanner, target) [CPException raise:CPInvalidArgumentException reason:@"unable to parse " + target + " at index " + [aScanner scanLocation]]; }; -@import "CPCompoundPredicate.j" -@import "CPComparisonPredicate.j" -@import "CPExpression.j" +//@import "CPCompoundPredicate.j" +//@import "CPComparisonPredicate.j" +//@import "CPExpression.j" diff --git a/Foundation/CPPredicate/_CPKeyPathExpression.j b/Foundation/CPPredicate/_CPKeyPathExpression.j index e60e8f331..53b1cfc2e 100644 --- a/Foundation/CPPredicate/_CPKeyPathExpression.j +++ b/Foundation/CPPredicate/_CPKeyPathExpression.j @@ -26,6 +26,7 @@ @import "_CPFunctionExpression.j" @import "CPKeyValueCoding.j" @import "CPString.j" +@import "_CPConstantValueExpression.j" @implementation _CPKeyPathExpression : _CPFunctionExpression { diff --git a/Foundation/CPProxy.j b/Foundation/CPProxy.j index e935ad344..98e0aa50f 100644 --- a/Foundation/CPProxy.j +++ b/Foundation/CPProxy.j @@ -27,6 +27,7 @@ @implementation CPProxy { + Class isa; } + (void)load @@ -80,7 +81,7 @@ if (typeof self._UID === "undefined") self._UID = objj_generateObjectUID(); - return _UID; + return self._UID; } - (BOOL)isEqual:(id)anObject diff --git a/Foundation/CPSet+KVO.j b/Foundation/CPSet+KVO.j index 4af539b36..6153cf5d1 100644 --- a/Foundation/CPSet+KVO.j +++ b/Foundation/CPSet+KVO.j @@ -22,7 +22,7 @@ @import "CPException.j" @import "CPObject.j" -@import "CPSet.j" +@import "CPMutableSet.j" @import "_CPCollectionKVCOperators.j" @implementation CPObject (CPSetKVO) diff --git a/Foundation/CPSet/CPMutableSet.j b/Foundation/CPSet/CPMutableSet.j index 79b76aee0..0458c636f 100644 --- a/Foundation/CPSet/CPMutableSet.j +++ b/Foundation/CPSet/CPMutableSet.j @@ -146,4 +146,4 @@ @end -@import "_CPConcreteMutableSet.j" +//@import "_CPConcreteMutableSet.j" diff --git a/Foundation/CPSet/CPSet.j b/Foundation/CPSet/CPSet.j index 4c0773bb4..078e29c34 100644 --- a/Foundation/CPSet/CPSet.j +++ b/Foundation/CPSet/CPSet.j @@ -511,4 +511,4 @@ var _CPSharedPlaceholderSet = nil; // We actually want _CPConcreteMutableSet, but this introduces the possibility of an invalid @import loop. // This will be correctly solved when we move to true immutable/mutable pairs. -@import "CPMutableSet.j" +//@import "CPMutableSet.j" diff --git a/Foundation/CPURLConnection.j b/Foundation/CPURLConnection.j index db8198ff9..e4a48a1df 100644 --- a/Foundation/CPURLConnection.j +++ b/Foundation/CPURLConnection.j @@ -94,7 +94,7 @@ var CPURLConnectionDelegate = nil; @param anError not used @return the data at the URL or \c nil if there was an error */ -+ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:({CPURLResponse})aURLResponse ++ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(/*{*/CPURLResponse/*}*/)aURLResponse { try { @@ -276,7 +276,7 @@ var CPURLConnectionDelegate = nil; @implementation CPURLConnection (Deprecated) -+ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:({CPURLResponse})aURLResponse error:(id)anError ++ (CPData)sendSynchronousRequest:(CPURLRequest)aRequest returningResponse:(/*{*/CPURLResponse/*}*/)aURLResponse error:(id)anError { _CPReportLenientDeprecation(self, _cmd, @selector(sendSynchronousRequest:returningResponse:)); diff --git a/Foundation/CPValueTransformer.j b/Foundation/CPValueTransformer.j index 69090a51a..1802a2bc0 100644 --- a/Foundation/CPValueTransformer.j +++ b/Foundation/CPValueTransformer.j @@ -43,10 +43,10 @@ var transformerMap = [CPDictionary dictionary]; if (self !== [CPValueTransformer class]) return; - [CPValueTransformer setValueTransformer:[[CPNegateBooleanTransformer alloc] init] forName:CPNegateBooleanTransformerName]; - [CPValueTransformer setValueTransformer:[[CPIsNilTransformer alloc] init] forName:CPIsNilTransformerName]; - [CPValueTransformer setValueTransformer:[[CPIsNotNilTransformer alloc] init] forName:CPIsNotNilTransformerName]; - [CPValueTransformer setValueTransformer:[[CPUnarchiveFromDataTransformer alloc] init] forName:CPUnarchiveFromDataTransformerName]; +// [CPValueTransformer setValueTransformer:[[CPNegateBooleanTransformer alloc] init] forName:CPNegateBooleanTransformerName]; +// [CPValueTransformer setValueTransformer:[[CPIsNilTransformer alloc] init] forName:CPIsNilTransformerName]; +// [CPValueTransformer setValueTransformer:[[CPIsNotNilTransformer alloc] init] forName:CPIsNotNilTransformerName]; +// [CPValueTransformer setValueTransformer:[[CPUnarchiveFromDataTransformer alloc] init] forName:CPUnarchiveFromDataTransformerName]; } + (void)setValueTransformer:(CPValueTransformer)transformer forName:(CPString)aName @@ -192,3 +192,8 @@ CPIsNilTransformerName = @"CPIsNil"; CPIsNotNilTransformerName = @"CPIsNotNil"; CPUnarchiveFromDataTransformerName = @"CPUnarchiveFromData"; CPKeyedUnarchiveFromDataTransformerName = @"CPKeyedUnarchiveFromData"; + + [CPValueTransformer setValueTransformer:[[CPNegateBooleanTransformer alloc] init] forName:CPNegateBooleanTransformerName]; + [CPValueTransformer setValueTransformer:[[CPIsNilTransformer alloc] init] forName:CPIsNilTransformerName]; + [CPValueTransformer setValueTransformer:[[CPIsNotNilTransformer alloc] init] forName:CPIsNotNilTransformerName]; + [CPValueTransformer setValueTransformer:[[CPUnarchiveFromDataTransformer alloc] init] forName:CPUnarchiveFromDataTransformerName]; diff --git a/Foundation/Foundation.j b/Foundation/Foundation.j index 422501616..be4f44fde 100755 --- a/Foundation/Foundation.j +++ b/Foundation/Foundation.j @@ -75,6 +75,8 @@ @import "CPValue.j" @import "CPValueTransformer.j" +@import "_CPJavaScriptArray.j" + /*! @mainpage Cappuccino is distributed under the @ref license "GNU LGPL". diff --git a/Foundation/_CPCollectionKVCOperators.j b/Foundation/_CPCollectionKVCOperators.j index f2be4101d..7046fe58f 100644 --- a/Foundation/_CPCollectionKVCOperators.j +++ b/Foundation/_CPCollectionKVCOperators.j @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPObject.j" + @implementation _CPCollectionKVCOperator : CPObject + (id)performOperation:(CPString)operator withCollection:(id)aCollection propertyPath:(CPString)propertyPath diff --git a/Objective-J/CFBundle.js b/Objective-J/CFBundle.js index 44280e871..0faec4273 100644 --- a/Objective-J/CFBundle.js +++ b/Objective-J/CFBundle.js @@ -106,6 +106,15 @@ function addClassToBundle(aClass, aBundle) CFBundlesForClasses[aClass.name] = aBundle; } +function resetBundle() +{ + CFBundlesForURLStrings = { }; + CFBundlesForClasses = { }; + //CFCacheBuster = new Date().getTime(), + CFTotalBytesLoaded = 0; + CPApplicationSizeInBytes = 0; +} + CFBundle.bundleForClass = function(/*Class*/ aClass) { return CFBundlesForClasses[aClass.name] || CFBundle.mainBundle(); diff --git a/Objective-J/CFHTTPRequest.js b/Objective-J/CFHTTPRequest.js index 6d57fc3da..ceb61120e 100644 --- a/Objective-J/CFHTTPRequest.js +++ b/Objective-J/CFHTTPRequest.js @@ -300,6 +300,36 @@ function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure) if (aURL.pathExtension() === "plist") request.overrideMimeType("text/xml"); +#if COMMONJS + if (aURL.pathExtension() === "j") + { + var FILE = require("file"), + FileList = require("jake").FileList, + aFilePath = aURL.toString().substring(5); + + var OS = require("os"), + gccFlags = require("objective-j").currentCompilerFlags(), +// gcc = OS.popen("gcc -E -x c -P -DPLATFORM_COMMONJS " + INCLUDES + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), + gcc = OS.popen("gcc -E -x c -P " + (gccFlags ? gccFlags : "") + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), + chunk, + fileContents = ""; + + while (chunk = gcc.stdout.read()) + fileContents += chunk; + + if (fileContents.length > 0) + { + request._nativeRequest.responseText = fileContents; + onsuccess({request: request}); + } + else + { + onfailure({request: request}); + } + return; + } +#endif + if (exports.asyncLoader) { request.onsuccess = Asynchronous(onsuccess); diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 8b0d4e2f5..6e4658155 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -149,13 +149,14 @@ exports.repl = function() }; // creates a narwhal factory function in the objj module scope -exports.make_narwhal_factory = function(path) +exports.make_narwhal_factory = function(path, basePath, filenameTranslateDictionary) { return function(require, exports, module, system, print) { Executable.setCommonJSParameters("require", "exports", "module", "system", "print", "window"); Executable.setCommonJSArguments(require, exports, module, system, print, window); - Executable.fileImporterForURL(FILE.dirname(path))(path, YES); + filenameTranslateDictionary && Executable.setFilenameTranslateDictionary(filenameTranslateDictionary); + Executable.fileImporterForURL(basePath ? basePath : FILE.dirname(path))(path, YES); } }; diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 156c855ab..eb73ef14b 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -789,7 +789,13 @@ BundleTask.prototype.defineStaticTask = function() fileStream.write("e;"); fileStream.close(); - }); + + // Make sure all classes are removed and all FileExecutables are removed. + require("objective-j").Executable.resetCachedFileExecutableSearchers(); + require("objective-j").StaticResource.resetRootResources(); + require("objective-j").FileExecutable.resetFileExecutables(); + objj_resetRegisterClasses(); + }); this.enhance([staticPath]); }, this); @@ -797,7 +803,7 @@ BundleTask.prototype.defineStaticTask = function() BundleTask.prototype.defineSourceTasks = function() { - var sources = this.sources(); + var sources = this.sources(); if (!sources) return; @@ -832,7 +838,18 @@ BundleTask.prototype.defineSourceTasks = function() environmentCompilerFlags = anEnvironment.compilerFlags().join(" ") + " " + compilerFlags, flattensSources = this.flattensSources(), basePath = directoryInCommon(environmentSources), - basePathLength = basePath.length; + basePathLength = basePath.length, + translateFilenameToPath = {}, + otherwayTranslateFilenameToPath = {}; + + // Create a filename to filename path dictionary. (For example: CPArray.j -> CPArray/CPArray.j) + environmentSources.forEach(function(/*String*/ aFilename) + { + translateFilenameToPath[flattensSources ? FILE.basename(aFilename) : aFilename] = aFilename; + otherwayTranslateFilenameToPath[aFilename] = flattensSources ? FILE.basename(aFilename) : aFilename; + }, this); + + var e = {}; environmentSources.forEach(function(/*String*/ aFilename) { @@ -853,8 +870,21 @@ BundleTask.prototype.defineSourceTasks = function() } else { + var translatedFilename = translateFilenameToPath[aFilename] ? translateFilenameToPath[aFilename] : aFilename, + otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilename] ? otherwayTranslateFilenameToPath[aFilename] : aFilename, + theTranslatedFilename = otherwayTranslatedFilename ? otherwayTranslatedFilename : translatedFilename, + absolutePath = FILE.absolute(theTranslatedFilename), + basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length); + + require("objective-j").setCurrentCompilerFlags(environmentCompilerFlags); + require("objective-j").make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print, window); TERM.stream.write("Compiling [\0blue(" + anEnvironment + "\0)] \0purple(" + aFilename + "\0)").flush(); - var compiled = require("objective-j/compiler").compile(aFilename, environmentCompilerFlags); + + var otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilename] ? otherwayTranslateFilenameToPath[aFilename] : aFilename, + translatedFilename = translateFilenameToPath[aFilename] ? translateFilenameToPath[aFilename] : aFilename, + executer = new require("objective-j").FileExecutable(otherwayTranslatedFilename); + + var compiled = executer.toMarkedString(); } TERM.stream.print(Array(Math.round(compiled.length / 1024) + 3).join(".")); @@ -863,11 +893,12 @@ BundleTask.prototype.defineSourceTasks = function() filedir (staticPath, [compiledEnvironmentSource]); + replacedFiles.push(flattensSources ? FILE.basename(aFilename) : relativePath); }, this); this._replacedFiles[anEnvironment] = replacedFiles; - }, this); + }, this); } exports.BundleTask = BundleTask; diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index ea38196e6..3885691eb 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -26,7 +26,7 @@ var ExecutableUnloadedFileDependencies = 0, ExecutableLoadedFileDependencies = 2, AnonymousExecutableCount = 0; -function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction, /*ObjJCompiler*/aCompiler) +function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String*/ aURL, /*Function*/ aFunction, /*ObjJCompiler*/aCompiler, /*Dictionary*/ aFilenameTranslateDictionary) { if (arguments.length === 0) return this; @@ -38,6 +38,7 @@ function Executable(/*String*/ aCode, /*Array*/ fileDependencies, /*CFURL|String this._compiler = aCompiler || null; this._fileDependencies = fileDependencies; + this._filenameTranslateDictionary = aFilenameTranslateDictionary; if (fileDependencies.length) { @@ -117,6 +118,17 @@ Executable.commonJSArguments = function() return this._commonJSArguments || []; }; +Executable.setFilenameTranslateDictionary = function(dict) +{ + this._filenameTranslateDictionary = dict; +}; + +Executable.filenameTranslateDictionary = function() +{ + return this._filenameTranslateDictionary || {}; +}; + + Executable.prototype.toMarkedString = function() { var markedString = "@STATIC;1.0;", @@ -139,26 +151,25 @@ Executable.prototype.execute = function() CPLog("EXECUTION: " + this.URL()); #endif + var fileDependencies = this.fileDependencies(), + index = 0, + count = fileDependencies.length; + + for (; index < count; ++index) + { + var fileDependency = fileDependencies[index], + isQuoted = fileDependency.isLocal(), + URL = fileDependency.URL(); + + this.fileExecuter()(URL, isQuoted); + } + if (this._compiler) { - var fileDependencies = this.fileDependencies(), - index = 0, - count = fileDependencies.length; - - for (; index < count; ++index) - { - var fileDependency = fileDependencies[index], - isQuoted = fileDependency.isLocal(), - URL = fileDependency.URL(); - - CPLog("Execute FileDependant: " + URL); - objj_executeFile(URL, isQuoted); - } - - CPLog("Compile Pass 2: " + this.URL()); this.setCode(this._compiler.compilePass2()); + this._compiler = null; } - + var oldContextBundle = CONTEXT_BUNDLE; // FIXME: Should we have stored this? @@ -434,10 +445,30 @@ DISPLAY_NAME(Executable.fileImporterForURL); var cachedFileExecutableSearchers = { }, cachedFileExecutableSearchResults = { }; +function countProp(x) { + var count = 0; + for (var k in x) { + if (x.hasOwnProperty(k)) { + ++count; + } + } + return count; +} + +Executable.resetCachedFileExecutableSearchers = function() +{ + cachedFileExecutableSearchers = { }; + cachedFileExecutableSearchResults = { }; + cachedFileImporters = { }; + cachedFileExecuters = { }; + fileDependencyMarkers = { }; +} + Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) { var referenceURLString = referenceURL.absoluteString(), cachedFileExecutableSearcher = cachedFileExecutableSearchers[referenceURLString], + aFilenameTranslateDictionary = this.filenameTranslateDictionary(); cachedSearchResults = { }; if (!cachedFileExecutableSearcher) @@ -457,7 +488,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) if (!isAbsoluteURL) aURL = new CFURL(aURL, referenceURL); - StaticResource.resolveResourceAtURL(aURL, NO, completed); + StaticResource.resolveResourceAtURL(aURL, NO, completed, aFilenameTranslateDictionary); } else StaticResource.resolveResourceAtURLSearchingIncludeURLs(aURL, completed); @@ -465,11 +496,11 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) function completed(/*StaticResource*/ aStaticResource) { if (!aStaticResource) - throw new Error("Could not load file at " + aURL); + throw new Error("Could not load file at " + aURL); cachedFileExecutableSearchResults[cacheUID] = aStaticResource; - success(new FileExecutable(aStaticResource.URL())); + success(new FileExecutable(aStaticResource.URL(), aFilenameTranslateDictionary)); } }; diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 4e5f59f1e..cb355e031 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -22,7 +22,7 @@ var FileExecutablesForURLStrings = { }; -function FileExecutable(/*CFURL|String*/ aURL) +function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslateDictionary) { aURL = makeAbsoluteURL(aURL); @@ -41,7 +41,7 @@ function FileExecutable(/*CFURL|String*/ aURL) if (fileContents.match(/^@STATIC;/)) executable = decompile(fileContents, aURL); - else if (extension === "j" || !extension) { + else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) { // console.log("Compile: " + aURL); // if (!aURL || aURL.toString().indexOf("Boplats/Office/Applications") === -1) // executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); @@ -51,7 +51,7 @@ function FileExecutable(/*CFURL|String*/ aURL) else executable = new Executable(fileContents, [], aURL); - Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler]); + Executable.apply(this, [executable.code(), executable.fileDependencies(), aURL, executable._function, executable._compiler, aFilenameTranslateDictionary]); this._hasExecuted = NO; } @@ -74,6 +74,12 @@ FileExecutable.allFileExecutables = function() } #endif +FileExecutable.resetFileExecutables = function() +{ + FileExecutablesForURLStrings = { }; + FunctionCache = { }; +} + FileExecutable.prototype.execute = function(/*BOOL*/ shouldForce) { if (this._hasExecuted && !shouldForce) diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index 5506ba990..87d2d8970 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -27,7 +27,8 @@ }*/ //var FileDependency = {}; // Dummy declaration !!!!!!! REMOVE!!!!!!!! -var ObjJCompiler = { }; +var ObjJCompiler = { }, + currentCompilerFlags = ""; //(function(global, exports, module) //{ @@ -80,22 +81,36 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla aString = aString.replace(/^#[^\n]+\n/, "\n"); this._URL = new CFURL(aURL); this._pass = pass; - // If this is pass one we should not save anything in buffers + // If this is pass one we should not save anything in javascript buffer if (pass === 1) this._jsBuffer = null; else this._jsBuffer = new StringBuffer(); this._imBuffer = null; this._cmBuffer = null; - console.time("Parse - " + aURL); + var start = new Date().getTime(); + //console.time("Parse - " + aURL); this._tokens = exports.Parser.parse(aString); - console.timeEnd("Parse - " + aURL); + var end = new Date().getTime(); + var time = (end - start) / 1000; + //print("Parse: " + aURL + " in " + time + " seconds"); + //console.timeEnd("Parse - " + aURL); this._dependencies = []; this._flags = flags | ObjJCompiler.Flags.IncludeDebugSymbols; this._classDefs = {}; - console.time("Compile" + pass + " - " + aURL); + var start = new Date().getTime(); +// console.time("Compile" + pass + " - " + aURL); + try { this.nodeDocument(this._tokens); - console.timeEnd("Compile" + pass + " - " + aURL); + } + catch (e) { + print("Error: " + e + ", file content: " + aString); + throw e; + } + var end = new Date().getTime(); + var time = (end - start) / 1000; + //print("Compile pass 1: " + aURL + " in " + time + " seconds"); +// console.timeEnd("Compile" + pass + " - " + aURL); // console.log("JS: " + this._jsBuffer); } @@ -103,14 +118,29 @@ ObjJCompiler.prototype.compilePass2 = function() { this._pass = 2; this._jsBuffer = new StringBuffer(); - console.time("Compile" + this._pass + " - " + this._URL); + //print("Start Compile2: " + this._URL); + var start = new Date().getTime(); +// console.time("Compile" + this._pass + " - " + this._URL); this.nodeDocument(this._tokens); - console.timeEnd("Compile" + this._pass + " - " + this._URL); - return this._jsBuffer; + var end = new Date().getTime(); + var time = (end - start) / 1000; + //print("Compile pass 2: " + this._URL + " in " + time + " seconds"); +// console.timeEnd("Compile" + this._pass + " - " + this._URL); + return this._jsBuffer.toString(); } exports.ObjJCompiler = ObjJCompiler; +exports.setCurrentCompilerFlags = function(/*String*/ compilerFlags) +{ + currentCompilerFlags = compilerFlags; +} + +exports.currentCompilerFlags = function(/*String*/ compilerFlags) +{ + return currentCompilerFlags; +} + ObjJCompiler.Flags = { }; ObjJCompiler.Flags.IncludeDebugSymbols = 1 << 0; @@ -1228,7 +1258,8 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast var className = this.nodeIdentifier(children[2]), superClassName = null, - classDef = null; + classDef = null, + isCategoryDeclaration = false; this.nodeUnderline(children[3], false); @@ -1251,6 +1282,7 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast } else if (child && child.name === ObjJCompiler.AstNodeCategoryDeclaration) { + isCategoryDeclaration = true; this.nodeCategoryDeclaration(child); offset++; @@ -1265,6 +1297,15 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast CONCAT(saveJSBuffer, "var meta_class = the_class.isa;"); } } + else + { + classDef = {"className": className, "superClassName": null, "ivars": {}, "methods": {}}; + + this._classDefs[className] = classDef; + + if (saveJSBuffer) + CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(Nil, \"" + className + "\"),\nmeta_class = the_class.isa;"); + } this._currentSuperClass = "objj_getClass(\"" + className + "\").super_class"; this._currentSuperMetaClass = "objj_getMetaClass(\"" + className + "\").super_class"; @@ -1387,10 +1428,12 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast this.nodeEND(children[8 + offset]); this.nodeEOS(children[9 + offset]); - // We must make a new class object for our class definition. if (saveJSBuffer) { - CONCAT(saveJSBuffer, "objj_registerClassPair(the_class);\n"); + // We must make a new class object for our class definition. + if (!isCategoryDeclaration) { + CONCAT(saveJSBuffer, "objj_registerClassPair(the_class);\n"); + } if (IS_NOT_EMPTY(this._imBuffer)) { @@ -1573,8 +1616,11 @@ ObjJCompiler.prototype.nodeAccessorsConfiguration = function(/*SyntaxNode*/ astN case ObjJCompiler.AstNodeIvarSetterName: return {"setter": this.nodeIvarSetterName(child)}; default: - this.nodeREADONLY(child); - return {"readonly": true}; + // Here we accept anything the parser accepts: "readonly", "copy" or "readwrite" + this.nodeWORD(child); + var r = {}; + r[child] = true; + return r; } } @@ -1764,8 +1810,8 @@ ObjJCompiler.prototype.genericMethodDeclaration = function(/*SyntaxNode*/ astNod } this.nodeUnderline(children[4 + offset], false); this.nodeOpenBrace(children[5 + offset]); - this._jsBuffer = buffer; // Now write the FunctionBody to buffer this.nodeUnderline(children[6 + offset], false); + this._jsBuffer = buffer; // Now write the FunctionBody to buffer this.nodeFunctionBody(children[7 + offset]); this._jsBuffer = null; // Turn back off again so nothing is written this.nodeUnderline(children[8 + offset], false); @@ -1873,7 +1919,8 @@ ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) var children = astNode.children, child = children[2], size = children.length, - methodTypes = []; + methodTypes = [], + offset = 3; this.nodeOpenParenthesis(children[0]); this.nodeUnderline(children[1], false); @@ -1881,16 +1928,39 @@ ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) if (child && child.name === ObjJCompiler.AstNodeACTION) methodTypes.push(this.nodeACTION(child)); else + { methodTypes.push(this.nodeIdentifierName(child)); + if (children[4] === "<") + { + this.nodeUnderline(children[3], false); + this.nodeWORD(children[4]); // "<" + this.nodeUnderline(children[5], false); + this.nodeIdentifierName(children[6]); + this.nodeUnderline(children[7], false); + this.nodeWORD(children[8]); // ">" + offset += 6; + } + } - for (var i = 3; i + 1 < size - 2; i += 2) + for (var i = offset; i + 1 < size - 2; i += 2) { this.nodeUnderline(children[i], true); child = children[i + 1]; if (child && child.name === ObjJCompiler.AstNodeACTION) methodTypes.push(this.nodeACTION(child)); else + { methodTypes.push(this.nodeIdentifierName(child)); + if (i + 7 < size && children[i + 3] === "<") + { + this.nodeUnderline(children[i++ + 2], false); + this.nodeWORD(children[i++ + 2]); // "<" + this.nodeUnderline(children[i++ + 2], false); + this.nodeIdentifierName(children[i++ + 2]); + this.nodeUnderline(children[i++ + 2], false); + this.nodeWORD(children[i++ + 2]); // ">" + } + } } this.nodeUnderline(children[size - 2], false); @@ -2571,13 +2641,13 @@ ObjJCompiler.prototype.nodeArgumentList = function(/*SyntaxNode*/ astNode) size = children.length; this.nodeAssignmentExpression(children[0]); - this.nodeUnderline(children[1], false); - for (var i = 2; i + 2 < size; i += 3) + for (var i = 1; i + 3 < size; i += 4) { - this.nodeCOMMA(children[i]); - this.nodeUnderline(children[i + 1], false); - this.nodeAssignmentExpression(children[i + 2]); + this.nodeUnderline(children[i], false); + this.nodeCOMMA(children[i + 1]); + this.nodeUnderline(children[i + 2], false); + this.nodeAssignmentExpression(children[i + 3]); } } @@ -3387,7 +3457,7 @@ ObjJCompiler.prototype.nodeRegularExpressionClass = function(/*SyntaxNode*/ astN while (child && child.name === ObjJCompiler.AstNodeRegularExpressionClassChar) { regString += this.nodeRegularExpressionClassChar(children[offset++]); - child = children[++offset]; + child = children[offset]; } return regString + this.nodeWORD(child); @@ -4017,11 +4087,6 @@ ObjJCompiler.prototype.nodeSETTER = function(/*SyntaxNode*/ astNode) return this.nodeWORD(astNode); } -ObjJCompiler.prototype.nodeREADONLY = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - ObjJCompiler.prototype.nodeLESSTHEN = function(/*SyntaxNode*/ astNode) { return this.nodeWORD(astNode); diff --git a/Objective-J/Parser.js b/Objective-J/Parser.js index 39f3aba60..4859744ba 100644 --- a/Objective-J/Parser.js +++ b/Objective-J/Parser.js @@ -1,7 +1,7 @@ var Parser = { }; -var compiledGrammar = {"table":[[0,"source",1],[0,"start",2],[4,3,4,3],[0,"_",5],[8,6],[6,7],[0,"SourceElements",8],[3,9,10,11],[4,12,13],[0,"WhiteSpace",14],[0,"LineTerminator",15],[0,"Comment",16],[0,"SourceElement",17],[6,18],[2,"[\\u0009\\u000B\\u000C\\u0020\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"],[2,"[\\u000A\\u000D\\u2028\\u2029]"],[3,19,20],[3,21,22],[4,3,12],[0,"MultiLineComment",23],[0,"SingleLineComment",24],[0,"Statement",25],[0,"FunctionDeclaration",26],[4,27,28,29],[4,30,31],[3,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,22,47,48,49],[4,50,3,51,3,52,3,53,3,54,3,55,3,56,3,57],[5,"/*"],[6,58],[5,"*/"],[5,"//"],[6,59],[0,"Block",60],[0,"VariableStatement",61],[0,"EmptyStatement",62],[0,"ExpressionStatement",63],[0,"IfStatement",64],[0,"IterationStatement",65],[0,"ContinueStatement",66],[0,"BreakStatement",67],[0,"ReturnStatement",68],[0,"WithStatement",69],[0,"LabelledStatement",70],[0,"SwitchStatement",71],[0,"ThrowStatement",72],[0,"TryStatement",73],[0,"DebuggerStatement",74],[0,"FunctionExpression",75],[0,"ImportStatement",76],[0,"ClassDeclarationStatement",77],[0,"FUNCTION",78],[0,"Identifier",79],[5,"("],[8,80],[5,")"],[5,"{"],[0,"FunctionBody",2],[5,"}"],[4,81,82],[0,"SingleLineCommentChar",83],[4,55,3,84,3,57],[4,85,3,86,87,88],[5,";"],[4,89,90,88],[4,91,3,52,3,90,3,54,3,21,92],[3,93,94,95,96,97],[4,98,99,100],[4,101,99,100],[4,102,99,103],[4,104,3,52,3,90,3,54,3,21],[4,51,3,105,3,21],[4,106,3,52,3,90,3,54,3,107],[4,108,99,103],[4,109,3,32,3,110],[4,111,88],[4,50,3,112,3,52,3,53,3,54,3,55,3,56,3,57],[4,113,3,114,88],[4,115,3,51,3,116,3,117,3,118,3,119,88],[4,120,121],[4,122,123],[0,"FormalParameterList",124],[9,29],[1],[4,125,82],[8,126],[0,"VAR",127],[0,"VariableDeclaration",128],[6,129],[0,"EOS",130],[9,131],[0,"Expression",132],[0,"IF",133],[8,134],[0,"DoWhileStatement",135],[0,"WhileStatement",136],[0,"ForStatement",137],[0,"ForInStatement",138],[0,"EachStatement",139],[0,"CONTINUE",140],[0,"__",141],[3,142,143],[0,"BREAK",144],[0,"RETURN",145],[3,143,146],[0,"WITH",147],[5,":"],[0,"SWITCH",148],[0,"CaseBlock",149],[0,"THROW",150],[0,"TRY",151],[3,152,153],[0,"DEBUGGER",154],[8,51],[5,"@import"],[3,155,156],[5,"@implementation"],[8,157],[8,158],[0,"ClassBody",159],[5,"@end"],[5,"function"],[9,160],[9,161],[0,"IdentifierName",162],[4,51,163],[9,10],[0,"StatementList",164],[4,165,121],[4,51,166],[4,3,167,3,86],[3,168,169,170,171],[3,55,50],[4,172,173],[4,174,121],[4,3,175,3,21],[4,176,3,21,3,177,3,52,3,90,3,54,88],[4,177,3,52,3,90,3,54,3,21],[4,178,3,52,3,179,3,62,3,180,3,62,3,180,3,54,3,21],[4,178,3,52,3,181,3,182,3,90,3,54,3,21],[4,183,3,52,3,181,3,182,3,90,3,54,3,21],[4,184,121],[6,185],[4,51,88],[0,"SemicolonInsertionEOS",186],[4,187,121],[4,188,121],[4,90,88],[4,189,121],[4,190,121],[4,55,3,191,3,192,3,191,3,57],[4,193,121],[4,194,121],[4,195,196],[0,"Finally",197],[4,198,121],[0,"LocalFilePath",199],[0,"StandardFilePath",200],[3,201,202],[4,55,203,3,57],[8,204],[0,"IdentifierPart",205],[4,206,121],[4,207,208],[6,209],[4,21,210],[5,"var"],[8,211],[5,","],[4,3,62],[4,99,212],[4,99,213],[4,99,214],[0,"AssignmentExpression",215],[6,216],[5,"if"],[0,"ELSE",217],[0,"DO",218],[0,"WHILE",219],[0,"FOR",220],[8,221],[8,90],[0,"ForInFirstExpression",222],[0,"IN",223],[5,"@each"],[5,"continue"],[3,9,224,20],[3,225,169,170,171],[5,"break"],[5,"return"],[5,"with"],[5,"switch"],[8,226],[8,227],[5,"throw"],[5,"try"],[0,"Catch",228],[8,229],[4,230,3,32],[5,"debugger"],[0,"StringLiteral",231],[4,232,3,233,3,234],[0,"SuperclassDeclaration",235],[0,"CategoryDeclaration",236],[6,237],[0,"ClassElements",238],[3,207,239,240,241,242,243],[0,"ReservedWord",244],[0,"IdentifierStart",245],[6,160],[4,3,167,3,51],[6,246],[4,3,247,248,3,172],[0,"LineTerminatorSequence",249],[10,57],[0,"EOF",250],[3,251,252],[4,3,167,3,172],[4,253,121],[4,254,121],[4,255,121],[4,256,121],[0,"ForFirstExpression",257],[3,258,259],[4,260,121],[0,"SingleLineMultiLineComment",261],[4,99,62],[0,"CaseClauses",262],[0,"DefaultClause",263],[4,264,3,52,3,51,3,54,3,32],[4,3,153],[0,"FINALLY",265],[3,266,267],[5,"<"],[6,268],[5,">"],[4,105,3,51],[4,52,3,51,3,54],[4,3,269],[4,270,271],[0,"UnicodeCombiningMark",272],[0,"UnicodeDigit",273],[0,"UnicodeConnectorPunctuation",274],[0,"ZWNJ",275],[0,"ZWJ",276],[3,277,278,279,280],[3,281,282,283],[4,3,21],[5,"="],[9,247],[3,284,285,286,287,288],[9,82],[4,258,3,289,3,172],[0,"ConditionalExpression",290],[5,"else"],[5,"do"],[5,"while"],[5,"for"],[3,291,292],[0,"LeftHandSideExpression",293],[4,85,3,294],[5,"in"],[4,27,295,29],[4,296,297],[4,298,3,105,299],[0,"CATCH",300],[4,301,121],[4,302,303,304,303],[4,305,306,305],[3,307,308],[0,"CompoundIvarDeclaration",309],[0,"ClassElement",310],[6,311],[3,312,313,314,315,316,317],[3,318,319,320,321],[2,"[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]"],[5,"\u200C"],[5,"\u200D"],[0,"Keyword",322],[0,"FutureReservedWord",323],[0,"NullLiteral",324],[0,"BooleanLiteral",325],[0,"UnicodeLetter",326],[2,"[$_]"],[4,327,328],[5,"\n"],[4,288,329],[5,"\u2028"],[5,"\u2029"],[5,"\r"],[0,"AssignmentOperator",330],[4,331,332],[0,"ExpressionNoIn",333],[4,85,3,334],[3,335,336],[0,"VariableDeclarationNoIn",337],[6,338],[0,"CaseClause",339],[6,340],[0,"DEFAULT",341],[8,342],[4,343,121],[5,"finally"],[8,344],[5,"\""],[6,345],[5,"'"],[6,346],[5,"\\>"],[4,347,82],[4,348,3,349,350,88],[3,351,352,21,22],[4,3,270],[2,"[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0900-\\u0902\\u093A\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0957\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135D-\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1BE6\\u1BE8\\u1BE9\\u1BED\\u1BEF-\\u1BF1\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFC-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26\\u0903\\u093B\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u094F\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1BE7\\u1BEA-\\u1BEC\\u1BEE\\u1BF2\\u1BF3\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"],[4,353,354],[4,355,356],[4,357,358],[4,359,360],[4,361,362],[2,"[\\u0030-\\u0039\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]"],[4,363,364],[4,357,365],[4,366,367],[3,187,368,343,184,198,369,370,254,253,301,256,120,174,371,260,372,188,190,373,193,194,374,165,375,255,189],[3,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405],[0,"NULL",406],[3,407,408],[3,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426],[5,"\\"],[0,"UnicodeEscapeSequence",427],[8,284],[3,428,429,430,431,432,433,434,435,436,437,438,439],[0,"LogicalOrExpression",440],[8,441],[4,442,443],[0,"VariableDeclarationListNoIn",444],[0,"CallExpression",445],[0,"NewExpression",446],[4,51,447],[4,81,125,82],[4,448,3,90,3,105,299],[4,3,296],[4,369,121],[4,3,126],[5,"catch"],[4,449,3],[0,"DoubleStringCharacter",450],[0,"SingleStringCharacter",451],[9,234],[0,"IvarType",452],[0,"IvarDeclaration",453],[6,454],[0,"ClassMethodDeclaration",455],[0,"InstanceMethodDeclaration",456],[5,"\uDB40"],[2,"[\\uDD00-\\uDDEF]"],[5,"\uD834"],[2,"[\\uDD67-\\uDD69\\uDD7B-\\uDD82\\uDD85-\\uDD8B\\uDDAA-\\uDDAD\\uDE42-\\uDE44\\uDD65\\uDD66\\uDD6D-\\uDD72]"],[5,"\uD804"],[2,"[\\uDC01\\uDC38-\\uDC46\\uDC80\\uDC81\\uDCB3-\\uDCB6\\uDCB9\\uDCBA\\uDC00\\uDC02\\uDC82\\uDCB0-\\uDCB2\\uDCB7\\uDCB8]"],[5,"\uD800"],[2,"[\\uDDFD]"],[5,"\uD802"],[2,"[\\uDE01-\\uDE03\\uDE05\\uDE06\\uDE0C-\\uDE0F\\uDE38-\\uDE3A\\uDE3F]"],[5,"\uD835"],[2,"[\\uDFCE-\\uDFFF]"],[2,"[\\uDC66-\\uDC6F]"],[5,"\uD801"],[2,"[\\uDCA0-\\uDCA9]"],[5,"case"],[5,"default"],[5,"delete"],[5,"instanceof"],[5,"new"],[5,"this"],[5,"typeof"],[5,"void"],[5,"abstract"],[5,"boolean"],[5,"byte"],[5,"char"],[5,"class"],[5,"const"],[5,"double"],[5,"enum"],[5,"export"],[5,"extends"],[5,"final"],[5,"float"],[5,"goto"],[5,"implements"],[5,"import"],[5,"interface"],[5,"int"],[5,"long"],[5,"native"],[5,"package"],[5,"private"],[5,"protected"],[5,"public"],[5,"short"],[5,"static"],[5,"super"],[5,"synchronized"],[5,"throws"],[5,"transient"],[5,"volatile"],[4,457,121],[0,"TRUE",458],[0,"FALSE",459],[2,"[\\u0041-\\u005A\\u00C0-\\u00D6\\u00D8-\\u00DE\\u0100\\u0102\\u0104\\u0106\\u0108\\u010A\\u010C\\u010E\\u0110\\u0112\\u0114\\u0116\\u0118\\u011A\\u011C\\u011E\\u0120\\u0122\\u0124\\u0126\\u0128\\u012A\\u012C\\u012E\\u0130\\u0132\\u0134\\u0136\\u0139\\u013B\\u013D\\u013F\\u0141\\u0143\\u0145\\u0147\\u014A\\u014C\\u014E\\u0150\\u0152\\u0154\\u0156\\u0158\\u015A\\u015C\\u015E\\u0160\\u0162\\u0164\\u0166\\u0168\\u016A\\u016C\\u016E\\u0170\\u0172\\u0174\\u0176\\u0178\\u0179\\u017B\\u017D\\u0181\\u0182\\u0184\\u0186\\u0187\\u0189-\\u018B\\u018E-\\u0191\\u0193\\u0194\\u0196-\\u0198\\u019C\\u019D\\u019F\\u01A0\\u01A2\\u01A4\\u01A6\\u01A7\\u01A9\\u01AC\\u01AE\\u01AF\\u01B1-\\u01B3\\u01B5\\u01B7\\u01B8\\u01BC\\u01C4\\u01C7\\u01CA\\u01CD\\u01CF\\u01D1\\u01D3\\u01D5\\u01D7\\u01D9\\u01DB\\u01DE\\u01E0\\u01E2\\u01E4\\u01E6\\u01E8\\u01EA\\u01EC\\u01EE\\u01F1\\u01F4\\u01F6-\\u01F8\\u01FA\\u01FC\\u01FE\\u0200\\u0202\\u0204\\u0206\\u0208\\u020A\\u020C\\u020E\\u0210\\u0212\\u0214\\u0216\\u0218\\u021A\\u021C\\u021E\\u0220\\u0222\\u0224\\u0226\\u0228\\u022A\\u022C\\u022E\\u0230\\u0232\\u023A\\u023B\\u023D\\u023E\\u0241\\u0243-\\u0246\\u0248\\u024A\\u024C\\u024E\\u0370\\u0372\\u0376\\u0386\\u0388-\\u038A\\u038C\\u038E\\u038F\\u0391-\\u03A1\\u03A3-\\u03AB\\u03CF\\u03D2-\\u03D4\\u03D8\\u03DA\\u03DC\\u03DE\\u03E0\\u03E2\\u03E4\\u03E6\\u03E8\\u03EA\\u03EC\\u03EE\\u03F4\\u03F7\\u03F9\\u03FA\\u03FD-\\u042F\\u0460\\u0462\\u0464\\u0466\\u0468\\u046A\\u046C\\u046E\\u0470\\u0472\\u0474\\u0476\\u0478\\u047A\\u047C\\u047E\\u0480\\u048A\\u048C\\u048E\\u0490\\u0492\\u0494\\u0496\\u0498\\u049A\\u049C\\u049E\\u04A0\\u04A2\\u04A4\\u04A6\\u04A8\\u04AA\\u04AC\\u04AE\\u04B0\\u04B2\\u04B4\\u04B6\\u04B8\\u04BA\\u04BC\\u04BE\\u04C0\\u04C1\\u04C3\\u04C5\\u04C7\\u04C9\\u04CB\\u04CD\\u04D0\\u04D2\\u04D4\\u04D6\\u04D8\\u04DA\\u04DC\\u04DE\\u04E0\\u04E2\\u04E4\\u04E6\\u04E8\\u04EA\\u04EC\\u04EE\\u04F0\\u04F2\\u04F4\\u04F6\\u04F8\\u04FA\\u04FC\\u04FE\\u0500\\u0502\\u0504\\u0506\\u0508\\u050A\\u050C\\u050E\\u0510\\u0512\\u0514\\u0516\\u0518\\u051A\\u051C\\u051E\\u0520\\u0522\\u0524\\u0526\\u0531-\\u0556\\u10A0-\\u10C5\\u1E00\\u1E02\\u1E04\\u1E06\\u1E08\\u1E0A\\u1E0C\\u1E0E\\u1E10\\u1E12\\u1E14\\u1E16\\u1E18\\u1E1A\\u1E1C\\u1E1E\\u1E20\\u1E22\\u1E24\\u1E26\\u1E28\\u1E2A\\u1E2C\\u1E2E\\u1E30\\u1E32\\u1E34\\u1E36\\u1E38\\u1E3A\\u1E3C\\u1E3E\\u1E40\\u1E42\\u1E44\\u1E46\\u1E48\\u1E4A\\u1E4C\\u1E4E\\u1E50\\u1E52\\u1E54\\u1E56\\u1E58\\u1E5A\\u1E5C\\u1E5E\\u1E60\\u1E62\\u1E64\\u1E66\\u1E68\\u1E6A\\u1E6C\\u1E6E\\u1E70\\u1E72\\u1E74\\u1E76\\u1E78\\u1E7A\\u1E7C\\u1E7E\\u1E80\\u1E82\\u1E84\\u1E86\\u1E88\\u1E8A\\u1E8C\\u1E8E\\u1E90\\u1E92\\u1E94\\u1E9E\\u1EA0\\u1EA2\\u1EA4\\u1EA6\\u1EA8\\u1EAA\\u1EAC\\u1EAE\\u1EB0\\u1EB2\\u1EB4\\u1EB6\\u1EB8\\u1EBA\\u1EBC\\u1EBE\\u1EC0\\u1EC2\\u1EC4\\u1EC6\\u1EC8\\u1ECA\\u1ECC\\u1ECE\\u1ED0\\u1ED2\\u1ED4\\u1ED6\\u1ED8\\u1EDA\\u1EDC\\u1EDE\\u1EE0\\u1EE2\\u1EE4\\u1EE6\\u1EE8\\u1EEA\\u1EEC\\u1EEE\\u1EF0\\u1EF2\\u1EF4\\u1EF6\\u1EF8\\u1EFA\\u1EFC\\u1EFE\\u1F08-\\u1F0F\\u1F18-\\u1F1D\\u1F28-\\u1F2F\\u1F38-\\u1F3F\\u1F48-\\u1F4D\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F68-\\u1F6F\\u1FB8-\\u1FBB\\u1FC8-\\u1FCB\\u1FD8-\\u1FDB\\u1FE8-\\u1FEC\\u1FF8-\\u1FFB\\u2102\\u2107\\u210B-\\u210D\\u2110-\\u2112\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u2130-\\u2133\\u213E\\u213F\\u2145\\u2183\\u2C00-\\u2C2E\\u2C60\\u2C62-\\u2C64\\u2C67\\u2C69\\u2C6B\\u2C6D-\\u2C70\\u2C72\\u2C75\\u2C7E-\\u2C80\\u2C82\\u2C84\\u2C86\\u2C88\\u2C8A\\u2C8C\\u2C8E\\u2C90\\u2C92\\u2C94\\u2C96\\u2C98\\u2C9A\\u2C9C\\u2C9E\\u2CA0\\u2CA2\\u2CA4\\u2CA6\\u2CA8\\u2CAA\\u2CAC\\u2CAE\\u2CB0\\u2CB2\\u2CB4\\u2CB6\\u2CB8\\u2CBA\\u2CBC\\u2CBE\\u2CC0\\u2CC2\\u2CC4\\u2CC6\\u2CC8\\u2CCA\\u2CCC\\u2CCE\\u2CD0\\u2CD2\\u2CD4\\u2CD6\\u2CD8\\u2CDA\\u2CDC\\u2CDE\\u2CE0\\u2CE2\\u2CEB\\u2CED\\uA640\\uA642\\uA644\\uA646\\uA648\\uA64A\\uA64C\\uA64E\\uA650\\uA652\\uA654\\uA656\\uA658\\uA65A\\uA65C\\uA65E\\uA660\\uA662\\uA664\\uA666\\uA668\\uA66A\\uA66C\\uA680\\uA682\\uA684\\uA686\\uA688\\uA68A\\uA68C\\uA68E\\uA690\\uA692\\uA694\\uA696\\uA722\\uA724\\uA726\\uA728\\uA72A\\uA72C\\uA72E\\uA732\\uA734\\uA736\\uA738\\uA73A\\uA73C\\uA73E\\uA740\\uA742\\uA744\\uA746\\uA748\\uA74A\\uA74C\\uA74E\\uA750\\uA752\\uA754\\uA756\\uA758\\uA75A\\uA75C\\uA75E\\uA760\\uA762\\uA764\\uA766\\uA768\\uA76A\\uA76C\\uA76E\\uA779\\uA77B\\uA77D\\uA77E\\uA780\\uA782\\uA784\\uA786\\uA78B\\uA78D\\uA790\\uA7A0\\uA7A2\\uA7A4\\uA7A6\\uA7A8\\uFF21-\\uFF3A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00DF-\\u00F6\\u00F8-\\u00FF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F-\\u0293\\u0295-\\u02AF\\u0371\\u0373\\u0377\\u037B-\\u037D\\u0390\\u03AC-\\u03CE\\u03D0\\u03D1\\u03D5-\\u03D7\\u03D9\\u03DB\\u03DD\\u03DF\\u03E1\\u03E3\\u03E5\\u03E7\\u03E9\\u03EB\\u03ED\\u03EF-\\u03F3\\u03F5\\u03F8\\u03FB\\u03FC\\u0430-\\u045F\\u0461\\u0463\\u0465\\u0467\\u0469\\u046B\\u046D\\u046F\\u0471\\u0473\\u0475\\u0477\\u0479\\u047B\\u047D\\u047F\\u0481\\u048B\\u048D\\u048F\\u0491\\u0493\\u0495\\u0497\\u0499\\u049B\\u049D\\u049F\\u04A1\\u04A3\\u04A5\\u04A7\\u04A9\\u04AB\\u04AD\\u04AF\\u04B1\\u04B3\\u04B5\\u04B7\\u04B9\\u04BB\\u04BD\\u04BF\\u04C2\\u04C4\\u04C6\\u04C8\\u04CA\\u04CC\\u04CE\\u04CF\\u04D1\\u04D3\\u04D5\\u04D7\\u04D9\\u04DB\\u04DD\\u04DF\\u04E1\\u04E3\\u04E5\\u04E7\\u04E9\\u04EB\\u04ED\\u04EF\\u04F1\\u04F3\\u04F5\\u04F7\\u04F9\\u04FB\\u04FD\\u04FF\\u0501\\u0503\\u0505\\u0507\\u0509\\u050B\\u050D\\u050F\\u0511\\u0513\\u0515\\u0517\\u0519\\u051B\\u051D\\u051F\\u0521\\u0523\\u0525\\u0527\\u0561-\\u0587\\u1D00-\\u1D2B\\u1D62-\\u1D77\\u1D79-\\u1D9A\\u1E01\\u1E03\\u1E05\\u1E07\\u1E09\\u1E0B\\u1E0D\\u1E0F\\u1E11\\u1E13\\u1E15\\u1E17\\u1E19\\u1E1B\\u1E1D\\u1E1F\\u1E21\\u1E23\\u1E25\\u1E27\\u1E29\\u1E2B\\u1E2D\\u1E2F\\u1E31\\u1E33\\u1E35\\u1E37\\u1E39\\u1E3B\\u1E3D\\u1E3F\\u1E41\\u1E43\\u1E45\\u1E47\\u1E49\\u1E4B\\u1E4D\\u1E4F\\u1E51\\u1E53\\u1E55\\u1E57\\u1E59\\u1E5B\\u1E5D\\u1E5F\\u1E61\\u1E63\\u1E65\\u1E67\\u1E69\\u1E6B\\u1E6D\\u1E6F\\u1E71\\u1E73\\u1E75\\u1E77\\u1E79\\u1E7B\\u1E7D\\u1E7F\\u1E81\\u1E83\\u1E85\\u1E87\\u1E89\\u1E8B\\u1E8D\\u1E8F\\u1E91\\u1E93\\u1E95-\\u1E9D\\u1E9F\\u1EA1\\u1EA3\\u1EA5\\u1EA7\\u1EA9\\u1EAB\\u1EAD\\u1EAF\\u1EB1\\u1EB3\\u1EB5\\u1EB7\\u1EB9\\u1EBB\\u1EBD\\u1EBF\\u1EC1\\u1EC3\\u1EC5\\u1EC7\\u1EC9\\u1ECB\\u1ECD\\u1ECF\\u1ED1\\u1ED3\\u1ED5\\u1ED7\\u1ED9\\u1EDB\\u1EDD\\u1EDF\\u1EE1\\u1EE3\\u1EE5\\u1EE7\\u1EE9\\u1EEB\\u1EED\\u1EEF\\u1EF1\\u1EF3\\u1EF5\\u1EF7\\u1EF9\\u1EFB\\u1EFD\\u1EFF-\\u1F07\\u1F10-\\u1F15\\u1F20-\\u1F27\\u1F30-\\u1F37\\u1F40-\\u1F45\\u1F50-\\u1F57\\u1F60-\\u1F67\\u1F70-\\u1F7D\\u1F80-\\u1F87\\u1F90-\\u1F97\\u1FA0-\\u1FA7\\u1FB0-\\u1FB4\\u1FB6\\u1FB7\\u1FBE\\u1FC2-\\u1FC4\\u1FC6\\u1FC7\\u1FD0-\\u1FD3\\u1FD6\\u1FD7\\u1FE0-\\u1FE7\\u1FF2-\\u1FF4\\u1FF6\\u1FF7\\u210A\\u210E\\u210F\\u2113\\u212F\\u2134\\u2139\\u213C\\u213D\\u2146-\\u2149\\u214E\\u2184\\u2C30-\\u2C5E\\u2C61\\u2C65\\u2C66\\u2C68\\u2C6A\\u2C6C\\u2C71\\u2C73\\u2C74\\u2C76-\\u2C7C\\u2C81\\u2C83\\u2C85\\u2C87\\u2C89\\u2C8B\\u2C8D\\u2C8F\\u2C91\\u2C93\\u2C95\\u2C97\\u2C99\\u2C9B\\u2C9D\\u2C9F\\u2CA1\\u2CA3\\u2CA5\\u2CA7\\u2CA9\\u2CAB\\u2CAD\\u2CAF\\u2CB1\\u2CB3\\u2CB5\\u2CB7\\u2CB9\\u2CBB\\u2CBD\\u2CBF\\u2CC1\\u2CC3\\u2CC5\\u2CC7\\u2CC9\\u2CCB\\u2CCD\\u2CCF\\u2CD1\\u2CD3\\u2CD5\\u2CD7\\u2CD9\\u2CDB\\u2CDD\\u2CDF\\u2CE1\\u2CE3\\u2CE4\\u2CEC\\u2CEE\\u2D00-\\u2D25\\uA641\\uA643\\uA645\\uA647\\uA649\\uA64B\\uA64D\\uA64F\\uA651\\uA653\\uA655\\uA657\\uA659\\uA65B\\uA65D\\uA65F\\uA661\\uA663\\uA665\\uA667\\uA669\\uA66B\\uA66D\\uA681\\uA683\\uA685\\uA687\\uA689\\uA68B\\uA68D\\uA68F\\uA691\\uA693\\uA695\\uA697\\uA723\\uA725\\uA727\\uA729\\uA72B\\uA72D\\uA72F-\\uA731\\uA733\\uA735\\uA737\\uA739\\uA73B\\uA73D\\uA73F\\uA741\\uA743\\uA745\\uA747\\uA749\\uA74B\\uA74D\\uA74F\\uA751\\uA753\\uA755\\uA757\\uA759\\uA75B\\uA75D\\uA75F\\uA761\\uA763\\uA765\\uA767\\uA769\\uA76B\\uA76D\\uA76F\\uA771-\\uA778\\uA77A\\uA77C\\uA77F\\uA781\\uA783\\uA785\\uA787\\uA78C\\uA78E\\uA791\\uA7A1\\uA7A3\\uA7A5\\uA7A7\\uA7A9\\uA7FA\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFF41-\\uFF5A\\u01C5\\u01C8\\u01CB\\u01F2\\u1F88-\\u1F8F\\u1F98-\\u1F9F\\u1FA8-\\u1FAF\\u1FBC\\u1FCC\\u1FFC\\u02B0-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0374\\u037A\\u0559\\u0640\\u06E5\\u06E6\\u07F4\\u07F5\\u07FA\\u081A\\u0824\\u0828\\u0971\\u0E46\\u0EC6\\u10FC\\u17D7\\u1843\\u1AA7\\u1C78-\\u1C7D\\u1D2C-\\u1D61\\u1D78\\u1D9B-\\u1DBF\\u2071\\u207F\\u2090-\\u209C\\u2C7D\\u2D6F\\u2E2F\\u3005\\u3031-\\u3035\\u303B\\u309D\\u309E\\u30FC-\\u30FE\\uA015\\uA4F8-\\uA4FD\\uA60C\\uA67F\\uA717-\\uA71F\\uA770\\uA788\\uA9CF\\uAA70\\uAADD\\uFF70\\uFF9E\\uFF9F\\u01BB\\u01C0-\\u01C3\\u0294\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u063F\\u0641-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u0800-\\u0815\\u0840-\\u0858\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0972-\\u0977\\u0979-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E45\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10D0-\\u10FA\\u1100-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17DC\\u1820-\\u1842\\u1844-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BC0-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C77\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u2135-\\u2138\\u2D30-\\u2D65\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3006\\u303C\\u3041-\\u3096\\u309F\\u30A1-\\u30FA\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FCB\\uA000-\\uA014\\uA016-\\uA48C\\uA4D0-\\uA4F7\\uA500-\\uA60B\\uA610-\\uA61F\\uA62A\\uA62B\\uA66E\\uA6A0-\\uA6E5\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA6F\\uAA71-\\uAA76\\uAA7A\\uAA80-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB\\uAADC\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uABC0-\\uABE2\\uAC00\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA2D\\uFA30-\\uFA6D\\uFA70-\\uFAD9\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF66-\\uFF6F\\uFF71-\\uFF9D\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u16EE-\\u16F0\\u2160-\\u2182\\u2185-\\u2188\\u3007\\u3021-\\u3029\\u3038-\\u303A\\uA6E6-\\uA6EF]"],[4,460,461],[4,462,463],[4,464,465],[4,466,467],[4,363,468],[4,357,469],[4,359,470],[4,471,472],[4,366,473],[4,474,475],[4,476,477],[4,478,479],[4,480,481],[4,482,483],[4,484,485],[4,361,486],[4,487,488],[4,489,490,490,490,490],[4,247,248],[5,"*="],[5,"/="],[5,"%="],[5,"+="],[5,"-="],[5,"<<="],[5,">>="],[5,">>>="],[5,"&="],[5,"^="],[5,"|="],[4,491,492],[4,3,493,3,172,3,105,3,172],[0,"AssignmentExpressionNoIn",494],[6,495],[4,294,496],[4,497,3,498,499],[3,497,500],[8,501],[0,"CASE",502],[5,"@"],[3,503,504,505],[3,506,504,505],[4,507,508],[4,51,3,509],[4,3,167,3,349],[4,510,511,3,512,3,513,3,55,3,56,3,57],[4,514,511,3,512,3,513,3,55,3,56,3,57],[5,"null"],[4,515,121],[4,516,121],[5,"\uD82C"],[2,"[\\uDC00\\uDC01]"],[5,"\uD808"],[2,"[\\uDC00-\\uDF6E]"],[5,"\uD869"],[2,"[\\uDED6\\uDF00]"],[5,"\uD809"],[2,"[\\uDC00-\\uDC62]"],[2,"[\\uDC00-\\uDC19\\uDC34-\\uDC4D\\uDC68-\\uDC81\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB5\\uDCD0-\\uDCE9\\uDD04\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD38\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD6C-\\uDD85\\uDDA0-\\uDDB9\\uDDD4-\\uDDED\\uDE08-\\uDE21\\uDE3C-\\uDE55\\uDE70-\\uDE89\\uDEA8-\\uDEC0\\uDEE2-\\uDEFA\\uDF1C-\\uDF34\\uDF56-\\uDF6E\\uDF90-\\uDFA8\\uDFCA\\uDC1A-\\uDC33\\uDC4E-\\uDC54\\uDC56-\\uDC67\\uDC82-\\uDC9B\\uDCB6-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDCEA-\\uDD03\\uDD1E-\\uDD37\\uDD52-\\uDD6B\\uDD86-\\uDD9F\\uDDBA-\\uDDD3\\uDDEE-\\uDE07\\uDE22-\\uDE3B\\uDE56-\\uDE6F\\uDE8A-\\uDEA5\\uDEC2-\\uDEDA\\uDEDC-\\uDEE1\\uDEFC-\\uDF14\\uDF16-\\uDF1B\\uDF36-\\uDF4E\\uDF50-\\uDF55\\uDF70-\\uDF88\\uDF8A-\\uDF8F\\uDFAA-\\uDFC2\\uDFC4-\\uDFC9\\uDFCB]"],[2,"[\\uDC03-\\uDC37\\uDC83-\\uDCAF]"],[2,"[\\uDC00-\\uDC0B\\uDC0D-\\uDC26\\uDC28-\\uDC3A\\uDC3C\\uDC3D\\uDC3F-\\uDC4D\\uDC50-\\uDC5D\\uDC80-\\uDCFA\\uDE80-\\uDE9C\\uDEA0-\\uDED0\\uDF00-\\uDF1E\\uDF30-\\uDF40\\uDF42-\\uDF49\\uDF80-\\uDF9D\\uDFA0-\\uDFC3\\uDFC8-\\uDFCF\\uDD40-\\uDD74\\uDF41\\uDF4A\\uDFD1-\\uDFD5]"],[5,"\uD80C"],[2,"[\\uDC00-\\uDFFF]"],[2,"[\\uDC00-\\uDC9D]"],[5,"\uD86E"],[2,"[\\uDC1D]"],[5,"\uD803"],[2,"[\\uDC00-\\uDC48]"],[5,"\uD840"],[2,"[\\uDC00]"],[5,"\uD87E"],[2,"[\\uDC00-\\uDE1D]"],[5,"\uD86D"],[2,"[\\uDF34\\uDF40]"],[5,"\uD81A"],[2,"[\\uDC00-\\uDE38]"],[2,"[\\uDC00-\\uDC05\\uDC08\\uDC0A-\\uDC35\\uDC37\\uDC38\\uDC3C\\uDC3F-\\uDC55\\uDD00-\\uDD15\\uDD20-\\uDD39\\uDE00\\uDE10-\\uDE13\\uDE15-\\uDE17\\uDE19-\\uDE33\\uDE60-\\uDE7C\\uDF00-\\uDF35\\uDF40-\\uDF55\\uDF60-\\uDF72]"],[5,"\uD80D"],[2,"[\\uDC00-\\uDC2E]"],[5,"u"],[0,"HexDigit",517],[0,"LogicalAndExpression",518],[6,519],[5,"?"],[3,520,521],[4,3,167,3,442],[6,522],[0,"MemberExpression",523],[0,"Arguments",524],[6,525],[4,526,3,336],[4,3,247,248,3,442],[4,368,121],[4,527,82],[4,327,528],[0,"LineContinuation",529],[4,530,82],[0,"IvarTypeElement",531],[6,532],[8,533],[5,"+"],[8,534],[0,"MethodSelector",535],[8,62],[5,"-"],[5,"true"],[5,"false"],[2,"[0-9a-fA-F]"],[4,536,537],[4,3,538,3,491],[4,258,3,289,3,442],[0,"ConditionalExpressionNoIn",539],[4,3,167,3,294],[4,540,541],[4,52,3,542,3,54],[4,3,543],[0,"NEW",544],[9,545],[0,"EscapeSequence",546],[4,327,212],[9,547],[4,548,549],[4,3,507],[0,"Accessors",550],[4,3,551],[3,552,553],[0,"BitwiseOrExpression",554],[6,555],[5,"||"],[4,556,557],[3,558,47,559,560],[6,561],[8,562],[3,498,563,564],[4,372,121],[3,565,327,10],[3,566,567,568,328],[3,569,327,10],[9,570],[3,123,571],[4,572,573],[0,"MethodType",574],[4,575,576],[0,"UnarySelector",577],[4,578,579],[4,3,580,3,536],[0,"LogicalOrExpressionNoIn",581],[8,582],[0,"PrimaryExpression",583],[0,"MessageExpression",584],[4,526,3,497,3,498],[4,3,585],[0,"ArgumentList",586],[0,"BracketedAccessor",587],[0,"DotAccessor",588],[2,"[\"]"],[0,"CharacterEscapeSequence",589],[4,590,591],[0,"HexEscapeSequence",592],[2,"[']"],[4,549,3,593],[5,"@outlet"],[5,"@accessors"],[8,594],[4,52,3,595,596,3,54],[0,"KeywordSelector",597],[8,598],[0,"Selector",123],[0,"BitwiseXOrExpression",599],[6,600],[5,"&&"],[4,601,602],[4,3,493,3,442,3,105,3,442],[3,603,51,604,605,606,607],[4,608,3,609,3,610,3,611],[3,563,564],[4,172,3,612],[4,608,3,90,3,611],[4,613,3,123],[3,614,615],[5,"0"],[9,616],[4,617,490,490],[3,533,88,167],[4,52,618,54],[3,619,123],[6,620],[4,621,622],[4,3,167,3,623],[4,624,625],[4,3,626,248,3,578],[0,"LogicalAndExpressionNoIn",627],[6,628],[0,"THIS",629],[0,"Literal",630],[0,"ArrayLiteral",631],[0,"ObjectLiteral",632],[4,52,3,90,3,54],[5,"["],[3,633,90],[0,"SelectorCall",634],[5,"]"],[6,635],[5,"."],[0,"SingleEscapeCharacter",636],[0,"NonEscapeCharacter",637],[0,"DecimalDigit",638],[5,"x"],[8,639],[0,"ACTION",640],[4,3,595],[0,"KeywordDeclarator",641],[6,642],[5,"..."],[0,"BitwiseAndExpression",643],[6,644],[5,"|"],[4,645,646],[4,3,538,3,601],[4,373,121],[3,279,280,647,199,648,649],[4,608,3,650,3,611],[4,55,3,651,3,57],[0,"SUPER",652],[3,653,553],[4,167,3,172],[2,"['\"\\\\bfnrtv]"],[4,125,654,82],[2,"[0-9]"],[4,655,656],[3,657,658],[4,659,105,511,3,51],[4,3,621],[4,660,661],[4,3,662,248,3,624],[0,"BitwiseOrExpressionNoIn",663],[6,664],[0,"NumericLiteral",665],[0,"RegularExpressionLiteral",666],[0,"SelectorLiteral",667],[0,"ElementList",668],[8,669],[4,401,121],[4,670,671],[9,672],[0,"AccessorsConfiguration",673],[6,674],[4,675,121],[4,676,121],[8,677],[0,"EqualityExpression",678],[6,679],[5,"^"],[4,680,681],[4,3,580,3,645],[4,682,683],[4,684,685,684,686],[4,687,3,52,3,688,3,54],[4,689,690,3,691],[4,692,3,693],[0,"KeywordSelectorCall",694],[6,695],[0,"EscapeCharacter",696],[3,697,698,699,700],[4,3,167,3,655],[5,"@action"],[5,"IBAction"],[4,577,3],[4,701,702],[4,3,703,248,3,660],[0,"BitwiseXOrExpressionNoIn",704],[6,705],[3,706,707],[9,207],[5,"/"],[0,"RegularExpressionBody",708],[0,"RegularExpressionFlags",208],[5,"@selector"],[0,"SelectorLiteralContents",709],[6,710],[6,711],[8,172],[0,"PropertyNameAndValueList",712],[8,167],[4,713,714],[4,3,167,3,90],[3,614,616,617,489],[0,"IvarPropertyName",715],[0,"IvarGetterName",716],[0,"IvarSetterName",717],[5,"readonly"],[0,"RelationalExpression",718],[6,719],[5,"&"],[4,720,721],[4,3,626,248,3,680],[0,"HexIntegerLiteral",722],[0,"DecimalLiteral",723],[4,724,725],[3,726,51],[4,167,3],[4,3,172,727],[4,728,729],[0,"KeywordCall",730],[6,731],[4,732,3,247,3,51],[4,733,3,247,3,51],[4,734,3,247,3,51,735],[4,736,737],[4,3,738,3,701],[0,"BitwiseAndExpressionNoIn",739],[6,740],[4,590,741,742],[4,743,744],[0,"RegularExpressionFirstChar",745],[6,746],[7,747],[7,748],[0,"PropertyAssignment",749],[6,750],[4,751,3,105,3,90],[4,3,713],[5,"property"],[5,"getter"],[5,"setter"],[8,752],[0,"ShiftExpression",753],[6,754],[0,"EqualityOperator",755],[4,756,757],[4,3,662,248,3,720],[2,"[Xx]"],[7,490],[3,758,759,760],[8,761],[3,762,763,764],[0,"RegularExpressionChar",765],[4,751,3,105,3],[4,3,167],[3,766,767,768],[4,3,167,3,728],[8,577],[4,3,105],[4,769,770],[4,3,771,3,736],[3,772,773,774,775],[0,"EqualityExpressionNoIn",776],[6,777],[4,760,613,778],[4,613,779],[0,"DecimalIntegerLiteral",780],[0,"ExponentPart",781],[4,782,783],[0,"RegularExpressionBackslashSequence",784],[0,"RegularExpressionClass",785],[3,786,763,764],[4,787,3,105,3,172],[0,"PropertyGetter",788],[0,"PropertySetter",789],[0,"AdditiveExpression",790],[6,791],[0,"RelationalOperator",792],[5,"==="],[5,"!=="],[5,"=="],[5,"!="],[4,793,794],[4,3,703,248,3,756],[6,616],[7,616],[3,590,795],[4,796,797],[9,798],[0,"RegularExpressionNonTerminator",83],[4,327,783],[4,608,799,611],[4,800,783],[0,"PropertyName",801],[4,802,3,787,3,52,3,54,3,55,3,56,3,57],[4,803,3,787,3,52,3,804,3,54,3,55,3,56,3,57],[4,805,806],[4,3,807,3,769],[3,808,809,232,234,810,182],[0,"RelationalExpressionNoIn",811],[6,812],[4,813,778],[2,"[eE]"],[0,"SignedInteger",814],[2,"[*\\u005C/[]"],[6,815],[9,816],[3,123,199,647],[5,"get"],[5,"set"],[0,"PropertySetParameterList",51],[0,"MultiplicativeExpression",817],[6,818],[0,"ShiftOperator",819],[5,"<="],[5,">="],[0,"INSTANCEOF",820],[4,736,821],[4,3,738,3,793],[2,"[1-9]"],[4,822,779],[0,"RegularExpressionClassChar",823],[2,"[\\u005C/[]"],[4,824,825],[4,3,826,3,805],[3,827,828,829],[4,371,121],[6,830],[8,831],[3,832,763],[0,"UnaryExpression",833],[6,834],[0,"AdditiveOperator",835],[5,"<<"],[5,">>"],[5,">>>"],[4,3,836,3,736],[2,"[+-]"],[4,837,783],[3,838,839,840,841,842,843,844,845,846,847],[4,3,848,3,824],[4,849,248],[0,"RelationalOperatorNoIn",850],[9,851],[0,"PostfixExpression",852],[4,853,3,824],[4,854,3,824],[4,855,3,824],[4,856,3,824],[4,857,3,824],[4,510,3,824],[4,514,3,824],[4,858,3,824],[4,859,3,824],[0,"MultiplicativeOperator",860],[3,861,862],[3,808,809,232,234,810],[2,"[\\u005C\\]]"],[4,258,863],[0,"DELETE",864],[0,"VOID",865],[0,"TYPEOF",866],[5,"++"],[5,"--"],[5,"~"],[5,"!"],[4,867,248],[4,510,868],[4,514,869],[8,870],[4,370,121],[4,375,121],[4,374,121],[3,871,684,872],[9,510],[9,514],[4,99,873],[5,"*"],[5,"%"],[3,856,857],[0,"%start",875],[4,876,877,876],[0,"%_",878],[8,879],[6,880],[0,"%SourceElements",881],[3,882,883,884],[4,885,886],[0,"%WhiteSpace",14],[0,"%LineTerminator",15],[0,"%Comment",887],[0,"%SourceElement",888],[6,889],[3,890,891],[3,892,893],[4,876,885],[0,"%MultiLineComment",23],[0,"%SingleLineComment",894],[0,"%Statement",895],[0,"%FunctionDeclaration",896],[4,30,897],[3,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,893,913,914,915],[4,916,876,917,876,52,876,918,876,54,876,55,876,919,876,57],[6,920],[0,"%Block",921],[0,"%VariableStatement",922],[0,"%EmptyStatement",62],[0,"%ExpressionStatement",923],[0,"%IfStatement",924],[0,"%IterationStatement",925],[0,"%ContinueStatement",926],[0,"%BreakStatement",927],[0,"%ReturnStatement",928],[0,"%WithStatement",929],[0,"%LabelledStatement",930],[0,"%SwitchStatement",931],[0,"%ThrowStatement",932],[0,"%TryStatement",933],[0,"%DebuggerStatement",934],[0,"%FunctionExpression",935],[0,"%ImportStatement",936],[0,"%ClassDeclarationStatement",937],[0,"%FUNCTION",938],[0,"%Identifier",939],[8,940],[0,"%FunctionBody",875],[0,"%SingleLineCommentChar",941],[12,942,943],[4,944,876,945,946,947],[4,948,949,947],[4,950,876,52,876,949,876,54,876,892,951],[3,952,953,954,955,956],[4,957,958,959],[4,960,958,959],[4,961,958,962],[4,963,876,52,876,949,876,54,876,892],[4,917,876,105,876,892],[4,964,876,52,876,949,876,54,876,965],[4,966,958,962],[4,967,876,898,876,968],[4,969,947],[4,916,876,970,876,52,876,918,876,54,876,55,876,919,876,57],[4,113,876,971,947],[4,115,876,917,876,972,876,973,876,974,876,119,947],[4,120,975],[12,976,977],[0,"%FormalParameterList",978],[4,979,82],[4,55,876,980,876,57],[11,"%BadBlock",981,"Missing ending brace"],[0,"%VAR",982],[0,"%VariableDeclaration",983],[6,984],[0,"%EOS",985],[9,986],[0,"%Expression",987],[0,"%IF",988],[8,989],[0,"%DoWhileStatement",990],[0,"%WhileStatement",991],[0,"%ForStatement",992],[0,"%ForInStatement",993],[0,"%EachStatement",994],[0,"%CONTINUE",995],[0,"%__",996],[3,997,998],[0,"%BREAK",999],[0,"%RETURN",1000],[3,998,1001],[0,"%WITH",1002],[0,"%SWITCH",1003],[0,"%CaseBlock",1004],[0,"%THROW",1005],[0,"%TRY",1006],[3,1007,1008],[0,"%DEBUGGER",1009],[8,917],[3,1010,1011],[8,1012],[8,1013],[0,"%ClassBody",1014],[9,1015],[4,1016,1017],[0,"%BadIdentifier",1018],[4,917,1019],[9,883],[8,1020],[4,55,876,980,876],[4,165,975],[4,917,1021],[4,876,167,876,945],[3,1022,1023,1024,1025],[3,55,916],[4,1026,1027],[4,174,975],[4,876,1028,876,892],[4,1029,876,892,876,1030,876,52,876,949,876,54,947],[4,1030,876,52,876,949,876,54,876,892],[4,1031,876,52,876,1032,876,62,876,1033,876,62,876,1033,876,54,876,892],[4,1031,876,52,876,1034,876,1035,876,949,876,54,876,892],[4,183,876,52,876,1034,876,1035,876,949,876,54,876,892],[4,184,975],[6,1036],[4,917,947],[0,"%SemicolonInsertionEOS",1037],[4,187,975],[4,188,975],[4,949,947],[4,189,975],[4,190,975],[4,55,876,1038,876,1039,876,1038,876,57],[4,193,975],[4,194,975],[4,1040,1041],[0,"%Finally",1042],[4,198,975],[0,"%LocalFilePath",1043],[0,"%StandardFilePath",1044],[3,1045,1046],[4,55,1047,876,57],[8,1048],[0,"%IdentifierPart",1049],[9,1050],[0,"%IdentifierName",1051],[3,1052,1053],[6,1054],[0,"%StatementList",1055],[8,1056],[4,876,62],[4,958,1057],[4,958,213],[4,958,1058],[0,"%AssignmentExpression",1059],[6,1060],[0,"%ELSE",1061],[0,"%DO",1062],[0,"%WHILE",1063],[0,"%FOR",1064],[8,1065],[8,949],[0,"%ForInFirstExpression",1066],[0,"%IN",1067],[3,882,1068,891],[3,1069,1023,1024,1025],[8,1070],[8,1071],[0,"%Catch",1072],[8,1073],[4,1074,876,898],[0,"%StringLiteral",1075],[4,232,876,233,876,234],[0,"%SuperclassDeclaration",1076],[0,"%CategoryDeclaration",1077],[6,1078],[0,"%ClassElements",1079],[3,1080,1081,1082,1083,1084,1085],[4,1086,975],[4,1080,1087],[11,"%ReservedWordIdentifier",1050,"Identifier cannot be a reserved word"],[11,"%DigitIdentifier",1088,"Identifier cannot start with a digit"],[4,876,167,876,917],[4,892,1089],[4,876,247,248,876,1026],[0,"%LineTerminatorSequence",249],[0,"%EOF",250],[3,1090,1091],[4,876,167,876,1026],[4,253,975],[4,254,975],[4,255,975],[4,256,975],[0,"%ForFirstExpression",1092],[3,1093,1094],[4,260,975],[0,"%SingleLineMultiLineComment",1095],[4,958,62],[0,"%CaseClauses",1096],[0,"%DefaultClause",1097],[4,1098,876,52,876,917,876,54,876,898],[4,876,1008],[0,"%FINALLY",1099],[3,1100,1101],[4,105,876,917],[4,52,876,917,876,54],[4,876,1102],[4,1103,1104],[0,"%IdentifierStart",1105],[0,"%UnicodeCombiningMark",272],[0,"%UnicodeDigit",273],[0,"%UnicodeConnectorPunctuation",274],[0,"%ZWNJ",275],[0,"%ZWJ",276],[0,"%ReservedWord",1106],[6,1015],[4,1082,1107],[6,1108],[4,1093,876,1109,876,1026],[0,"%ConditionalExpression",1110],[3,1111,1112],[0,"%LeftHandSideExpression",1113],[4,944,876,1114],[4,27,1115,29],[4,1116,1117],[4,1118,876,105,1119],[0,"%CATCH",1120],[4,301,975],[4,1121,303,1122,303],[4,305,1123,305],[0,"%CompoundIvarDeclaration",1124],[0,"%ClassElement",1125],[6,1126],[3,1127,282,1128],[3,1129,1130,1131,1132],[7,1015],[4,876,892],[0,"%AssignmentOperator",330],[4,1133,1134],[0,"%ExpressionNoIn",1135],[4,944,876,1136],[3,1137,1138],[0,"%VariableDeclarationNoIn",1139],[6,1140],[0,"%CaseClause",1141],[6,1142],[0,"%DEFAULT",1143],[8,1144],[4,343,975],[8,1145],[6,1146],[6,1147],[4,1148,876,1149,1150,947],[3,1151,1152,892,893],[4,876,1103],[0,"%UnicodeLetter",326],[4,327,1153],[0,"%Keyword",322],[0,"%FutureReservedWord",323],[0,"%NullLiteral",1154],[0,"%BooleanLiteral",1155],[0,"%LogicalOrExpression",1156],[8,1157],[4,1158,1159],[0,"%VariableDeclarationListNoIn",1160],[0,"%CallExpression",1161],[0,"%NewExpression",1162],[4,917,1163],[4,81,979,82],[4,1164,876,949,876,105,1119],[4,876,1116],[4,369,975],[4,876,1020],[4,449,876],[0,"%DoubleStringCharacter",1165],[0,"%SingleStringCharacter",1166],[0,"%IvarType",1167],[0,"%IvarDeclaration",1168],[6,1169],[0,"%ClassMethodDeclaration",1170],[0,"%InstanceMethodDeclaration",1171],[0,"%UnicodeEscapeSequence",1172],[0,"%NULL",1173],[3,1174,1175],[4,1176,1177],[4,876,493,876,1026,876,105,876,1026],[0,"%AssignmentExpressionNoIn",1178],[6,1179],[4,1114,1180],[4,1181,876,1182,1183],[3,1181,1184],[8,1185],[0,"%CASE",1186],[3,1187,1188,1189],[3,1190,1188,1189],[4,1191,1192],[4,917,876,1193],[4,876,167,876,1149],[4,510,1194,876,1195,876,513,876,55,876,919,876,57],[4,514,1194,876,1195,876,513,876,55,876,919,876,57],[4,489,1196,1196,1196,1196],[4,457,975],[0,"%TRUE",1197],[0,"%FALSE",1198],[0,"%LogicalAndExpression",1199],[6,1200],[3,1201,1202],[4,876,167,876,1158],[6,1203],[0,"%MemberExpression",1204],[0,"%Arguments",1205],[6,1206],[4,1207,876,1138],[4,876,247,248,876,1158],[4,368,975],[4,1208,82],[4,327,1209],[0,"%LineContinuation",1210],[4,1211,82],[0,"%IvarTypeElement",1212],[6,1213],[8,1214],[8,1215],[0,"%MethodSelector",1216],[0,"%HexDigit",517],[4,515,975],[4,516,975],[4,1217,1218],[4,876,538,876,1176],[4,1093,876,1109,876,1158],[0,"%ConditionalExpressionNoIn",1219],[4,876,167,876,1114],[4,1220,1221],[4,52,876,1222,876,54],[4,876,1223],[0,"%NEW",1224],[9,1225],[0,"%EscapeSequence",1226],[4,327,1057],[9,1227],[4,1228,1229],[4,876,1191],[0,"%Accessors",1230],[4,876,1231],[3,1232,1233],[0,"%BitwiseOrExpression",1234],[6,1235],[4,1236,1237],[3,1238,913,1239,1240],[6,1241],[8,1242],[3,1182,1243,1244],[4,372,975],[3,565,327,883],[3,1245,1246,1247,1153],[3,569,327,883],[9,1248],[3,1017,571],[4,572,1249],[0,"%MethodType",1250],[4,1251,1252],[0,"%UnarySelector",1253],[4,1254,1255],[4,876,580,876,1217],[0,"%LogicalOrExpressionNoIn",1256],[8,1257],[0,"%PrimaryExpression",1258],[0,"%MessageExpression",1259],[4,1207,876,1181,876,1182],[4,876,1260],[0,"%ArgumentList",1261],[0,"%BracketedAccessor",1262],[0,"%DotAccessor",1263],[0,"%CharacterEscapeSequence",1264],[4,590,1265],[0,"%HexEscapeSequence",1266],[4,1229,876,1267],[8,1268],[4,52,876,1269,1270,876,54],[0,"%KeywordSelector",1271],[8,1272],[0,"%Selector",1017],[0,"%BitwiseXOrExpression",1273],[6,1274],[4,1275,1276],[4,876,493,876,1158,876,105,876,1158],[3,1277,917,1278,1279,1280,1281],[4,608,876,1282,876,1283,876,611],[3,1243,1244],[4,1026,876,1284],[4,608,876,949,876,611],[4,613,876,1017],[3,1285,1286],[9,1287],[4,617,1196,1196],[3,1214,947,167],[4,52,1288,54],[3,1289,1017],[6,1290],[4,1291,1292],[4,876,167,876,623],[4,1293,1294],[4,876,626,248,876,1254],[0,"%LogicalAndExpressionNoIn",1295],[6,1296],[0,"%THIS",1297],[0,"%Literal",1298],[0,"%ArrayLiteral",1299],[0,"%ObjectLiteral",1300],[4,52,876,949,876,54],[3,1301,949],[0,"%SelectorCall",1302],[6,1303],[0,"%SingleEscapeCharacter",636],[0,"%NonEscapeCharacter",1304],[0,"%DecimalDigit",638],[8,1305],[0,"%ACTION",1306],[4,876,1269],[0,"%KeywordDeclarator",1307],[6,1308],[0,"%BitwiseAndExpression",1309],[6,1310],[4,1311,1312],[4,876,538,876,1275],[4,373,975],[3,1131,1132,1313,1043,1314,1315],[4,608,876,1316,876,611],[4,55,876,1317,876,57],[0,"%SUPER",1318],[3,1319,1233],[4,167,876,1026],[4,979,1320,82],[4,1321,1322],[3,1323,1324],[4,1325,105,1194,876,917],[4,876,1291],[4,1326,1327],[4,876,662,248,876,1293],[0,"%BitwiseOrExpressionNoIn",1328],[6,1329],[0,"%NumericLiteral",1330],[0,"%RegularExpressionLiteral",1331],[0,"%SelectorLiteral",1332],[0,"%ElementList",1333],[8,1334],[4,401,975],[4,1335,1336],[9,1337],[0,"%AccessorsConfiguration",1338],[6,1339],[4,675,975],[4,676,975],[8,1340],[0,"%EqualityExpression",1341],[6,1342],[4,1343,1344],[4,876,580,876,1311],[4,1345,1346],[4,684,1347,684,1348],[4,687,876,52,876,1349,876,54],[4,1350,1351,876,1352],[4,1353,876,693],[0,"%KeywordSelectorCall",1354],[6,1355],[0,"%EscapeCharacter",1356],[3,1357,1358,1359,700],[4,876,167,876,1321],[4,1253,876],[4,1360,1361],[4,876,703,248,876,1326],[0,"%BitwiseXOrExpressionNoIn",1362],[6,1363],[3,1364,1365],[9,1080],[0,"%RegularExpressionBody",1366],[0,"%RegularExpressionFlags",1087],[0,"%SelectorLiteralContents",1367],[6,1368],[6,1369],[8,1026],[0,"%PropertyNameAndValueList",1370],[4,1371,1372],[4,876,167,876,949],[3,1285,1287,617,489],[0,"%IvarPropertyName",1373],[0,"%IvarGetterName",1374],[0,"%IvarSetterName",1375],[0,"%RelationalExpression",1376],[6,1377],[4,1378,1379],[4,876,626,248,876,1343],[0,"%HexIntegerLiteral",1380],[0,"%DecimalLiteral",1381],[4,1382,1383],[3,1384,917],[4,167,876],[4,876,1026,1385],[4,1386,1387],[0,"%KeywordCall",1388],[6,1389],[4,732,876,247,876,917],[4,733,876,247,876,917],[4,734,876,247,876,917,1390],[4,1391,1392],[4,876,1393,876,1360],[0,"%BitwiseAndExpressionNoIn",1394],[6,1395],[4,590,741,1396],[4,1397,1398],[0,"%RegularExpressionFirstChar",1399],[6,1400],[7,1401],[7,1402],[0,"%PropertyAssignment",1403],[6,1404],[4,1405,876,105,876,949],[4,876,1371],[8,1406],[0,"%ShiftExpression",1407],[6,1408],[0,"%EqualityOperator",755],[4,1409,1410],[4,876,662,248,876,1378],[7,1196],[3,1411,1412,1413],[8,1414],[3,1415,1416,1417],[0,"%RegularExpressionChar",1418],[4,1405,876,105,876],[4,876,167],[3,1419,1420,1421],[4,876,167,876,1386],[8,1253],[4,876,105],[4,1422,1423],[4,876,1424,876,1391],[0,"%EqualityExpressionNoIn",1425],[6,1426],[4,1413,613,1427],[4,613,1428],[0,"%DecimalIntegerLiteral",1429],[0,"%ExponentPart",1430],[4,782,1431],[0,"%RegularExpressionBackslashSequence",1432],[0,"%RegularExpressionClass",1433],[3,1434,1416,1417],[4,1435,876,105,876,1026],[0,"%PropertyGetter",1436],[0,"%PropertySetter",1437],[0,"%AdditiveExpression",1438],[6,1439],[0,"%RelationalOperator",1440],[4,1441,1442],[4,876,703,248,876,1409],[6,1287],[7,1287],[3,590,1443],[4,796,1444],[0,"%RegularExpressionNonTerminator",941],[4,327,1431],[4,608,1445,611],[4,800,1431],[0,"%PropertyName",1446],[4,802,876,1435,876,52,876,54,876,55,876,919,876,57],[4,803,876,1435,876,52,876,1447,876,54,876,55,876,919,876,57],[4,1448,1449],[4,876,1450,876,1422],[3,808,809,232,234,1451,1035],[0,"%RelationalExpressionNoIn",1452],[6,1453],[4,813,1427],[0,"%SignedInteger",1454],[6,1455],[3,1017,1043,1313],[0,"%PropertySetParameterList",917],[0,"%MultiplicativeExpression",1456],[6,1457],[0,"%ShiftOperator",819],[0,"%INSTANCEOF",1458],[4,1391,1459],[4,876,1393,876,1441],[4,822,1428],[0,"%RegularExpressionClassChar",1460],[4,1461,1462],[4,876,1463,876,1448],[4,371,975],[6,1464],[3,1465,1416],[0,"%UnaryExpression",1466],[6,1467],[0,"%AdditiveOperator",835],[4,876,1468,876,1391],[4,837,1431],[3,1469,1470,1471,1472,1473,1474,1475,1476,1477,1478],[4,876,1479,876,1461],[0,"%RelationalOperatorNoIn",1480],[0,"%PostfixExpression",1481],[4,1482,876,1461],[4,1483,876,1461],[4,1484,876,1461],[4,856,876,1461],[4,857,876,1461],[4,510,876,1461],[4,514,876,1461],[4,858,876,1461],[4,859,876,1461],[0,"%MultiplicativeOperator",860],[3,808,809,232,234,1451],[4,1093,1485],[0,"%DELETE",1486],[0,"%VOID",1487],[0,"%TYPEOF",1488],[8,1489],[4,370,975],[4,375,975],[4,374,975],[4,958,873]],"nameToUID":{"start":1,"_":3,"SourceElements":6,"WhiteSpace":9,"LineTerminator":10,"Comment":11,"SourceElement":12,"MultiLineComment":19,"SingleLineComment":20,"Statement":21,"FunctionDeclaration":22,"Block":32,"VariableStatement":33,"EmptyStatement":34,"ExpressionStatement":35,"IfStatement":36,"IterationStatement":37,"ContinueStatement":38,"BreakStatement":39,"ReturnStatement":40,"WithStatement":41,"LabelledStatement":42,"SwitchStatement":43,"ThrowStatement":44,"TryStatement":45,"DebuggerStatement":46,"FunctionExpression":47,"ImportStatement":48,"ClassDeclarationStatement":49,"FUNCTION":50,"Identifier":51,"FunctionBody":56,"SingleLineCommentChar":59,"FormalParameterList":80,"VAR":85,"VariableDeclaration":86,"EOS":88,"Expression":90,"IF":91,"DoWhileStatement":93,"WhileStatement":94,"ForStatement":95,"ForInStatement":96,"EachStatement":97,"CONTINUE":98,"__":99,"BREAK":101,"RETURN":102,"WITH":104,"SWITCH":106,"CaseBlock":107,"THROW":108,"TRY":109,"DEBUGGER":111,"ClassBody":118,"IdentifierName":123,"StatementList":126,"SemicolonInsertionEOS":143,"Finally":153,"LocalFilePath":155,"StandardFilePath":156,"IdentifierPart":160,"AssignmentExpression":172,"ELSE":175,"DO":176,"WHILE":177,"FOR":178,"ForInFirstExpression":181,"IN":182,"Catch":195,"StringLiteral":199,"SuperclassDeclaration":201,"CategoryDeclaration":202,"ClassElements":204,"ReservedWord":206,"IdentifierStart":207,"LineTerminatorSequence":212,"EOF":214,"ForFirstExpression":221,"SingleLineMultiLineComment":224,"CaseClauses":226,"DefaultClause":227,"FINALLY":230,"UnicodeCombiningMark":239,"UnicodeDigit":240,"UnicodeConnectorPunctuation":241,"ZWNJ":242,"ZWJ":243,"ConditionalExpression":252,"LeftHandSideExpression":258,"CATCH":264,"CompoundIvarDeclaration":269,"ClassElement":270,"Keyword":277,"FutureReservedWord":278,"NullLiteral":279,"BooleanLiteral":280,"UnicodeLetter":281,"AssignmentOperator":289,"ExpressionNoIn":291,"VariableDeclarationNoIn":294,"CaseClause":296,"DEFAULT":298,"NULL":324,"UnicodeEscapeSequence":328,"LogicalOrExpression":331,"VariableDeclarationListNoIn":334,"CallExpression":335,"NewExpression":336,"DoubleStringCharacter":345,"SingleStringCharacter":346,"IvarType":348,"IvarDeclaration":349,"ClassMethodDeclaration":351,"InstanceMethodDeclaration":352,"TRUE":407,"FALSE":408,"AssignmentExpressionNoIn":442,"CASE":448,"HexDigit":490,"LogicalAndExpression":491,"MemberExpression":497,"Arguments":498,"LineContinuation":505,"IvarTypeElement":507,"MethodSelector":512,"ConditionalExpressionNoIn":521,"NEW":526,"EscapeSequence":528,"Accessors":533,"BitwiseOrExpression":536,"MethodType":551,"UnarySelector":553,"LogicalOrExpressionNoIn":556,"PrimaryExpression":558,"MessageExpression":559,"ArgumentList":562,"BracketedAccessor":563,"DotAccessor":564,"CharacterEscapeSequence":566,"HexEscapeSequence":568,"KeywordSelector":575,"Selector":577,"BitwiseXOrExpression":578,"LogicalAndExpressionNoIn":601,"THIS":603,"Literal":604,"ArrayLiteral":605,"ObjectLiteral":606,"SelectorCall":610,"SingleEscapeCharacter":614,"NonEscapeCharacter":615,"DecimalDigit":616,"ACTION":619,"KeywordDeclarator":621,"BitwiseAndExpression":624,"SUPER":633,"BitwiseOrExpressionNoIn":645,"NumericLiteral":647,"RegularExpressionLiteral":648,"SelectorLiteral":649,"ElementList":650,"AccessorsConfiguration":655,"EqualityExpression":660,"KeywordSelectorCall":670,"EscapeCharacter":672,"BitwiseXOrExpressionNoIn":680,"RegularExpressionBody":685,"RegularExpressionFlags":686,"SelectorLiteralContents":688,"PropertyNameAndValueList":692,"IvarPropertyName":697,"IvarGetterName":698,"IvarSetterName":699,"RelationalExpression":701,"HexIntegerLiteral":706,"DecimalLiteral":707,"KeywordCall":713,"BitwiseAndExpressionNoIn":720,"RegularExpressionFirstChar":724,"PropertyAssignment":728,"ShiftExpression":736,"EqualityOperator":738,"RegularExpressionChar":746,"EqualityExpressionNoIn":756,"DecimalIntegerLiteral":760,"ExponentPart":761,"RegularExpressionBackslashSequence":763,"RegularExpressionClass":764,"PropertyGetter":767,"PropertySetter":768,"AdditiveExpression":769,"RelationalOperator":771,"RegularExpressionNonTerminator":783,"PropertyName":787,"RelationalExpressionNoIn":793,"SignedInteger":797,"PropertySetParameterList":804,"MultiplicativeExpression":805,"ShiftOperator":807,"INSTANCEOF":810,"RegularExpressionClassChar":815,"UnaryExpression":824,"AdditiveOperator":826,"RelationalOperatorNoIn":836,"PostfixExpression":838,"MultiplicativeOperator":848,"DELETE":853,"VOID":854,"TYPEOF":855,"%start":874,"%_":876,"%SourceElements":879,"%WhiteSpace":882,"%LineTerminator":883,"%Comment":884,"%SourceElement":885,"%MultiLineComment":890,"%SingleLineComment":891,"%Statement":892,"%FunctionDeclaration":893,"%Block":898,"%VariableStatement":899,"%EmptyStatement":900,"%ExpressionStatement":901,"%IfStatement":902,"%IterationStatement":903,"%ContinueStatement":904,"%BreakStatement":905,"%ReturnStatement":906,"%WithStatement":907,"%LabelledStatement":908,"%SwitchStatement":909,"%ThrowStatement":910,"%TryStatement":911,"%DebuggerStatement":912,"%FunctionExpression":913,"%ImportStatement":914,"%ClassDeclarationStatement":915,"%FUNCTION":916,"%Identifier":917,"%FunctionBody":919,"%SingleLineCommentChar":920,"%FormalParameterList":940,"%BadBlock":943,"%VAR":944,"%VariableDeclaration":945,"%EOS":947,"%Expression":949,"%IF":950,"%DoWhileStatement":952,"%WhileStatement":953,"%ForStatement":954,"%ForInStatement":955,"%EachStatement":956,"%CONTINUE":957,"%__":958,"%BREAK":960,"%RETURN":961,"%WITH":963,"%SWITCH":964,"%CaseBlock":965,"%THROW":966,"%TRY":967,"%DEBUGGER":969,"%ClassBody":974,"%BadIdentifier":977,"%SemicolonInsertionEOS":998,"%Finally":1008,"%LocalFilePath":1010,"%StandardFilePath":1011,"%IdentifierPart":1015,"%IdentifierName":1017,"%StatementList":1020,"%AssignmentExpression":1026,"%ELSE":1028,"%DO":1029,"%WHILE":1030,"%FOR":1031,"%ForInFirstExpression":1034,"%IN":1035,"%Catch":1040,"%StringLiteral":1043,"%SuperclassDeclaration":1045,"%CategoryDeclaration":1046,"%ClassElements":1048,"%ReservedWordIdentifier":1052,"%DigitIdentifier":1053,"%LineTerminatorSequence":1057,"%EOF":1058,"%ForFirstExpression":1065,"%SingleLineMultiLineComment":1068,"%CaseClauses":1070,"%DefaultClause":1071,"%FINALLY":1074,"%IdentifierStart":1080,"%UnicodeCombiningMark":1081,"%UnicodeDigit":1082,"%UnicodeConnectorPunctuation":1083,"%ZWNJ":1084,"%ZWJ":1085,"%ReservedWord":1086,"%ConditionalExpression":1091,"%LeftHandSideExpression":1093,"%CATCH":1098,"%CompoundIvarDeclaration":1102,"%ClassElement":1103,"%AssignmentOperator":1109,"%ExpressionNoIn":1111,"%VariableDeclarationNoIn":1114,"%CaseClause":1116,"%DEFAULT":1118,"%UnicodeLetter":1127,"%Keyword":1129,"%FutureReservedWord":1130,"%NullLiteral":1131,"%BooleanLiteral":1132,"%LogicalOrExpression":1133,"%VariableDeclarationListNoIn":1136,"%CallExpression":1137,"%NewExpression":1138,"%DoubleStringCharacter":1146,"%SingleStringCharacter":1147,"%IvarType":1148,"%IvarDeclaration":1149,"%ClassMethodDeclaration":1151,"%InstanceMethodDeclaration":1152,"%UnicodeEscapeSequence":1153,"%NULL":1154,"%AssignmentExpressionNoIn":1158,"%CASE":1164,"%TRUE":1174,"%FALSE":1175,"%LogicalAndExpression":1176,"%MemberExpression":1181,"%Arguments":1182,"%LineContinuation":1189,"%IvarTypeElement":1191,"%MethodSelector":1195,"%HexDigit":1196,"%ConditionalExpressionNoIn":1202,"%NEW":1207,"%EscapeSequence":1209,"%Accessors":1214,"%BitwiseOrExpression":1217,"%MethodType":1231,"%UnarySelector":1233,"%LogicalOrExpressionNoIn":1236,"%PrimaryExpression":1238,"%MessageExpression":1239,"%ArgumentList":1242,"%BracketedAccessor":1243,"%DotAccessor":1244,"%CharacterEscapeSequence":1245,"%HexEscapeSequence":1247,"%KeywordSelector":1251,"%Selector":1253,"%BitwiseXOrExpression":1254,"%LogicalAndExpressionNoIn":1275,"%THIS":1277,"%Literal":1278,"%ArrayLiteral":1279,"%ObjectLiteral":1280,"%SelectorCall":1283,"%SingleEscapeCharacter":1285,"%NonEscapeCharacter":1286,"%DecimalDigit":1287,"%ACTION":1289,"%KeywordDeclarator":1291,"%BitwiseAndExpression":1293,"%SUPER":1301,"%BitwiseOrExpressionNoIn":1311,"%NumericLiteral":1313,"%RegularExpressionLiteral":1314,"%SelectorLiteral":1315,"%ElementList":1316,"%AccessorsConfiguration":1321,"%EqualityExpression":1326,"%KeywordSelectorCall":1335,"%EscapeCharacter":1337,"%BitwiseXOrExpressionNoIn":1343,"%RegularExpressionBody":1347,"%RegularExpressionFlags":1348,"%SelectorLiteralContents":1349,"%PropertyNameAndValueList":1353,"%IvarPropertyName":1357,"%IvarGetterName":1358,"%IvarSetterName":1359,"%RelationalExpression":1360,"%HexIntegerLiteral":1364,"%DecimalLiteral":1365,"%KeywordCall":1371,"%BitwiseAndExpressionNoIn":1378,"%RegularExpressionFirstChar":1382,"%PropertyAssignment":1386,"%ShiftExpression":1391,"%EqualityOperator":1393,"%RegularExpressionChar":1400,"%EqualityExpressionNoIn":1409,"%DecimalIntegerLiteral":1413,"%ExponentPart":1414,"%RegularExpressionBackslashSequence":1416,"%RegularExpressionClass":1417,"%PropertyGetter":1420,"%PropertySetter":1421,"%AdditiveExpression":1422,"%RelationalOperator":1424,"%RegularExpressionNonTerminator":1431,"%PropertyName":1435,"%RelationalExpressionNoIn":1441,"%SignedInteger":1444,"%PropertySetParameterList":1447,"%MultiplicativeExpression":1448,"%ShiftOperator":1450,"%INSTANCEOF":1451,"%RegularExpressionClassChar":1455,"%UnaryExpression":1461,"%AdditiveOperator":1463,"%RelationalOperatorNoIn":1468,"%PostfixExpression":1469,"%MultiplicativeOperator":1479,"%DELETE":1482,"%VOID":1483,"%TYPEOF":1484}}; +var compiledGrammar = {"table":[[0,"source",1],[0,"start",2],[4,3,4,3],[0,"_",5],[8,6],[6,7],[0,"SourceElements",8],[3,9,10,11],[4,12,13],[0,"WhiteSpace",14],[0,"LineTerminator",15],[0,"Comment",16],[0,"SourceElement",17],[6,18],[2,"[\\u0009\\u000B\\u000C\\u0020\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"],[2,"[\\u000A\\u000D\\u2028\\u2029]"],[3,19,20],[3,21,22],[4,3,12],[0,"MultiLineComment",23],[0,"SingleLineComment",24],[0,"Statement",25],[0,"FunctionDeclaration",26],[4,27,28,29],[4,30,31],[3,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,22,47,48,49],[4,50,3,51,3,52,3,53,3,54,3,55,3,56,3,57],[5,"/*"],[6,58],[5,"*/"],[5,"//"],[6,59],[0,"Block",60],[0,"VariableStatement",61],[0,"EmptyStatement",62],[0,"ExpressionStatement",63],[0,"IfStatement",64],[0,"IterationStatement",65],[0,"ContinueStatement",66],[0,"BreakStatement",67],[0,"ReturnStatement",68],[0,"WithStatement",69],[0,"LabelledStatement",70],[0,"SwitchStatement",71],[0,"ThrowStatement",72],[0,"TryStatement",73],[0,"DebuggerStatement",74],[0,"FunctionExpression",75],[0,"ImportStatement",76],[0,"ClassDeclarationStatement",77],[0,"FUNCTION",78],[0,"Identifier",79],[5,"("],[8,80],[5,")"],[5,"{"],[0,"FunctionBody",2],[5,"}"],[4,81,82],[0,"SingleLineCommentChar",83],[4,55,3,84,3,57],[4,85,3,86,87,88],[5,";"],[4,89,90,88],[4,91,3,52,3,90,3,54,3,21,92],[3,93,94,95,96,97],[4,98,99,100],[4,101,99,100],[4,102,99,103],[4,104,3,52,3,90,3,54,3,21],[4,51,3,105,3,21],[4,106,3,52,3,90,3,54,3,107],[4,108,99,103],[4,109,3,32,3,110],[4,111,88],[4,50,3,112,3,52,3,53,3,54,3,55,3,56,3,57],[4,113,3,114,88],[4,115,3,51,3,116,3,117,3,118,3,119,88],[4,120,121],[4,122,123],[0,"FormalParameterList",124],[9,29],[1],[4,125,82],[8,126],[0,"VAR",127],[0,"VariableDeclaration",128],[6,129],[0,"EOS",130],[9,131],[0,"Expression",132],[0,"IF",133],[8,134],[0,"DoWhileStatement",135],[0,"WhileStatement",136],[0,"ForStatement",137],[0,"ForInStatement",138],[0,"EachStatement",139],[0,"CONTINUE",140],[0,"__",141],[3,142,143],[0,"BREAK",144],[0,"RETURN",145],[3,143,146],[0,"WITH",147],[5,":"],[0,"SWITCH",148],[0,"CaseBlock",149],[0,"THROW",150],[0,"TRY",151],[3,152,153],[0,"DEBUGGER",154],[8,51],[5,"@import"],[3,155,156],[5,"@implementation"],[8,157],[8,158],[0,"ClassBody",159],[5,"@end"],[5,"function"],[9,160],[9,161],[0,"IdentifierName",162],[4,51,163],[9,10],[0,"StatementList",164],[4,165,121],[4,51,166],[4,3,167,3,86],[3,168,169,170,171],[3,55,50],[4,172,173],[4,174,121],[4,3,175,3,21],[4,176,3,21,3,177,3,52,3,90,3,54,88],[4,177,3,52,3,90,3,54,3,21],[4,178,3,52,3,179,3,62,3,180,3,62,3,180,3,54,3,21],[4,178,3,52,3,181,3,182,3,90,3,54,3,21],[4,183,3,52,3,181,3,182,3,90,3,54,3,21],[4,184,121],[6,185],[4,51,88],[0,"SemicolonInsertionEOS",186],[4,187,121],[4,188,121],[4,90,88],[4,189,121],[4,190,121],[4,55,3,191,3,192,3,191,3,57],[4,193,121],[4,194,121],[4,195,196],[0,"Finally",197],[4,198,121],[0,"LocalFilePath",199],[0,"StandardFilePath",200],[3,201,202],[4,55,203,3,57],[8,204],[0,"IdentifierPart",205],[4,206,121],[4,207,208],[6,209],[4,21,210],[5,"var"],[8,211],[5,","],[4,3,62],[4,99,212],[4,99,213],[4,99,214],[0,"AssignmentExpression",215],[6,216],[5,"if"],[0,"ELSE",217],[0,"DO",218],[0,"WHILE",219],[0,"FOR",220],[8,221],[8,90],[0,"ForInFirstExpression",222],[0,"IN",223],[5,"@each"],[5,"continue"],[3,9,224,20],[3,225,169,170,171],[5,"break"],[5,"return"],[5,"with"],[5,"switch"],[8,226],[8,227],[5,"throw"],[5,"try"],[0,"Catch",228],[8,229],[4,230,3,32],[5,"debugger"],[0,"StringLiteral",231],[4,232,3,233,3,234],[0,"SuperclassDeclaration",235],[0,"CategoryDeclaration",236],[6,237],[0,"ClassElements",238],[3,207,239,240,241,242,243],[0,"ReservedWord",244],[0,"IdentifierStart",245],[6,160],[4,3,167,3,51],[6,246],[4,3,247,248,3,172],[0,"LineTerminatorSequence",249],[10,57],[0,"EOF",250],[3,251,252],[4,3,167,3,172],[4,253,121],[4,254,121],[4,255,121],[4,256,121],[0,"ForFirstExpression",257],[3,258,259],[4,260,121],[0,"SingleLineMultiLineComment",261],[4,99,62],[0,"CaseClauses",262],[0,"DefaultClause",263],[4,264,3,52,3,51,3,54,3,32],[4,3,153],[0,"FINALLY",265],[3,266,267],[5,"<"],[6,268],[5,">"],[4,105,3,51],[4,52,3,51,3,54],[4,3,269],[4,270,271],[0,"UnicodeCombiningMark",272],[0,"UnicodeDigit",273],[0,"UnicodeConnectorPunctuation",274],[0,"ZWNJ",275],[0,"ZWJ",276],[3,277,278,279,280],[3,281,282,283],[4,3,21],[5,"="],[9,247],[3,284,285,286,287,288],[9,82],[4,258,3,289,3,172],[0,"ConditionalExpression",290],[5,"else"],[5,"do"],[5,"while"],[5,"for"],[3,291,292],[0,"LeftHandSideExpression",293],[4,85,3,294],[5,"in"],[4,27,295,29],[4,296,297],[4,298,3,105,299],[0,"CATCH",300],[4,301,121],[4,302,303,304,303],[4,305,306,305],[3,307,308],[0,"CompoundIvarDeclaration",309],[0,"ClassElement",310],[6,311],[3,312,313,314,315,316,317],[3,318,319,320,321],[2,"[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]"],[5,"\u200C"],[5,"\u200D"],[0,"Keyword",322],[0,"FutureReservedWord",323],[0,"NullLiteral",324],[0,"BooleanLiteral",325],[0,"UnicodeLetter",326],[2,"[$_]"],[4,327,328],[5,"\n"],[4,288,329],[5,"\u2028"],[5,"\u2029"],[5,"\r"],[0,"AssignmentOperator",330],[4,331,332],[0,"ExpressionNoIn",333],[4,85,3,334],[3,335,336],[0,"VariableDeclarationNoIn",337],[6,338],[0,"CaseClause",339],[6,340],[0,"DEFAULT",341],[8,342],[4,343,121],[5,"finally"],[8,344],[5,"\""],[6,345],[5,"'"],[6,346],[5,"\\>"],[4,347,82],[4,348,3,349,350,88],[3,351,352,21,22],[4,3,270],[2,"[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0900-\\u0902\\u093A\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0957\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135D-\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1BE6\\u1BE8\\u1BE9\\u1BED\\u1BEF-\\u1BF1\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFC-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26\\u0903\\u093B\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u094F\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1BE7\\u1BEA-\\u1BEC\\u1BEE\\u1BF2\\u1BF3\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"],[4,353,354],[4,355,356],[4,357,358],[4,359,360],[4,361,362],[2,"[\\u0030-\\u0039\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]"],[4,363,364],[4,357,365],[4,366,367],[3,187,368,343,184,198,369,370,254,253,301,256,120,174,371,260,372,188,190,373,193,194,374,165,375,255,189],[3,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405],[0,"NULL",406],[3,407,408],[3,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426],[5,"\\"],[0,"UnicodeEscapeSequence",427],[8,284],[3,428,429,430,431,432,433,434,435,436,437,438,439],[0,"LogicalOrExpression",440],[8,441],[4,442,443],[0,"VariableDeclarationListNoIn",444],[0,"CallExpression",445],[0,"NewExpression",446],[4,51,447],[4,81,125,82],[4,448,3,90,3,105,299],[4,3,296],[4,369,121],[4,3,126],[5,"catch"],[4,449,3],[0,"DoubleStringCharacter",450],[0,"SingleStringCharacter",451],[9,234],[0,"IvarType",452],[0,"IvarDeclaration",453],[6,454],[0,"ClassMethodDeclaration",455],[0,"InstanceMethodDeclaration",456],[5,"\uDB40"],[2,"[\\uDD00-\\uDDEF]"],[5,"\uD834"],[2,"[\\uDD67-\\uDD69\\uDD7B-\\uDD82\\uDD85-\\uDD8B\\uDDAA-\\uDDAD\\uDE42-\\uDE44\\uDD65\\uDD66\\uDD6D-\\uDD72]"],[5,"\uD804"],[2,"[\\uDC01\\uDC38-\\uDC46\\uDC80\\uDC81\\uDCB3-\\uDCB6\\uDCB9\\uDCBA\\uDC00\\uDC02\\uDC82\\uDCB0-\\uDCB2\\uDCB7\\uDCB8]"],[5,"\uD800"],[2,"[\\uDDFD]"],[5,"\uD802"],[2,"[\\uDE01-\\uDE03\\uDE05\\uDE06\\uDE0C-\\uDE0F\\uDE38-\\uDE3A\\uDE3F]"],[5,"\uD835"],[2,"[\\uDFCE-\\uDFFF]"],[2,"[\\uDC66-\\uDC6F]"],[5,"\uD801"],[2,"[\\uDCA0-\\uDCA9]"],[5,"case"],[5,"default"],[5,"delete"],[5,"instanceof"],[5,"new"],[5,"this"],[5,"typeof"],[5,"void"],[5,"abstract"],[5,"boolean"],[5,"byte"],[5,"char"],[5,"class"],[5,"const"],[5,"double"],[5,"enum"],[5,"export"],[5,"extends"],[5,"final"],[5,"float"],[5,"goto"],[5,"implements"],[5,"import"],[5,"interface"],[5,"int"],[5,"long"],[5,"native"],[5,"package"],[5,"private"],[5,"protected"],[5,"public"],[5,"short"],[5,"static"],[5,"super"],[5,"synchronized"],[5,"throws"],[5,"transient"],[5,"volatile"],[4,457,121],[0,"TRUE",458],[0,"FALSE",459],[2,"[\\u0041-\\u005A\\u00C0-\\u00D6\\u00D8-\\u00DE\\u0100\\u0102\\u0104\\u0106\\u0108\\u010A\\u010C\\u010E\\u0110\\u0112\\u0114\\u0116\\u0118\\u011A\\u011C\\u011E\\u0120\\u0122\\u0124\\u0126\\u0128\\u012A\\u012C\\u012E\\u0130\\u0132\\u0134\\u0136\\u0139\\u013B\\u013D\\u013F\\u0141\\u0143\\u0145\\u0147\\u014A\\u014C\\u014E\\u0150\\u0152\\u0154\\u0156\\u0158\\u015A\\u015C\\u015E\\u0160\\u0162\\u0164\\u0166\\u0168\\u016A\\u016C\\u016E\\u0170\\u0172\\u0174\\u0176\\u0178\\u0179\\u017B\\u017D\\u0181\\u0182\\u0184\\u0186\\u0187\\u0189-\\u018B\\u018E-\\u0191\\u0193\\u0194\\u0196-\\u0198\\u019C\\u019D\\u019F\\u01A0\\u01A2\\u01A4\\u01A6\\u01A7\\u01A9\\u01AC\\u01AE\\u01AF\\u01B1-\\u01B3\\u01B5\\u01B7\\u01B8\\u01BC\\u01C4\\u01C7\\u01CA\\u01CD\\u01CF\\u01D1\\u01D3\\u01D5\\u01D7\\u01D9\\u01DB\\u01DE\\u01E0\\u01E2\\u01E4\\u01E6\\u01E8\\u01EA\\u01EC\\u01EE\\u01F1\\u01F4\\u01F6-\\u01F8\\u01FA\\u01FC\\u01FE\\u0200\\u0202\\u0204\\u0206\\u0208\\u020A\\u020C\\u020E\\u0210\\u0212\\u0214\\u0216\\u0218\\u021A\\u021C\\u021E\\u0220\\u0222\\u0224\\u0226\\u0228\\u022A\\u022C\\u022E\\u0230\\u0232\\u023A\\u023B\\u023D\\u023E\\u0241\\u0243-\\u0246\\u0248\\u024A\\u024C\\u024E\\u0370\\u0372\\u0376\\u0386\\u0388-\\u038A\\u038C\\u038E\\u038F\\u0391-\\u03A1\\u03A3-\\u03AB\\u03CF\\u03D2-\\u03D4\\u03D8\\u03DA\\u03DC\\u03DE\\u03E0\\u03E2\\u03E4\\u03E6\\u03E8\\u03EA\\u03EC\\u03EE\\u03F4\\u03F7\\u03F9\\u03FA\\u03FD-\\u042F\\u0460\\u0462\\u0464\\u0466\\u0468\\u046A\\u046C\\u046E\\u0470\\u0472\\u0474\\u0476\\u0478\\u047A\\u047C\\u047E\\u0480\\u048A\\u048C\\u048E\\u0490\\u0492\\u0494\\u0496\\u0498\\u049A\\u049C\\u049E\\u04A0\\u04A2\\u04A4\\u04A6\\u04A8\\u04AA\\u04AC\\u04AE\\u04B0\\u04B2\\u04B4\\u04B6\\u04B8\\u04BA\\u04BC\\u04BE\\u04C0\\u04C1\\u04C3\\u04C5\\u04C7\\u04C9\\u04CB\\u04CD\\u04D0\\u04D2\\u04D4\\u04D6\\u04D8\\u04DA\\u04DC\\u04DE\\u04E0\\u04E2\\u04E4\\u04E6\\u04E8\\u04EA\\u04EC\\u04EE\\u04F0\\u04F2\\u04F4\\u04F6\\u04F8\\u04FA\\u04FC\\u04FE\\u0500\\u0502\\u0504\\u0506\\u0508\\u050A\\u050C\\u050E\\u0510\\u0512\\u0514\\u0516\\u0518\\u051A\\u051C\\u051E\\u0520\\u0522\\u0524\\u0526\\u0531-\\u0556\\u10A0-\\u10C5\\u1E00\\u1E02\\u1E04\\u1E06\\u1E08\\u1E0A\\u1E0C\\u1E0E\\u1E10\\u1E12\\u1E14\\u1E16\\u1E18\\u1E1A\\u1E1C\\u1E1E\\u1E20\\u1E22\\u1E24\\u1E26\\u1E28\\u1E2A\\u1E2C\\u1E2E\\u1E30\\u1E32\\u1E34\\u1E36\\u1E38\\u1E3A\\u1E3C\\u1E3E\\u1E40\\u1E42\\u1E44\\u1E46\\u1E48\\u1E4A\\u1E4C\\u1E4E\\u1E50\\u1E52\\u1E54\\u1E56\\u1E58\\u1E5A\\u1E5C\\u1E5E\\u1E60\\u1E62\\u1E64\\u1E66\\u1E68\\u1E6A\\u1E6C\\u1E6E\\u1E70\\u1E72\\u1E74\\u1E76\\u1E78\\u1E7A\\u1E7C\\u1E7E\\u1E80\\u1E82\\u1E84\\u1E86\\u1E88\\u1E8A\\u1E8C\\u1E8E\\u1E90\\u1E92\\u1E94\\u1E9E\\u1EA0\\u1EA2\\u1EA4\\u1EA6\\u1EA8\\u1EAA\\u1EAC\\u1EAE\\u1EB0\\u1EB2\\u1EB4\\u1EB6\\u1EB8\\u1EBA\\u1EBC\\u1EBE\\u1EC0\\u1EC2\\u1EC4\\u1EC6\\u1EC8\\u1ECA\\u1ECC\\u1ECE\\u1ED0\\u1ED2\\u1ED4\\u1ED6\\u1ED8\\u1EDA\\u1EDC\\u1EDE\\u1EE0\\u1EE2\\u1EE4\\u1EE6\\u1EE8\\u1EEA\\u1EEC\\u1EEE\\u1EF0\\u1EF2\\u1EF4\\u1EF6\\u1EF8\\u1EFA\\u1EFC\\u1EFE\\u1F08-\\u1F0F\\u1F18-\\u1F1D\\u1F28-\\u1F2F\\u1F38-\\u1F3F\\u1F48-\\u1F4D\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F68-\\u1F6F\\u1FB8-\\u1FBB\\u1FC8-\\u1FCB\\u1FD8-\\u1FDB\\u1FE8-\\u1FEC\\u1FF8-\\u1FFB\\u2102\\u2107\\u210B-\\u210D\\u2110-\\u2112\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u2130-\\u2133\\u213E\\u213F\\u2145\\u2183\\u2C00-\\u2C2E\\u2C60\\u2C62-\\u2C64\\u2C67\\u2C69\\u2C6B\\u2C6D-\\u2C70\\u2C72\\u2C75\\u2C7E-\\u2C80\\u2C82\\u2C84\\u2C86\\u2C88\\u2C8A\\u2C8C\\u2C8E\\u2C90\\u2C92\\u2C94\\u2C96\\u2C98\\u2C9A\\u2C9C\\u2C9E\\u2CA0\\u2CA2\\u2CA4\\u2CA6\\u2CA8\\u2CAA\\u2CAC\\u2CAE\\u2CB0\\u2CB2\\u2CB4\\u2CB6\\u2CB8\\u2CBA\\u2CBC\\u2CBE\\u2CC0\\u2CC2\\u2CC4\\u2CC6\\u2CC8\\u2CCA\\u2CCC\\u2CCE\\u2CD0\\u2CD2\\u2CD4\\u2CD6\\u2CD8\\u2CDA\\u2CDC\\u2CDE\\u2CE0\\u2CE2\\u2CEB\\u2CED\\uA640\\uA642\\uA644\\uA646\\uA648\\uA64A\\uA64C\\uA64E\\uA650\\uA652\\uA654\\uA656\\uA658\\uA65A\\uA65C\\uA65E\\uA660\\uA662\\uA664\\uA666\\uA668\\uA66A\\uA66C\\uA680\\uA682\\uA684\\uA686\\uA688\\uA68A\\uA68C\\uA68E\\uA690\\uA692\\uA694\\uA696\\uA722\\uA724\\uA726\\uA728\\uA72A\\uA72C\\uA72E\\uA732\\uA734\\uA736\\uA738\\uA73A\\uA73C\\uA73E\\uA740\\uA742\\uA744\\uA746\\uA748\\uA74A\\uA74C\\uA74E\\uA750\\uA752\\uA754\\uA756\\uA758\\uA75A\\uA75C\\uA75E\\uA760\\uA762\\uA764\\uA766\\uA768\\uA76A\\uA76C\\uA76E\\uA779\\uA77B\\uA77D\\uA77E\\uA780\\uA782\\uA784\\uA786\\uA78B\\uA78D\\uA790\\uA7A0\\uA7A2\\uA7A4\\uA7A6\\uA7A8\\uFF21-\\uFF3A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00DF-\\u00F6\\u00F8-\\u00FF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F-\\u0293\\u0295-\\u02AF\\u0371\\u0373\\u0377\\u037B-\\u037D\\u0390\\u03AC-\\u03CE\\u03D0\\u03D1\\u03D5-\\u03D7\\u03D9\\u03DB\\u03DD\\u03DF\\u03E1\\u03E3\\u03E5\\u03E7\\u03E9\\u03EB\\u03ED\\u03EF-\\u03F3\\u03F5\\u03F8\\u03FB\\u03FC\\u0430-\\u045F\\u0461\\u0463\\u0465\\u0467\\u0469\\u046B\\u046D\\u046F\\u0471\\u0473\\u0475\\u0477\\u0479\\u047B\\u047D\\u047F\\u0481\\u048B\\u048D\\u048F\\u0491\\u0493\\u0495\\u0497\\u0499\\u049B\\u049D\\u049F\\u04A1\\u04A3\\u04A5\\u04A7\\u04A9\\u04AB\\u04AD\\u04AF\\u04B1\\u04B3\\u04B5\\u04B7\\u04B9\\u04BB\\u04BD\\u04BF\\u04C2\\u04C4\\u04C6\\u04C8\\u04CA\\u04CC\\u04CE\\u04CF\\u04D1\\u04D3\\u04D5\\u04D7\\u04D9\\u04DB\\u04DD\\u04DF\\u04E1\\u04E3\\u04E5\\u04E7\\u04E9\\u04EB\\u04ED\\u04EF\\u04F1\\u04F3\\u04F5\\u04F7\\u04F9\\u04FB\\u04FD\\u04FF\\u0501\\u0503\\u0505\\u0507\\u0509\\u050B\\u050D\\u050F\\u0511\\u0513\\u0515\\u0517\\u0519\\u051B\\u051D\\u051F\\u0521\\u0523\\u0525\\u0527\\u0561-\\u0587\\u1D00-\\u1D2B\\u1D62-\\u1D77\\u1D79-\\u1D9A\\u1E01\\u1E03\\u1E05\\u1E07\\u1E09\\u1E0B\\u1E0D\\u1E0F\\u1E11\\u1E13\\u1E15\\u1E17\\u1E19\\u1E1B\\u1E1D\\u1E1F\\u1E21\\u1E23\\u1E25\\u1E27\\u1E29\\u1E2B\\u1E2D\\u1E2F\\u1E31\\u1E33\\u1E35\\u1E37\\u1E39\\u1E3B\\u1E3D\\u1E3F\\u1E41\\u1E43\\u1E45\\u1E47\\u1E49\\u1E4B\\u1E4D\\u1E4F\\u1E51\\u1E53\\u1E55\\u1E57\\u1E59\\u1E5B\\u1E5D\\u1E5F\\u1E61\\u1E63\\u1E65\\u1E67\\u1E69\\u1E6B\\u1E6D\\u1E6F\\u1E71\\u1E73\\u1E75\\u1E77\\u1E79\\u1E7B\\u1E7D\\u1E7F\\u1E81\\u1E83\\u1E85\\u1E87\\u1E89\\u1E8B\\u1E8D\\u1E8F\\u1E91\\u1E93\\u1E95-\\u1E9D\\u1E9F\\u1EA1\\u1EA3\\u1EA5\\u1EA7\\u1EA9\\u1EAB\\u1EAD\\u1EAF\\u1EB1\\u1EB3\\u1EB5\\u1EB7\\u1EB9\\u1EBB\\u1EBD\\u1EBF\\u1EC1\\u1EC3\\u1EC5\\u1EC7\\u1EC9\\u1ECB\\u1ECD\\u1ECF\\u1ED1\\u1ED3\\u1ED5\\u1ED7\\u1ED9\\u1EDB\\u1EDD\\u1EDF\\u1EE1\\u1EE3\\u1EE5\\u1EE7\\u1EE9\\u1EEB\\u1EED\\u1EEF\\u1EF1\\u1EF3\\u1EF5\\u1EF7\\u1EF9\\u1EFB\\u1EFD\\u1EFF-\\u1F07\\u1F10-\\u1F15\\u1F20-\\u1F27\\u1F30-\\u1F37\\u1F40-\\u1F45\\u1F50-\\u1F57\\u1F60-\\u1F67\\u1F70-\\u1F7D\\u1F80-\\u1F87\\u1F90-\\u1F97\\u1FA0-\\u1FA7\\u1FB0-\\u1FB4\\u1FB6\\u1FB7\\u1FBE\\u1FC2-\\u1FC4\\u1FC6\\u1FC7\\u1FD0-\\u1FD3\\u1FD6\\u1FD7\\u1FE0-\\u1FE7\\u1FF2-\\u1FF4\\u1FF6\\u1FF7\\u210A\\u210E\\u210F\\u2113\\u212F\\u2134\\u2139\\u213C\\u213D\\u2146-\\u2149\\u214E\\u2184\\u2C30-\\u2C5E\\u2C61\\u2C65\\u2C66\\u2C68\\u2C6A\\u2C6C\\u2C71\\u2C73\\u2C74\\u2C76-\\u2C7C\\u2C81\\u2C83\\u2C85\\u2C87\\u2C89\\u2C8B\\u2C8D\\u2C8F\\u2C91\\u2C93\\u2C95\\u2C97\\u2C99\\u2C9B\\u2C9D\\u2C9F\\u2CA1\\u2CA3\\u2CA5\\u2CA7\\u2CA9\\u2CAB\\u2CAD\\u2CAF\\u2CB1\\u2CB3\\u2CB5\\u2CB7\\u2CB9\\u2CBB\\u2CBD\\u2CBF\\u2CC1\\u2CC3\\u2CC5\\u2CC7\\u2CC9\\u2CCB\\u2CCD\\u2CCF\\u2CD1\\u2CD3\\u2CD5\\u2CD7\\u2CD9\\u2CDB\\u2CDD\\u2CDF\\u2CE1\\u2CE3\\u2CE4\\u2CEC\\u2CEE\\u2D00-\\u2D25\\uA641\\uA643\\uA645\\uA647\\uA649\\uA64B\\uA64D\\uA64F\\uA651\\uA653\\uA655\\uA657\\uA659\\uA65B\\uA65D\\uA65F\\uA661\\uA663\\uA665\\uA667\\uA669\\uA66B\\uA66D\\uA681\\uA683\\uA685\\uA687\\uA689\\uA68B\\uA68D\\uA68F\\uA691\\uA693\\uA695\\uA697\\uA723\\uA725\\uA727\\uA729\\uA72B\\uA72D\\uA72F-\\uA731\\uA733\\uA735\\uA737\\uA739\\uA73B\\uA73D\\uA73F\\uA741\\uA743\\uA745\\uA747\\uA749\\uA74B\\uA74D\\uA74F\\uA751\\uA753\\uA755\\uA757\\uA759\\uA75B\\uA75D\\uA75F\\uA761\\uA763\\uA765\\uA767\\uA769\\uA76B\\uA76D\\uA76F\\uA771-\\uA778\\uA77A\\uA77C\\uA77F\\uA781\\uA783\\uA785\\uA787\\uA78C\\uA78E\\uA791\\uA7A1\\uA7A3\\uA7A5\\uA7A7\\uA7A9\\uA7FA\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFF41-\\uFF5A\\u01C5\\u01C8\\u01CB\\u01F2\\u1F88-\\u1F8F\\u1F98-\\u1F9F\\u1FA8-\\u1FAF\\u1FBC\\u1FCC\\u1FFC\\u02B0-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0374\\u037A\\u0559\\u0640\\u06E5\\u06E6\\u07F4\\u07F5\\u07FA\\u081A\\u0824\\u0828\\u0971\\u0E46\\u0EC6\\u10FC\\u17D7\\u1843\\u1AA7\\u1C78-\\u1C7D\\u1D2C-\\u1D61\\u1D78\\u1D9B-\\u1DBF\\u2071\\u207F\\u2090-\\u209C\\u2C7D\\u2D6F\\u2E2F\\u3005\\u3031-\\u3035\\u303B\\u309D\\u309E\\u30FC-\\u30FE\\uA015\\uA4F8-\\uA4FD\\uA60C\\uA67F\\uA717-\\uA71F\\uA770\\uA788\\uA9CF\\uAA70\\uAADD\\uFF70\\uFF9E\\uFF9F\\u01BB\\u01C0-\\u01C3\\u0294\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u063F\\u0641-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u0800-\\u0815\\u0840-\\u0858\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0972-\\u0977\\u0979-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E45\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10D0-\\u10FA\\u1100-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17DC\\u1820-\\u1842\\u1844-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BC0-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C77\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u2135-\\u2138\\u2D30-\\u2D65\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3006\\u303C\\u3041-\\u3096\\u309F\\u30A1-\\u30FA\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FCB\\uA000-\\uA014\\uA016-\\uA48C\\uA4D0-\\uA4F7\\uA500-\\uA60B\\uA610-\\uA61F\\uA62A\\uA62B\\uA66E\\uA6A0-\\uA6E5\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA6F\\uAA71-\\uAA76\\uAA7A\\uAA80-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB\\uAADC\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uABC0-\\uABE2\\uAC00\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA2D\\uFA30-\\uFA6D\\uFA70-\\uFAD9\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF66-\\uFF6F\\uFF71-\\uFF9D\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u16EE-\\u16F0\\u2160-\\u2182\\u2185-\\u2188\\u3007\\u3021-\\u3029\\u3038-\\u303A\\uA6E6-\\uA6EF]"],[4,460,461],[4,462,463],[4,464,465],[4,466,467],[4,363,468],[4,357,469],[4,359,470],[4,471,472],[4,366,473],[4,474,475],[4,476,477],[4,478,479],[4,480,481],[4,482,483],[4,484,485],[4,361,486],[4,487,488],[4,489,490,490,490,490],[4,247,248],[5,"*="],[5,"/="],[5,"%="],[5,"+="],[5,"-="],[5,"<<="],[5,">>="],[5,">>>="],[5,"&="],[5,"^="],[5,"|="],[4,491,492],[4,3,493,3,172,3,105,3,172],[0,"AssignmentExpressionNoIn",494],[6,495],[4,294,496],[4,497,3,498,499],[3,497,500],[8,501],[0,"CASE",502],[5,"@"],[3,503,504,505],[3,506,504,505],[4,507,508],[4,51,3,509],[4,3,167,3,349],[4,510,511,3,512,3,513,3,55,3,56,3,57],[4,514,511,3,512,3,513,3,55,3,56,3,57],[5,"null"],[4,515,121],[4,516,121],[5,"\uD82C"],[2,"[\\uDC00\\uDC01]"],[5,"\uD808"],[2,"[\\uDC00-\\uDF6E]"],[5,"\uD869"],[2,"[\\uDED6\\uDF00]"],[5,"\uD809"],[2,"[\\uDC00-\\uDC62]"],[2,"[\\uDC00-\\uDC19\\uDC34-\\uDC4D\\uDC68-\\uDC81\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB5\\uDCD0-\\uDCE9\\uDD04\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD38\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD6C-\\uDD85\\uDDA0-\\uDDB9\\uDDD4-\\uDDED\\uDE08-\\uDE21\\uDE3C-\\uDE55\\uDE70-\\uDE89\\uDEA8-\\uDEC0\\uDEE2-\\uDEFA\\uDF1C-\\uDF34\\uDF56-\\uDF6E\\uDF90-\\uDFA8\\uDFCA\\uDC1A-\\uDC33\\uDC4E-\\uDC54\\uDC56-\\uDC67\\uDC82-\\uDC9B\\uDCB6-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDCEA-\\uDD03\\uDD1E-\\uDD37\\uDD52-\\uDD6B\\uDD86-\\uDD9F\\uDDBA-\\uDDD3\\uDDEE-\\uDE07\\uDE22-\\uDE3B\\uDE56-\\uDE6F\\uDE8A-\\uDEA5\\uDEC2-\\uDEDA\\uDEDC-\\uDEE1\\uDEFC-\\uDF14\\uDF16-\\uDF1B\\uDF36-\\uDF4E\\uDF50-\\uDF55\\uDF70-\\uDF88\\uDF8A-\\uDF8F\\uDFAA-\\uDFC2\\uDFC4-\\uDFC9\\uDFCB]"],[2,"[\\uDC03-\\uDC37\\uDC83-\\uDCAF]"],[2,"[\\uDC00-\\uDC0B\\uDC0D-\\uDC26\\uDC28-\\uDC3A\\uDC3C\\uDC3D\\uDC3F-\\uDC4D\\uDC50-\\uDC5D\\uDC80-\\uDCFA\\uDE80-\\uDE9C\\uDEA0-\\uDED0\\uDF00-\\uDF1E\\uDF30-\\uDF40\\uDF42-\\uDF49\\uDF80-\\uDF9D\\uDFA0-\\uDFC3\\uDFC8-\\uDFCF\\uDD40-\\uDD74\\uDF41\\uDF4A\\uDFD1-\\uDFD5]"],[5,"\uD80C"],[2,"[\\uDC00-\\uDFFF]"],[2,"[\\uDC00-\\uDC9D]"],[5,"\uD86E"],[2,"[\\uDC1D]"],[5,"\uD803"],[2,"[\\uDC00-\\uDC48]"],[5,"\uD840"],[2,"[\\uDC00]"],[5,"\uD87E"],[2,"[\\uDC00-\\uDE1D]"],[5,"\uD86D"],[2,"[\\uDF34\\uDF40]"],[5,"\uD81A"],[2,"[\\uDC00-\\uDE38]"],[2,"[\\uDC00-\\uDC05\\uDC08\\uDC0A-\\uDC35\\uDC37\\uDC38\\uDC3C\\uDC3F-\\uDC55\\uDD00-\\uDD15\\uDD20-\\uDD39\\uDE00\\uDE10-\\uDE13\\uDE15-\\uDE17\\uDE19-\\uDE33\\uDE60-\\uDE7C\\uDF00-\\uDF35\\uDF40-\\uDF55\\uDF60-\\uDF72]"],[5,"\uD80D"],[2,"[\\uDC00-\\uDC2E]"],[5,"u"],[0,"HexDigit",517],[0,"LogicalAndExpression",518],[6,519],[5,"?"],[3,520,521],[4,3,167,3,442],[6,522],[0,"MemberExpression",523],[0,"Arguments",524],[6,525],[4,526,3,336],[4,3,247,248,3,442],[4,368,121],[4,527,82],[4,327,528],[0,"LineContinuation",529],[4,530,82],[0,"IvarTypeElement",531],[6,532],[8,533],[5,"+"],[8,534],[0,"MethodSelector",535],[8,62],[5,"-"],[5,"true"],[5,"false"],[2,"[0-9a-fA-F]"],[4,536,537],[4,3,538,3,491],[4,258,3,289,3,442],[0,"ConditionalExpressionNoIn",539],[4,3,167,3,294],[4,540,541],[4,52,3,542,3,54],[4,3,543],[0,"NEW",544],[9,545],[0,"EscapeSequence",546],[4,327,212],[9,547],[4,548,549],[4,3,507],[0,"Accessors",550],[4,3,551],[3,552,553],[0,"BitwiseOrExpression",554],[6,555],[5,"||"],[4,556,557],[3,558,47,559,560],[6,561],[8,562],[3,498,563,564],[4,372,121],[3,565,327,10],[3,566,567,568,328],[3,569,327,10],[9,570],[3,123,571],[4,572,573],[0,"MethodType",574],[4,575,576],[0,"UnarySelector",577],[4,578,579],[4,3,580,3,536],[0,"LogicalOrExpressionNoIn",581],[8,582],[0,"PrimaryExpression",583],[0,"MessageExpression",584],[4,526,3,497,3,498],[4,3,585],[0,"ArgumentList",132],[0,"BracketedAccessor",586],[0,"DotAccessor",587],[2,"[\"]"],[0,"CharacterEscapeSequence",588],[4,589,590],[0,"HexEscapeSequence",591],[2,"[']"],[4,549,3,592],[5,"@outlet"],[5,"@accessors"],[8,593],[4,52,3,594,595,3,54],[0,"KeywordSelector",596],[8,597],[0,"Selector",123],[0,"BitwiseXOrExpression",598],[6,599],[5,"&&"],[4,600,601],[4,3,493,3,442,3,105,3,442],[3,602,51,603,604,605,606],[4,607,3,608,3,609,3,610],[3,563,564],[4,607,3,90,3,610],[4,611,3,123],[3,612,613],[5,"0"],[9,614],[4,615,490,490],[3,533,88,167],[4,52,616,54],[3,617,618],[6,619],[4,620,621],[4,3,167,3,622],[4,623,624],[4,3,625,248,3,578],[0,"LogicalAndExpressionNoIn",626],[6,627],[0,"THIS",628],[0,"Literal",629],[0,"ArrayLiteral",630],[0,"ObjectLiteral",631],[4,52,3,90,3,54],[5,"["],[3,632,90],[0,"SelectorCall",633],[5,"]"],[5,"."],[0,"SingleEscapeCharacter",634],[0,"NonEscapeCharacter",635],[0,"DecimalDigit",636],[5,"x"],[8,637],[0,"ACTION",638],[4,123,639],[4,3,594],[0,"KeywordDeclarator",640],[6,641],[5,"..."],[0,"BitwiseAndExpression",642],[6,643],[5,"|"],[4,644,645],[4,3,538,3,600],[4,373,121],[3,279,280,646,199,647,648],[4,607,3,649,3,610],[4,55,3,650,3,57],[0,"SUPER",651],[3,652,553],[2,"['\"\\\\bfnrtv]"],[4,125,653,82],[2,"[0-9]"],[4,654,655],[3,656,657],[8,658],[4,659,105,511,3,51],[4,3,620],[4,660,661],[4,3,662,248,3,623],[0,"BitwiseOrExpressionNoIn",663],[6,664],[0,"NumericLiteral",665],[0,"RegularExpressionLiteral",666],[0,"SelectorLiteral",667],[0,"ElementList",668],[8,669],[4,401,121],[4,670,671],[9,672],[0,"AccessorsConfiguration",673],[6,674],[4,675,121],[4,676,121],[4,3,232,3,123,3,234],[8,677],[0,"EqualityExpression",678],[6,679],[5,"^"],[4,680,681],[4,3,580,3,644],[4,682,683],[4,684,685,684,686],[4,687,3,52,3,688,3,54],[4,689,690,3,691],[4,692,3,693],[0,"KeywordSelectorCall",694],[6,695],[0,"EscapeCharacter",696],[3,697,698,699,700,701,702],[4,3,167,3,654],[5,"@action"],[5,"IBAction"],[4,577,3],[4,703,704],[4,3,705,248,3,660],[0,"BitwiseXOrExpressionNoIn",706],[6,707],[3,708,709],[9,207],[5,"/"],[0,"RegularExpressionBody",710],[0,"RegularExpressionFlags",208],[5,"@selector"],[0,"SelectorLiteralContents",711],[6,712],[6,713],[8,172],[0,"PropertyNameAndValueList",714],[8,167],[4,715,716],[4,3,167,3,90],[3,612,614,615,489],[0,"IvarPropertyName",717],[0,"IvarGetterName",718],[0,"IvarSetterName",719],[5,"readonly"],[5,"readwrite"],[5,"copy"],[0,"RelationalExpression",720],[6,721],[5,"&"],[4,722,723],[4,3,625,248,3,680],[0,"HexIntegerLiteral",724],[0,"DecimalLiteral",725],[4,726,727],[3,728,51],[4,167,3],[4,3,172,729],[4,730,731],[0,"KeywordCall",732],[6,733],[4,734,3,247,3,51],[4,735,3,247,3,51],[4,736,3,247,3,51,737],[4,738,739],[4,3,740,3,703],[0,"BitwiseAndExpressionNoIn",741],[6,742],[4,589,743,744],[4,745,746],[0,"RegularExpressionFirstChar",747],[6,748],[7,749],[7,750],[0,"PropertyAssignment",751],[6,752],[4,753,3,105,3,90],[4,3,715],[5,"property"],[5,"getter"],[5,"setter"],[8,754],[0,"ShiftExpression",755],[6,756],[0,"EqualityOperator",757],[4,758,759],[4,3,662,248,3,722],[2,"[Xx]"],[7,490],[3,760,761,762],[8,763],[3,764,765,766],[0,"RegularExpressionChar",767],[4,753,3,105,3],[4,3,167],[3,768,769,770],[4,3,167,3,730],[8,577],[4,3,105],[4,771,772],[4,3,773,3,738],[3,774,775,776,777],[0,"EqualityExpressionNoIn",778],[6,779],[4,762,611,780],[4,611,781],[0,"DecimalIntegerLiteral",782],[0,"ExponentPart",783],[4,784,785],[0,"RegularExpressionBackslashSequence",786],[0,"RegularExpressionClass",787],[3,788,765,766],[4,789,3,105,3,172],[0,"PropertyGetter",790],[0,"PropertySetter",791],[0,"AdditiveExpression",792],[6,793],[0,"RelationalOperator",794],[5,"==="],[5,"!=="],[5,"=="],[5,"!="],[4,795,796],[4,3,705,248,3,758],[6,614],[7,614],[3,589,797],[4,798,799],[9,800],[0,"RegularExpressionNonTerminator",83],[4,327,785],[4,607,801,610],[4,802,785],[0,"PropertyName",803],[4,804,3,789,3,52,3,54,3,55,3,56,3,57],[4,805,3,789,3,52,3,806,3,54,3,55,3,56,3,57],[4,807,808],[4,3,809,3,771],[3,810,811,232,234,812,182],[0,"RelationalExpressionNoIn",813],[6,814],[4,815,780],[2,"[eE]"],[0,"SignedInteger",816],[2,"[*\\u005C/[]"],[6,817],[9,818],[3,123,199,646],[5,"get"],[5,"set"],[0,"PropertySetParameterList",51],[0,"MultiplicativeExpression",819],[6,820],[0,"ShiftOperator",821],[5,"<="],[5,">="],[0,"INSTANCEOF",822],[4,738,823],[4,3,740,3,795],[2,"[1-9]"],[4,824,781],[0,"RegularExpressionClassChar",825],[2,"[\\u005C/[]"],[4,826,827],[4,3,828,3,807],[3,829,830,831],[4,371,121],[6,832],[8,833],[3,834,765],[0,"UnaryExpression",835],[6,836],[0,"AdditiveOperator",837],[5,"<<"],[5,">>"],[5,">>>"],[4,3,838,3,738],[2,"[+-]"],[4,839,785],[3,840,841,842,843,844,845,846,847,848,849],[4,3,850,3,826],[4,851,248],[0,"RelationalOperatorNoIn",852],[9,853],[0,"PostfixExpression",854],[4,855,3,826],[4,856,3,826],[4,857,3,826],[4,858,3,826],[4,859,3,826],[4,510,3,826],[4,514,3,826],[4,860,3,826],[4,861,3,826],[0,"MultiplicativeOperator",862],[3,863,864],[3,810,811,232,234,812],[2,"[\\u005C\\]]"],[4,258,865],[0,"DELETE",866],[0,"VOID",867],[0,"TYPEOF",868],[5,"++"],[5,"--"],[5,"~"],[5,"!"],[4,869,248],[4,510,870],[4,514,871],[8,872],[4,370,121],[4,375,121],[4,374,121],[3,873,684,874],[9,510],[9,514],[4,99,875],[5,"*"],[5,"%"],[3,858,859],[0,"%start",877],[4,878,879,878],[0,"%_",880],[8,881],[6,882],[0,"%SourceElements",883],[3,884,885,886],[4,887,888],[0,"%WhiteSpace",14],[0,"%LineTerminator",15],[0,"%Comment",889],[0,"%SourceElement",890],[6,891],[3,892,893],[3,894,895],[4,878,887],[0,"%MultiLineComment",23],[0,"%SingleLineComment",896],[0,"%Statement",897],[0,"%FunctionDeclaration",898],[4,30,899],[3,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,895,915,916,917],[4,918,878,919,878,52,878,920,878,54,878,55,878,921,878,57],[6,922],[0,"%Block",923],[0,"%VariableStatement",924],[0,"%EmptyStatement",62],[0,"%ExpressionStatement",925],[0,"%IfStatement",926],[0,"%IterationStatement",927],[0,"%ContinueStatement",928],[0,"%BreakStatement",929],[0,"%ReturnStatement",930],[0,"%WithStatement",931],[0,"%LabelledStatement",932],[0,"%SwitchStatement",933],[0,"%ThrowStatement",934],[0,"%TryStatement",935],[0,"%DebuggerStatement",936],[0,"%FunctionExpression",937],[0,"%ImportStatement",938],[0,"%ClassDeclarationStatement",939],[0,"%FUNCTION",940],[0,"%Identifier",941],[8,942],[0,"%FunctionBody",877],[0,"%SingleLineCommentChar",943],[12,944,945],[4,946,878,947,948,949],[4,950,951,949],[4,952,878,52,878,951,878,54,878,894,953],[3,954,955,956,957,958],[4,959,960,961],[4,962,960,961],[4,963,960,964],[4,965,878,52,878,951,878,54,878,894],[4,919,878,105,878,894],[4,966,878,52,878,951,878,54,878,967],[4,968,960,964],[4,969,878,900,878,970],[4,971,949],[4,918,878,972,878,52,878,920,878,54,878,55,878,921,878,57],[4,113,878,973,949],[4,115,878,919,878,974,878,975,878,976,878,119,949],[4,120,977],[12,978,979],[0,"%FormalParameterList",980],[4,981,82],[4,55,878,982,878,57],[11,"%BadBlock",983,"Missing ending brace"],[0,"%VAR",984],[0,"%VariableDeclaration",985],[6,986],[0,"%EOS",987],[9,988],[0,"%Expression",989],[0,"%IF",990],[8,991],[0,"%DoWhileStatement",992],[0,"%WhileStatement",993],[0,"%ForStatement",994],[0,"%ForInStatement",995],[0,"%EachStatement",996],[0,"%CONTINUE",997],[0,"%__",998],[3,999,1000],[0,"%BREAK",1001],[0,"%RETURN",1002],[3,1000,1003],[0,"%WITH",1004],[0,"%SWITCH",1005],[0,"%CaseBlock",1006],[0,"%THROW",1007],[0,"%TRY",1008],[3,1009,1010],[0,"%DEBUGGER",1011],[8,919],[3,1012,1013],[8,1014],[8,1015],[0,"%ClassBody",1016],[9,1017],[4,1018,1019],[0,"%BadIdentifier",1020],[4,919,1021],[9,885],[8,1022],[4,55,878,982,878],[4,165,977],[4,919,1023],[4,878,167,878,947],[3,1024,1025,1026,1027],[3,55,918],[4,1028,1029],[4,174,977],[4,878,1030,878,894],[4,1031,878,894,878,1032,878,52,878,951,878,54,949],[4,1032,878,52,878,951,878,54,878,894],[4,1033,878,52,878,1034,878,62,878,1035,878,62,878,1035,878,54,878,894],[4,1033,878,52,878,1036,878,1037,878,951,878,54,878,894],[4,183,878,52,878,1036,878,1037,878,951,878,54,878,894],[4,184,977],[6,1038],[4,919,949],[0,"%SemicolonInsertionEOS",1039],[4,187,977],[4,188,977],[4,951,949],[4,189,977],[4,190,977],[4,55,878,1040,878,1041,878,1040,878,57],[4,193,977],[4,194,977],[4,1042,1043],[0,"%Finally",1044],[4,198,977],[0,"%LocalFilePath",1045],[0,"%StandardFilePath",1046],[3,1047,1048],[4,55,1049,878,57],[8,1050],[0,"%IdentifierPart",1051],[9,1052],[0,"%IdentifierName",1053],[3,1054,1055],[6,1056],[0,"%StatementList",1057],[8,1058],[4,878,62],[4,960,1059],[4,960,213],[4,960,1060],[0,"%AssignmentExpression",1061],[6,1062],[0,"%ELSE",1063],[0,"%DO",1064],[0,"%WHILE",1065],[0,"%FOR",1066],[8,1067],[8,951],[0,"%ForInFirstExpression",1068],[0,"%IN",1069],[3,884,1070,893],[3,1071,1025,1026,1027],[8,1072],[8,1073],[0,"%Catch",1074],[8,1075],[4,1076,878,900],[0,"%StringLiteral",1077],[4,232,878,233,878,234],[0,"%SuperclassDeclaration",1078],[0,"%CategoryDeclaration",1079],[6,1080],[0,"%ClassElements",1081],[3,1082,1083,1084,1085,1086,1087],[4,1088,977],[4,1082,1089],[11,"%ReservedWordIdentifier",1052,"Identifier cannot be a reserved word"],[11,"%DigitIdentifier",1090,"Identifier cannot start with a digit"],[4,878,167,878,919],[4,894,1091],[4,878,247,248,878,1028],[0,"%LineTerminatorSequence",249],[0,"%EOF",250],[3,1092,1093],[4,878,167,878,1028],[4,253,977],[4,254,977],[4,255,977],[4,256,977],[0,"%ForFirstExpression",1094],[3,1095,1096],[4,260,977],[0,"%SingleLineMultiLineComment",1097],[4,960,62],[0,"%CaseClauses",1098],[0,"%DefaultClause",1099],[4,1100,878,52,878,919,878,54,878,900],[4,878,1010],[0,"%FINALLY",1101],[3,1102,1103],[4,105,878,919],[4,52,878,919,878,54],[4,878,1104],[4,1105,1106],[0,"%IdentifierStart",1107],[0,"%UnicodeCombiningMark",272],[0,"%UnicodeDigit",273],[0,"%UnicodeConnectorPunctuation",274],[0,"%ZWNJ",275],[0,"%ZWJ",276],[0,"%ReservedWord",1108],[6,1017],[4,1084,1109],[6,1110],[4,1095,878,1111,878,1028],[0,"%ConditionalExpression",1112],[3,1113,1114],[0,"%LeftHandSideExpression",1115],[4,946,878,1116],[4,27,1117,29],[4,1118,1119],[4,1120,878,105,1121],[0,"%CATCH",1122],[4,301,977],[4,1123,303,1124,303],[4,305,1125,305],[0,"%CompoundIvarDeclaration",1126],[0,"%ClassElement",1127],[6,1128],[3,1129,282,1130],[3,1131,1132,1133,1134],[7,1017],[4,878,894],[0,"%AssignmentOperator",330],[4,1135,1136],[0,"%ExpressionNoIn",1137],[4,946,878,1138],[3,1139,1140],[0,"%VariableDeclarationNoIn",1141],[6,1142],[0,"%CaseClause",1143],[6,1144],[0,"%DEFAULT",1145],[8,1146],[4,343,977],[8,1147],[6,1148],[6,1149],[4,1150,878,1151,1152,949],[3,1153,1154,894,895],[4,878,1105],[0,"%UnicodeLetter",326],[4,327,1155],[0,"%Keyword",322],[0,"%FutureReservedWord",323],[0,"%NullLiteral",1156],[0,"%BooleanLiteral",1157],[0,"%LogicalOrExpression",1158],[8,1159],[4,1160,1161],[0,"%VariableDeclarationListNoIn",1162],[0,"%CallExpression",1163],[0,"%NewExpression",1164],[4,919,1165],[4,81,981,82],[4,1166,878,951,878,105,1121],[4,878,1118],[4,369,977],[4,878,1022],[4,449,878],[0,"%DoubleStringCharacter",1167],[0,"%SingleStringCharacter",1168],[0,"%IvarType",1169],[0,"%IvarDeclaration",1170],[6,1171],[0,"%ClassMethodDeclaration",1172],[0,"%InstanceMethodDeclaration",1173],[0,"%UnicodeEscapeSequence",1174],[0,"%NULL",1175],[3,1176,1177],[4,1178,1179],[4,878,493,878,1028,878,105,878,1028],[0,"%AssignmentExpressionNoIn",1180],[6,1181],[4,1116,1182],[4,1183,878,1184,1185],[3,1183,1186],[8,1187],[0,"%CASE",1188],[3,1189,1190,1191],[3,1192,1190,1191],[4,1193,1194],[4,919,878,1195],[4,878,167,878,1151],[4,510,1196,878,1197,878,513,878,55,878,921,878,57],[4,514,1196,878,1197,878,513,878,55,878,921,878,57],[4,489,1198,1198,1198,1198],[4,457,977],[0,"%TRUE",1199],[0,"%FALSE",1200],[0,"%LogicalAndExpression",1201],[6,1202],[3,1203,1204],[4,878,167,878,1160],[6,1205],[0,"%MemberExpression",1206],[0,"%Arguments",1207],[6,1208],[4,1209,878,1140],[4,878,247,248,878,1160],[4,368,977],[4,1210,82],[4,327,1211],[0,"%LineContinuation",1212],[4,1213,82],[0,"%IvarTypeElement",1214],[6,1215],[8,1216],[8,1217],[0,"%MethodSelector",1218],[0,"%HexDigit",517],[4,515,977],[4,516,977],[4,1219,1220],[4,878,538,878,1178],[4,1095,878,1111,878,1160],[0,"%ConditionalExpressionNoIn",1221],[4,878,167,878,1116],[4,1222,1223],[4,52,878,1224,878,54],[4,878,1225],[0,"%NEW",1226],[9,1227],[0,"%EscapeSequence",1228],[4,327,1059],[9,1229],[4,1230,1231],[4,878,1193],[0,"%Accessors",1232],[4,878,1233],[3,1234,1235],[0,"%BitwiseOrExpression",1236],[6,1237],[4,1238,1239],[3,1240,915,1241,1242],[6,1243],[8,1244],[3,1184,1245,1246],[4,372,977],[3,565,327,885],[3,1247,1248,1249,1155],[3,569,327,885],[9,1250],[3,1019,571],[4,572,1251],[0,"%MethodType",1252],[4,1253,1254],[0,"%UnarySelector",1255],[4,1256,1257],[4,878,580,878,1219],[0,"%LogicalOrExpressionNoIn",1258],[8,1259],[0,"%PrimaryExpression",1260],[0,"%MessageExpression",1261],[4,1209,878,1183,878,1184],[4,878,1262],[0,"%ArgumentList",989],[0,"%BracketedAccessor",1263],[0,"%DotAccessor",1264],[0,"%CharacterEscapeSequence",1265],[4,589,1266],[0,"%HexEscapeSequence",1267],[4,1231,878,1268],[8,1269],[4,52,878,1270,1271,878,54],[0,"%KeywordSelector",1272],[8,1273],[0,"%Selector",1019],[0,"%BitwiseXOrExpression",1274],[6,1275],[4,1276,1277],[4,878,493,878,1160,878,105,878,1160],[3,1278,919,1279,1280,1281,1282],[4,607,878,1283,878,1284,878,610],[3,1245,1246],[4,607,878,951,878,610],[4,611,878,1019],[3,1285,1286],[9,1287],[4,615,1198,1198],[3,1216,949,167],[4,52,1288,54],[3,1289,1290],[6,1291],[4,1292,1293],[4,878,167,878,622],[4,1294,1295],[4,878,625,248,878,1256],[0,"%LogicalAndExpressionNoIn",1296],[6,1297],[0,"%THIS",1298],[0,"%Literal",1299],[0,"%ArrayLiteral",1300],[0,"%ObjectLiteral",1301],[4,52,878,951,878,54],[3,1302,951],[0,"%SelectorCall",1303],[0,"%SingleEscapeCharacter",634],[0,"%NonEscapeCharacter",1304],[0,"%DecimalDigit",636],[8,1305],[0,"%ACTION",1306],[4,1019,1307],[4,878,1270],[0,"%KeywordDeclarator",1308],[6,1309],[0,"%BitwiseAndExpression",1310],[6,1311],[4,1312,1313],[4,878,538,878,1276],[4,373,977],[3,1133,1134,1314,1045,1315,1316],[4,607,878,1317,878,610],[4,55,878,1318,878,57],[0,"%SUPER",1319],[3,1320,1235],[4,981,1321,82],[4,1322,1323],[3,1324,1325],[8,1326],[4,1327,105,1196,878,919],[4,878,1292],[4,1328,1329],[4,878,662,248,878,1294],[0,"%BitwiseOrExpressionNoIn",1330],[6,1331],[0,"%NumericLiteral",1332],[0,"%RegularExpressionLiteral",1333],[0,"%SelectorLiteral",1334],[0,"%ElementList",1335],[8,1336],[4,401,977],[4,1337,1338],[9,1339],[0,"%AccessorsConfiguration",1340],[6,1341],[4,675,977],[4,676,977],[4,878,232,878,1019,878,234],[8,1342],[0,"%EqualityExpression",1343],[6,1344],[4,1345,1346],[4,878,580,878,1312],[4,1347,1348],[4,684,1349,684,1350],[4,687,878,52,878,1351,878,54],[4,1352,1353,878,1354],[4,1355,878,693],[0,"%KeywordSelectorCall",1356],[6,1357],[0,"%EscapeCharacter",1358],[3,1359,1360,1361,700,701,702],[4,878,167,878,1322],[4,1255,878],[4,1362,1363],[4,878,705,248,878,1328],[0,"%BitwiseXOrExpressionNoIn",1364],[6,1365],[3,1366,1367],[9,1082],[0,"%RegularExpressionBody",1368],[0,"%RegularExpressionFlags",1089],[0,"%SelectorLiteralContents",1369],[6,1370],[6,1371],[8,1028],[0,"%PropertyNameAndValueList",1372],[4,1373,1374],[4,878,167,878,951],[3,1285,1287,615,489],[0,"%IvarPropertyName",1375],[0,"%IvarGetterName",1376],[0,"%IvarSetterName",1377],[0,"%RelationalExpression",1378],[6,1379],[4,1380,1381],[4,878,625,248,878,1345],[0,"%HexIntegerLiteral",1382],[0,"%DecimalLiteral",1383],[4,1384,1385],[3,1386,919],[4,167,878],[4,878,1028,1387],[4,1388,1389],[0,"%KeywordCall",1390],[6,1391],[4,734,878,247,878,919],[4,735,878,247,878,919],[4,736,878,247,878,919,1392],[4,1393,1394],[4,878,1395,878,1362],[0,"%BitwiseAndExpressionNoIn",1396],[6,1397],[4,589,743,1398],[4,1399,1400],[0,"%RegularExpressionFirstChar",1401],[6,1402],[7,1403],[7,1404],[0,"%PropertyAssignment",1405],[6,1406],[4,1407,878,105,878,951],[4,878,1373],[8,1408],[0,"%ShiftExpression",1409],[6,1410],[0,"%EqualityOperator",757],[4,1411,1412],[4,878,662,248,878,1380],[7,1198],[3,1413,1414,1415],[8,1416],[3,1417,1418,1419],[0,"%RegularExpressionChar",1420],[4,1407,878,105,878],[4,878,167],[3,1421,1422,1423],[4,878,167,878,1388],[8,1255],[4,878,105],[4,1424,1425],[4,878,1426,878,1393],[0,"%EqualityExpressionNoIn",1427],[6,1428],[4,1415,611,1429],[4,611,1430],[0,"%DecimalIntegerLiteral",1431],[0,"%ExponentPart",1432],[4,784,1433],[0,"%RegularExpressionBackslashSequence",1434],[0,"%RegularExpressionClass",1435],[3,1436,1418,1419],[4,1437,878,105,878,1028],[0,"%PropertyGetter",1438],[0,"%PropertySetter",1439],[0,"%AdditiveExpression",1440],[6,1441],[0,"%RelationalOperator",1442],[4,1443,1444],[4,878,705,248,878,1411],[6,1287],[7,1287],[3,589,1445],[4,798,1446],[0,"%RegularExpressionNonTerminator",943],[4,327,1433],[4,607,1447,610],[4,802,1433],[0,"%PropertyName",1448],[4,804,878,1437,878,52,878,54,878,55,878,921,878,57],[4,805,878,1437,878,52,878,1449,878,54,878,55,878,921,878,57],[4,1450,1451],[4,878,1452,878,1424],[3,810,811,232,234,1453,1037],[0,"%RelationalExpressionNoIn",1454],[6,1455],[4,815,1429],[0,"%SignedInteger",1456],[6,1457],[3,1019,1045,1314],[0,"%PropertySetParameterList",919],[0,"%MultiplicativeExpression",1458],[6,1459],[0,"%ShiftOperator",821],[0,"%INSTANCEOF",1460],[4,1393,1461],[4,878,1395,878,1443],[4,824,1430],[0,"%RegularExpressionClassChar",1462],[4,1463,1464],[4,878,1465,878,1450],[4,371,977],[6,1466],[3,1467,1418],[0,"%UnaryExpression",1468],[6,1469],[0,"%AdditiveOperator",837],[4,878,1470,878,1393],[4,839,1433],[3,1471,1472,1473,1474,1475,1476,1477,1478,1479,1480],[4,878,1481,878,1463],[0,"%RelationalOperatorNoIn",1482],[0,"%PostfixExpression",1483],[4,1484,878,1463],[4,1485,878,1463],[4,1486,878,1463],[4,858,878,1463],[4,859,878,1463],[4,510,878,1463],[4,514,878,1463],[4,860,878,1463],[4,861,878,1463],[0,"%MultiplicativeOperator",862],[3,810,811,232,234,1453],[4,1095,1487],[0,"%DELETE",1488],[0,"%VOID",1489],[0,"%TYPEOF",1490],[8,1491],[4,370,977],[4,375,977],[4,374,977],[4,960,875]],"nameToUID":{"start":1,"_":3,"SourceElements":6,"WhiteSpace":9,"LineTerminator":10,"Comment":11,"SourceElement":12,"MultiLineComment":19,"SingleLineComment":20,"Statement":21,"FunctionDeclaration":22,"Block":32,"VariableStatement":33,"EmptyStatement":34,"ExpressionStatement":35,"IfStatement":36,"IterationStatement":37,"ContinueStatement":38,"BreakStatement":39,"ReturnStatement":40,"WithStatement":41,"LabelledStatement":42,"SwitchStatement":43,"ThrowStatement":44,"TryStatement":45,"DebuggerStatement":46,"FunctionExpression":47,"ImportStatement":48,"ClassDeclarationStatement":49,"FUNCTION":50,"Identifier":51,"FunctionBody":56,"SingleLineCommentChar":59,"FormalParameterList":80,"VAR":85,"VariableDeclaration":86,"EOS":88,"Expression":90,"IF":91,"DoWhileStatement":93,"WhileStatement":94,"ForStatement":95,"ForInStatement":96,"EachStatement":97,"CONTINUE":98,"__":99,"BREAK":101,"RETURN":102,"WITH":104,"SWITCH":106,"CaseBlock":107,"THROW":108,"TRY":109,"DEBUGGER":111,"ClassBody":118,"IdentifierName":123,"StatementList":126,"SemicolonInsertionEOS":143,"Finally":153,"LocalFilePath":155,"StandardFilePath":156,"IdentifierPart":160,"AssignmentExpression":172,"ELSE":175,"DO":176,"WHILE":177,"FOR":178,"ForInFirstExpression":181,"IN":182,"Catch":195,"StringLiteral":199,"SuperclassDeclaration":201,"CategoryDeclaration":202,"ClassElements":204,"ReservedWord":206,"IdentifierStart":207,"LineTerminatorSequence":212,"EOF":214,"ForFirstExpression":221,"SingleLineMultiLineComment":224,"CaseClauses":226,"DefaultClause":227,"FINALLY":230,"UnicodeCombiningMark":239,"UnicodeDigit":240,"UnicodeConnectorPunctuation":241,"ZWNJ":242,"ZWJ":243,"ConditionalExpression":252,"LeftHandSideExpression":258,"CATCH":264,"CompoundIvarDeclaration":269,"ClassElement":270,"Keyword":277,"FutureReservedWord":278,"NullLiteral":279,"BooleanLiteral":280,"UnicodeLetter":281,"AssignmentOperator":289,"ExpressionNoIn":291,"VariableDeclarationNoIn":294,"CaseClause":296,"DEFAULT":298,"NULL":324,"UnicodeEscapeSequence":328,"LogicalOrExpression":331,"VariableDeclarationListNoIn":334,"CallExpression":335,"NewExpression":336,"DoubleStringCharacter":345,"SingleStringCharacter":346,"IvarType":348,"IvarDeclaration":349,"ClassMethodDeclaration":351,"InstanceMethodDeclaration":352,"TRUE":407,"FALSE":408,"AssignmentExpressionNoIn":442,"CASE":448,"HexDigit":490,"LogicalAndExpression":491,"MemberExpression":497,"Arguments":498,"LineContinuation":505,"IvarTypeElement":507,"MethodSelector":512,"ConditionalExpressionNoIn":521,"NEW":526,"EscapeSequence":528,"Accessors":533,"BitwiseOrExpression":536,"MethodType":551,"UnarySelector":553,"LogicalOrExpressionNoIn":556,"PrimaryExpression":558,"MessageExpression":559,"ArgumentList":562,"BracketedAccessor":563,"DotAccessor":564,"CharacterEscapeSequence":566,"HexEscapeSequence":568,"KeywordSelector":575,"Selector":577,"BitwiseXOrExpression":578,"LogicalAndExpressionNoIn":600,"THIS":602,"Literal":603,"ArrayLiteral":604,"ObjectLiteral":605,"SelectorCall":609,"SingleEscapeCharacter":612,"NonEscapeCharacter":613,"DecimalDigit":614,"ACTION":617,"KeywordDeclarator":620,"BitwiseAndExpression":623,"SUPER":632,"BitwiseOrExpressionNoIn":644,"NumericLiteral":646,"RegularExpressionLiteral":647,"SelectorLiteral":648,"ElementList":649,"AccessorsConfiguration":654,"EqualityExpression":660,"KeywordSelectorCall":670,"EscapeCharacter":672,"BitwiseXOrExpressionNoIn":680,"RegularExpressionBody":685,"RegularExpressionFlags":686,"SelectorLiteralContents":688,"PropertyNameAndValueList":692,"IvarPropertyName":697,"IvarGetterName":698,"IvarSetterName":699,"RelationalExpression":703,"HexIntegerLiteral":708,"DecimalLiteral":709,"KeywordCall":715,"BitwiseAndExpressionNoIn":722,"RegularExpressionFirstChar":726,"PropertyAssignment":730,"ShiftExpression":738,"EqualityOperator":740,"RegularExpressionChar":748,"EqualityExpressionNoIn":758,"DecimalIntegerLiteral":762,"ExponentPart":763,"RegularExpressionBackslashSequence":765,"RegularExpressionClass":766,"PropertyGetter":769,"PropertySetter":770,"AdditiveExpression":771,"RelationalOperator":773,"RegularExpressionNonTerminator":785,"PropertyName":789,"RelationalExpressionNoIn":795,"SignedInteger":799,"PropertySetParameterList":806,"MultiplicativeExpression":807,"ShiftOperator":809,"INSTANCEOF":812,"RegularExpressionClassChar":817,"UnaryExpression":826,"AdditiveOperator":828,"RelationalOperatorNoIn":838,"PostfixExpression":840,"MultiplicativeOperator":850,"DELETE":855,"VOID":856,"TYPEOF":857,"%start":876,"%_":878,"%SourceElements":881,"%WhiteSpace":884,"%LineTerminator":885,"%Comment":886,"%SourceElement":887,"%MultiLineComment":892,"%SingleLineComment":893,"%Statement":894,"%FunctionDeclaration":895,"%Block":900,"%VariableStatement":901,"%EmptyStatement":902,"%ExpressionStatement":903,"%IfStatement":904,"%IterationStatement":905,"%ContinueStatement":906,"%BreakStatement":907,"%ReturnStatement":908,"%WithStatement":909,"%LabelledStatement":910,"%SwitchStatement":911,"%ThrowStatement":912,"%TryStatement":913,"%DebuggerStatement":914,"%FunctionExpression":915,"%ImportStatement":916,"%ClassDeclarationStatement":917,"%FUNCTION":918,"%Identifier":919,"%FunctionBody":921,"%SingleLineCommentChar":922,"%FormalParameterList":942,"%BadBlock":945,"%VAR":946,"%VariableDeclaration":947,"%EOS":949,"%Expression":951,"%IF":952,"%DoWhileStatement":954,"%WhileStatement":955,"%ForStatement":956,"%ForInStatement":957,"%EachStatement":958,"%CONTINUE":959,"%__":960,"%BREAK":962,"%RETURN":963,"%WITH":965,"%SWITCH":966,"%CaseBlock":967,"%THROW":968,"%TRY":969,"%DEBUGGER":971,"%ClassBody":976,"%BadIdentifier":979,"%SemicolonInsertionEOS":1000,"%Finally":1010,"%LocalFilePath":1012,"%StandardFilePath":1013,"%IdentifierPart":1017,"%IdentifierName":1019,"%StatementList":1022,"%AssignmentExpression":1028,"%ELSE":1030,"%DO":1031,"%WHILE":1032,"%FOR":1033,"%ForInFirstExpression":1036,"%IN":1037,"%Catch":1042,"%StringLiteral":1045,"%SuperclassDeclaration":1047,"%CategoryDeclaration":1048,"%ClassElements":1050,"%ReservedWordIdentifier":1054,"%DigitIdentifier":1055,"%LineTerminatorSequence":1059,"%EOF":1060,"%ForFirstExpression":1067,"%SingleLineMultiLineComment":1070,"%CaseClauses":1072,"%DefaultClause":1073,"%FINALLY":1076,"%IdentifierStart":1082,"%UnicodeCombiningMark":1083,"%UnicodeDigit":1084,"%UnicodeConnectorPunctuation":1085,"%ZWNJ":1086,"%ZWJ":1087,"%ReservedWord":1088,"%ConditionalExpression":1093,"%LeftHandSideExpression":1095,"%CATCH":1100,"%CompoundIvarDeclaration":1104,"%ClassElement":1105,"%AssignmentOperator":1111,"%ExpressionNoIn":1113,"%VariableDeclarationNoIn":1116,"%CaseClause":1118,"%DEFAULT":1120,"%UnicodeLetter":1129,"%Keyword":1131,"%FutureReservedWord":1132,"%NullLiteral":1133,"%BooleanLiteral":1134,"%LogicalOrExpression":1135,"%VariableDeclarationListNoIn":1138,"%CallExpression":1139,"%NewExpression":1140,"%DoubleStringCharacter":1148,"%SingleStringCharacter":1149,"%IvarType":1150,"%IvarDeclaration":1151,"%ClassMethodDeclaration":1153,"%InstanceMethodDeclaration":1154,"%UnicodeEscapeSequence":1155,"%NULL":1156,"%AssignmentExpressionNoIn":1160,"%CASE":1166,"%TRUE":1176,"%FALSE":1177,"%LogicalAndExpression":1178,"%MemberExpression":1183,"%Arguments":1184,"%LineContinuation":1191,"%IvarTypeElement":1193,"%MethodSelector":1197,"%HexDigit":1198,"%ConditionalExpressionNoIn":1204,"%NEW":1209,"%EscapeSequence":1211,"%Accessors":1216,"%BitwiseOrExpression":1219,"%MethodType":1233,"%UnarySelector":1235,"%LogicalOrExpressionNoIn":1238,"%PrimaryExpression":1240,"%MessageExpression":1241,"%ArgumentList":1244,"%BracketedAccessor":1245,"%DotAccessor":1246,"%CharacterEscapeSequence":1247,"%HexEscapeSequence":1249,"%KeywordSelector":1253,"%Selector":1255,"%BitwiseXOrExpression":1256,"%LogicalAndExpressionNoIn":1276,"%THIS":1278,"%Literal":1279,"%ArrayLiteral":1280,"%ObjectLiteral":1281,"%SelectorCall":1284,"%SingleEscapeCharacter":1285,"%NonEscapeCharacter":1286,"%DecimalDigit":1287,"%ACTION":1289,"%KeywordDeclarator":1292,"%BitwiseAndExpression":1294,"%SUPER":1302,"%BitwiseOrExpressionNoIn":1312,"%NumericLiteral":1314,"%RegularExpressionLiteral":1315,"%SelectorLiteral":1316,"%ElementList":1317,"%AccessorsConfiguration":1322,"%EqualityExpression":1328,"%KeywordSelectorCall":1337,"%EscapeCharacter":1339,"%BitwiseXOrExpressionNoIn":1345,"%RegularExpressionBody":1349,"%RegularExpressionFlags":1350,"%SelectorLiteralContents":1351,"%PropertyNameAndValueList":1355,"%IvarPropertyName":1359,"%IvarGetterName":1360,"%IvarSetterName":1361,"%RelationalExpression":1362,"%HexIntegerLiteral":1366,"%DecimalLiteral":1367,"%KeywordCall":1373,"%BitwiseAndExpressionNoIn":1380,"%RegularExpressionFirstChar":1384,"%PropertyAssignment":1388,"%ShiftExpression":1393,"%EqualityOperator":1395,"%RegularExpressionChar":1402,"%EqualityExpressionNoIn":1411,"%DecimalIntegerLiteral":1415,"%ExponentPart":1416,"%RegularExpressionBackslashSequence":1418,"%RegularExpressionClass":1419,"%PropertyGetter":1422,"%PropertySetter":1423,"%AdditiveExpression":1424,"%RelationalOperator":1426,"%RegularExpressionNonTerminator":1433,"%PropertyName":1437,"%RelationalExpressionNoIn":1443,"%SignedInteger":1446,"%PropertySetParameterList":1449,"%MultiplicativeExpression":1450,"%ShiftOperator":1452,"%INSTANCEOF":1453,"%RegularExpressionClassChar":1457,"%UnaryExpression":1463,"%AdditiveOperator":1465,"%RelationalOperatorNoIn":1470,"%PostfixExpression":1471,"%MultiplicativeOperator":1481,"%DELETE":1484,"%VOID":1485,"%TYPEOF":1486}}; //function Parser(/*String | CompiledGrammar*/ aGrammar) diff --git a/Objective-J/Runtime.js b/Objective-J/Runtime.js index 311fe373b..31e5505d0 100644 --- a/Objective-J/Runtime.js +++ b/Objective-J/Runtime.js @@ -484,6 +484,18 @@ GLOBAL(objj_registerClassPair) = function(/*Class*/ aClass) DISPLAY_NAME(objj_registerClassPair); +GLOBAL(objj_resetRegisterClasses) = function() +{ + for (var key in REGISTERED_CLASSES) + delete global[key]; + + REGISTERED_CLASSES = {}; + + resetBundle(); +} + +DISPLAY_NAME(objj_resetRegisterClasses); + // Instantiating Classes GLOBAL(class_createInstance) = function(/*Class*/ aClass) @@ -574,6 +586,15 @@ GLOBAL(objj_getClass) = function(/*String*/ aName) { var theClass = REGISTERED_CLASSES[aName]; + /*if (!theClass) + { + for (var key in REGISTERED_CLASSES) + { + print("regClass: " + key + ", regClass.isa: " + REGISTERED_CLASSES[key].isa); + } + print(""); + }*/ + if (!theClass) { // class handler callback??? diff --git a/Objective-J/StaticResource.js b/Objective-J/StaticResource.js index a8b4b24d2..7991532ea 100644 --- a/Objective-J/StaticResource.js +++ b/Objective-J/StaticResource.js @@ -1,7 +1,7 @@ var rootResources = { }; -function StaticResource(/*CFURL*/ aURL, /*StaticResource*/ aParent, /*BOOL*/ isDirectory, /*BOOL*/ isResolved) +function StaticResource(/*CFURL*/ aURL, /*StaticResource*/ aParent, /*BOOL*/ isDirectory, /*BOOL*/ isResolved, /*Dictionary*/ aFilenameTranslateDictionary) { this._parent = aParent; this._eventDispatcher = new EventDispatcher(this); @@ -11,6 +11,7 @@ function StaticResource(/*CFURL*/ aURL, /*StaticResource*/ aParent, /*BOOL*/ isD this._name = name; this._URL = aURL; //new CFURL(aName, aParent && aParent.URL().asDirectoryPathURL()); this._isResolved = !!isResolved; + this._filenameTranslateDictionary = aFilenameTranslateDictionary; if (isDirectory) this._URL = this._URL.asDirectoryPathURL(); @@ -36,6 +37,26 @@ StaticResource.rootResources = function() return rootResources; }; +function countProp(x) { + var count = 0; + for (var k in x) { + if (x.hasOwnProperty(k)) { + ++count; + } + } + return count; +} + +StaticResource.resetRootResources = function() +{ + rootResources = {}; +}; + +StaticResource.prototype.filenameTranslateDictionary = function() +{ + return this._filenameTranslateDictionary || {}; +}; + exports.StaticResource = StaticResource; function resolveStaticResource(/*StaticResource*/ aResource) @@ -76,7 +97,20 @@ StaticResource.prototype.resolve = function() resolveStaticResource(self); } - new FileRequest(this.URL(), onsuccess, onfailure); + var url = this.URL(), + aFilenameTranslateDictionary = this.filenameTranslateDictionary(); + + if (aFilenameTranslateDictionary) + { + var urlString = url.toString(), + lastPathComponent = url.lastPathComponent(), + basePath = urlString.substring(0, urlString.length - lastPathComponent.length), + translatedName = aFilenameTranslateDictionary[lastPathComponent]; + + if (translatedName && urlString.slice(-translatedName.length) !== translatedName) + url = new CFURL(basePath + translatedName); // FIXME: do an add component to url or something better.... + } + new FileRequest(url, onsuccess, onfailure); } }; @@ -163,11 +197,11 @@ StaticResource.prototype.resourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL* return StaticResource.resourceAtURL(new CFURL(aURL, this.URL()), resolveAsDirectoriesIfNecessary); }; -StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback) +StaticResource.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback, /*Dictionary*/ aFilenameTranslateDictionary) { aURL = makeAbsoluteURL(aURL).absoluteURL(); - resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback); + resolveResourceComponents(rootResourceForAbsoluteURL(aURL), isDirectory, aURL.pathComponents(), 0, aCallback, aFilenameTranslateDictionary); }; StaticResource.prototype.resolveResourceAtURL = function(/*CFURL|String*/ aURL, /*BOOL*/ isDirectory, /*Function*/ aCallback) @@ -175,7 +209,7 @@ StaticResource.prototype.resolveResourceAtURL = function(/*CFURL|String*/ aURL, StaticResource.resolveResourceAtURL(new CFURL(aURL, this.URL()).absoluteURL(), isDirectory, aCallback); }; -function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDirectory, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback) +function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDirectory, /*Array*/ components, /*Integer*/ index, /*Function*/ aCallback, /*Dictionry*/ aFilenameTranslateDictionary) { var count = components.length; @@ -187,7 +221,7 @@ function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDire // If the child doesn't exist, create and resolve it. if (!child) { - child = new StaticResource(new CFURL(name, aResource.URL()), aResource, index + 1 < count || isDirectory , NO); + child = new StaticResource(new CFURL(name, aResource.URL()), aResource, index + 1 < count || isDirectory , NO, aFilenameTranslateDictionary); child.resolve(); } @@ -196,7 +230,7 @@ function resolveResourceComponents(/*StaticResource*/ aResource, /*BOOL*/ isDire return child.addEventListener("resolve", function() { // Continue resolving once this is done. - resolveResourceComponents(aResource, isDirectory, components, index, aCallback); + resolveResourceComponents(aResource, isDirectory, components, index, aCallback, aFilenameTranslateDictionary); }); // If we've already determined that this file doesn't exist... diff --git a/Tests/AppKit/CPApplicationTest.j b/Tests/AppKit/CPApplicationTest.j index 7ab0de490..5677435a3 100644 --- a/Tests/AppKit/CPApplicationTest.j +++ b/Tests/AppKit/CPApplicationTest.j @@ -1,5 +1,6 @@ @import @import +@import var globalResults = []; diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 939d8881e..4a1d9756a 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -1,4 +1,5 @@ +@import @import @import @@ -428,7 +429,7 @@ { [self _initTestRemoveObjects_SimpleArray]; [self _testRemoveObjects_MultipleSelectedObjects_AvoidingEmptySelection]; -}/ +} - (void)testRemoveObjects_MultipleSelectedObjects_AvoidingEmptySelection_ContentBinding { diff --git a/Tests/AppKit/CPOutlineViewTest.j b/Tests/AppKit/CPOutlineViewTest.j index eac2c4f34..7cebdee09 100644 --- a/Tests/AppKit/CPOutlineViewTest.j +++ b/Tests/AppKit/CPOutlineViewTest.j @@ -4,7 +4,7 @@ { CPOutlineView outlineView; CPTableColumn tableColumn; - TestDataSource dataSource; + TestOutlineDataSource dataSource; } - (void)setUp @@ -17,7 +17,7 @@ [outlineView setAllowsMultipleSelection:YES]; - dataSource = [TestDataSource new]; + dataSource = [TestOutlineDataSource new]; [dataSource setEntries:[".1", ".1.1", ".1.2", ".1.2.1", ".1.2.2", ".2", ".3", ".3.1"]]; [outlineView setDataSource:dataSource]; @@ -188,7 +188,7 @@ @end -@implementation TestDataSource : CPObject +@implementation TestOutlineDataSource : CPObject { CPArray entries @accessors; } diff --git a/Tests/AppKit/CPPredicateEditorTest.j b/Tests/AppKit/CPPredicateEditorTest.j index 7789f83b9..b94a126ac 100644 --- a/Tests/AppKit/CPPredicateEditorTest.j +++ b/Tests/AppKit/CPPredicateEditorTest.j @@ -50,5 +50,7 @@ expected = [t2, t2]; [self assertTrue:[templates isEqualToArray:expected] message:[CPString stringWithFormat:errorFormat, title, [expected description], [templates description]]]; - } + } } + +@end diff --git a/Tests/AppKit/CPSearchFieldTest.j b/Tests/AppKit/CPSearchFieldTest.j index 0ee5ff3a1..28f45a61c 100644 --- a/Tests/AppKit/CPSearchFieldTest.j +++ b/Tests/AppKit/CPSearchFieldTest.j @@ -26,3 +26,5 @@ [_searchField setRecentSearches:searches] [self assertTrue:[[_searchField recentSearches] count] == 3 message:@"After setRecentSearches array doesn't include results"]; } + +@end diff --git a/Tests/AppKit/CPWindowTest.j b/Tests/AppKit/CPWindowTest.j index ec415d032..95f8467f1 100644 --- a/Tests/AppKit/CPWindowTest.j +++ b/Tests/AppKit/CPWindowTest.j @@ -1,5 +1,6 @@ @import +@import [CPApplication sharedApplication]; diff --git a/Tests/Foundation/CPArrayPerformanceTest.j b/Tests/Foundation/CPArrayPerformanceTest.j index 5c1f4235a..edad83cf6 100644 --- a/Tests/Foundation/CPArrayPerformanceTest.j +++ b/Tests/Foundation/CPArrayPerformanceTest.j @@ -1,6 +1,6 @@ var FILE = require("file"); -@import +@import @import @import @import diff --git a/Tests/Foundation/CPDataTest.j b/Tests/Foundation/CPDataTest.j index 7a97a1850..c0c37c21a 100644 --- a/Tests/Foundation/CPDataTest.j +++ b/Tests/Foundation/CPDataTest.j @@ -1,4 +1,4 @@ -@import +@import @import @import @import diff --git a/Tests/Manual/ArrayController1/AppController.j b/Tests/Manual/ArrayController1/AppController.j index 8619a17a4..a62ee2a6a 100644 --- a/Tests/Manual/ArrayController1/AppController.j +++ b/Tests/Manual/ArrayController1/AppController.j @@ -184,7 +184,7 @@ CPLogRegister(CPLogConsole); return self; } -- (BOOL)validatePrice:(id)value error:({CPError})error +- (BOOL)validatePrice:(id)value error:(/*{*/CPError/*}*/)error { if ([value intValue] >= 0) return YES; diff --git a/Tests/Manual/CPOutlineViewTest/AppController.j b/Tests/Manual/CPOutlineViewTest/AppController.j index 038372766..3e18f9d58 100644 --- a/Tests/Manual/CPOutlineViewTest/AppController.j +++ b/Tests/Manual/CPOutlineViewTest/AppController.j @@ -262,7 +262,7 @@ var rowHeights = [ ]; return YES; } -- (CPDragOperation)outlineView:(CPOutlineView)anOutlineView validateDrop:(id < CPDraggingInfo >)theInfo proposedItem:(id)theItem proposedChildIndex:(int)theIndex +- (CPDragOperation)outlineView:(CPOutlineView)anOutlineView validateDrop:(id /*< CPDraggingInfo >*/)theInfo proposedItem:(id)theItem proposedChildIndex:(int)theIndex { CPLog.debug(@"validate item: %@ at index: %i", theItem, theIndex); @@ -274,7 +274,7 @@ var rowHeights = [ ]; return CPDragOperationEvery; } -- (BOOL)outlineView:(CPOutlineView)outlineView acceptDrop:(id < CPDraggingInfo >)theInfo item:(id)theItem childIndex:(int)theIndex +- (BOOL)outlineView:(CPOutlineView)outlineView acceptDrop:(id /*< CPDraggingInfo >*/)theInfo item:(id)theItem childIndex:(int)theIndex { if (theItem === nil) theItem = [self menu]; diff --git a/Tools/NativeHost/AppController+WebPolicyDelegate.m b/Tools/NativeHost/AppController+WebPolicyDelegate.m index 209870a55..2c098dcd0 100644 --- a/Tools/NativeHost/AppController+WebPolicyDelegate.m +++ b/Tools/NativeHost/AppController+WebPolicyDelegate.m @@ -12,13 +12,13 @@ @implementation AppController (WebPolicyDelegate) -- (void)webView:(WebView *)aWebView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)aRequest newFrameName:(NSString *)aFrameName decisionListener:(id < WebPolicyDecisionListener >)aListener +- (void)webView:(WebView *)aWebView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)aRequest newFrameName:(NSString *)aFrameName decisionListener:(id /*< WebPolicyDecisionListener >*/)aListener { [[NSWorkspace sharedWorkspace] openURL:[actionInformation objectForKey:WebActionOriginalURLKey]]; [aListener ignore]; } -- (void)webView:(WebView *)aWebView decidePolicyForNavigationAction:(NSDictionary *)aDictionary request:(NSURLRequest *)aRequest frame:(WebFrame *)aWebFrame decisionListener:(id )aDecisionListener +- (void)webView:(WebView *)aWebView decidePolicyForNavigationAction:(NSDictionary *)aDictionary request:(NSURLRequest *)aRequest frame:(WebFrame *)aWebFrame decisionListener:(id /**/)aDecisionListener { NSURL * requestURL = [aRequest URL]; diff --git a/Tools/nib2cib/NSExpression.j b/Tools/nib2cib/NSExpression.j index da908860d..7fc3bf309 100644 --- a/Tools/nib2cib/NSExpression.j +++ b/Tools/nib2cib/NSExpression.j @@ -1,4 +1,11 @@ @import +@import +@import +@import +@import +@import +@import +@import @implementation NSKeyPathExpression : _CPKeyPathExpression { From 0280a10832ccb3f32aa251dd230e7f40dfe8057b Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sun, 16 Dec 2012 19:20:59 +0100 Subject: [PATCH 03/46] More changes now when we don't have with(self) --- Foundation/CPArray/CPMutableArray.j | 4 +-- Foundation/CPString.j | 52 ++++++++++++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index 629bb9382..30621c022 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -217,7 +217,7 @@ */ - (void)removeObject:(id)anObject { - [self removeObject:anObject inRange:CPMakeRange(0, length)]; + [self removeObject:anObject inRange:CPMakeRange(0, self.length)]; } /*! @@ -232,7 +232,7 @@ while ((index = [self indexOfObject:anObject inRange:aRange]) != CPNotFound) { [self removeObjectAtIndex:index]; - aRange = CPIntersectionRange(CPMakeRange(index, length - index), aRange); + aRange = CPIntersectionRange(CPMakeRange(index, self.length - index), aRange); } } diff --git a/Foundation/CPString.j b/Foundation/CPString.j index c7da015b1..fc9427369 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -194,7 +194,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (int)length { - return length; + return self.length; } /*! @@ -203,7 +203,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)characterAtIndex:(unsigned)anIndex { - return charAt(anIndex); + return self.charAt(anIndex); } // Combining strings @@ -246,15 +246,15 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)stringByPaddingToLength:(unsigned)aLength withString:(CPString)aString startingAtIndex:(unsigned)anIndex { - if (length == aLength) + if (self.length == aLength) return self; - if (aLength < length) + if (aLength < self.length) return substr(0, aLength); var string = self, substring = aString.substring(anIndex), - difference = aLength - length; + difference = aLength - self.length; while ((difference -= substring.length) >= 0) string += substring; @@ -279,7 +279,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPArray)componentsSeparatedByString:(CPString)aString { - return split(aString); + return self.split(aString); } /*! @@ -289,7 +289,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)substringFromIndex:(unsigned)anIndex { - return substr(anIndex); + return self.substr(anIndex); } /*! @@ -299,10 +299,10 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)substringWithRange:(CPRange)aRange { - if (aRange.location < 0 || _CPMaxRange(aRange) > length) + if (aRange.location < 0 || _CPMaxRange(aRange) > self.length) [CPException raise:CPRangeException reason:"aRange out of bounds"]; - return substr(aRange.location, aRange.length); + return self.substr(aRange.location, aRange.length); } /*! @@ -314,10 +314,10 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)substringToIndex:(unsigned)anIndex { - if (anIndex > length) + if (anIndex > self.length) [CPException raise:CPRangeException reason:"index out of bounds"]; - return substring(0, anIndex); + return self.substring(0, anIndex); } // Finding characters and substrings @@ -436,9 +436,9 @@ var CPStringUIDs = new CFMutableDictionary(), - (CPString)stringByReplacingOccurrencesOfString:(CPString)target withString:(CPString)replacement options:(int)options range:(CPRange)searchRange { - var start = substring(0, searchRange.location), - stringSegmentToSearch = substr(searchRange.location, searchRange.length), - end = substring(searchRange.location + searchRange.length, self.length), + var start = self.substring(0, searchRange.location), + stringSegmentToSearch = self.substr(searchRange.location, searchRange.length), + end = self.substring(searchRange.location + searchRange.length, self.length), target = [target stringByEscapingRegexControlCharacters], regExp; @@ -459,7 +459,7 @@ var CPStringUIDs = new CFMutableDictionary(), - (CPString)stringByReplacingCharactersInRange:(CPRange)range withString:(CPString)replacement { - return '' + substring(0, range.location) + replacement + substring(range.location + range.length, self.length); + return '' + self.substring(0, range.location) + replacement + self.substring(range.location + range.length, self.length); } /*! @@ -546,7 +546,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (BOOL)hasPrefix:(CPString)aString { - return aString && aString != "" && indexOf(aString) == 0; + return aString && aString != "" && self.indexOf(aString) == 0; } /*! @@ -556,7 +556,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (BOOL)hasSuffix:(CPString)aString { - return aString && aString != "" && length >= aString.length && lastIndexOf(aString) == (length - aString.length); + return aString && aString != "" && self.length >= aString.length && self.lastIndexOf(aString) == (self.length - aString.length); } - (BOOL)isEqual:(id)anObject @@ -657,7 +657,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)lowercaseString { - return toLowerCase(); + return self.toLowerCase(); } /*! @@ -665,7 +665,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)uppercaseString { - return toUpperCase(); + return self.toUpperCase(); } /*! @@ -716,7 +716,7 @@ var CPStringUIDs = new CFMutableDictionary(), if (self === "/") return ["/"]; - var result = split('/'); + var result = self.split('/'); if (result[0] === "") result[0] = "/"; @@ -787,10 +787,10 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)pathExtension { - if (lastIndexOf('.') === CPNotFound) + if (self.lastIndexOf('.') === CPNotFound) return ""; - return substr(lastIndexOf('.') + 1); + return self.substr(self.lastIndexOf('.') + 1); } /*! @@ -830,7 +830,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)stringByAppendingPathExtension:(CPString)ext { - if (ext.indexOf('/') >= 0 || length === 0 || self === "/") // Can't handle these + if (ext.indexOf('/') >= 0 || self.length === 0 || self === "/") // Can't handle these return self; var components = [self pathComponents], @@ -852,7 +852,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPString)stringByDeletingLastPathComponent { - if (length === 0) + if (self.length === 0) return ""; else if (self === "/") return "/"; @@ -880,10 +880,10 @@ var CPStringUIDs = new CFMutableDictionary(), if (extension === "") return self; - else if (lastIndexOf('.') < 1) + else if (self.lastIndexOf('.') < 1) return self; - return substr(0, [self length] - (extension.length + 1)); + return self.substr(0, [self length] - (extension.length + 1)); } - (CPString)stringByStandardizingPath From b52217e8a007e2a4a87736dc348b847bf6054515 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 17 Dec 2012 00:40:26 +0100 Subject: [PATCH 04/46] =?UTF-8?q?Tried=20to=20make=20the=20import=20mess?= =?UTF-8?q?=20a=20little=20better.=20Fixed=20a=20lot=20of=20bugs.=20Change?= =?UTF-8?q?d=20some=20class=20names=20in=20the=20test=20cases.=20Looks=20l?= =?UTF-8?q?ike=20all=20the=20tests=20are=20being=20run=20in=20the=20same?= =?UTF-8?q?=20space.=20Has=20to=20look=20into=20this=E2=80=A6..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppKit/CPAccordionView.j | 2 +- AppKit/CPCollectionView.j | 2 +- AppKit/CPDocument.j | 2 +- AppKit/CPKeyValueBinding.j | 2 +- AppKit/CPMenu/CPMenu.j | 2 +- AppKit/CPPasteboard.j | 2 +- AppKit/CPRuleEditor/CPRuleEditor.j | 2 +- AppKit/CPSegmentedControl.j | 2 +- AppKit/CPTableView.j | 2 +- AppKit/CPView.j | 2 +- AppKit/CPViewController.j | 2 +- AppKit/CPWindow/CPWindow.j | 3322 +--------------- AppKit/CPWindow/_CPWindow.j | 3349 +++++++++++++++++ AppKit/Cib/_CPCibObjectData.j | 2 +- AppKit/Platform/DOM/CPDOMWindowLayer.j | 2 +- Foundation/CPArray+KVO.j | 2 +- Foundation/CPArray/CPArray.j | 998 +---- Foundation/CPArray/CPMutableArray.j | 2 +- Foundation/CPArray/_CPArray.j | 1018 +++++ Foundation/CPDictionary.j | 6 +- Foundation/CPPredicate/CPExpression.j | 385 +- Foundation/CPPredicate/CPPredicate.j | 2 +- Foundation/CPPredicate/_CPExpression.j | 397 ++ Foundation/CPString.j | 2 +- Foundation/Foundation.j | 2 - Objective-J/ObjJCompiler.js | 22 +- Tests/AppKit/CPArrayControllerTest.j | 2 +- Tests/AppKit/CPPredicateEditorTest.j | 21 +- Tests/AppKit/CPTokenFieldTest.j | 2 +- .../01_WithoutBindings/MyDocument.j | 2 +- .../01_WithoutBindings/TableViewDataSource.j | 1 + .../01_WithoutBindings/WithoutBindingsTest.j | 4 +- .../{Bookmark.j => Bookmark2.j} | 2 +- .../{MyDocument.j => MyDocument2.j} | 4 +- .../Resources/02_WithBindings.xib | 2 +- .../02_WithBindings/TableViewDataSource.j | 2 +- .../02_WithBindings/WithBindingsTest.j | 6 +- Tests/Foundation/CPArrayPerformanceTest.j | 7 +- Tests/Foundation/CPAttributedStringTest.j | 2 +- Tests/Foundation/CPDataTest.j | 2 +- Tests/Foundation/CPInvocationOperationTest.j | 4 +- Tests/Foundation/CPKVCArrayTest.j | 4 +- Tests/Foundation/CPKVOTest.j | 4 +- Tests/Foundation/CPKeyValueCodingTest.j | 10 +- Tests/Foundation/CPOperationTest.j | 12 +- Tests/Foundation/SubclassTollFreeTest.j | 32 +- Tests/Objective-J/MethodDispatchTest.j | 1 + 47 files changed, 4881 insertions(+), 4778 deletions(-) create mode 100644 AppKit/CPWindow/_CPWindow.j mode change 100755 => 100644 Foundation/CPArray/CPArray.j create mode 100755 Foundation/CPArray/_CPArray.j create mode 100644 Foundation/CPPredicate/_CPExpression.j rename Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/{Bookmark.j => Bookmark2.j} (97%) rename Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/{MyDocument.j => MyDocument2.j} (97%) diff --git a/AppKit/CPAccordionView.j b/AppKit/CPAccordionView.j index 669cad8b2..c4a6e6e49 100644 --- a/AppKit/CPAccordionView.j +++ b/AppKit/CPAccordionView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 588161cc9..e1c934f4c 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPDocument.j b/AppKit/CPDocument.j index 4e8bdf3e7..674a8dc0a 100644 --- a/AppKit/CPDocument.j +++ b/AppKit/CPDocument.j @@ -21,7 +21,7 @@ */ @import -@import +@import @import "CPApplication.j" @import "CPResponder.j" diff --git a/AppKit/CPKeyValueBinding.j b/AppKit/CPKeyValueBinding.j index 90f5a624c..450de2152 100644 --- a/AppKit/CPKeyValueBinding.j +++ b/AppKit/CPKeyValueBinding.j @@ -24,7 +24,7 @@ */ @import -@import +@import @import @import diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 20f98508e..2d4bf62fe 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPPasteboard.j b/AppKit/CPPasteboard.j index ebcfe36fb..5a898ead0 100644 --- a/AppKit/CPPasteboard.j +++ b/AppKit/CPPasteboard.j @@ -21,7 +21,7 @@ */ @import -@import +@import @import @import diff --git a/AppKit/CPRuleEditor/CPRuleEditor.j b/AppKit/CPRuleEditor/CPRuleEditor.j index 1b7c05c7c..a8798e475 100644 --- a/AppKit/CPRuleEditor/CPRuleEditor.j +++ b/AppKit/CPRuleEditor/CPRuleEditor.j @@ -21,7 +21,7 @@ */ @import -@import +@import @import @import @import "CPTextField.j" diff --git a/AppKit/CPSegmentedControl.j b/AppKit/CPSegmentedControl.j index b85d28eaf..0399cf050 100644 --- a/AppKit/CPSegmentedControl.j +++ b/AppKit/CPSegmentedControl.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import "CPControl.j" diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 7b08b408f..49a08a7d3 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import "CGGradient.j" diff --git a/AppKit/CPView.j b/AppKit/CPView.j index ba0753e26..a1b1d42ba 100644 --- a/AppKit/CPView.j +++ b/AppKit/CPView.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import @import diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index f140716e8..f6268b4dc 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import "CPApplication.j" @import "CPCib.j" diff --git a/AppKit/CPWindow/CPWindow.j b/AppKit/CPWindow/CPWindow.j index 98f3441de..ef64ba089 100644 --- a/AppKit/CPWindow/CPWindow.j +++ b/AppKit/CPWindow/CPWindow.j @@ -20,3324 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import -@import -@import - -@import "CGGeometry.j" -@import "CPAnimation.j" -@import "CPPlatformWindow.j" -@import "CPResponder.j" -@import "CPScreen.j" -#if PLATFORM(BROWSER) -@import "CPPlatformWindow+DOM.j" -#endif - - -/* - Borderless window mask option. - @global - @class CPWindow -*/ -CPBorderlessWindowMask = 0; -/* - Titled window mask option. - @global - @class CPWindow -*/ -CPTitledWindowMask = 1 << 0; -/* - Closeable window mask option. - @global - @class CPWindow -*/ -CPClosableWindowMask = 1 << 1; -/* - Miniaturizabe window mask option. - @global - @class CPWindow -*/ -CPMiniaturizableWindowMask = 1 << 2; -/* - Resizable window mask option. - @global - @class CPWindow -*/ -CPResizableWindowMask = 1 << 3; -/* - Textured window mask option. - @global - @class CPWindow -*/ -CPTexturedBackgroundWindowMask = 1 << 8; -/* - @global - @class CPWindow -*/ -CPBorderlessBridgeWindowMask = 1 << 20; -/* - @global - @class CPWindow -*/ -CPHUDBackgroundWindowMask = 1 << 21; - -CPWindowNotSizable = 0; -CPWindowMinXMargin = 1; -CPWindowWidthSizable = 2; -CPWindowMaxXMargin = 4; -CPWindowMinYMargin = 8; -CPWindowHeightSizable = 16; -CPWindowMaxYMargin = 32; - -CPBackgroundWindowLevel = -1; -/* - Default level for windows - @group CPWindowLevel - @global -*/ -CPNormalWindowLevel = 0; -/* - Floating palette type window - @group CPWindowLevel - @global -*/ -CPFloatingWindowLevel = 3; -/* - Submenu type window - @group CPWindowLevel - @global -*/ -CPSubmenuWindowLevel = 3; -/* - For a torn-off menu - @group CPWindowLevel - @global -*/ -CPTornOffMenuWindowLevel = 3; -/* - For the application's main menu - @group CPWindowLevel - @global -*/ -CPMainMenuWindowLevel = 24; -/* - Status window level - @group CPWindowLevel - @global -*/ -CPStatusWindowLevel = 25; -/* - Level for a modal panel - @group CPWindowLevel - @global -*/ -CPModalPanelWindowLevel = 8; -/* - Level for a pop up menu - @group CPWindowLevel - @global -*/ -CPPopUpMenuWindowLevel = 101; -/* - Level for a window being dragged - @group CPWindowLevel - @global -*/ -CPDraggingWindowLevel = 500; -/* - Level for the screens saver - @group CPWindowLevel - @global -*/ -CPScreenSaverWindowLevel = 1000; - -/* - The receiver is removed from the screen list and hidden. - @global - @class CPWindowOrderingMode -*/ -CPWindowOut = 0; -/* - The receiver is placed directly in front of the window specified. - @global - @class CPWindowOrderingMode -*/ -CPWindowAbove = 1; -/* - The receiver is placed directly behind the window specified. - @global - @class CPWindowOrderingMode -*/ -CPWindowBelow = 2; - -CPWindowWillCloseNotification = @"CPWindowWillCloseNotification"; -CPWindowDidBecomeMainNotification = @"CPWindowDidBecomeMainNotification"; -CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification"; -CPWindowDidBecomeKeyNotification = @"CPWindowDidBecomeKeyNotification"; -CPWindowDidResignKeyNotification = @"CPWindowDidResignKeyNotification"; -CPWindowDidResizeNotification = @"CPWindowDidResizeNotification"; -CPWindowDidMoveNotification = @"CPWindowDidMoveNotification"; -CPWindowWillBeginSheetNotification = @"CPWindowWillBeginSheetNotification"; -CPWindowDidEndSheetNotification = @"CPWindowDidEndSheetNotification"; -CPWindowDidMiniaturizeNotification = @"CPWindowDidMiniaturizeNotification"; -CPWindowWillMiniaturizeNotification = @"CPWindowWillMiniaturizeNotification"; -CPWindowDidDeminiaturizeNotification = @"CPWindowDidDeminiaturizeNotification"; - -_CPWindowDidChangeFirstResponderNotification = @"_CPWindowDidChangeFirstResponderNotification"; - -CPWindowShadowStyleStandard = 0; -CPWindowShadowStyleMenu = 1; -CPWindowShadowStylePanel = 2; - -var SHADOW_MARGIN_LEFT = 20.0, - SHADOW_MARGIN_RIGHT = 19.0, - SHADOW_MARGIN_TOP = 10.0, - SHADOW_MARGIN_BOTTOM = 10.0, - SHADOW_DISTANCE = 5.0, - - _CPWindowShadowColor = nil; - -var CPWindowSaveImage = nil, - CPWindowSavingImage = nil, - - CPWindowResizeTime = 0.2; - -/* - Keys for which action messages will be sent by default when unhandled, e.g. complete:. -*/ -var CPWindowActionMessageKeys = [ - CPLeftArrowFunctionKey, - CPRightArrowFunctionKey, - CPUpArrowFunctionKey, - CPDownArrowFunctionKey, - CPPageUpFunctionKey, - CPPageDownFunctionKey, - CPHomeFunctionKey, - CPEndFunctionKey, - CPEscapeFunctionKey - ]; - -/*! - @ingroup appkit - @class CPWindow - - An CPWindow instance represents a window, panel or menu on the screen.

- -

Each window has a style, which determines how the window is decorated; whether it has a border, a title bar, a resize bar, minimise and close buttons.

- -

A window has a frame. This is the frame of the entire window on the screen, including all decorations and borders. The origin of the frame represents its bottom left corner and the frame is expressed in screen coordinates.

- -

A window always contains a content view which is the highest level view available for public (application) use. This view fills the area of the window inside any decoration/border. This is the only part of the window that application programmers are allowed to draw in directly.

- -

You can convert between view coordinates and window base coordinates using the [CPView -convertPoint:fromView:], [CPView -convertPoint:toView:], [CPView -convertRect:fromView:], and [CPView -convertRect:toView:] methods with a nil view argument. - - @par Delegate Methods - - @delegate -(void)windowDidResize:(CPNotification)notification; - Sent from the notification center when the window has been resized. - @param notification contains information about the resize event - - @delegate -(CPUndoManager)windowWillReturnUndoManager:(CPWindow)window; - Called to obtain the undo manager for a window - @param window the window for which to return the undo manager - @return the window's undo manager - - @delegate -(void)windowDidBecomeMain:(CPNotification)notification; - Sent from the notification center when the delegate's window becomes - the main window. - @param notification contains information about the event - - @delegate -(void)windowDidResignMain:(CPNotification)notification; - Sent from the notification center when the delegate's window has - resigned main window status. - @param notification contains information about the event - - @delegate -(void)windowDidResignKey:(CPNotification)notification; - Sent from the notification center when the delegate's window has - resigned key window status. - @param notification contains information about the event - - @delegate -(BOOL)windowShouldClose:(id)window; - Called when the user tries to close the window. - @param window the window to close - @return \c YES allows the window to close. \c NO - vetoes the close operation and leaves the window open. - - @delegate -(BOOL)windowWillBeginSheet:(CPNotification)notification; - Sent from the notification center before sheet is visible on - the delegate's window. - @param notification contains information about the event - - @delegate -(BOOL)windowDidEndSheet:(CPNotification)notification; - Sent from the notification center when an attached sheet on the - delegate's window has been animated out and is no longer visible. - @param notification contains information about the event -*/ -@implementation CPWindow : CPResponder -{ - CPPlatformWindow _platformWindow; - - int _windowNumber; - unsigned _styleMask; - CGRect _frame; - int _level; - BOOL _isVisible; - BOOL _isMiniaturized; - BOOL _isAnimating; - BOOL _hasShadow; - BOOL _isMovableByWindowBackground; - BOOL _isMovable; - unsigned _shadowStyle; - BOOL _showsResizeIndicator; - - int _positioningMask; - CGRect _positioningScreenRect; - - BOOL _isDocumentEdited; - BOOL _isDocumentSaving; - - CPImageView _shadowView; - - CPView _windowView; - CPView _contentView; - CPView _toolbarView; - - CPArray _mouseEnteredStack; - CPView _leftMouseDownView; - CPView _rightMouseDownView; - - CPToolbar _toolbar; - CPResponder _firstResponder; - CPResponder _initialFirstResponder; - id _delegate; - - CPString _title; - - BOOL _acceptsMouseMovedEvents; - BOOL _ignoresMouseEvents; - - CPWindowController _windowController; - - CGSize _minSize; - CGSize _maxSize; - - CPUndoManager _undoManager; - CPURL _representedURL; - - CPSet _registeredDraggedTypes; - CPArray _registeredDraggedTypesArray; - CPCountedSet _inclusiveRegisteredDraggedTypes; - - CPButton _defaultButton; - BOOL _defaultButtonEnabled; - - BOOL _autorecalculatesKeyViewLoop; - BOOL _keyViewLoopIsDirty; - - BOOL _sharesChromeWithPlatformWindow; - - // Bridge Support -#if PLATFORM(DOM) - DOMElement _DOMElement; -#endif - - unsigned _autoresizingMask; - - BOOL _delegateRespondsToWindowWillReturnUndoManagerSelector; - - BOOL _isFullPlatformWindow; - _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; - - CPDictionary _sheetContext; - CPWindow _parentView; - BOOL _isSheet; - _CPWindowFrameAnimation _frameAnimation; -} - -/* - Private initializer for Objective-J - @ignore -*/ -+ (void)initialize -{ - if (self !== [CPWindow class]) - return; - - var bundle = [CPBundle bundleForClass:[CPWindow class]]; - - CPWindowSavingImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(16.0, 16.0)] -} - -- (id)init -{ - return [self initWithContentRect:_CGRectMakeZero() styleMask:CPTitledWindowMask]; -} - -/*! - Initializes the window. The method also takes a style bit mask made up - of any of the following values: -

-CPBorderlessWindowMask
-CPTitledWindowMask
-CPClosableWindowMask
-CPMiniaturizableWindowMask
-CPResizableWindowMask
-CPTexturedBackgroundWindowMask
-
- @param aContentRect the size and location of the window in screen space - @param aStyleMask a style mask - @return the initialized window -*/ -- (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask -{ - self = [super init]; - - if (self) - { - var windowViewClass = [[self class] _windowViewClassForStyleMask:aStyleMask]; - - _frame = [windowViewClass frameRectForContentRect:aContentRect]; - - [self _setSharesChromeWithPlatformWindow:![CPPlatform isBrowser]]; - - if ([CPPlatform isBrowser]) - [self setPlatformWindow:[CPPlatformWindow primaryPlatformWindow]]; - else - { - // give zero sized borderless bridge windows a default size if we're not in the browser so they show up in NativeHost. - if ((aStyleMask & CPBorderlessBridgeWindowMask) && aContentRect.size.width === 0 && aContentRect.size.height === 0) - { - var visibleFrame = [[[CPScreen alloc] init] visibleFrame]; - _frame.size.height = MIN(768.0, visibleFrame.size.height); - _frame.size.width = MIN(1024.0, visibleFrame.size.width); - _frame.origin.x = (visibleFrame.size.width - _frame.size.width) / 2; - _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2; - } - [self setPlatformWindow:[[CPPlatformWindow alloc] initWithContentRect:_frame]]; - [self platformWindow]._only = self; - } - - _isFullPlatformWindow = NO; - _registeredDraggedTypes = [CPSet set]; - _registeredDraggedTypesArray = []; - _acceptsMouseMovedEvents = YES; - _isMovable = YES; - - _isSheet = NO; - _sheetContext = nil; - _parentView = nil; - - // Set up our window number. - _windowNumber = [CPApp._windows count]; - CPApp._windows[_windowNumber] = self; - - _styleMask = aStyleMask; - - [self setLevel:CPNormalWindowLevel]; - - _minSize = CGSizeMake(0.0, 0.0); - _maxSize = CGSizeMake(1000000.0, 1000000.0); - - // Create our border view which is the actual root of our view hierarchy. - _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask]; - - [_windowView _setWindow:self]; - [_windowView setNextResponder:self]; - - [self setMovableByWindowBackground:aStyleMask & CPHUDBackgroundWindowMask]; - - // Create a generic content view. - [self setContentView:[[CPView alloc] initWithFrame:CGRectMakeZero()]]; - [self setInitialFirstResponder:[self contentView]]; - - _firstResponder = self; - -#if PLATFORM(DOM) - _DOMElement = document.createElement("div"); - - _DOMElement.style.position = "absolute"; - _DOMElement.style.visibility = "visible"; - _DOMElement.style.zIndex = 0; - - if (![self _sharesChromeWithPlatformWindow]) - { - CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(_frame), _CGRectGetMinY(_frame)); - } - - CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1); - CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement); -#endif - - [self setNextResponder:CPApp]; - - [self setHasShadow:aStyleMask !== CPBorderlessWindowMask]; - - if (aStyleMask & CPBorderlessBridgeWindowMask) - [self setFullPlatformWindow:YES]; - - _autorecalculatesKeyViewLoop = NO; - _defaultButtonEnabled = YES; - _keyViewLoopIsDirty = YES; - - [self setShowsResizeIndicator:_styleMask & CPResizableWindowMask]; - } - - return self; -} - -- (CPPlatformWindow)platformWindow -{ - return _platformWindow; -} - -/*! - Sets the platform window of the reciver. - This method will first close the reciever, - change the platform window, then reopen the window (if it was originally open). -*/ -- (void)setPlatformWindow:(CPPlatformWindow)aPlatformWindow -{ - var wasVisible = [self isVisible]; - - // we have to close it first, otherwise we get a DOM exception. - if (wasVisible) - [self close]; - - _platformWindow = aPlatformWindow; - [_platformWindow _setTitle:_title window:self]; - - if (wasVisible) - [self orderFront:self]; -} - - -/*! - @ignore -*/ -+ (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask -{ - if (aStyleMask & CPHUDBackgroundWindowMask) - return _CPHUDWindowView; - - else if (aStyleMask === CPBorderlessWindowMask) - return _CPBorderlessWindowView; - - else if (aStyleMask & CPDocModalWindowMask) - return _CPDocModalWindowView; - - return _CPStandardWindowView; -} - -+ (Class)_windowViewClassForFullPlatformWindowStyleMask:(unsigned)aStyleMask -{ - return _CPBorderlessBridgeWindowView; -} - -- (void)awakeFromCib -{ - _keyViewLoopIsDirty = ![self _hasKeyViewLoop]; - - // If no key view loop has been specified by hand, and we are not intending to auto recalculate, - // set up a default key view loop. - if (_keyViewLoopIsDirty && ![self autorecalculatesKeyViewLoop]) - [self recalculateKeyViewLoop]; - - // At this time we know the final screen (or browser) size and can apply the positioning mask, if any, from the nib. - if (_positioningScreenRect) - { - var actualScreenRect = [CPPlatform isBrowser] ? [_platformWindow contentBounds] : [[self screen] visibleFrame], - frame = [self frame], - origin = frame.origin; - - if (actualScreenRect) - { - if ((_positioningMask & CPWindowPositionFlexibleLeft) && (_positioningMask & CPWindowPositionFlexibleRight)) - { - // Proportional Horizontal. - origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width); - } - else if (_positioningMask & CPWindowPositionFlexibleLeft) - { - // Fixed from Right - origin.x += actualScreenRect.size.width - _positioningScreenRect.size.width; - } - else if (_positioningMask & CPWindowPositionFlexibleRight) - { - // Fixed from Left - } - - if ((_positioningMask & CPWindowPositionFlexibleTop) && (_positioningMask & CPWindowPositionFlexibleBottom)) - { - // Proportional Vertical. - origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height); - } - else if (_positioningMask & CPWindowPositionFlexibleTop) - { - // Fixed from Bottom - origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height; - } - else if (_positioningMask & CPWindowPositionFlexibleBottom) - { - // Fixed from Top - } - - [self setFrameOrigin:origin]; - } - } -} - -- (void)_setWindowView:(CPView)aWindowView -{ - if (_windowView === aWindowView) - return; - - var oldWindowView = _windowView; - - _windowView = aWindowView; - - if (oldWindowView) - { - [oldWindowView _setWindow:nil]; - [oldWindowView noteToolbarChanged]; - -#if PLATFORM(DOM) - CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement); -#endif - } - - if (_windowView) - { -#if PLATFORM(DOM) - CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement); -#endif - - var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil]; - - contentRect.origin = [self convertBaseToGlobal:contentRect.origin]; - - [_windowView _setWindow:self]; - [_windowView setNextResponder:self]; - [_windowView addSubview:_contentView]; - [_windowView setTitle:_title]; - [_windowView noteToolbarChanged]; - [_windowView setShowsResizeIndicator:[self showsResizeIndicator]]; - - [self setFrame:[self frameRectForContentRect:contentRect]]; - } -} - -/*! - Sets the receiver as a full platform window. If you pass YES the CPWindow instance will fill the entire browser content area, - otherwise the CPWindow will be a window inside of your browser window which the user can drag around, and resize (if you allow). - - @param BOOL - YES if the window should fill the browser window, otherwise NO. -*/ -- (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow -{ - if (![_platformWindow supportsFullPlatformWindows]) - return; - - shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow; - - if (_isFullPlatformWindow === shouldBeFullPlatformWindow) - return; - - _isFullPlatformWindow = shouldBeFullPlatformWindow; - - if (_isFullPlatformWindow) - { - _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [self contentRectForFrameRect:[self frame]], [self hasShadow], [self level]); - - var fullPlatformWindowViewClass = [[self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask], - windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask]; - - [self _setWindowView:windowView]; - - [self setLevel:CPBackgroundWindowLevel]; - [self setHasShadow:NO]; - [self setAutoresizingMask:CPWindowWidthSizable | CPWindowHeightSizable]; - [self setFrame:[_platformWindow visibleFrame]]; - } - else - { - var windowView = _fullPlatformWindowSession.windowView; - - [self _setWindowView:windowView]; - - [self setLevel:_fullPlatformWindowSession.level]; - [self setHasShadow:_fullPlatformWindowSession.hasShadow]; - [self setAutoresizingMask:CPWindowNotSizable]; - - [self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]]; - } -} - -/*! - @return BOOL - YES if the CPWindow fills the browser window, otherwise NO. -*/ -- (BOOL)isFullPlatformWindow -{ - return _isFullPlatformWindow; -} - -/*! - Returns the window's style mask. -*/ -- (unsigned)styleMask -{ - return _styleMask; -} - -/*! - Returns the frame rectangle used by a window. - Style masks include: -
-    CPBorderlessWindowMask
-    CPTitledWindowMask
-    CPClosableWindowMask
-    CPMiniaturizableWindowMask (NOTE: only available in NativeHost)
-    CPResizableWindowMask
-    CPTexturedBackgroundWindowMask
-    CPBorderlessBridgeWindowMask
-    CPHUDBackgroundWindowMask
-    
- - @param aContentRect the content rectangle of the window - @param aStyleMask the style mask of the window - @return the matching window's frame rectangle -*/ -+ (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask -{ - return [[[self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect]; -} - -/*! - Returns the receiver's content rectangle. A content rectangle does not include toolbars. - @param aFrame the window's frame rectangle -*/ -- (CGRect)contentRectForFrameRect:(CGRect)aFrame -{ - return [_windowView contentRectForFrameRect:aFrame]; -} - -/*! - Retrieves the frame rectangle for this window. - @param aContentRect the window's content rectangle - @return the window's frame rectangle -*/ -- (CGRect)frameRectForContentRect:(CGRect)aContentRect -{ - return [_windowView frameRectForContentRect:aContentRect]; -} - -/*! - Returns the window's frame rectangle -*/ -- (CGRect)frame -{ - return _CGRectMakeCopy(_frame); -} - -/*! - Sets the window's frame rectangle. Also tells the window whether it should animate - the resize operation, and redraw itself if necessary. - @param aFrame the new size and location for the window - @param shouldDisplay whether the window should redraw its views - @param shouldAnimate whether the window resize should be animated. -*/ -- (void)_setClippedFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate -{ - aFrame.size.width = MIN(MAX(aFrame.size.width, _minSize.width), _maxSize.width) - aFrame.size.height = MIN(MAX(aFrame.size.height, _minSize.height), _maxSize.height); - [self setFrame:aFrame display:shouldDisplay animate:shouldAnimate]; -} - -/*! - Sets the frame of the window. - - @param aFrame - A CGRect of the new frame for the receiver. - @param shouldDisplay - YES if the window should call setNeedsDisplay otherwise NO. - @param shouldAnimate - YES if the window should animate to it's new size and position, otherwise NO. -*/ -- (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate -{ - aFrame = _CGRectMakeCopy(aFrame); - - var value = aFrame.origin.x, - delta = value - FLOOR(value); - - if (delta) - aFrame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value); - - value = aFrame.origin.y; - delta = value - FLOOR(value); - - if (delta) - aFrame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value); - - value = aFrame.size.width; - delta = value - FLOOR(value); - - if (delta) - aFrame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value); - - value = aFrame.size.height; - delta = value - FLOOR(value); - - if (delta) - aFrame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value); - - if (shouldAnimate) - { - [_frameAnimation stopAnimation]; - _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; - - [_frameAnimation startAnimation]; - } - else - { - var origin = _frame.origin, - newOrigin = aFrame.origin; - - if (!_CGPointEqualToPoint(origin, newOrigin)) - { - origin.x = newOrigin.x; - origin.y = newOrigin.y; - -#if PLATFORM(DOM) - if (![self _sharesChromeWithPlatformWindow]) - { - CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y); - } -#endif - - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMoveNotification object:self]; - } - - var size = _frame.size, - newSize = aFrame.size; - - if (!_CGSizeEqualToSize(size, newSize)) - { - size.width = newSize.width; - size.height = newSize.height; - - [_windowView setFrameSize:size]; - - if (_hasShadow) - { - // if the shadow would be taller/wider than the window height, - // make it the same as the window height. this allows views to - // become 0, 0 with no shadow on them and makes the sheet - // animation look nicer - var shadowSize = _CGSizeMake(size.width, size.height); - - if (size.width >= (SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT)) - shadowSize.width += SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT; - - if (size.height >= (SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE)) - shadowSize.height += SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE; - - [_shadowView setFrameSize:shadowSize]; - } - - if (!_isAnimating) - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResizeNotification object:self]; - } - - if ([self _sharesChromeWithPlatformWindow]) - [_platformWindow setContentRect:_frame]; - } -} - -/*! - Sets the window's frame rect. - @param aFrame - The new CGRect of the window. - @param shouldDisplay - YES if the window should call setNeedsDisplay: otherwise NO. -*/ -- (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay -{ - [self _setClippedFrame:aFrame display:shouldDisplay animate:NO]; -} - -/*! - Sets the window's frame rectangle - @param aFrame - The CGRect of the windows new frame -*/ -- (void)setFrame:(CGRect)aFrame -{ - [self _setClippedFrame:aFrame display:YES animate:NO]; -} - -/*! - Sets the window's location. - @param anOrigin the new location for the window -*/ -- (void)setFrameOrigin:(CGPoint)anOrigin -{ - [self _setClippedFrame:_CGRectMake(anOrigin.x, anOrigin.y, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame)) display:YES animate:NO]; - - // reposition sheet - if ([self attachedSheet]) - [self _setAttachedSheetFrameOrigin]; -} - -/*! - Sets the window's size. - @param aSize the new size for the window -*/ -- (void)setFrameSize:(CGSize)aSize -{ - [self _setClippedFrame:_CGRectMake(_CGRectGetMinX(_frame), _CGRectGetMinY(_frame), aSize.width, aSize.height) display:YES animate:NO]; -} - -/*! - Makes the receiver the front most window in the screen ordering. - @param aSender the object that requested this -*/ -- (void)orderFront:(id)aSender -{ -#if PLATFORM(DOM) - // -dw- if a sheet is clicked, the parent window should come up too - if ([self isSheet]) - [_parentView orderFront:self]; - - [_platformWindow orderFront:self]; - [_platformWindow order:CPWindowAbove window:self relativeTo:nil]; -#endif - - if (!CPApp._keyWindow) - [self makeKeyWindow]; - - if ([self isKeyWindow] && (_firstResponder === self || !_firstResponder)) - [self makeFirstResponder:_initialFirstResponder]; - - if (!CPApp._mainWindow) - [self makeMainWindow]; -} - -/* - Makes the receiver the last window in the screen ordering. - @param aSender the object that requested this - @ignore -*/ -- (void)orderBack:(id)aSender -{ - //[_platformWindow order:CPWindowBelow -} - -/*! - Hides the window. - @param the object that requested this -*/ -- (void)orderOut:(id)aSender -{ - if ([self isSheet]) - { - // -dw- as in Cocoa, orderOut: detaches the sheet and animates out - [self._parentView _detachSheetWindow]; - return; - } - -#if PLATFORM(DOM) - if ([self _sharesChromeWithPlatformWindow]) - [_platformWindow orderOut:self]; -#endif - - if ([_delegate respondsToSelector:@selector(windowWillClose:)]) - [_delegate windowWillClose:self]; - -#if PLATFORM(DOM) - [_platformWindow order:CPWindowOut window:self relativeTo:nil]; -#endif - - [self _updateMainAndKeyWindows]; -} - -/*! - Relocates the window in the screen list. - @param aPlace the positioning relative to \c otherWindowNumber - @param otherWindowNumber the window relative to which the receiver should be placed -*/ -- (void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(int)otherWindowNumber -{ -#if PLATFORM(DOM) - [_platformWindow order:aPlace window:self relativeTo:CPApp._windows[otherWindowNumber]]; -#endif -} - -/*! - Sets the window's level - @param the window's new level -*/ -- (void)setLevel:(int)aLevel -{ - if (aLevel === _level) - return; - - [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel]; - - _level = aLevel; - - if ([self _sharesChromeWithPlatformWindow]) - [_platformWindow setLevel:aLevel]; -} - -/*! - Returns the window's current level -*/ -- (int)level -{ - return _level; -} - -/*! - Returns \c YES if the window is visible. It does not mean that the window is not obscured by other windows. -*/ -- (BOOL)isVisible -{ - return _isVisible; -} - -/*! - Returns \c YES if the window's resize indicator is showing. \c NO otherwise. -*/ -- (BOOL)showsResizeIndicator -{ - return _showsResizeIndicator; -} - -/*! - Sets the window's resize indicator. - @param shouldShowResizeIndicator \c YES sets the window to show its resize indicator. -*/ -- (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator -{ - shouldShowResizeIndicator = !!shouldShowResizeIndicator; - - if (_showsResizeIndicator === shouldShowResizeIndicator) - return; - - _showsResizeIndicator = shouldShowResizeIndicator; - [_windowView setShowsResizeIndicator:[self showsResizeIndicator]]; -} - -/*! - Returns the offset of the window's resize indicator. -*/ -- (CGSize)resizeIndicatorOffset -{ - return [_windowView resizeIndicatorOffset]; -} - -/*! - Sets the offset of the window's resize indicator. - @param aSize the offset for the resize indicator -*/ -- (void)setResizeIndicatorOffset:(CGSize)anOffset -{ - [_windowView setResizeIndicatorOffset:anOffset]; -} - -/*! - Sets the window's content view. The new view will be resized to fit - inside the content rectangle of the window. - @param aView the new content view for the receiver -*/ -- (void)setContentView:(CPView)aView -{ - if (_contentView) - [_contentView removeFromSuperview]; - - var bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)); - - // During init the initial first responder is set to the contentView - // if it hasn't changed in the mean time we need to update that reference - // to the new contentView - if (_initialFirstResponder === _contentView) - [self setInitialFirstResponder:aView]; - - _contentView = aView; - [_contentView setFrame:[self contentRectForFrameRect:bounds]]; - - [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; - [_windowView addSubview:_contentView]; -} - -/*! - Returns the window's current content view. -*/ -- (CPView)contentView -{ - return _contentView; -} - -/*! - Applies an alpha value to the window. - @param aValue the alpha value to apply -*/ -- (void)setAlphaValue:(float)aValue -{ - [_windowView setAlphaValue:aValue]; -} - -/*! - Returns the alpha value of the window. -*/ -- (float)alphaValue -{ - return [_windowView alphaValue]; -} - -/*! - Sets the window's background color. - @param aColor the new color for the background -*/ -- (void)setBackgroundColor:(CPColor)aColor -{ - [_windowView setBackgroundColor:aColor]; -} - -/*! - Returns the window's background color. -*/ -- (CPColor)backgroundColor -{ - return [_windowView backgroundColor]; -} - -/*! - Sets the window's minimum size. If the provided - size is the same as the current minimum size, the method simply returns. - @param aSize the new minimum size for the window -*/ -- (void)setMinSize:(CGSize)aSize -{ - if (CGSizeEqualToSize(_minSize, aSize)) - return; - - _minSize = CGSizeCreateCopy(aSize); - - var size = CGSizeMakeCopy([self frame].size), - needsFrameChange = NO; - - if (size.width < _minSize.width) - { - size.width = _minSize.width; - needsFrameChange = YES; - } - - if (size.height < _minSize.height) - { - size.height = _minSize.height; - needsFrameChange = YES; - } - - if (needsFrameChange) - [self setFrameSize:size]; -} - -/*! - Returns the windows minimum size. -*/ -- (CGSize)minSize -{ - return _minSize; -} - -/*! - Sets the window's maximum size. If the provided - size is the same as the current maximum size, - the method simply returns. - @param aSize the new maximum size -*/ -- (void)setMaxSize:(CGSize)aSize -{ - if (CGSizeEqualToSize(_maxSize, aSize)) - return; - - _maxSize = CGSizeCreateCopy(aSize); - - var size = CGSizeMakeCopy([self frame].size), - needsFrameChange = NO; - - if (size.width > _maxSize.width) - { - size.width = _maxSize.width; - needsFrameChange = YES; - } - - if (size.height > _maxSize.height) - { - size.height = _maxSize.height; - needsFrameChange = YES; - } - - if (needsFrameChange) - [self setFrameSize:size]; -} - -/*! - Returns the window's maximum size. -*/ -- (CGSize)maxSize -{ - return _maxSize; -} - -/*! - Returns \c YES if the window has a drop shadow. \c NO otherwise. -*/ -- (BOOL)hasShadow -{ - return _hasShadow; -} - -- (void)_updateShadow -{ - if ([self _sharesChromeWithPlatformWindow]) - { - if (_shadowView) - { -#if PLATFORM(DOM) - CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement); -#endif - _shadowView = nil; - } - - [_platformWindow setHasShadow:_hasShadow]; - - return; - } - - if (_hasShadow && !_shadowView) - { - var bounds = [_windowView bounds]; - - _shadowView = [[CPView alloc] initWithFrame:CGRectMake(-SHADOW_MARGIN_LEFT, -SHADOW_MARGIN_TOP + SHADOW_DISTANCE, - SHADOW_MARGIN_LEFT + CGRectGetWidth(bounds) + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_TOP + CGRectGetHeight(bounds) + SHADOW_MARGIN_BOTTOM)]; - - if (!_CPWindowShadowColor) - { - var bundle = [CPBundle bundleForClass:[CPWindow class]]; - - _CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices: - [ - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow0.png"] size:CGSizeMake(20.0, 19.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow1.png"] size:CGSizeMake(1.0, 19.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow2.png"] size:CGSizeMake(19.0, 19.0)], - - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow3.png"] size:CGSizeMake(20.0, 1.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow4.png"] size:CGSizeMake(1.0, 1.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow5.png"] size:CGSizeMake(19.0, 1.0)], - - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow6.png"] size:CGSizeMake(20.0, 18.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow7.png"] size:CGSizeMake(1.0, 18.0)], - [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow8.png"] size:CGSizeMake(19.0, 18.0)] - ]]]; - } - - [_shadowView setBackgroundColor:_CPWindowShadowColor]; - [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; - -#if PLATFORM(DOM) - CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement); -#endif - } - else if (!_hasShadow && _shadowView) - { -#if PLATFORM(DOM) - CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement); -#endif - _shadowView = nil; - } -} - -/*! - Sets whether the window should have a drop shadow. - @param shouldHaveShadow \c YES to have a drop shadow. -*/ -- (void)setHasShadow:(BOOL)shouldHaveShadow -{ - if (_hasShadow === shouldHaveShadow) - return; - - _hasShadow = shouldHaveShadow; - - [self _updateShadow]; -} - -/*! - Sets the shadow style of the receiver. - Values are: -
-    CPWindowShadowStyleStandard
-    CPWindowShadowStyleMenu
-    CPWindowShadowStylePanel
-    
- - @param aStyle - The new shadow style of the receiver. -*/ -- (void)setShadowStyle:(unsigned)aStyle -{ - _shadowStyle = aStyle; - - [[self platformWindow] setShadowStyle:_shadowStyle]; -} - -/*! - Sets the delegate for the window. Passing \c nil will just remove the window's current delegate. - @param aDelegate an object to respond to the various delegate methods of CPWindow -*/ -- (void)setDelegate:(id)aDelegate -{ - var defaultCenter = [CPNotificationCenter defaultCenter]; - - [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self]; - [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self]; - - _delegate = aDelegate; - _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)]; - - if ([_delegate respondsToSelector:@selector(windowDidResignKey:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidResignKey:) - name:CPWindowDidResignKeyNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidBecomeKey:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidBecomeKey:) - name:CPWindowDidBecomeKeyNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidBecomeMain:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidBecomeMain:) - name:CPWindowDidBecomeMainNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidResignMain:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidResignMain:) - name:CPWindowDidResignMainNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidMove:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidMove:) - name:CPWindowDidMoveNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidResize:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidResize:) - name:CPWindowDidResizeNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowWillBeginSheet:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowWillBeginSheet:) - name:CPWindowWillBeginSheetNotification - object:self]; - - if ([_delegate respondsToSelector:@selector(windowDidEndSheet:)]) - [defaultCenter - addObserver:_delegate - selector:@selector(windowDidEndSheet:) - name:CPWindowDidEndSheetNotification - object:self]; -} - -/*! - Returns window's delegate -*/ -- (id)delegate -{ - return _delegate; -} - -/*! - Sets the window's controller - @param aWindowController a window controller -*/ -- (void)setWindowController:(CPWindowController)aWindowController -{ - _windowController = aWindowController; -} - -/*! - Returns the window's controller. -*/ -- (CPWindowController)windowController -{ - return _windowController; -} - -- (void)doCommandBySelector:(SEL)aSelector -{ - if ([_delegate respondsToSelector:aSelector]) - [_delegate performSelector:aSelector]; - else - [super doCommandBySelector:aSelector]; -} - -- (BOOL)acceptsFirstResponder -{ - return NO; -} - -- (CPView)initialFirstResponder -{ - return _initialFirstResponder; -} - -- (void)setInitialFirstResponder:(CPView)aView -{ - // Before an initial first responder is set, be sure to calculate the key loop - [self _setupFirstResponder:aView]; - - _initialFirstResponder = aView; -} - -- (void)_setupFirstResponder:(CPView)anInitialFirstResponder -{ - /* - If: - - - The key loop is dirty - - The key loop does not auto-recalculate - - No view within the window has become first responder - - No initial first responder has been set - - Then calculate the key view loop and set the first responder - to the first view in the loop if no initial responder has been set, since we should - always have an initial first responder and a key loop by default. - */ - if (_keyViewLoopIsDirty && - !_autorecalculatesKeyViewLoop && - _firstResponder === self && - _initialFirstResponder === [self contentView]) - { - [self recalculateKeyViewLoop]; - - if (anInitialFirstResponder) - [self makeFirstResponder:anInitialFirstResponder]; - else - { - // Make the first key view of the content view the first responder - var firstKeyView = [[self contentView] nextValidKeyView]; - - [self makeFirstResponder:firstKeyView]; - } - } -} - -/*! - Attempts to make the \c aResponder the first responder. Before trying - to make it the first responder, the receiver will ask the current first responder - to resign its first responder status. If it resigns, it will ask - \c aResponder accept first responder, then finally tell it to become first responder. - @return \c YES if the attempt was successful. \c NO otherwise. -*/ -- (BOOL)makeFirstResponder:(CPResponder)aResponder -{ - if (_firstResponder === aResponder) - return YES; - - if (![_firstResponder resignFirstResponder]) - return NO; - - if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder]) - { - _firstResponder = self; - - return NO; - } - - _firstResponder = aResponder; - - [[CPNotificationCenter defaultCenter] postNotificationName:_CPWindowDidChangeFirstResponderNotification object:self]; - - return YES; -} - -/*! - Returns the window's current first responder. -*/ -- (CPResponder)firstResponder -{ - return _firstResponder; -} - -- (BOOL)acceptsMouseMovedEvents -{ - return _acceptsMouseMovedEvents; -} - -- (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents -{ - _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents; -} - -- (BOOL)ignoresMouseEvents -{ - return _ignoresMouseEvents; -} - -- (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents -{ - _ignoresMouseEvents = shouldIgnoreMouseEvents; -} - -// Managing Titles - -/*! - Returns the window's title bar string -*/ -- (CPString)title -{ - return _title; -} - -/*! - Sets the window's title bar string -*/ -- (void)setTitle:(CPString)aTitle -{ - _title = aTitle; - - [_windowView setTitle:aTitle]; - [_platformWindow _setTitle:_title window:self]; - - [self _synchronizeMenuBarTitleWithWindowTitle]; -} - -/*! - Sets the title bar to represent a file path -*/ -- (void)setTitleWithRepresentedFilename:(CPString)aFilePath -{ - [self setRepresentedFilename:aFilePath]; - [self setTitle:[aFilePath lastPathComponent]]; -} - -/*! - Sets the path to the file the receiver represents -*/ -- (void)setRepresentedFilename:(CPString)aFilePath -{ - // FIXME: urls vs filepaths and all. - [self setRepresentedURL:aFilePath]; -} - -/*! - Returns the path to the file the receiver represents -*/ -- (CPString)representedFilename -{ - return _representedURL; -} - -/*! - Sets the URL that the receiver represents -*/ -- (void)setRepresentedURL:(CPURL)aURL -{ - _representedURL = aURL; -} - -/*! - Returns the URL that the receiver represents -*/ -- (CPURL)representedURL -{ - return _representedURL; -} - -- (CPScreen)screen -{ - return [[CPScreen alloc] init]; -} - -// Moving - -/*! - Sets whether the window can be moved by dragging its background. The default is based on the window style. - @param shouldBeMovableByWindowBackground \c YES makes the window move from a background drag. -*/ -- (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground -{ - _isMovableByWindowBackground = shouldBeMovableByWindowBackground; -} - -/*! - Returns \c YES if the window can be moved by dragging its background. -*/ -- (BOOL)isMovableByWindowBackground -{ - return _isMovableByWindowBackground; -} - -/*! - Sets whether the window can be moved. - @param shouldBeMovable \c YES makes the window movable. -*/ -- (void)setMovable:(BOOL)shouldBeMovable -{ - _isMovable = shouldBeMovable; -} - -/*! - Returns \c YES if the window can be moved. -*/ -- (void)isMovable -{ - return _isMovable; -} - -/*! - Sets the window location to be the center of the screen -*/ -- (void)center -{ - if (_isFullPlatformWindow) - return; - - var size = [self frame].size, - containerSize = [CPPlatform isBrowser] ? [_platformWindow contentBounds].size : [[self screen] visibleFrame].size; - - var origin = CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0); - - if (origin.x < 0.0) - origin.x = 0.0; - - if (origin.y < 0.0) - origin.y = 0.0; - - [self setFrameOrigin:origin]; -} - -/*! - Dispatches events that are sent to it from CPApplication. - @param anEvent the event to be dispatched -*/ -- (void)sendEvent:(CPEvent)anEvent -{ - var type = [anEvent type], - point = [anEvent locationInWindow]; - - // If a sheet is attached events get filtered here. - // It is not clear what events should be passed to the view, perhaps all? - // CPLeftMouseDown is needed for window moving and resizing to work. - // CPMouseMoved is needed for rollover effects on title bar buttons. - var sheet = [self attachedSheet]; - if (sheet) - { - switch (type) - { - case CPLeftMouseDown: - [_windowView mouseDown:anEvent]; - - // -dw- if the window is clicked, the sheet should come to front, and become key, - // and the window should be immediately behind - [sheet makeKeyAndOrderFront:self]; - break; - case CPMouseMoved: - [_windowView mouseMoved:anEvent]; - break; - } - - return; - } - - switch (type) - { - case CPFlagsChanged: return [[self firstResponder] flagsChanged:anEvent]; - - case CPKeyUp: return [[self firstResponder] keyUp:anEvent]; - - case CPKeyDown: if ([anEvent charactersIgnoringModifiers] === CPTabCharacter) - { - if ([anEvent modifierFlags] & CPShiftKeyMask) - [self selectPreviousKeyView:self]; - else - [self selectNextKeyView:self]; -#if PLATFORM(DOM) - // Make sure the browser doesn't try to do its own tab handling. - // This is important or the browser might blur the shared text field or token field input field, - // even that we just moved it to a new first responder. - [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO] -#endif - return; - } - else if ([anEvent charactersIgnoringModifiers] === CPBackTabCharacter) - { - var didTabBack = [self selectPreviousKeyView:self]; - if (didTabBack) - { -#if PLATFORM(DOM) - // Make sure the browser doesn't try to do its own tab handling. - // This is important or the browser might blur the shared text field or token field input field, - // even that we just moved it to a new first responder. - [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO] -#endif - } - - return didTabBack; - } - - [[self firstResponder] keyDown:anEvent]; - - // Trigger the default button if needed - // FIXME: Is this only applicable in a sheet? See isse: #722. - if (![self disableKeyEquivalentForDefaultButton]) - { - var defaultButton = [self defaultButton], - keyEquivalent = [defaultButton keyEquivalent], - modifierMask = [defaultButton keyEquivalentModifierMask]; - - if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask]) - [[self defaultButton] performClick:self]; - } - - return; - - case CPScrollWheel: return [[_windowView hitTest:point] scrollWheel:anEvent]; - - case CPLeftMouseUp: - case CPRightMouseUp: var hitTestedView = _leftMouseDownView, - selector = type == CPRightMouseUp ? @selector(rightMouseUp:) : @selector(mouseUp:); - - if (!hitTestedView) - hitTestedView = [_windowView hitTest:point]; - - [hitTestedView performSelector:selector withObject:anEvent]; - - _leftMouseDownView = nil; - - return; - case CPLeftMouseDown: - case CPRightMouseDown: _leftMouseDownView = [_windowView hitTest:point]; - - if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder]) - [self makeFirstResponder:_leftMouseDownView]; - - [CPApp activateIgnoringOtherApps:YES]; - - var theWindow = [anEvent window], - selector = type == CPRightMouseDown ? @selector(rightMouseDown:) : @selector(mouseDown:); - - if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey]) - return [_leftMouseDownView performSelector:selector withObject:anEvent]; - else - { - // FIXME: delayed ordering? - [self makeKeyAndOrderFront:self]; - - if ([_leftMouseDownView acceptsFirstMouse:anEvent]) - return [_leftMouseDownView performSelector:selector withObject:anEvent]; - } - break; - - case CPLeftMouseDragged: - case CPRightMouseDragged: if (!_leftMouseDownView) - return [[_windowView hitTest:point] mouseDragged:anEvent]; - - var selector; - if (type == CPRightMouseDragged) - { - selector = @selector(rightMouseDragged:) - if (![_leftMouseDownView respondsToSelector:selector]) - selector = nil; - } - - if (!selector) - selector = @selector(mouseDragged:) - - return [_leftMouseDownView performSelector:selector withObject:anEvent]; - - case CPMouseMoved: if (!_acceptsMouseMovedEvents) - return; - - if (!_mouseEnteredStack) - _mouseEnteredStack = []; - - var hitTestView = [_windowView hitTest:point]; - - if ([_mouseEnteredStack count] && [_mouseEnteredStack lastObject] === hitTestView) - return [hitTestView mouseMoved:anEvent]; - - var view = hitTestView, - mouseEnteredStack = []; - - while (view) - { - mouseEnteredStack.unshift(view); - - view = [view superview]; - } - - var deviation = MIN(_mouseEnteredStack.length, mouseEnteredStack.length); - - while (deviation--) - if (_mouseEnteredStack[deviation] === mouseEnteredStack[deviation]) - break; - - var index = deviation + 1, - count = _mouseEnteredStack.length; - - if (index < count) - { - var event = [CPEvent mouseEventWithType:CPMouseExited location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]; - - for (; index < count; ++index) - [_mouseEnteredStack[index] mouseExited:event]; - } - - index = deviation + 1; - count = mouseEnteredStack.length; - - if (index < count) - { - var event = [CPEvent mouseEventWithType:CPMouseEntered location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]; - - for (; index < count; ++index) - [mouseEnteredStack[index] mouseEntered:event]; - } - - _mouseEnteredStack = mouseEnteredStack; - - [hitTestView mouseMoved:anEvent]; - } -} - -/*! - Returns the window's number in the desktop's screen list -*/ -- (int)windowNumber -{ - return _windowNumber; -} - -/*! - Called when the receiver should become the key window. It also sends - the \c -becomeKeyWindow message to the first responder. -*/ -- (void)becomeKeyWindow -{ - CPApp._keyWindow = self; - - if (_firstResponder !== self && [_firstResponder respondsToSelector:@selector(becomeKeyWindow)]) - [_firstResponder becomeKeyWindow]; - - [self _setupFirstResponder:nil]; - - [_windowView noteKeyWindowStateChanged]; - - [[CPNotificationCenter defaultCenter] - postNotificationName:CPWindowDidBecomeKeyNotification - object:self]; -} - -/*! - Determines if the window can become the key window. - @return \c YES means the window can become the key window. -*/ -- (BOOL)canBecomeKeyWindow -{ - // In Cocoa only resizable or titled windows return YES here by default. But the main browser window in Cappuccino - // doesn't have these masks even that it's both titled and resizable, so we return YES when isFullPlatformWindow too. - return (_styleMask & CPTitledWindowMask) || (_styleMask & CPResizableWindowMask) || [self isFullPlatformWindow]; -} - -/*! - Returns \c YES if the window is the key window. -*/ -- (BOOL)isKeyWindow -{ - return [CPApp keyWindow] == self; -} - -/*! - Makes the window the key window and brings it to the front of the screen list. - @param aSender the object requesting this -*/ -- (void)makeKeyAndOrderFront:(id)aSender -{ - [self orderFront:self]; - - [self makeKeyWindow]; - [self makeMainWindow]; -} - -/*! - Makes this window the key window. -*/ -- (void)makeKeyWindow -{ - if ([CPApp keyWindow] === self || ![self canBecomeKeyWindow]) - return; - - [[CPApp keyWindow] resignKeyWindow]; - [self becomeKeyWindow]; -} - -/*! - Causes the window to resign it's key window status. -*/ -- (void)resignKeyWindow -{ - if (_firstResponder !== self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)]) - [_firstResponder resignKeyWindow]; - - if (CPApp._keyWindow === self) - CPApp._keyWindow = nil; - - [_windowView noteKeyWindowStateChanged]; - - [[CPNotificationCenter defaultCenter] - postNotificationName:CPWindowDidResignKeyNotification - object:self]; -} - -/*! - Initiates a drag operation from the receiver to another view that accepts dragged data. - @param anImage the image to be dragged - @param aLocation the lower-left corner coordinate of \c anImage - @param mouseOffset the distance from the \c -mouseDown: location and the current location - @param anEvent the \c -mouseDown: that triggered the drag - @param aPasteboard the pasteboard that holds the drag data - @param aSourceObject the drag operation controller - @param slideBack Whether the image should 'slide back' if the drag is rejected -*/ -- (void)dragImage:(CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack -{ - [[CPDragServer sharedDragServer] dragImage:anImage fromWindow:self at:[self convertBaseToGlobal:imageLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack]; -} - -- (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes -{ - if (!pasteboardTypes) - return; - - if (!_inclusiveRegisteredDraggedTypes) - _inclusiveRegisteredDraggedTypes = [CPCountedSet set]; - - [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes]; -} - -- (void)_noteUnregisteredDraggedTypes:(CPSet)pasteboardTypes -{ - if (!pasteboardTypes) - return; - - [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes]; - - if ([_inclusiveRegisteredDraggedTypes count] === 0) - _inclusiveRegisteredDraggedTypes = nil; -} - -/*! - Initiates a drag operation from the receiver to another view that accepts dragged data. - @param aView the view to be dragged - @param aLocation the lower-left corner coordinate of \c aView - @param mouseOffset the distance from the \c -mouseDown: location and the current location - @param anEvent the \c -mouseDown: that triggered the drag - @param aPasteboard the pasteboard that holds the drag data - @param aSourceObject the drag operation controller - @param slideBack Whether the view should 'slide back' if the drag is rejected -*/ -- (void)dragView:(CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack -{ - [[CPDragServer sharedDragServer] dragView:aView fromWindow:self at:[self convertBaseToGlobal:viewLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack]; -} - -/*! - Sets the receiver's list of acceptable data types for a dragging operation. - @param pasteboardTypes an array of CPPasteboards -*/ -- (void)registerForDraggedTypes:(CPArray)pasteboardTypes -{ - if (!pasteboardTypes) - return; - - [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes]; - [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes]; - [self _noteRegisteredDraggedTypes:_registeredDraggedTypes]; - - _registeredDraggedTypesArray = nil; -} - -/*! - Returns an array of all types the receiver accepts for dragging operations. - @return an array of CPPasteBoards -*/ -- (CPArray)registeredDraggedTypes -{ - if (!_registeredDraggedTypesArray) - _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects]; - - return _registeredDraggedTypesArray; -} - -/*! - Resets the array of acceptable data types for a dragging operation. -*/ -- (void)unregisterDraggedTypes -{ - [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes]; - - _registeredDraggedTypes = [CPSet set]; - _registeredDraggedTypesArray = []; -} - -// Accessing Editing Status - -/*! - Sets whether the document has been edited. - @param isDocumentEdited \c YES if the document has been edited. -*/ -- (void)setDocumentEdited:(BOOL)isDocumentEdited -{ - if (_isDocumentEdited == isDocumentEdited) - return; - - _isDocumentEdited = isDocumentEdited; - - [CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0]; - - [_windowView setDocumentEdited:isDocumentEdited]; -} - -/*! - Returns \c YES if the document has been edited. -*/ -- (BOOL)isDocumentEdited -{ - return _isDocumentEdited; -} - -- (void)setDocumentSaving:(BOOL)isDocumentSaving -{ - if (_isDocumentSaving == isDocumentSaving) - return; - - _isDocumentSaving = isDocumentSaving; - - [self _synchronizeSaveMenuWithDocumentSaving]; - - [_windowView windowDidChangeDocumentSaving]; -} - -- (BOOL)isDocumentSaving -{ - return _isDocumentSaving; -} - -/* @ignore */ -- (void)_synchronizeSaveMenuWithDocumentSaving -{ - if (![self isMainWindow]) - return; - - var mainMenu = [CPApp mainMenu], - index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."]; - - if (index == CPNotFound) - return; - - var item = [mainMenu itemAtIndex:index]; - - if (_isDocumentSaving) - { - CPWindowSaveImage = [item image]; - - [item setTitle:@"Saving..."]; - [item setImage:CPWindowSavingImage]; - [item setEnabled:NO]; - } - else - { - [item setTitle:@"Save"]; - [item setImage:CPWindowSaveImage]; - [item setEnabled:YES]; - } -} - -// Minimizing Windows - -/*! - Simulates the user minimizing the window, then minimizes the window. - @param aSender the object making this request -*/ -- (void)performMiniaturize:(id)aSender -{ - //FIXME show stuff - [self miniaturize:aSender]; -} - -/*! - Minimizes the window. Posts a \c CPWindowWillMiniaturizeNotification to the - notification center before minimizing the window. -*/ -- (void)miniaturize:(id)sender -{ - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillMiniaturizeNotification object:self]; - - [[self platformWindow] miniaturize:sender]; - - [self _updateMainAndKeyWindows]; - - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMiniaturizeNotification object:self]; - - _isMiniaturized = YES; -} - -/*! - Restores a minimized window to it's original size. -*/ -- (void)deminiaturize:(id)sender -{ - [[self platformWindow] deminiaturize:sender]; - - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidDeminiaturizeNotification object:self]; - - _isMiniaturized = NO; -} - -/*! - Returns YES if the window is minimized. -*/ -- (void)isMiniaturized -{ - return _isMiniaturized; -} - -// Closing Windows - -/*! - Simulates the user closing the window, then closes the window. - @param aSender the object making this request -*/ -- (void)performClose:(id)aSender -{ - if (!(_styleMask & CPClosableWindowMask)) - return; - - if ([self isFullBridge]) - { - var event = [CPApp currentEvent]; - - if ([event type] === CPKeyDown && [event characters] === "w" && ([event modifierFlags] & CPPlatformActionKeyMask)) - { - [[self platformWindow] _propagateCurrentDOMEvent:YES]; - return; - } - } - - // Only send ONE windowShouldClose: message. - if ([_delegate respondsToSelector:@selector(windowShouldClose:)]) - { - if (![_delegate windowShouldClose:self]) - return; - } - - // Only check self is delegate does NOT implement this. This also ensures this when delegate == self (returns true). - else if ([self respondsToSelector:@selector(windowShouldClose:)] && ![self windowShouldClose:self]) - return; - - var documents = [_windowController documents]; - if ([documents count]) - { - var index = [documents indexOfObject:[_windowController document]]; - - [documents[index] shouldCloseWindowController:_windowController - delegate:self - shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) - contextInfo:{documents:[documents copy], visited:0, index:index}]; - } - else - [self close]; -} - -- (void)_windowControllerContainingDocument:(CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context -{ - if (shouldClose) - { - var windowController = [self windowController], - documents = context.documents, - count = [documents count], - visited = ++context.visited, - index = ++context.index % count; - - [document removeWindowController:windowController]; - - if (visited < count) - { - [windowController setDocument:documents[index]]; - - [documents[index] shouldCloseWindowController:_windowController - delegate:self - shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) - contextInfo:context]; - } - else - [self close]; - } -} - -/*! - Closes the window. Posts a \c CPWindowWillCloseNotification to the - notification center before closing the window. -*/ -- (void)close -{ - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillCloseNotification object:self]; - - [self orderOut:nil]; -} - -// Managing Main Status -/*! - Returns \c YES if this the main window. -*/ -- (BOOL)isMainWindow -{ - return [CPApp mainWindow] === self; -} - -/*! - Returns \c YES if the window can become the main window. -*/ -- (BOOL)canBecomeMainWindow -{ - // FIXME: Also check if we can resize and titlebar. - if ([self isVisible]) - return YES; - - return NO; -} - -/*! - Makes the receiver the main window. -*/ -- (void)makeMainWindow -{ - if ([CPApp mainWindow] === self || ![self canBecomeMainWindow]) - return; - - [[CPApp mainWindow] resignMainWindow]; - [self becomeMainWindow]; -} - -/*! - Called to tell the receiver that it has become the main window. -*/ -- (void)becomeMainWindow -{ - CPApp._mainWindow = self; - - [self _synchronizeMenuBarTitleWithWindowTitle]; - [self _synchronizeSaveMenuWithDocumentSaving]; - - [_windowView noteMainWindowStateChanged]; - - [[CPNotificationCenter defaultCenter] - postNotificationName:CPWindowDidBecomeMainNotification - object:self]; -} - -/*! - Called when the window resigns main window status. -*/ -- (void)resignMainWindow -{ - [[CPNotificationCenter defaultCenter] - postNotificationName:CPWindowDidResignMainNotification - object:self]; - - if (CPApp._mainWindow === self) - CPApp._mainWindow = nil; - - [_windowView noteMainWindowStateChanged]; -} - -- (void)_updateMainAndKeyWindows -{ - var allWindows = [CPApp orderedWindows], - windowCount = [allWindows count]; - - if ([self isKeyWindow]) - { - var keyWindow = [CPApp keyWindow]; - [self resignKeyWindow]; - - if (keyWindow && keyWindow !== self && [keyWindow canBecomeKeyWindow]) - [keyWindow makeKeyWindow]; - else - { - var mainMenu = [CPApp mainMenu], - menuBarClass = objj_getClass("_CPMenuBarWindow"), - menuWindow; - - for (var i = 0; i < windowCount; i++) - { - var currentWindow = allWindows[i]; - - if ([currentWindow isKindOfClass:menuBarClass]) - menuWindow = currentWindow; - - if (currentWindow === self || currentWindow === menuWindow) - continue; - - if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow]) - { - [currentWindow makeKeyWindow]; - break; - } - } - - if (![CPApp keyWindow]) - [menuWindow makeKeyWindow]; - } - } - - if ([self isMainWindow]) - { - var mainWindow = [CPApp mainWindow]; - [self resignMainWindow]; - - if (mainWindow && mainWindow !== self && [mainWindow canBecomeMainWindow]) - [mainWindow makeMainWindow]; - else - { - var mainMenu = [CPApp mainMenu], - menuBarClass = objj_getClass("_CPMenuBarWindow"), - menuWindow; - - for (var i = 0; i < windowCount; i++) - { - var currentWindow = allWindows[i]; - - if ([currentWindow isKindOfClass:menuBarClass]) - menuWindow = currentWindow; - - if (currentWindow === self || currentWindow === menuWindow) - continue; - - if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow]) - { - [currentWindow makeMainWindow]; - break; - } - } - } - } -} - -// Managing Toolbars -/*! - Return's the window's toolbar -*/ -- (CPToolbar)toolbar -{ - return _toolbar; -} - -/*! - Sets the window's toolbar. - @param aToolbar the window's new toolbar -*/ -- (void)setToolbar:(CPToolbar)aToolbar -{ - if (_toolbar === aToolbar) - return; - - // If this has an owner, dump it! - [[aToolbar _window] setToolbar:nil]; - - // This is no longer out toolbar. - [_toolbar _setWindow:nil]; - - _toolbar = aToolbar; - - // THIS is our toolbar. - [_toolbar _setWindow:self]; - - [self _noteToolbarChanged]; -} - -- (void)toggleToolbarShown:(id)aSender -{ - var toolbar = [self toolbar]; - - [toolbar setVisible:![toolbar isVisible]]; -} - -- (void)_noteToolbarChanged -{ - var frame = CGRectMakeCopy([self frame]), - newFrame; - - [_windowView noteToolbarChanged]; - - if (_isFullPlatformWindow) - newFrame = [_platformWindow visibleFrame]; - else - { - newFrame = CGRectMakeCopy([self frame]); - - newFrame.origin = frame.origin; - } - - [self setFrame:newFrame]; - /* - [_windowView setAnimatingToolbar:YES]; - [self setFrame:frame]; - [self setFrame:newFrame display:YES animate:YES]; - [_windowView setAnimatingToolbar:NO]; - */ -} - -- (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve -{ - [_frameAnimation stopAnimation]; - _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; - [_frameAnimation setDelegate:delegate]; - [_frameAnimation setAnimationCurve:curve]; - [_frameAnimation setDuration:duration]; - [_frameAnimation startAnimation]; -} - -- (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame -{ - return CPWindowResizeTime; -} - -/* @ignore */ -- (void)_setAttachedSheetFrameOrigin -{ - // Position the sheet above the contentRect. - var attachedSheet = [self attachedSheet]; - var contentRect = [[self contentView] frame], - sheetFrame = CGRectMakeCopy([attachedSheet frame]); - - sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); - sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); - - [attachedSheet setFrame:sheetFrame display:YES animate:NO]; -} - -/* @ignore - Starting point for sheet session, called from CPApplication beginSheet: -*/ -- (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate - didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo -{ - if (_sheetContext) - { - [CPException raise:CPInternalInconsistencyException - reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"]; - return; - } - - var sheetFrame = [aSheet frame]; - - _sheetContext = {"sheet": aSheet, "modalDelegate": aModalDelegate, "endSelector": aDidEndSelector, - "contextInfo": aContextInfo, "frame": _CGRectMakeCopy(sheetFrame), "returnCode": -1, - "opened": NO}; - - [self _attachSheetWindow]; -} - -/* @ignore - Called to animate the sheet in. The timer seems to solve a bug where sheets would - be partially animated under certain conditions. -*/ -- (void)_attachSheetWindow -{ - _sheetContext["isAttached"] = YES; - - // it would be ideal to block here and spin an event loop, until attach is complete - [CPTimer scheduledTimerWithTimeInterval:0.0 - target:self - selector:@selector(_sheetShouldAnimateIn:) - userInfo:nil - repeats:NO]; -} - -/* @ignore - Called to end the sheet. Note that orderOut: is needed to animate the sheet out, as in Cocoa. - The sheet isn't completely gone until _cleanupSheetWindow gets called. -*/ -- (void)_endSheet -{ - var delegate = _sheetContext["modalDelegate"], - endSelector = _sheetContext["endSelector"]; - - // If the sheet has been ordered out, defer didEndSelector until after sheet animates out. - // This must be done since we cannot block and wait for the animation to complete. - if (delegate && endSelector) - { - if (_sheetContext["isAttached"]) - objj_msgSend(delegate, endSelector, _sheetContext["sheet"], _sheetContext["returnCode"], - _sheetContext["contextInfo"]); - else - _sheetContext["deferDidEndSelector"] = YES; - } -} - -/* @ignore - Called to animate the sheet out. If called while animating in, schedules an animate - out at completion -*/ -- (void)_detachSheetWindow -{ - _sheetContext["isAttached"] = NO; - - // it would be ideal to block here and spin the event loop, until attach is complete - [CPTimer scheduledTimerWithTimeInterval:0.0 - target:self - selector:@selector(_sheetShouldAnimateOut:) - userInfo:nil - repeats:NO]; -} - -/* @ignore - Called to cleanup sheet, when we are definitely done with it -*/ -- (void)_cleanupSheetWindow -{ - var sheet = _sheetContext["sheet"], - lastFrame = _sheetContext["frame"], - deferDidEnd = _sheetContext["deferDidEndSelector"]; - - [sheet setFrame:lastFrame]; - [self _restoreMasksForView:[sheet contentView]]; - - // if the parent window is modal, the sheet started its own modal session - if (sheet._isModal) - [CPApp stopModal]; - - // restore the state of window before it was sheetified - [sheet._windowView _enableSheet:NO]; - - // close it - sheet._isSheet = NO; - [sheet orderOut:self]; - - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidEndSheetNotification object:self]; - - if (deferDidEnd) - { - var delegate = _sheetContext["modalDelegate"], - selector = _sheetContext["endSelector"], - returnCode = _sheetContext["returnCode"], - contextInfo = _sheetContext["contextInfo"]; - - // context must be destroyed, since didEnd might want to attach another sheet - _sheetContext = nil; - sheet._parentView = nil; - - objj_msgSend(delegate, selector, sheet, returnCode, contextInfo); - } - else - { - _sheetContext = nil; - sheet._parentView = nil; - } -} - -/* @ignore */ -- (void)animationDidEnd:(id)anim -{ - var sheet = _sheetContext["sheet"]; - if (anim._window != sheet) - return; - - [CPTimer scheduledTimerWithTimeInterval:0.0 - target:self - selector:@selector(_sheetAnimationDidEnd:) - userInfo:nil - repeats:NO]; -} - -/* @ignore */ -- (void)_sheetShouldAnimateIn:(CPTimer)timer -{ - // can't open sheet while opening or closing animation is going on - if (_sheetContext["isOpening"] || - _sheetContext["isClosing"]) - return; - - var sheet = _sheetContext["sheet"], - sheetFrame = [sheet frame], - frame = [self frame]; - - [self _setUpMasksForView:[sheet contentView]]; - - sheet._isSheet = YES; - sheet._parentView = self; - - var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width) / 2), - originy = frame.origin.y + [[self contentView] frame].origin.y, - startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0), - endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); - - [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillBeginSheetNotification object:self]; - - // if sheet is attached to a modal window, the sheet runs - // as if itself and the parent window are modal - sheet._isModal = NO; - if ([CPApp modalWindow] === self) - { - [CPApp runModalForWindow:sheet]; - sheet._isModal = YES; - } - - [sheet orderFront:self]; - [sheet setFrame:startFrame display:YES animate:NO]; - - _sheetContext["opened"] = YES; - _sheetContext["shouldClose"] = NO; - _sheetContext["isOpening"] = YES; - - [sheet _setFrame:endFrame delegate:self duration:[self animationResizeTime:endFrame] curve:CPAnimationEaseOut]; - - // NOTE: cocoa doesn't make window key until animation is done, but a - // keypress while animating eventually gets to the window. Therefore, - // there must be a runloop specifically designed for sheets? - [sheet makeKeyWindow]; -} - -/* @ignore */ -- (void)_sheetShouldAnimateOut:(CPTimer)timer -{ - var sheet = _sheetContext["sheet"], - startFrame = [sheet frame], - endFrame = CGRectMakeCopy(startFrame); - - if (_sheetContext["isOpening"]) - { - // allow sheet to be closed while opening, it will close when animate in completes - _sheetContext["shouldClose"] = YES; - return; - } - - if (_sheetContext["isClosing"]) - return; - - _sheetContext["opened"] = NO; - _sheetContext["frame"] = startFrame; - _sheetContext["isClosing"] = YES; - - // the parent window can be orderedOut to disable the sheet animate out, as in Cocoa - if ([self isVisible]) - { - endFrame.size.height = 0; - [self _setUpMasksForView:[sheet contentView]]; - [sheet _setFrame:endFrame delegate:self duration:[self animationResizeTime:endFrame] curve:CPAnimationEaseIn]; - } - else - { - [self _sheetAnimationDidEnd:nil]; - } -} - -/* @ignore */ -- (void)_sheetAnimationDidEnd:(CPTimer)timer -{ - var sheet = _sheetContext["sheet"]; - - _sheetContext["isOpening"] = NO; - _sheetContext["isClosing"] = NO; - - if (_sheetContext["opened"] === YES) - { - // sheet is open and completely visible - [self _restoreMasksForView:[sheet contentView]]; - - // we wanted to close the sheet while it animated in, do that now - if (_sheetContext["shouldClose"] === YES) - [self _detachSheetWindow]; - } - else - { - // sheet is closed and not visible - [self _cleanupSheetWindow]; - } -} - -- (void)_setUpMasksForView:(CPView)aView -{ - var views = [aView subviews]; - - [views addObject:aView]; - - for (var i = 0, count = [views count]; i < count; i++) - { - var view = [views objectAtIndex:i], - mask = [view autoresizingMask], - maskToAdd = (mask & CPViewMinYMargin) ? 128 : CPViewMinYMargin; - - [view setAutoresizingMask:(mask | maskToAdd)]; - } -} - -- (void)_restoreMasksForView:(CPView)aView -{ - var views = [aView subviews]; - - [views addObject:aView]; - - for (var i = 0, count = [views count]; i < count; i++) - { - var view = [views objectAtIndex:i], - mask = [view autoresizingMask], - maskToRemove = (mask & 128) ? 128 : CPViewMinYMargin; - - [view setAutoresizingMask:(mask & (~ maskToRemove))]; - } -} - -/*! - Returns the window's attached sheet. -*/ -- (CPWindow)attachedSheet -{ - if (_sheetContext === nil) - return nil; - - return _sheetContext["sheet"]; -} - -/*! - Returns \c YES if the window has ever run as a sheet. -*/ -- (BOOL)isSheet -{ - return _isSheet; -} - -// -/* - Used privately. - @ignore -*/ -- (BOOL)becomesKeyOnlyIfNeeded -{ - return NO; -} - -/*! - Returns \c YES if the receiver is able to receive input events - even when a modal session is active. -*/ -- (BOOL)worksWhenModal -{ - return NO; -} - -- (BOOL)performKeyEquivalent:(CPEvent)anEvent -{ - // FIXME: should we be starting at the root, in other words _windowView? - // The evidence seems to point to no... - return [[self contentView] performKeyEquivalent:anEvent]; -} - -- (void)keyDown:(CPEvent)anEvent -{ - // It's not clear why we do performKeyEquivalent again here... - // Perhaps to allow something to happen between sendEvent: and keyDown:? - if ([anEvent _couldBeKeyEquivalent] && [self performKeyEquivalent:anEvent]) - return; - - // Apple's documentation is inconsistent with their behavior here. According to the docs - // an event going of the responder chain is passed to the input system as a last resort. - // However, the only methods I could get Cocoa to call automatically are - // moveUp: moveDown: moveLeft: moveRight: pageUp: pageDown: and complete: - // Unhandled events just travel further up the responder chain _past_ the window. - if (![self _processKeyboardUIKey:anEvent]) - [super keyDown:anEvent]; -} - -/* - @ignore - Interprets the key event for action messages and sends the action message down the responder chain - Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages. - We deviate from this by sending (the default) scrollPageUp:, scrollPageDown:, scrollToBeginningOfDocument: and scrollToEndOfDocument: for pageUp, pageDown, home and end keys. - @param anEvent the event to handle. - @return YES if the key event was handled, NO if no responder handled the key event -*/ -- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent -{ - var character = [anEvent charactersIgnoringModifiers]; - - if (![CPWindowActionMessageKeys containsObject:character]) - return NO; - - var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0]; - - if ([selectors count] <= 0) - return NO; - - if (character !== CPEscapeFunctionKey) - { - var selector = [selectors objectAtIndex:0]; - return [[self firstResponder] tryToPerform:selector with:self]; - } - else - { - // Cocoa sends complete: for the escape key (in stead of the default cancelOperation:) - // This is also the only action that is not sent directly to the first responder, but through doCommandBySelector. - // The difference is that doCommandBySelector: will also send the action to the window and application delegates. - [[self firstResponder] doCommandBySelector:@selector(complete:)]; - } - - return NO; -} - -- (void)_dirtyKeyViewLoop -{ - if (_autorecalculatesKeyViewLoop) - _keyViewLoopIsDirty = YES; -} - -- (BOOL)_hasKeyViewLoop -{ - var views = allViews(self), - index = [views count]; - - while (index--) - if ([views[index] nextKeyView]) - return YES; - - return NO; -} - -- (void)recalculateKeyViewLoop -{ - var views = allViews(self); - - [views sortUsingFunction:keyViewComparator context:nil]; - - for (var index = 0, count = [views count]; index < count; ++index) - [views[index] setNextKeyView:views[(index + 1) % count]]; - - _keyViewLoopIsDirty = NO; -} - -- (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate -{ - if (_autorecalculatesKeyViewLoop === shouldRecalculate) - return; - - _autorecalculatesKeyViewLoop = shouldRecalculate; - - if (_autorecalculatesKeyViewLoop) - [self _dirtyKeyViewLoop]; -} - -- (BOOL)autorecalculatesKeyViewLoop -{ - return _autorecalculatesKeyViewLoop; -} - -- (void)selectNextKeyView:(id)sender -{ - if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) - [self recalculateKeyViewLoop]; - - var nextValidKeyView = nil; - - if ([_firstResponder isKindOfClass:[CPView class]]) - nextValidKeyView = [_firstResponder nextValidKeyView]; - - if (!nextValidKeyView) - { - var initialFirstResponder = _initialFirstResponder; - - if ([initialFirstResponder acceptsFirstResponder]) - nextValidKeyView = initialFirstResponder; - else - nextValidKeyView = [initialFirstResponder nextValidKeyView]; - } - - [self makeFirstResponder:nextValidKeyView]; -} - -- (void)selectPreviousKeyView:(id)sender -{ - if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) - [self recalculateKeyViewLoop]; - - var previousValidKeyView = nil; - - if ([_firstResponder isKindOfClass:[CPView class]]) - previousValidKeyView = [_firstResponder previousValidKeyView]; - - if (!previousValidKeyView) - { - var initialFirstResponder = _initialFirstResponder; - - if ([initialFirstResponder acceptsFirstResponder]) - previousValidKeyView = initialFirstResponder; - else - previousValidKeyView = [initialFirstResponder previousValidKeyView]; - } - - [self makeFirstResponder:previousValidKeyView]; -} - -- (void)selectKeyViewFollowingView:(CPView)aView -{ - if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) - [self recalculateKeyViewLoop]; - - var nextValidKeyView = [aView nextValidKeyView]; - - if ([nextValidKeyView isKindOfClass:[CPView class]]) - [self makeFirstResponder:nextValidKeyView]; -} - -- (void)selectKeyViewPrecedingView:(CPView)aView -{ - if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) - [self recalculateKeyViewLoop]; - - var previousValidKeyView = [aView previousValidKeyView]; - - if ([previousValidKeyView isKindOfClass:[CPView class]]) - [self makeFirstResponder:previousValidKeyView]; -} - -/*! - Sets the default button for the window. - Note: this method is deprecated use setDefaultButton: instead. - @param aButton - The button that should become default. -*/ -- (void)setDefaultButtonCell:(CPButton)aButton -{ - [self setDefaultButton:aButton]; -} - -/*! - Returns the default button of the receiver. - NOTE: This method is deprecated. Use defaultButton instead. -*/ -- (CPButton)defaultButtonCell -{ - return [self defaultButton]; -} - -/*! - Sets the default button for the window. - This is equivalent to setting the the key equivalent of the button to "return". - Additionally this will turn your button blue (with the Aristo theme). - @param aButton - The button that should become default. -*/ -- (void)setDefaultButton:(CPButton)aButton -{ - if (_defaultButton === aButton) - return; - - if ([_defaultButton keyEquivalent] === CPCarriageReturnCharacter) - [_defaultButton setKeyEquivalent:nil]; - - _defaultButton = aButton; - - if ([_defaultButton keyEquivalent] !== CPCarriageReturnCharacter) - [_defaultButton setKeyEquivalent:CPCarriageReturnCharacter]; -} - -/*! - Returns the default button of the receiver. -*/ -- (CPButton)defaultButton -{ - return _defaultButton; -} - -/*! - Sets the default button key equivalent to "return". -*/ -- (void)enableKeyEquivalentForDefaultButton -{ - _defaultButtonEnabled = YES; -} - -/*! - Sets the default button key equivalent to "return". - NOTE: this method is deprecated. Use enableKeyEquivalentForDefaultButton instead. -*/ -- (void)enableKeyEquivalentForDefaultButtonCell -{ - [self enableKeyEquivalentForDefaultButton]; -} - -/*! - Removes the key equivalent for the default button. -*/ -- (void)disableKeyEquivalentForDefaultButton -{ - _defaultButtonEnabled = NO; -} - -/*! - Removes the key equivalent for the default button. - Note: this method is deprecated. Use disableKeyEquivalentForDefaultButton instead. -*/ -- (void)disableKeyEquivalentForDefaultButtonCell -{ - [self disableKeyEquivalentForDefaultButton]; -} - -@end - -var allViews = function(aWindow) -{ - var views = [CPArray arrayWithObject:[aWindow contentView]]; - - [views addObjectsFromArray:[[aWindow contentView] subviews]]; - - // Start from index 1 because index 0 is the contentView and its subviews have already been added - for (var index = 1; index < views.length; ++index) - views = views.concat([views[index] subviews]); - - return views; -}; - -var keyViewComparator = function(lhs, rhs, context) -{ - var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil], - rhsBounds = [rhs convertRect:[rhs bounds] toView:nil], - lhsY = _CGRectGetMinY(lhsBounds), - rhsY = _CGRectGetMinY(rhsBounds), - lhsX = _CGRectGetMinX(lhsBounds), - rhsX = _CGRectGetMinX(rhsBounds), - intersectsVertically = MIN(_CGRectGetMaxY(lhsBounds), _CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY); - - // If two views are "on the same line" (intersect vertically), then rely on the x comparison. - if (intersectsVertically > 0) - { - if (lhsX < rhsX) - return CPOrderedAscending; - - if (lhsX === rhsX) - return CPOrderedSame; - - return CPOrderedDescending; - } - - if (lhsY < rhsY) - return CPOrderedAscending; - - if (lhsY === rhsY) - return CPOrderedSame; - - return CPOrderedDescending; -}; - -@implementation CPWindow (MenuBar) - -- (void)_synchronizeMenuBarTitleWithWindowTitle -{ - // Windows with Documents automatically update the native window title and the menu bar title. - if (![_windowController document] || ![self isMainWindow]) - return; - - [CPMenu setMenuBarTitle:_title]; -} - -@end - -@implementation CPWindow (BridgeSupport) - -/* - @ignore -*/ -- (void)resizeWithOldPlatformWindowSize:(CGSize)aSize -{ - if ([self isFullPlatformWindow]) - return [self setFrame:[_platformWindow visibleFrame]]; - - if (_autoresizingMask == CPWindowNotSizable) - return; - - var frame = [_platformWindow contentBounds], - newFrame = CGRectMakeCopy(_frame), - dX = (CGRectGetWidth(frame) - aSize.width) / - (((_autoresizingMask & CPWindowMinXMargin) ? 1 : 0) + (_autoresizingMask & CPWindowWidthSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxXMargin ? 1 : 0)), - dY = (CGRectGetHeight(frame) - aSize.height) / - ((_autoresizingMask & CPWindowMinYMargin ? 1 : 0) + (_autoresizingMask & CPWindowHeightSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxYMargin ? 1 : 0)); - - if (_autoresizingMask & CPWindowMinXMargin) - newFrame.origin.x += dX; - if (_autoresizingMask & CPWindowWidthSizable) - newFrame.size.width += dX; - - if (_autoresizingMask & CPWindowMinYMargin) - newFrame.origin.y += dY; - if (_autoresizingMask & CPWindowHeightSizable) - newFrame.size.height += dY; - - [self setFrame:newFrame]; -} - -/* - @ignore -*/ -- (void)setAutoresizingMask:(unsigned)anAutoresizingMask -{ - _autoresizingMask = anAutoresizingMask; -} - -/* - @ignore -*/ -- (unsigned)autoresizingMask -{ - return _autoresizingMask; -} - -/*! - Converts aPoint from the window coordinate system to the global coordinate system. -*/ -- (CGPoint)convertBaseToGlobal:(CGPoint)aPoint -{ - return [CPPlatform isBrowser] ? [self convertBaseToPlatformWindow:aPoint] : [self convertBaseToScreen:aPoint]; -} - -/*! - Converts aPoint from the global coordinate system to the window coordinate system. -*/ -- (CGPoint)convertGlobalToBase:(CGPoint)aPoint -{ - return [CPPlatform isBrowser] ? [self convertPlatformWindowToBase:aPoint] : [self convertScreenToBase:aPoint]; -} - -/*! - Converts aPoint from the window coordinate system to the coordinate system of the parent platform window. -*/ -- (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint -{ - if ([self _sharesChromeWithPlatformWindow]) - return _CGPointMakeCopy(aPoint); - - var origin = [self frame].origin; - - return _CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y); -} - -/*! - Converts aPoint from the parent platform window coordinate system to the window's coordinate system. -*/ -- (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint -{ - if ([self _sharesChromeWithPlatformWindow]) - return _CGPointMakeCopy(aPoint); - - var origin = [self frame].origin; - - return _CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y); -} - -- (CGPoint)convertScreenToBase:(CGPoint)aPoint -{ - return [self convertPlatformWindowToBase:[_platformWindow convertScreenToBase:aPoint]]; -} - -- (CGPoint)convertBaseToScreen:(CGPoint)aPoint -{ - return [_platformWindow convertBaseToScreen:[self convertBaseToPlatformWindow:aPoint]]; -} - -- (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow -{ - // We canna' do it captain! We just don't have the power! - if (shouldShareFrameWithPlatformWindow && [CPPlatform isBrowser]) - return; - - _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow; - - [self _updateShadow]; -} - -- (BOOL)_sharesChromeWithPlatformWindow -{ - return _sharesChromeWithPlatformWindow; -} - -// Undo and Redo Support -/*! - Returns the window's undo manager. -*/ -- (CPUndoManager)undoManager -{ - // If we've ever created an undo manager, return it. - if (_undoManager) - return _undoManager; - - // If not, check to see if the document has one. - var documentUndoManager = [[_windowController document] undoManager]; - - if (documentUndoManager) - return documentUndoManager; - - // If not, check to see if the delegate has one. - if (_delegateRespondsToWindowWillReturnUndoManagerSelector) - return [_delegate windowWillReturnUndoManager:self]; - - // If not, create one. - if (!_undoManager) - _undoManager = [[CPUndoManager alloc] init]; - - return _undoManager; -} - -/*! - Sends the undo manager an \c -undo: message. - @param aSender the object requesting this -*/ -- (void)undo:(id)aSender -{ - [[self undoManager] undo]; -} - -/*! - Sends the undo manager a \c -redo: message. - @param aSender the object requesting this -*/ -- (void)redo:(id)aSender -{ - [[self undoManager] redo]; -} - -- (BOOL)containsPoint:(CGPoint)aPoint -{ - return CGRectContainsPoint(_frame, aPoint); -} - -@end - -@implementation CPWindow (Deprecated) -/*! - Sets the CPWindow to fill the whole browser window. - NOTE: this method has been deprecated in favor of setFullPlatformWindow: -*/ -- (void)setFullBridge:(BOOL)shouldBeFullBridge -{ - [self setFullPlatformWindow:shouldBeFullBridge]; -} - -/*! - Returns YES if the window fills the full browser window, otherwise NO. - NOTE: this method has been deprecated in favor of isFullPlatformWindow. -*/ -- (BOOL)isFullBridge -{ - return [self isFullPlatformWindow]; -} - -/* - @ignore -*/ -- (CGPoint)convertBaseToBridge:(CGPoint)aPoint -{ - return [self convertBaseToPlatformWindow:aPoint]; -} - -/* - @ignore -*/ -- (CGPoint)convertBridgeToBase:(CGPoint)aPoint -{ - return [self convertPlatformWindowToBase:aPoint]; -} - -@end - -var interpolate = function(fromValue, toValue, progress) -{ - return fromValue + (toValue - fromValue) * progress; -}; - -/* @ignore */ -@implementation _CPWindowFrameAnimation : CPAnimation -{ - CPWindow _window; - - CGRect _startFrame; - CGRect _targetFrame; -} - -- (id)initWithWindow:(CPWindow)aWindow targetFrame:(CGRect)aTargetFrame -{ - self = [super initWithDuration:[aWindow animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear]; - - if (self) - { - _window = aWindow; - - _targetFrame = CGRectMakeCopy(aTargetFrame); - _startFrame = CGRectMakeCopy([_window frame]); - } - - return self; -} - -- (void)startAnimation -{ - [super startAnimation]; - - _window._isAnimating = YES; -} - -- (void)setCurrentProgress:(float)aProgress -{ - [super setCurrentProgress:aProgress]; - - var value = [self currentValue]; - - if (value == 1.0) - _window._isAnimating = NO; - - var newFrame = CGRectMake(interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value), - interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value), - interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value), - interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value)); - - [_window setFrame:newFrame display:YES animate:NO]; -} - -@end - -function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel) -{ - return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel }; -} - -CPStandardWindowShadowStyle = 0; -CPMenuWindowShadowStyle = 1; -CPPanelWindowShadowStyle = 2; -CPCustomWindowShadowStyle = 3; - - -/*@import "_CPWindowView.j" +@import "_CPWindow.j" +@import "_CPWindowView.j" @import "_CPStandardWindowView.j" @import "_CPDocModalWindowView.j" @import "_CPToolTipWindowView.j" @@ -3346,4 +30,4 @@ CPCustomWindowShadowStyle = 3; @import "_CPBorderlessBridgeWindowView.j" @import "_CPAttachedWindowView.j" @import "CPDragServer.j" -@import "CPView.j"*/ +//@import "CPView.j" diff --git a/AppKit/CPWindow/_CPWindow.j b/AppKit/CPWindow/_CPWindow.j new file mode 100644 index 000000000..98f3441de --- /dev/null +++ b/AppKit/CPWindow/_CPWindow.j @@ -0,0 +1,3349 @@ +/* + * CPWindow.j + * AppKit + * + * Created by Francisco Tolmasky. + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import +@import +@import + +@import "CGGeometry.j" +@import "CPAnimation.j" +@import "CPPlatformWindow.j" +@import "CPResponder.j" +@import "CPScreen.j" +#if PLATFORM(BROWSER) +@import "CPPlatformWindow+DOM.j" +#endif + + +/* + Borderless window mask option. + @global + @class CPWindow +*/ +CPBorderlessWindowMask = 0; +/* + Titled window mask option. + @global + @class CPWindow +*/ +CPTitledWindowMask = 1 << 0; +/* + Closeable window mask option. + @global + @class CPWindow +*/ +CPClosableWindowMask = 1 << 1; +/* + Miniaturizabe window mask option. + @global + @class CPWindow +*/ +CPMiniaturizableWindowMask = 1 << 2; +/* + Resizable window mask option. + @global + @class CPWindow +*/ +CPResizableWindowMask = 1 << 3; +/* + Textured window mask option. + @global + @class CPWindow +*/ +CPTexturedBackgroundWindowMask = 1 << 8; +/* + @global + @class CPWindow +*/ +CPBorderlessBridgeWindowMask = 1 << 20; +/* + @global + @class CPWindow +*/ +CPHUDBackgroundWindowMask = 1 << 21; + +CPWindowNotSizable = 0; +CPWindowMinXMargin = 1; +CPWindowWidthSizable = 2; +CPWindowMaxXMargin = 4; +CPWindowMinYMargin = 8; +CPWindowHeightSizable = 16; +CPWindowMaxYMargin = 32; + +CPBackgroundWindowLevel = -1; +/* + Default level for windows + @group CPWindowLevel + @global +*/ +CPNormalWindowLevel = 0; +/* + Floating palette type window + @group CPWindowLevel + @global +*/ +CPFloatingWindowLevel = 3; +/* + Submenu type window + @group CPWindowLevel + @global +*/ +CPSubmenuWindowLevel = 3; +/* + For a torn-off menu + @group CPWindowLevel + @global +*/ +CPTornOffMenuWindowLevel = 3; +/* + For the application's main menu + @group CPWindowLevel + @global +*/ +CPMainMenuWindowLevel = 24; +/* + Status window level + @group CPWindowLevel + @global +*/ +CPStatusWindowLevel = 25; +/* + Level for a modal panel + @group CPWindowLevel + @global +*/ +CPModalPanelWindowLevel = 8; +/* + Level for a pop up menu + @group CPWindowLevel + @global +*/ +CPPopUpMenuWindowLevel = 101; +/* + Level for a window being dragged + @group CPWindowLevel + @global +*/ +CPDraggingWindowLevel = 500; +/* + Level for the screens saver + @group CPWindowLevel + @global +*/ +CPScreenSaverWindowLevel = 1000; + +/* + The receiver is removed from the screen list and hidden. + @global + @class CPWindowOrderingMode +*/ +CPWindowOut = 0; +/* + The receiver is placed directly in front of the window specified. + @global + @class CPWindowOrderingMode +*/ +CPWindowAbove = 1; +/* + The receiver is placed directly behind the window specified. + @global + @class CPWindowOrderingMode +*/ +CPWindowBelow = 2; + +CPWindowWillCloseNotification = @"CPWindowWillCloseNotification"; +CPWindowDidBecomeMainNotification = @"CPWindowDidBecomeMainNotification"; +CPWindowDidResignMainNotification = @"CPWindowDidResignMainNotification"; +CPWindowDidBecomeKeyNotification = @"CPWindowDidBecomeKeyNotification"; +CPWindowDidResignKeyNotification = @"CPWindowDidResignKeyNotification"; +CPWindowDidResizeNotification = @"CPWindowDidResizeNotification"; +CPWindowDidMoveNotification = @"CPWindowDidMoveNotification"; +CPWindowWillBeginSheetNotification = @"CPWindowWillBeginSheetNotification"; +CPWindowDidEndSheetNotification = @"CPWindowDidEndSheetNotification"; +CPWindowDidMiniaturizeNotification = @"CPWindowDidMiniaturizeNotification"; +CPWindowWillMiniaturizeNotification = @"CPWindowWillMiniaturizeNotification"; +CPWindowDidDeminiaturizeNotification = @"CPWindowDidDeminiaturizeNotification"; + +_CPWindowDidChangeFirstResponderNotification = @"_CPWindowDidChangeFirstResponderNotification"; + +CPWindowShadowStyleStandard = 0; +CPWindowShadowStyleMenu = 1; +CPWindowShadowStylePanel = 2; + +var SHADOW_MARGIN_LEFT = 20.0, + SHADOW_MARGIN_RIGHT = 19.0, + SHADOW_MARGIN_TOP = 10.0, + SHADOW_MARGIN_BOTTOM = 10.0, + SHADOW_DISTANCE = 5.0, + + _CPWindowShadowColor = nil; + +var CPWindowSaveImage = nil, + CPWindowSavingImage = nil, + + CPWindowResizeTime = 0.2; + +/* + Keys for which action messages will be sent by default when unhandled, e.g. complete:. +*/ +var CPWindowActionMessageKeys = [ + CPLeftArrowFunctionKey, + CPRightArrowFunctionKey, + CPUpArrowFunctionKey, + CPDownArrowFunctionKey, + CPPageUpFunctionKey, + CPPageDownFunctionKey, + CPHomeFunctionKey, + CPEndFunctionKey, + CPEscapeFunctionKey + ]; + +/*! + @ingroup appkit + @class CPWindow + + An CPWindow instance represents a window, panel or menu on the screen.

+ +

Each window has a style, which determines how the window is decorated; whether it has a border, a title bar, a resize bar, minimise and close buttons.

+ +

A window has a frame. This is the frame of the entire window on the screen, including all decorations and borders. The origin of the frame represents its bottom left corner and the frame is expressed in screen coordinates.

+ +

A window always contains a content view which is the highest level view available for public (application) use. This view fills the area of the window inside any decoration/border. This is the only part of the window that application programmers are allowed to draw in directly.

+ +

You can convert between view coordinates and window base coordinates using the [CPView -convertPoint:fromView:], [CPView -convertPoint:toView:], [CPView -convertRect:fromView:], and [CPView -convertRect:toView:] methods with a nil view argument. + + @par Delegate Methods + + @delegate -(void)windowDidResize:(CPNotification)notification; + Sent from the notification center when the window has been resized. + @param notification contains information about the resize event + + @delegate -(CPUndoManager)windowWillReturnUndoManager:(CPWindow)window; + Called to obtain the undo manager for a window + @param window the window for which to return the undo manager + @return the window's undo manager + + @delegate -(void)windowDidBecomeMain:(CPNotification)notification; + Sent from the notification center when the delegate's window becomes + the main window. + @param notification contains information about the event + + @delegate -(void)windowDidResignMain:(CPNotification)notification; + Sent from the notification center when the delegate's window has + resigned main window status. + @param notification contains information about the event + + @delegate -(void)windowDidResignKey:(CPNotification)notification; + Sent from the notification center when the delegate's window has + resigned key window status. + @param notification contains information about the event + + @delegate -(BOOL)windowShouldClose:(id)window; + Called when the user tries to close the window. + @param window the window to close + @return \c YES allows the window to close. \c NO + vetoes the close operation and leaves the window open. + + @delegate -(BOOL)windowWillBeginSheet:(CPNotification)notification; + Sent from the notification center before sheet is visible on + the delegate's window. + @param notification contains information about the event + + @delegate -(BOOL)windowDidEndSheet:(CPNotification)notification; + Sent from the notification center when an attached sheet on the + delegate's window has been animated out and is no longer visible. + @param notification contains information about the event +*/ +@implementation CPWindow : CPResponder +{ + CPPlatformWindow _platformWindow; + + int _windowNumber; + unsigned _styleMask; + CGRect _frame; + int _level; + BOOL _isVisible; + BOOL _isMiniaturized; + BOOL _isAnimating; + BOOL _hasShadow; + BOOL _isMovableByWindowBackground; + BOOL _isMovable; + unsigned _shadowStyle; + BOOL _showsResizeIndicator; + + int _positioningMask; + CGRect _positioningScreenRect; + + BOOL _isDocumentEdited; + BOOL _isDocumentSaving; + + CPImageView _shadowView; + + CPView _windowView; + CPView _contentView; + CPView _toolbarView; + + CPArray _mouseEnteredStack; + CPView _leftMouseDownView; + CPView _rightMouseDownView; + + CPToolbar _toolbar; + CPResponder _firstResponder; + CPResponder _initialFirstResponder; + id _delegate; + + CPString _title; + + BOOL _acceptsMouseMovedEvents; + BOOL _ignoresMouseEvents; + + CPWindowController _windowController; + + CGSize _minSize; + CGSize _maxSize; + + CPUndoManager _undoManager; + CPURL _representedURL; + + CPSet _registeredDraggedTypes; + CPArray _registeredDraggedTypesArray; + CPCountedSet _inclusiveRegisteredDraggedTypes; + + CPButton _defaultButton; + BOOL _defaultButtonEnabled; + + BOOL _autorecalculatesKeyViewLoop; + BOOL _keyViewLoopIsDirty; + + BOOL _sharesChromeWithPlatformWindow; + + // Bridge Support +#if PLATFORM(DOM) + DOMElement _DOMElement; +#endif + + unsigned _autoresizingMask; + + BOOL _delegateRespondsToWindowWillReturnUndoManagerSelector; + + BOOL _isFullPlatformWindow; + _CPWindowFullPlatformWindowSession _fullPlatformWindowSession; + + CPDictionary _sheetContext; + CPWindow _parentView; + BOOL _isSheet; + _CPWindowFrameAnimation _frameAnimation; +} + +/* + Private initializer for Objective-J + @ignore +*/ ++ (void)initialize +{ + if (self !== [CPWindow class]) + return; + + var bundle = [CPBundle bundleForClass:[CPWindow class]]; + + CPWindowSavingImage = [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPProgressIndicator/CPProgressIndicatorSpinningStyleRegular.gif"] size:CGSizeMake(16.0, 16.0)] +} + +- (id)init +{ + return [self initWithContentRect:_CGRectMakeZero() styleMask:CPTitledWindowMask]; +} + +/*! + Initializes the window. The method also takes a style bit mask made up + of any of the following values: +

+CPBorderlessWindowMask
+CPTitledWindowMask
+CPClosableWindowMask
+CPMiniaturizableWindowMask
+CPResizableWindowMask
+CPTexturedBackgroundWindowMask
+
+ @param aContentRect the size and location of the window in screen space + @param aStyleMask a style mask + @return the initialized window +*/ +- (id)initWithContentRect:(CGRect)aContentRect styleMask:(unsigned int)aStyleMask +{ + self = [super init]; + + if (self) + { + var windowViewClass = [[self class] _windowViewClassForStyleMask:aStyleMask]; + + _frame = [windowViewClass frameRectForContentRect:aContentRect]; + + [self _setSharesChromeWithPlatformWindow:![CPPlatform isBrowser]]; + + if ([CPPlatform isBrowser]) + [self setPlatformWindow:[CPPlatformWindow primaryPlatformWindow]]; + else + { + // give zero sized borderless bridge windows a default size if we're not in the browser so they show up in NativeHost. + if ((aStyleMask & CPBorderlessBridgeWindowMask) && aContentRect.size.width === 0 && aContentRect.size.height === 0) + { + var visibleFrame = [[[CPScreen alloc] init] visibleFrame]; + _frame.size.height = MIN(768.0, visibleFrame.size.height); + _frame.size.width = MIN(1024.0, visibleFrame.size.width); + _frame.origin.x = (visibleFrame.size.width - _frame.size.width) / 2; + _frame.origin.y = (visibleFrame.size.height - _frame.size.height) / 2; + } + [self setPlatformWindow:[[CPPlatformWindow alloc] initWithContentRect:_frame]]; + [self platformWindow]._only = self; + } + + _isFullPlatformWindow = NO; + _registeredDraggedTypes = [CPSet set]; + _registeredDraggedTypesArray = []; + _acceptsMouseMovedEvents = YES; + _isMovable = YES; + + _isSheet = NO; + _sheetContext = nil; + _parentView = nil; + + // Set up our window number. + _windowNumber = [CPApp._windows count]; + CPApp._windows[_windowNumber] = self; + + _styleMask = aStyleMask; + + [self setLevel:CPNormalWindowLevel]; + + _minSize = CGSizeMake(0.0, 0.0); + _maxSize = CGSizeMake(1000000.0, 1000000.0); + + // Create our border view which is the actual root of our view hierarchy. + _windowView = [[windowViewClass alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)) styleMask:aStyleMask]; + + [_windowView _setWindow:self]; + [_windowView setNextResponder:self]; + + [self setMovableByWindowBackground:aStyleMask & CPHUDBackgroundWindowMask]; + + // Create a generic content view. + [self setContentView:[[CPView alloc] initWithFrame:CGRectMakeZero()]]; + [self setInitialFirstResponder:[self contentView]]; + + _firstResponder = self; + +#if PLATFORM(DOM) + _DOMElement = document.createElement("div"); + + _DOMElement.style.position = "absolute"; + _DOMElement.style.visibility = "visible"; + _DOMElement.style.zIndex = 0; + + if (![self _sharesChromeWithPlatformWindow]) + { + CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, _CGRectGetMinX(_frame), _CGRectGetMinY(_frame)); + } + + CPDOMDisplayServerSetStyleSize(_DOMElement, 1, 1); + CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement); +#endif + + [self setNextResponder:CPApp]; + + [self setHasShadow:aStyleMask !== CPBorderlessWindowMask]; + + if (aStyleMask & CPBorderlessBridgeWindowMask) + [self setFullPlatformWindow:YES]; + + _autorecalculatesKeyViewLoop = NO; + _defaultButtonEnabled = YES; + _keyViewLoopIsDirty = YES; + + [self setShowsResizeIndicator:_styleMask & CPResizableWindowMask]; + } + + return self; +} + +- (CPPlatformWindow)platformWindow +{ + return _platformWindow; +} + +/*! + Sets the platform window of the reciver. + This method will first close the reciever, + change the platform window, then reopen the window (if it was originally open). +*/ +- (void)setPlatformWindow:(CPPlatformWindow)aPlatformWindow +{ + var wasVisible = [self isVisible]; + + // we have to close it first, otherwise we get a DOM exception. + if (wasVisible) + [self close]; + + _platformWindow = aPlatformWindow; + [_platformWindow _setTitle:_title window:self]; + + if (wasVisible) + [self orderFront:self]; +} + + +/*! + @ignore +*/ ++ (Class)_windowViewClassForStyleMask:(unsigned)aStyleMask +{ + if (aStyleMask & CPHUDBackgroundWindowMask) + return _CPHUDWindowView; + + else if (aStyleMask === CPBorderlessWindowMask) + return _CPBorderlessWindowView; + + else if (aStyleMask & CPDocModalWindowMask) + return _CPDocModalWindowView; + + return _CPStandardWindowView; +} + ++ (Class)_windowViewClassForFullPlatformWindowStyleMask:(unsigned)aStyleMask +{ + return _CPBorderlessBridgeWindowView; +} + +- (void)awakeFromCib +{ + _keyViewLoopIsDirty = ![self _hasKeyViewLoop]; + + // If no key view loop has been specified by hand, and we are not intending to auto recalculate, + // set up a default key view loop. + if (_keyViewLoopIsDirty && ![self autorecalculatesKeyViewLoop]) + [self recalculateKeyViewLoop]; + + // At this time we know the final screen (or browser) size and can apply the positioning mask, if any, from the nib. + if (_positioningScreenRect) + { + var actualScreenRect = [CPPlatform isBrowser] ? [_platformWindow contentBounds] : [[self screen] visibleFrame], + frame = [self frame], + origin = frame.origin; + + if (actualScreenRect) + { + if ((_positioningMask & CPWindowPositionFlexibleLeft) && (_positioningMask & CPWindowPositionFlexibleRight)) + { + // Proportional Horizontal. + origin.x *= (actualScreenRect.size.width / _positioningScreenRect.size.width); + } + else if (_positioningMask & CPWindowPositionFlexibleLeft) + { + // Fixed from Right + origin.x += actualScreenRect.size.width - _positioningScreenRect.size.width; + } + else if (_positioningMask & CPWindowPositionFlexibleRight) + { + // Fixed from Left + } + + if ((_positioningMask & CPWindowPositionFlexibleTop) && (_positioningMask & CPWindowPositionFlexibleBottom)) + { + // Proportional Vertical. + origin.y *= (actualScreenRect.size.height / _positioningScreenRect.size.height); + } + else if (_positioningMask & CPWindowPositionFlexibleTop) + { + // Fixed from Bottom + origin.y += actualScreenRect.size.height - _positioningScreenRect.size.height; + } + else if (_positioningMask & CPWindowPositionFlexibleBottom) + { + // Fixed from Top + } + + [self setFrameOrigin:origin]; + } + } +} + +- (void)_setWindowView:(CPView)aWindowView +{ + if (_windowView === aWindowView) + return; + + var oldWindowView = _windowView; + + _windowView = aWindowView; + + if (oldWindowView) + { + [oldWindowView _setWindow:nil]; + [oldWindowView noteToolbarChanged]; + +#if PLATFORM(DOM) + CPDOMDisplayServerRemoveChild(_DOMElement, oldWindowView._DOMElement); +#endif + } + + if (_windowView) + { +#if PLATFORM(DOM) + CPDOMDisplayServerAppendChild(_DOMElement, _windowView._DOMElement); +#endif + + var contentRect = [_contentView convertRect:[_contentView bounds] toView:nil]; + + contentRect.origin = [self convertBaseToGlobal:contentRect.origin]; + + [_windowView _setWindow:self]; + [_windowView setNextResponder:self]; + [_windowView addSubview:_contentView]; + [_windowView setTitle:_title]; + [_windowView noteToolbarChanged]; + [_windowView setShowsResizeIndicator:[self showsResizeIndicator]]; + + [self setFrame:[self frameRectForContentRect:contentRect]]; + } +} + +/*! + Sets the receiver as a full platform window. If you pass YES the CPWindow instance will fill the entire browser content area, + otherwise the CPWindow will be a window inside of your browser window which the user can drag around, and resize (if you allow). + + @param BOOL - YES if the window should fill the browser window, otherwise NO. +*/ +- (void)setFullPlatformWindow:(BOOL)shouldBeFullPlatformWindow +{ + if (![_platformWindow supportsFullPlatformWindows]) + return; + + shouldBeFullPlatformWindow = !!shouldBeFullPlatformWindow; + + if (_isFullPlatformWindow === shouldBeFullPlatformWindow) + return; + + _isFullPlatformWindow = shouldBeFullPlatformWindow; + + if (_isFullPlatformWindow) + { + _fullPlatformWindowSession = _CPWindowFullPlatformWindowSessionMake(_windowView, [self contentRectForFrameRect:[self frame]], [self hasShadow], [self level]); + + var fullPlatformWindowViewClass = [[self class] _windowViewClassForFullPlatformWindowStyleMask:_styleMask], + windowView = [[fullPlatformWindowViewClass alloc] initWithFrame:CGRectMakeZero() styleMask:_styleMask]; + + [self _setWindowView:windowView]; + + [self setLevel:CPBackgroundWindowLevel]; + [self setHasShadow:NO]; + [self setAutoresizingMask:CPWindowWidthSizable | CPWindowHeightSizable]; + [self setFrame:[_platformWindow visibleFrame]]; + } + else + { + var windowView = _fullPlatformWindowSession.windowView; + + [self _setWindowView:windowView]; + + [self setLevel:_fullPlatformWindowSession.level]; + [self setHasShadow:_fullPlatformWindowSession.hasShadow]; + [self setAutoresizingMask:CPWindowNotSizable]; + + [self setFrame:[windowView frameRectForContentRect:_fullPlatformWindowSession.contentRect]]; + } +} + +/*! + @return BOOL - YES if the CPWindow fills the browser window, otherwise NO. +*/ +- (BOOL)isFullPlatformWindow +{ + return _isFullPlatformWindow; +} + +/*! + Returns the window's style mask. +*/ +- (unsigned)styleMask +{ + return _styleMask; +} + +/*! + Returns the frame rectangle used by a window. + Style masks include: +
+    CPBorderlessWindowMask
+    CPTitledWindowMask
+    CPClosableWindowMask
+    CPMiniaturizableWindowMask (NOTE: only available in NativeHost)
+    CPResizableWindowMask
+    CPTexturedBackgroundWindowMask
+    CPBorderlessBridgeWindowMask
+    CPHUDBackgroundWindowMask
+    
+ + @param aContentRect the content rectangle of the window + @param aStyleMask the style mask of the window + @return the matching window's frame rectangle +*/ ++ (CGRect)frameRectForContentRect:(CGRect)aContentRect styleMask:(unsigned)aStyleMask +{ + return [[[self class] _windowViewClassForStyleMask:aStyleMask] frameRectForContentRect:aContentRect]; +} + +/*! + Returns the receiver's content rectangle. A content rectangle does not include toolbars. + @param aFrame the window's frame rectangle +*/ +- (CGRect)contentRectForFrameRect:(CGRect)aFrame +{ + return [_windowView contentRectForFrameRect:aFrame]; +} + +/*! + Retrieves the frame rectangle for this window. + @param aContentRect the window's content rectangle + @return the window's frame rectangle +*/ +- (CGRect)frameRectForContentRect:(CGRect)aContentRect +{ + return [_windowView frameRectForContentRect:aContentRect]; +} + +/*! + Returns the window's frame rectangle +*/ +- (CGRect)frame +{ + return _CGRectMakeCopy(_frame); +} + +/*! + Sets the window's frame rectangle. Also tells the window whether it should animate + the resize operation, and redraw itself if necessary. + @param aFrame the new size and location for the window + @param shouldDisplay whether the window should redraw its views + @param shouldAnimate whether the window resize should be animated. +*/ +- (void)_setClippedFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate +{ + aFrame.size.width = MIN(MAX(aFrame.size.width, _minSize.width), _maxSize.width) + aFrame.size.height = MIN(MAX(aFrame.size.height, _minSize.height), _maxSize.height); + [self setFrame:aFrame display:shouldDisplay animate:shouldAnimate]; +} + +/*! + Sets the frame of the window. + + @param aFrame - A CGRect of the new frame for the receiver. + @param shouldDisplay - YES if the window should call setNeedsDisplay otherwise NO. + @param shouldAnimate - YES if the window should animate to it's new size and position, otherwise NO. +*/ +- (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay animate:(BOOL)shouldAnimate +{ + aFrame = _CGRectMakeCopy(aFrame); + + var value = aFrame.origin.x, + delta = value - FLOOR(value); + + if (delta) + aFrame.origin.x = value > 0.879 ? CEIL(value) : FLOOR(value); + + value = aFrame.origin.y; + delta = value - FLOOR(value); + + if (delta) + aFrame.origin.y = value > 0.879 ? CEIL(value) : FLOOR(value); + + value = aFrame.size.width; + delta = value - FLOOR(value); + + if (delta) + aFrame.size.width = value > 0.15 ? CEIL(value) : FLOOR(value); + + value = aFrame.size.height; + delta = value - FLOOR(value); + + if (delta) + aFrame.size.height = value > 0.15 ? CEIL(value) : FLOOR(value); + + if (shouldAnimate) + { + [_frameAnimation stopAnimation]; + _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + + [_frameAnimation startAnimation]; + } + else + { + var origin = _frame.origin, + newOrigin = aFrame.origin; + + if (!_CGPointEqualToPoint(origin, newOrigin)) + { + origin.x = newOrigin.x; + origin.y = newOrigin.y; + +#if PLATFORM(DOM) + if (![self _sharesChromeWithPlatformWindow]) + { + CPDOMDisplayServerSetStyleLeftTop(_DOMElement, NULL, origin.x, origin.y); + } +#endif + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMoveNotification object:self]; + } + + var size = _frame.size, + newSize = aFrame.size; + + if (!_CGSizeEqualToSize(size, newSize)) + { + size.width = newSize.width; + size.height = newSize.height; + + [_windowView setFrameSize:size]; + + if (_hasShadow) + { + // if the shadow would be taller/wider than the window height, + // make it the same as the window height. this allows views to + // become 0, 0 with no shadow on them and makes the sheet + // animation look nicer + var shadowSize = _CGSizeMake(size.width, size.height); + + if (size.width >= (SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT)) + shadowSize.width += SHADOW_MARGIN_LEFT + SHADOW_MARGIN_RIGHT; + + if (size.height >= (SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE)) + shadowSize.height += SHADOW_MARGIN_BOTTOM + SHADOW_MARGIN_TOP + SHADOW_DISTANCE; + + [_shadowView setFrameSize:shadowSize]; + } + + if (!_isAnimating) + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidResizeNotification object:self]; + } + + if ([self _sharesChromeWithPlatformWindow]) + [_platformWindow setContentRect:_frame]; + } +} + +/*! + Sets the window's frame rect. + @param aFrame - The new CGRect of the window. + @param shouldDisplay - YES if the window should call setNeedsDisplay: otherwise NO. +*/ +- (void)setFrame:(CGRect)aFrame display:(BOOL)shouldDisplay +{ + [self _setClippedFrame:aFrame display:shouldDisplay animate:NO]; +} + +/*! + Sets the window's frame rectangle + @param aFrame - The CGRect of the windows new frame +*/ +- (void)setFrame:(CGRect)aFrame +{ + [self _setClippedFrame:aFrame display:YES animate:NO]; +} + +/*! + Sets the window's location. + @param anOrigin the new location for the window +*/ +- (void)setFrameOrigin:(CGPoint)anOrigin +{ + [self _setClippedFrame:_CGRectMake(anOrigin.x, anOrigin.y, _CGRectGetWidth(_frame), _CGRectGetHeight(_frame)) display:YES animate:NO]; + + // reposition sheet + if ([self attachedSheet]) + [self _setAttachedSheetFrameOrigin]; +} + +/*! + Sets the window's size. + @param aSize the new size for the window +*/ +- (void)setFrameSize:(CGSize)aSize +{ + [self _setClippedFrame:_CGRectMake(_CGRectGetMinX(_frame), _CGRectGetMinY(_frame), aSize.width, aSize.height) display:YES animate:NO]; +} + +/*! + Makes the receiver the front most window in the screen ordering. + @param aSender the object that requested this +*/ +- (void)orderFront:(id)aSender +{ +#if PLATFORM(DOM) + // -dw- if a sheet is clicked, the parent window should come up too + if ([self isSheet]) + [_parentView orderFront:self]; + + [_platformWindow orderFront:self]; + [_platformWindow order:CPWindowAbove window:self relativeTo:nil]; +#endif + + if (!CPApp._keyWindow) + [self makeKeyWindow]; + + if ([self isKeyWindow] && (_firstResponder === self || !_firstResponder)) + [self makeFirstResponder:_initialFirstResponder]; + + if (!CPApp._mainWindow) + [self makeMainWindow]; +} + +/* + Makes the receiver the last window in the screen ordering. + @param aSender the object that requested this + @ignore +*/ +- (void)orderBack:(id)aSender +{ + //[_platformWindow order:CPWindowBelow +} + +/*! + Hides the window. + @param the object that requested this +*/ +- (void)orderOut:(id)aSender +{ + if ([self isSheet]) + { + // -dw- as in Cocoa, orderOut: detaches the sheet and animates out + [self._parentView _detachSheetWindow]; + return; + } + +#if PLATFORM(DOM) + if ([self _sharesChromeWithPlatformWindow]) + [_platformWindow orderOut:self]; +#endif + + if ([_delegate respondsToSelector:@selector(windowWillClose:)]) + [_delegate windowWillClose:self]; + +#if PLATFORM(DOM) + [_platformWindow order:CPWindowOut window:self relativeTo:nil]; +#endif + + [self _updateMainAndKeyWindows]; +} + +/*! + Relocates the window in the screen list. + @param aPlace the positioning relative to \c otherWindowNumber + @param otherWindowNumber the window relative to which the receiver should be placed +*/ +- (void)orderWindow:(CPWindowOrderingMode)aPlace relativeTo:(int)otherWindowNumber +{ +#if PLATFORM(DOM) + [_platformWindow order:aPlace window:self relativeTo:CPApp._windows[otherWindowNumber]]; +#endif +} + +/*! + Sets the window's level + @param the window's new level +*/ +- (void)setLevel:(int)aLevel +{ + if (aLevel === _level) + return; + + [_platformWindow moveWindow:self fromLevel:_level toLevel:aLevel]; + + _level = aLevel; + + if ([self _sharesChromeWithPlatformWindow]) + [_platformWindow setLevel:aLevel]; +} + +/*! + Returns the window's current level +*/ +- (int)level +{ + return _level; +} + +/*! + Returns \c YES if the window is visible. It does not mean that the window is not obscured by other windows. +*/ +- (BOOL)isVisible +{ + return _isVisible; +} + +/*! + Returns \c YES if the window's resize indicator is showing. \c NO otherwise. +*/ +- (BOOL)showsResizeIndicator +{ + return _showsResizeIndicator; +} + +/*! + Sets the window's resize indicator. + @param shouldShowResizeIndicator \c YES sets the window to show its resize indicator. +*/ +- (void)setShowsResizeIndicator:(BOOL)shouldShowResizeIndicator +{ + shouldShowResizeIndicator = !!shouldShowResizeIndicator; + + if (_showsResizeIndicator === shouldShowResizeIndicator) + return; + + _showsResizeIndicator = shouldShowResizeIndicator; + [_windowView setShowsResizeIndicator:[self showsResizeIndicator]]; +} + +/*! + Returns the offset of the window's resize indicator. +*/ +- (CGSize)resizeIndicatorOffset +{ + return [_windowView resizeIndicatorOffset]; +} + +/*! + Sets the offset of the window's resize indicator. + @param aSize the offset for the resize indicator +*/ +- (void)setResizeIndicatorOffset:(CGSize)anOffset +{ + [_windowView setResizeIndicatorOffset:anOffset]; +} + +/*! + Sets the window's content view. The new view will be resized to fit + inside the content rectangle of the window. + @param aView the new content view for the receiver +*/ +- (void)setContentView:(CPView)aView +{ + if (_contentView) + [_contentView removeFromSuperview]; + + var bounds = CGRectMake(0.0, 0.0, CGRectGetWidth(_frame), CGRectGetHeight(_frame)); + + // During init the initial first responder is set to the contentView + // if it hasn't changed in the mean time we need to update that reference + // to the new contentView + if (_initialFirstResponder === _contentView) + [self setInitialFirstResponder:aView]; + + _contentView = aView; + [_contentView setFrame:[self contentRectForFrameRect:bounds]]; + + [_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + [_windowView addSubview:_contentView]; +} + +/*! + Returns the window's current content view. +*/ +- (CPView)contentView +{ + return _contentView; +} + +/*! + Applies an alpha value to the window. + @param aValue the alpha value to apply +*/ +- (void)setAlphaValue:(float)aValue +{ + [_windowView setAlphaValue:aValue]; +} + +/*! + Returns the alpha value of the window. +*/ +- (float)alphaValue +{ + return [_windowView alphaValue]; +} + +/*! + Sets the window's background color. + @param aColor the new color for the background +*/ +- (void)setBackgroundColor:(CPColor)aColor +{ + [_windowView setBackgroundColor:aColor]; +} + +/*! + Returns the window's background color. +*/ +- (CPColor)backgroundColor +{ + return [_windowView backgroundColor]; +} + +/*! + Sets the window's minimum size. If the provided + size is the same as the current minimum size, the method simply returns. + @param aSize the new minimum size for the window +*/ +- (void)setMinSize:(CGSize)aSize +{ + if (CGSizeEqualToSize(_minSize, aSize)) + return; + + _minSize = CGSizeCreateCopy(aSize); + + var size = CGSizeMakeCopy([self frame].size), + needsFrameChange = NO; + + if (size.width < _minSize.width) + { + size.width = _minSize.width; + needsFrameChange = YES; + } + + if (size.height < _minSize.height) + { + size.height = _minSize.height; + needsFrameChange = YES; + } + + if (needsFrameChange) + [self setFrameSize:size]; +} + +/*! + Returns the windows minimum size. +*/ +- (CGSize)minSize +{ + return _minSize; +} + +/*! + Sets the window's maximum size. If the provided + size is the same as the current maximum size, + the method simply returns. + @param aSize the new maximum size +*/ +- (void)setMaxSize:(CGSize)aSize +{ + if (CGSizeEqualToSize(_maxSize, aSize)) + return; + + _maxSize = CGSizeCreateCopy(aSize); + + var size = CGSizeMakeCopy([self frame].size), + needsFrameChange = NO; + + if (size.width > _maxSize.width) + { + size.width = _maxSize.width; + needsFrameChange = YES; + } + + if (size.height > _maxSize.height) + { + size.height = _maxSize.height; + needsFrameChange = YES; + } + + if (needsFrameChange) + [self setFrameSize:size]; +} + +/*! + Returns the window's maximum size. +*/ +- (CGSize)maxSize +{ + return _maxSize; +} + +/*! + Returns \c YES if the window has a drop shadow. \c NO otherwise. +*/ +- (BOOL)hasShadow +{ + return _hasShadow; +} + +- (void)_updateShadow +{ + if ([self _sharesChromeWithPlatformWindow]) + { + if (_shadowView) + { +#if PLATFORM(DOM) + CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement); +#endif + _shadowView = nil; + } + + [_platformWindow setHasShadow:_hasShadow]; + + return; + } + + if (_hasShadow && !_shadowView) + { + var bounds = [_windowView bounds]; + + _shadowView = [[CPView alloc] initWithFrame:CGRectMake(-SHADOW_MARGIN_LEFT, -SHADOW_MARGIN_TOP + SHADOW_DISTANCE, + SHADOW_MARGIN_LEFT + CGRectGetWidth(bounds) + SHADOW_MARGIN_RIGHT, SHADOW_MARGIN_TOP + CGRectGetHeight(bounds) + SHADOW_MARGIN_BOTTOM)]; + + if (!_CPWindowShadowColor) + { + var bundle = [CPBundle bundleForClass:[CPWindow class]]; + + _CPWindowShadowColor = [CPColor colorWithPatternImage:[[CPNinePartImage alloc] initWithImageSlices: + [ + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow0.png"] size:CGSizeMake(20.0, 19.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow1.png"] size:CGSizeMake(1.0, 19.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow2.png"] size:CGSizeMake(19.0, 19.0)], + + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow3.png"] size:CGSizeMake(20.0, 1.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow4.png"] size:CGSizeMake(1.0, 1.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow5.png"] size:CGSizeMake(19.0, 1.0)], + + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow6.png"] size:CGSizeMake(20.0, 18.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow7.png"] size:CGSizeMake(1.0, 18.0)], + [[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowShadow8.png"] size:CGSizeMake(19.0, 18.0)] + ]]]; + } + + [_shadowView setBackgroundColor:_CPWindowShadowColor]; + [_shadowView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable]; + +#if PLATFORM(DOM) + CPDOMDisplayServerInsertBefore(_DOMElement, _shadowView._DOMElement, _windowView._DOMElement); +#endif + } + else if (!_hasShadow && _shadowView) + { +#if PLATFORM(DOM) + CPDOMDisplayServerRemoveChild(_DOMElement, _shadowView._DOMElement); +#endif + _shadowView = nil; + } +} + +/*! + Sets whether the window should have a drop shadow. + @param shouldHaveShadow \c YES to have a drop shadow. +*/ +- (void)setHasShadow:(BOOL)shouldHaveShadow +{ + if (_hasShadow === shouldHaveShadow) + return; + + _hasShadow = shouldHaveShadow; + + [self _updateShadow]; +} + +/*! + Sets the shadow style of the receiver. + Values are: +
+    CPWindowShadowStyleStandard
+    CPWindowShadowStyleMenu
+    CPWindowShadowStylePanel
+    
+ + @param aStyle - The new shadow style of the receiver. +*/ +- (void)setShadowStyle:(unsigned)aStyle +{ + _shadowStyle = aStyle; + + [[self platformWindow] setShadowStyle:_shadowStyle]; +} + +/*! + Sets the delegate for the window. Passing \c nil will just remove the window's current delegate. + @param aDelegate an object to respond to the various delegate methods of CPWindow +*/ +- (void)setDelegate:(id)aDelegate +{ + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [defaultCenter removeObserver:_delegate name:CPWindowDidResignKeyNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeKeyNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidBecomeMainNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidResignMainNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidMoveNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidResizeNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowWillBeginSheetNotification object:self]; + [defaultCenter removeObserver:_delegate name:CPWindowDidEndSheetNotification object:self]; + + _delegate = aDelegate; + _delegateRespondsToWindowWillReturnUndoManagerSelector = [_delegate respondsToSelector:@selector(windowWillReturnUndoManager:)]; + + if ([_delegate respondsToSelector:@selector(windowDidResignKey:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidResignKey:) + name:CPWindowDidResignKeyNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidBecomeKey:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidBecomeKey:) + name:CPWindowDidBecomeKeyNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidBecomeMain:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidBecomeMain:) + name:CPWindowDidBecomeMainNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidResignMain:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidResignMain:) + name:CPWindowDidResignMainNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidMove:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidMove:) + name:CPWindowDidMoveNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidResize:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidResize:) + name:CPWindowDidResizeNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowWillBeginSheet:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowWillBeginSheet:) + name:CPWindowWillBeginSheetNotification + object:self]; + + if ([_delegate respondsToSelector:@selector(windowDidEndSheet:)]) + [defaultCenter + addObserver:_delegate + selector:@selector(windowDidEndSheet:) + name:CPWindowDidEndSheetNotification + object:self]; +} + +/*! + Returns window's delegate +*/ +- (id)delegate +{ + return _delegate; +} + +/*! + Sets the window's controller + @param aWindowController a window controller +*/ +- (void)setWindowController:(CPWindowController)aWindowController +{ + _windowController = aWindowController; +} + +/*! + Returns the window's controller. +*/ +- (CPWindowController)windowController +{ + return _windowController; +} + +- (void)doCommandBySelector:(SEL)aSelector +{ + if ([_delegate respondsToSelector:aSelector]) + [_delegate performSelector:aSelector]; + else + [super doCommandBySelector:aSelector]; +} + +- (BOOL)acceptsFirstResponder +{ + return NO; +} + +- (CPView)initialFirstResponder +{ + return _initialFirstResponder; +} + +- (void)setInitialFirstResponder:(CPView)aView +{ + // Before an initial first responder is set, be sure to calculate the key loop + [self _setupFirstResponder:aView]; + + _initialFirstResponder = aView; +} + +- (void)_setupFirstResponder:(CPView)anInitialFirstResponder +{ + /* + If: + + - The key loop is dirty + - The key loop does not auto-recalculate + - No view within the window has become first responder + - No initial first responder has been set + + Then calculate the key view loop and set the first responder + to the first view in the loop if no initial responder has been set, since we should + always have an initial first responder and a key loop by default. + */ + if (_keyViewLoopIsDirty && + !_autorecalculatesKeyViewLoop && + _firstResponder === self && + _initialFirstResponder === [self contentView]) + { + [self recalculateKeyViewLoop]; + + if (anInitialFirstResponder) + [self makeFirstResponder:anInitialFirstResponder]; + else + { + // Make the first key view of the content view the first responder + var firstKeyView = [[self contentView] nextValidKeyView]; + + [self makeFirstResponder:firstKeyView]; + } + } +} + +/*! + Attempts to make the \c aResponder the first responder. Before trying + to make it the first responder, the receiver will ask the current first responder + to resign its first responder status. If it resigns, it will ask + \c aResponder accept first responder, then finally tell it to become first responder. + @return \c YES if the attempt was successful. \c NO otherwise. +*/ +- (BOOL)makeFirstResponder:(CPResponder)aResponder +{ + if (_firstResponder === aResponder) + return YES; + + if (![_firstResponder resignFirstResponder]) + return NO; + + if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder]) + { + _firstResponder = self; + + return NO; + } + + _firstResponder = aResponder; + + [[CPNotificationCenter defaultCenter] postNotificationName:_CPWindowDidChangeFirstResponderNotification object:self]; + + return YES; +} + +/*! + Returns the window's current first responder. +*/ +- (CPResponder)firstResponder +{ + return _firstResponder; +} + +- (BOOL)acceptsMouseMovedEvents +{ + return _acceptsMouseMovedEvents; +} + +- (void)setAcceptsMouseMovedEvents:(BOOL)shouldAcceptMouseMovedEvents +{ + _acceptsMouseMovedEvents = shouldAcceptMouseMovedEvents; +} + +- (BOOL)ignoresMouseEvents +{ + return _ignoresMouseEvents; +} + +- (void)setIgnoresMouseEvents:(BOOL)shouldIgnoreMouseEvents +{ + _ignoresMouseEvents = shouldIgnoreMouseEvents; +} + +// Managing Titles + +/*! + Returns the window's title bar string +*/ +- (CPString)title +{ + return _title; +} + +/*! + Sets the window's title bar string +*/ +- (void)setTitle:(CPString)aTitle +{ + _title = aTitle; + + [_windowView setTitle:aTitle]; + [_platformWindow _setTitle:_title window:self]; + + [self _synchronizeMenuBarTitleWithWindowTitle]; +} + +/*! + Sets the title bar to represent a file path +*/ +- (void)setTitleWithRepresentedFilename:(CPString)aFilePath +{ + [self setRepresentedFilename:aFilePath]; + [self setTitle:[aFilePath lastPathComponent]]; +} + +/*! + Sets the path to the file the receiver represents +*/ +- (void)setRepresentedFilename:(CPString)aFilePath +{ + // FIXME: urls vs filepaths and all. + [self setRepresentedURL:aFilePath]; +} + +/*! + Returns the path to the file the receiver represents +*/ +- (CPString)representedFilename +{ + return _representedURL; +} + +/*! + Sets the URL that the receiver represents +*/ +- (void)setRepresentedURL:(CPURL)aURL +{ + _representedURL = aURL; +} + +/*! + Returns the URL that the receiver represents +*/ +- (CPURL)representedURL +{ + return _representedURL; +} + +- (CPScreen)screen +{ + return [[CPScreen alloc] init]; +} + +// Moving + +/*! + Sets whether the window can be moved by dragging its background. The default is based on the window style. + @param shouldBeMovableByWindowBackground \c YES makes the window move from a background drag. +*/ +- (void)setMovableByWindowBackground:(BOOL)shouldBeMovableByWindowBackground +{ + _isMovableByWindowBackground = shouldBeMovableByWindowBackground; +} + +/*! + Returns \c YES if the window can be moved by dragging its background. +*/ +- (BOOL)isMovableByWindowBackground +{ + return _isMovableByWindowBackground; +} + +/*! + Sets whether the window can be moved. + @param shouldBeMovable \c YES makes the window movable. +*/ +- (void)setMovable:(BOOL)shouldBeMovable +{ + _isMovable = shouldBeMovable; +} + +/*! + Returns \c YES if the window can be moved. +*/ +- (void)isMovable +{ + return _isMovable; +} + +/*! + Sets the window location to be the center of the screen +*/ +- (void)center +{ + if (_isFullPlatformWindow) + return; + + var size = [self frame].size, + containerSize = [CPPlatform isBrowser] ? [_platformWindow contentBounds].size : [[self screen] visibleFrame].size; + + var origin = CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height) / 2.0); + + if (origin.x < 0.0) + origin.x = 0.0; + + if (origin.y < 0.0) + origin.y = 0.0; + + [self setFrameOrigin:origin]; +} + +/*! + Dispatches events that are sent to it from CPApplication. + @param anEvent the event to be dispatched +*/ +- (void)sendEvent:(CPEvent)anEvent +{ + var type = [anEvent type], + point = [anEvent locationInWindow]; + + // If a sheet is attached events get filtered here. + // It is not clear what events should be passed to the view, perhaps all? + // CPLeftMouseDown is needed for window moving and resizing to work. + // CPMouseMoved is needed for rollover effects on title bar buttons. + var sheet = [self attachedSheet]; + if (sheet) + { + switch (type) + { + case CPLeftMouseDown: + [_windowView mouseDown:anEvent]; + + // -dw- if the window is clicked, the sheet should come to front, and become key, + // and the window should be immediately behind + [sheet makeKeyAndOrderFront:self]; + break; + case CPMouseMoved: + [_windowView mouseMoved:anEvent]; + break; + } + + return; + } + + switch (type) + { + case CPFlagsChanged: return [[self firstResponder] flagsChanged:anEvent]; + + case CPKeyUp: return [[self firstResponder] keyUp:anEvent]; + + case CPKeyDown: if ([anEvent charactersIgnoringModifiers] === CPTabCharacter) + { + if ([anEvent modifierFlags] & CPShiftKeyMask) + [self selectPreviousKeyView:self]; + else + [self selectNextKeyView:self]; +#if PLATFORM(DOM) + // Make sure the browser doesn't try to do its own tab handling. + // This is important or the browser might blur the shared text field or token field input field, + // even that we just moved it to a new first responder. + [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO] +#endif + return; + } + else if ([anEvent charactersIgnoringModifiers] === CPBackTabCharacter) + { + var didTabBack = [self selectPreviousKeyView:self]; + if (didTabBack) + { +#if PLATFORM(DOM) + // Make sure the browser doesn't try to do its own tab handling. + // This is important or the browser might blur the shared text field or token field input field, + // even that we just moved it to a new first responder. + [[[anEvent window] platformWindow] _propagateCurrentDOMEvent:NO] +#endif + } + + return didTabBack; + } + + [[self firstResponder] keyDown:anEvent]; + + // Trigger the default button if needed + // FIXME: Is this only applicable in a sheet? See isse: #722. + if (![self disableKeyEquivalentForDefaultButton]) + { + var defaultButton = [self defaultButton], + keyEquivalent = [defaultButton keyEquivalent], + modifierMask = [defaultButton keyEquivalentModifierMask]; + + if ([anEvent _triggersKeyEquivalent:keyEquivalent withModifierMask:modifierMask]) + [[self defaultButton] performClick:self]; + } + + return; + + case CPScrollWheel: return [[_windowView hitTest:point] scrollWheel:anEvent]; + + case CPLeftMouseUp: + case CPRightMouseUp: var hitTestedView = _leftMouseDownView, + selector = type == CPRightMouseUp ? @selector(rightMouseUp:) : @selector(mouseUp:); + + if (!hitTestedView) + hitTestedView = [_windowView hitTest:point]; + + [hitTestedView performSelector:selector withObject:anEvent]; + + _leftMouseDownView = nil; + + return; + case CPLeftMouseDown: + case CPRightMouseDown: _leftMouseDownView = [_windowView hitTest:point]; + + if (_leftMouseDownView != _firstResponder && [_leftMouseDownView acceptsFirstResponder]) + [self makeFirstResponder:_leftMouseDownView]; + + [CPApp activateIgnoringOtherApps:YES]; + + var theWindow = [anEvent window], + selector = type == CPRightMouseDown ? @selector(rightMouseDown:) : @selector(mouseDown:); + + if ([theWindow isKeyWindow] || [theWindow becomesKeyOnlyIfNeeded] && ![_leftMouseDownView needsPanelToBecomeKey]) + return [_leftMouseDownView performSelector:selector withObject:anEvent]; + else + { + // FIXME: delayed ordering? + [self makeKeyAndOrderFront:self]; + + if ([_leftMouseDownView acceptsFirstMouse:anEvent]) + return [_leftMouseDownView performSelector:selector withObject:anEvent]; + } + break; + + case CPLeftMouseDragged: + case CPRightMouseDragged: if (!_leftMouseDownView) + return [[_windowView hitTest:point] mouseDragged:anEvent]; + + var selector; + if (type == CPRightMouseDragged) + { + selector = @selector(rightMouseDragged:) + if (![_leftMouseDownView respondsToSelector:selector]) + selector = nil; + } + + if (!selector) + selector = @selector(mouseDragged:) + + return [_leftMouseDownView performSelector:selector withObject:anEvent]; + + case CPMouseMoved: if (!_acceptsMouseMovedEvents) + return; + + if (!_mouseEnteredStack) + _mouseEnteredStack = []; + + var hitTestView = [_windowView hitTest:point]; + + if ([_mouseEnteredStack count] && [_mouseEnteredStack lastObject] === hitTestView) + return [hitTestView mouseMoved:anEvent]; + + var view = hitTestView, + mouseEnteredStack = []; + + while (view) + { + mouseEnteredStack.unshift(view); + + view = [view superview]; + } + + var deviation = MIN(_mouseEnteredStack.length, mouseEnteredStack.length); + + while (deviation--) + if (_mouseEnteredStack[deviation] === mouseEnteredStack[deviation]) + break; + + var index = deviation + 1, + count = _mouseEnteredStack.length; + + if (index < count) + { + var event = [CPEvent mouseEventWithType:CPMouseExited location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]; + + for (; index < count; ++index) + [_mouseEnteredStack[index] mouseExited:event]; + } + + index = deviation + 1; + count = mouseEnteredStack.length; + + if (index < count) + { + var event = [CPEvent mouseEventWithType:CPMouseEntered location:point modifierFlags:[anEvent modifierFlags] timestamp:[anEvent timestamp] windowNumber:_windowNumber context:nil eventNumber:-1 clickCount:1 pressure:0]; + + for (; index < count; ++index) + [mouseEnteredStack[index] mouseEntered:event]; + } + + _mouseEnteredStack = mouseEnteredStack; + + [hitTestView mouseMoved:anEvent]; + } +} + +/*! + Returns the window's number in the desktop's screen list +*/ +- (int)windowNumber +{ + return _windowNumber; +} + +/*! + Called when the receiver should become the key window. It also sends + the \c -becomeKeyWindow message to the first responder. +*/ +- (void)becomeKeyWindow +{ + CPApp._keyWindow = self; + + if (_firstResponder !== self && [_firstResponder respondsToSelector:@selector(becomeKeyWindow)]) + [_firstResponder becomeKeyWindow]; + + [self _setupFirstResponder:nil]; + + [_windowView noteKeyWindowStateChanged]; + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidBecomeKeyNotification + object:self]; +} + +/*! + Determines if the window can become the key window. + @return \c YES means the window can become the key window. +*/ +- (BOOL)canBecomeKeyWindow +{ + // In Cocoa only resizable or titled windows return YES here by default. But the main browser window in Cappuccino + // doesn't have these masks even that it's both titled and resizable, so we return YES when isFullPlatformWindow too. + return (_styleMask & CPTitledWindowMask) || (_styleMask & CPResizableWindowMask) || [self isFullPlatformWindow]; +} + +/*! + Returns \c YES if the window is the key window. +*/ +- (BOOL)isKeyWindow +{ + return [CPApp keyWindow] == self; +} + +/*! + Makes the window the key window and brings it to the front of the screen list. + @param aSender the object requesting this +*/ +- (void)makeKeyAndOrderFront:(id)aSender +{ + [self orderFront:self]; + + [self makeKeyWindow]; + [self makeMainWindow]; +} + +/*! + Makes this window the key window. +*/ +- (void)makeKeyWindow +{ + if ([CPApp keyWindow] === self || ![self canBecomeKeyWindow]) + return; + + [[CPApp keyWindow] resignKeyWindow]; + [self becomeKeyWindow]; +} + +/*! + Causes the window to resign it's key window status. +*/ +- (void)resignKeyWindow +{ + if (_firstResponder !== self && [_firstResponder respondsToSelector:@selector(resignKeyWindow)]) + [_firstResponder resignKeyWindow]; + + if (CPApp._keyWindow === self) + CPApp._keyWindow = nil; + + [_windowView noteKeyWindowStateChanged]; + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidResignKeyNotification + object:self]; +} + +/*! + Initiates a drag operation from the receiver to another view that accepts dragged data. + @param anImage the image to be dragged + @param aLocation the lower-left corner coordinate of \c anImage + @param mouseOffset the distance from the \c -mouseDown: location and the current location + @param anEvent the \c -mouseDown: that triggered the drag + @param aPasteboard the pasteboard that holds the drag data + @param aSourceObject the drag operation controller + @param slideBack Whether the image should 'slide back' if the drag is rejected +*/ +- (void)dragImage:(CPImage)anImage at:(CGPoint)imageLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack +{ + [[CPDragServer sharedDragServer] dragImage:anImage fromWindow:self at:[self convertBaseToGlobal:imageLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack]; +} + +- (void)_noteRegisteredDraggedTypes:(CPSet)pasteboardTypes +{ + if (!pasteboardTypes) + return; + + if (!_inclusiveRegisteredDraggedTypes) + _inclusiveRegisteredDraggedTypes = [CPCountedSet set]; + + [_inclusiveRegisteredDraggedTypes unionSet:pasteboardTypes]; +} + +- (void)_noteUnregisteredDraggedTypes:(CPSet)pasteboardTypes +{ + if (!pasteboardTypes) + return; + + [_inclusiveRegisteredDraggedTypes minusSet:pasteboardTypes]; + + if ([_inclusiveRegisteredDraggedTypes count] === 0) + _inclusiveRegisteredDraggedTypes = nil; +} + +/*! + Initiates a drag operation from the receiver to another view that accepts dragged data. + @param aView the view to be dragged + @param aLocation the lower-left corner coordinate of \c aView + @param mouseOffset the distance from the \c -mouseDown: location and the current location + @param anEvent the \c -mouseDown: that triggered the drag + @param aPasteboard the pasteboard that holds the drag data + @param aSourceObject the drag operation controller + @param slideBack Whether the view should 'slide back' if the drag is rejected +*/ +- (void)dragView:(CPView)aView at:(CGPoint)viewLocation offset:(CGSize)mouseOffset event:(CPEvent)anEvent pasteboard:(CPPasteboard)aPasteboard source:(id)aSourceObject slideBack:(BOOL)slideBack +{ + [[CPDragServer sharedDragServer] dragView:aView fromWindow:self at:[self convertBaseToGlobal:viewLocation] offset:mouseOffset event:anEvent pasteboard:aPasteboard source:aSourceObject slideBack:slideBack]; +} + +/*! + Sets the receiver's list of acceptable data types for a dragging operation. + @param pasteboardTypes an array of CPPasteboards +*/ +- (void)registerForDraggedTypes:(CPArray)pasteboardTypes +{ + if (!pasteboardTypes) + return; + + [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes]; + [_registeredDraggedTypes addObjectsFromArray:pasteboardTypes]; + [self _noteRegisteredDraggedTypes:_registeredDraggedTypes]; + + _registeredDraggedTypesArray = nil; +} + +/*! + Returns an array of all types the receiver accepts for dragging operations. + @return an array of CPPasteBoards +*/ +- (CPArray)registeredDraggedTypes +{ + if (!_registeredDraggedTypesArray) + _registeredDraggedTypesArray = [_registeredDraggedTypes allObjects]; + + return _registeredDraggedTypesArray; +} + +/*! + Resets the array of acceptable data types for a dragging operation. +*/ +- (void)unregisterDraggedTypes +{ + [self _noteUnregisteredDraggedTypes:_registeredDraggedTypes]; + + _registeredDraggedTypes = [CPSet set]; + _registeredDraggedTypesArray = []; +} + +// Accessing Editing Status + +/*! + Sets whether the document has been edited. + @param isDocumentEdited \c YES if the document has been edited. +*/ +- (void)setDocumentEdited:(BOOL)isDocumentEdited +{ + if (_isDocumentEdited == isDocumentEdited) + return; + + _isDocumentEdited = isDocumentEdited; + + [CPMenu _setMenuBarIconImageAlphaValue:_isDocumentEdited ? 0.5 : 1.0]; + + [_windowView setDocumentEdited:isDocumentEdited]; +} + +/*! + Returns \c YES if the document has been edited. +*/ +- (BOOL)isDocumentEdited +{ + return _isDocumentEdited; +} + +- (void)setDocumentSaving:(BOOL)isDocumentSaving +{ + if (_isDocumentSaving == isDocumentSaving) + return; + + _isDocumentSaving = isDocumentSaving; + + [self _synchronizeSaveMenuWithDocumentSaving]; + + [_windowView windowDidChangeDocumentSaving]; +} + +- (BOOL)isDocumentSaving +{ + return _isDocumentSaving; +} + +/* @ignore */ +- (void)_synchronizeSaveMenuWithDocumentSaving +{ + if (![self isMainWindow]) + return; + + var mainMenu = [CPApp mainMenu], + index = [mainMenu indexOfItemWithTitle:_isDocumentSaving ? @"Save" : @"Saving..."]; + + if (index == CPNotFound) + return; + + var item = [mainMenu itemAtIndex:index]; + + if (_isDocumentSaving) + { + CPWindowSaveImage = [item image]; + + [item setTitle:@"Saving..."]; + [item setImage:CPWindowSavingImage]; + [item setEnabled:NO]; + } + else + { + [item setTitle:@"Save"]; + [item setImage:CPWindowSaveImage]; + [item setEnabled:YES]; + } +} + +// Minimizing Windows + +/*! + Simulates the user minimizing the window, then minimizes the window. + @param aSender the object making this request +*/ +- (void)performMiniaturize:(id)aSender +{ + //FIXME show stuff + [self miniaturize:aSender]; +} + +/*! + Minimizes the window. Posts a \c CPWindowWillMiniaturizeNotification to the + notification center before minimizing the window. +*/ +- (void)miniaturize:(id)sender +{ + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillMiniaturizeNotification object:self]; + + [[self platformWindow] miniaturize:sender]; + + [self _updateMainAndKeyWindows]; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidMiniaturizeNotification object:self]; + + _isMiniaturized = YES; +} + +/*! + Restores a minimized window to it's original size. +*/ +- (void)deminiaturize:(id)sender +{ + [[self platformWindow] deminiaturize:sender]; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidDeminiaturizeNotification object:self]; + + _isMiniaturized = NO; +} + +/*! + Returns YES if the window is minimized. +*/ +- (void)isMiniaturized +{ + return _isMiniaturized; +} + +// Closing Windows + +/*! + Simulates the user closing the window, then closes the window. + @param aSender the object making this request +*/ +- (void)performClose:(id)aSender +{ + if (!(_styleMask & CPClosableWindowMask)) + return; + + if ([self isFullBridge]) + { + var event = [CPApp currentEvent]; + + if ([event type] === CPKeyDown && [event characters] === "w" && ([event modifierFlags] & CPPlatformActionKeyMask)) + { + [[self platformWindow] _propagateCurrentDOMEvent:YES]; + return; + } + } + + // Only send ONE windowShouldClose: message. + if ([_delegate respondsToSelector:@selector(windowShouldClose:)]) + { + if (![_delegate windowShouldClose:self]) + return; + } + + // Only check self is delegate does NOT implement this. This also ensures this when delegate == self (returns true). + else if ([self respondsToSelector:@selector(windowShouldClose:)] && ![self windowShouldClose:self]) + return; + + var documents = [_windowController documents]; + if ([documents count]) + { + var index = [documents indexOfObject:[_windowController document]]; + + [documents[index] shouldCloseWindowController:_windowController + delegate:self + shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) + contextInfo:{documents:[documents copy], visited:0, index:index}]; + } + else + [self close]; +} + +- (void)_windowControllerContainingDocument:(CPDocument)document shouldClose:(BOOL)shouldClose contextInfo:(Object)context +{ + if (shouldClose) + { + var windowController = [self windowController], + documents = context.documents, + count = [documents count], + visited = ++context.visited, + index = ++context.index % count; + + [document removeWindowController:windowController]; + + if (visited < count) + { + [windowController setDocument:documents[index]]; + + [documents[index] shouldCloseWindowController:_windowController + delegate:self + shouldCloseSelector:@selector(_windowControllerContainingDocument:shouldClose:contextInfo:) + contextInfo:context]; + } + else + [self close]; + } +} + +/*! + Closes the window. Posts a \c CPWindowWillCloseNotification to the + notification center before closing the window. +*/ +- (void)close +{ + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillCloseNotification object:self]; + + [self orderOut:nil]; +} + +// Managing Main Status +/*! + Returns \c YES if this the main window. +*/ +- (BOOL)isMainWindow +{ + return [CPApp mainWindow] === self; +} + +/*! + Returns \c YES if the window can become the main window. +*/ +- (BOOL)canBecomeMainWindow +{ + // FIXME: Also check if we can resize and titlebar. + if ([self isVisible]) + return YES; + + return NO; +} + +/*! + Makes the receiver the main window. +*/ +- (void)makeMainWindow +{ + if ([CPApp mainWindow] === self || ![self canBecomeMainWindow]) + return; + + [[CPApp mainWindow] resignMainWindow]; + [self becomeMainWindow]; +} + +/*! + Called to tell the receiver that it has become the main window. +*/ +- (void)becomeMainWindow +{ + CPApp._mainWindow = self; + + [self _synchronizeMenuBarTitleWithWindowTitle]; + [self _synchronizeSaveMenuWithDocumentSaving]; + + [_windowView noteMainWindowStateChanged]; + + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidBecomeMainNotification + object:self]; +} + +/*! + Called when the window resigns main window status. +*/ +- (void)resignMainWindow +{ + [[CPNotificationCenter defaultCenter] + postNotificationName:CPWindowDidResignMainNotification + object:self]; + + if (CPApp._mainWindow === self) + CPApp._mainWindow = nil; + + [_windowView noteMainWindowStateChanged]; +} + +- (void)_updateMainAndKeyWindows +{ + var allWindows = [CPApp orderedWindows], + windowCount = [allWindows count]; + + if ([self isKeyWindow]) + { + var keyWindow = [CPApp keyWindow]; + [self resignKeyWindow]; + + if (keyWindow && keyWindow !== self && [keyWindow canBecomeKeyWindow]) + [keyWindow makeKeyWindow]; + else + { + var mainMenu = [CPApp mainMenu], + menuBarClass = objj_getClass("_CPMenuBarWindow"), + menuWindow; + + for (var i = 0; i < windowCount; i++) + { + var currentWindow = allWindows[i]; + + if ([currentWindow isKindOfClass:menuBarClass]) + menuWindow = currentWindow; + + if (currentWindow === self || currentWindow === menuWindow) + continue; + + if ([currentWindow isVisible] && [currentWindow canBecomeKeyWindow]) + { + [currentWindow makeKeyWindow]; + break; + } + } + + if (![CPApp keyWindow]) + [menuWindow makeKeyWindow]; + } + } + + if ([self isMainWindow]) + { + var mainWindow = [CPApp mainWindow]; + [self resignMainWindow]; + + if (mainWindow && mainWindow !== self && [mainWindow canBecomeMainWindow]) + [mainWindow makeMainWindow]; + else + { + var mainMenu = [CPApp mainMenu], + menuBarClass = objj_getClass("_CPMenuBarWindow"), + menuWindow; + + for (var i = 0; i < windowCount; i++) + { + var currentWindow = allWindows[i]; + + if ([currentWindow isKindOfClass:menuBarClass]) + menuWindow = currentWindow; + + if (currentWindow === self || currentWindow === menuWindow) + continue; + + if ([currentWindow isVisible] && [currentWindow canBecomeMainWindow]) + { + [currentWindow makeMainWindow]; + break; + } + } + } + } +} + +// Managing Toolbars +/*! + Return's the window's toolbar +*/ +- (CPToolbar)toolbar +{ + return _toolbar; +} + +/*! + Sets the window's toolbar. + @param aToolbar the window's new toolbar +*/ +- (void)setToolbar:(CPToolbar)aToolbar +{ + if (_toolbar === aToolbar) + return; + + // If this has an owner, dump it! + [[aToolbar _window] setToolbar:nil]; + + // This is no longer out toolbar. + [_toolbar _setWindow:nil]; + + _toolbar = aToolbar; + + // THIS is our toolbar. + [_toolbar _setWindow:self]; + + [self _noteToolbarChanged]; +} + +- (void)toggleToolbarShown:(id)aSender +{ + var toolbar = [self toolbar]; + + [toolbar setVisible:![toolbar isVisible]]; +} + +- (void)_noteToolbarChanged +{ + var frame = CGRectMakeCopy([self frame]), + newFrame; + + [_windowView noteToolbarChanged]; + + if (_isFullPlatformWindow) + newFrame = [_platformWindow visibleFrame]; + else + { + newFrame = CGRectMakeCopy([self frame]); + + newFrame.origin = frame.origin; + } + + [self setFrame:newFrame]; + /* + [_windowView setAnimatingToolbar:YES]; + [self setFrame:frame]; + [self setFrame:newFrame display:YES animate:YES]; + [_windowView setAnimatingToolbar:NO]; + */ +} + +- (void)_setFrame:(CGRect)aFrame delegate:(id)delegate duration:(int)duration curve:(CPAnimationCurve)curve +{ + [_frameAnimation stopAnimation]; + _frameAnimation = [[_CPWindowFrameAnimation alloc] initWithWindow:self targetFrame:aFrame]; + [_frameAnimation setDelegate:delegate]; + [_frameAnimation setAnimationCurve:curve]; + [_frameAnimation setDuration:duration]; + [_frameAnimation startAnimation]; +} + +- (CPTimeInterval)animationResizeTime:(CGRect)newWindowFrame +{ + return CPWindowResizeTime; +} + +/* @ignore */ +- (void)_setAttachedSheetFrameOrigin +{ + // Position the sheet above the contentRect. + var attachedSheet = [self attachedSheet]; + var contentRect = [[self contentView] frame], + sheetFrame = CGRectMakeCopy([attachedSheet frame]); + + sheetFrame.origin.y = CGRectGetMinY(_frame) + CGRectGetMinY(contentRect); + sheetFrame.origin.x = CGRectGetMinX(_frame) + FLOOR((CGRectGetWidth(_frame) - CGRectGetWidth(sheetFrame)) / 2.0); + + [attachedSheet setFrame:sheetFrame display:YES animate:NO]; +} + +/* @ignore + Starting point for sheet session, called from CPApplication beginSheet: +*/ +- (void)_attachSheet:(CPWindow)aSheet modalDelegate:(id)aModalDelegate + didEndSelector:(SEL)aDidEndSelector contextInfo:(id)aContextInfo +{ + if (_sheetContext) + { + [CPException raise:CPInternalInconsistencyException + reason:@"The target window of beginSheet: already has a sheet, did you forget orderOut: ?"]; + return; + } + + var sheetFrame = [aSheet frame]; + + _sheetContext = {"sheet": aSheet, "modalDelegate": aModalDelegate, "endSelector": aDidEndSelector, + "contextInfo": aContextInfo, "frame": _CGRectMakeCopy(sheetFrame), "returnCode": -1, + "opened": NO}; + + [self _attachSheetWindow]; +} + +/* @ignore + Called to animate the sheet in. The timer seems to solve a bug where sheets would + be partially animated under certain conditions. +*/ +- (void)_attachSheetWindow +{ + _sheetContext["isAttached"] = YES; + + // it would be ideal to block here and spin an event loop, until attach is complete + [CPTimer scheduledTimerWithTimeInterval:0.0 + target:self + selector:@selector(_sheetShouldAnimateIn:) + userInfo:nil + repeats:NO]; +} + +/* @ignore + Called to end the sheet. Note that orderOut: is needed to animate the sheet out, as in Cocoa. + The sheet isn't completely gone until _cleanupSheetWindow gets called. +*/ +- (void)_endSheet +{ + var delegate = _sheetContext["modalDelegate"], + endSelector = _sheetContext["endSelector"]; + + // If the sheet has been ordered out, defer didEndSelector until after sheet animates out. + // This must be done since we cannot block and wait for the animation to complete. + if (delegate && endSelector) + { + if (_sheetContext["isAttached"]) + objj_msgSend(delegate, endSelector, _sheetContext["sheet"], _sheetContext["returnCode"], + _sheetContext["contextInfo"]); + else + _sheetContext["deferDidEndSelector"] = YES; + } +} + +/* @ignore + Called to animate the sheet out. If called while animating in, schedules an animate + out at completion +*/ +- (void)_detachSheetWindow +{ + _sheetContext["isAttached"] = NO; + + // it would be ideal to block here and spin the event loop, until attach is complete + [CPTimer scheduledTimerWithTimeInterval:0.0 + target:self + selector:@selector(_sheetShouldAnimateOut:) + userInfo:nil + repeats:NO]; +} + +/* @ignore + Called to cleanup sheet, when we are definitely done with it +*/ +- (void)_cleanupSheetWindow +{ + var sheet = _sheetContext["sheet"], + lastFrame = _sheetContext["frame"], + deferDidEnd = _sheetContext["deferDidEndSelector"]; + + [sheet setFrame:lastFrame]; + [self _restoreMasksForView:[sheet contentView]]; + + // if the parent window is modal, the sheet started its own modal session + if (sheet._isModal) + [CPApp stopModal]; + + // restore the state of window before it was sheetified + [sheet._windowView _enableSheet:NO]; + + // close it + sheet._isSheet = NO; + [sheet orderOut:self]; + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowDidEndSheetNotification object:self]; + + if (deferDidEnd) + { + var delegate = _sheetContext["modalDelegate"], + selector = _sheetContext["endSelector"], + returnCode = _sheetContext["returnCode"], + contextInfo = _sheetContext["contextInfo"]; + + // context must be destroyed, since didEnd might want to attach another sheet + _sheetContext = nil; + sheet._parentView = nil; + + objj_msgSend(delegate, selector, sheet, returnCode, contextInfo); + } + else + { + _sheetContext = nil; + sheet._parentView = nil; + } +} + +/* @ignore */ +- (void)animationDidEnd:(id)anim +{ + var sheet = _sheetContext["sheet"]; + if (anim._window != sheet) + return; + + [CPTimer scheduledTimerWithTimeInterval:0.0 + target:self + selector:@selector(_sheetAnimationDidEnd:) + userInfo:nil + repeats:NO]; +} + +/* @ignore */ +- (void)_sheetShouldAnimateIn:(CPTimer)timer +{ + // can't open sheet while opening or closing animation is going on + if (_sheetContext["isOpening"] || + _sheetContext["isClosing"]) + return; + + var sheet = _sheetContext["sheet"], + sheetFrame = [sheet frame], + frame = [self frame]; + + [self _setUpMasksForView:[sheet contentView]]; + + sheet._isSheet = YES; + sheet._parentView = self; + + var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width) / 2), + originy = frame.origin.y + [[self contentView] frame].origin.y, + startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0), + endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height); + + [[CPNotificationCenter defaultCenter] postNotificationName:CPWindowWillBeginSheetNotification object:self]; + + // if sheet is attached to a modal window, the sheet runs + // as if itself and the parent window are modal + sheet._isModal = NO; + if ([CPApp modalWindow] === self) + { + [CPApp runModalForWindow:sheet]; + sheet._isModal = YES; + } + + [sheet orderFront:self]; + [sheet setFrame:startFrame display:YES animate:NO]; + + _sheetContext["opened"] = YES; + _sheetContext["shouldClose"] = NO; + _sheetContext["isOpening"] = YES; + + [sheet _setFrame:endFrame delegate:self duration:[self animationResizeTime:endFrame] curve:CPAnimationEaseOut]; + + // NOTE: cocoa doesn't make window key until animation is done, but a + // keypress while animating eventually gets to the window. Therefore, + // there must be a runloop specifically designed for sheets? + [sheet makeKeyWindow]; +} + +/* @ignore */ +- (void)_sheetShouldAnimateOut:(CPTimer)timer +{ + var sheet = _sheetContext["sheet"], + startFrame = [sheet frame], + endFrame = CGRectMakeCopy(startFrame); + + if (_sheetContext["isOpening"]) + { + // allow sheet to be closed while opening, it will close when animate in completes + _sheetContext["shouldClose"] = YES; + return; + } + + if (_sheetContext["isClosing"]) + return; + + _sheetContext["opened"] = NO; + _sheetContext["frame"] = startFrame; + _sheetContext["isClosing"] = YES; + + // the parent window can be orderedOut to disable the sheet animate out, as in Cocoa + if ([self isVisible]) + { + endFrame.size.height = 0; + [self _setUpMasksForView:[sheet contentView]]; + [sheet _setFrame:endFrame delegate:self duration:[self animationResizeTime:endFrame] curve:CPAnimationEaseIn]; + } + else + { + [self _sheetAnimationDidEnd:nil]; + } +} + +/* @ignore */ +- (void)_sheetAnimationDidEnd:(CPTimer)timer +{ + var sheet = _sheetContext["sheet"]; + + _sheetContext["isOpening"] = NO; + _sheetContext["isClosing"] = NO; + + if (_sheetContext["opened"] === YES) + { + // sheet is open and completely visible + [self _restoreMasksForView:[sheet contentView]]; + + // we wanted to close the sheet while it animated in, do that now + if (_sheetContext["shouldClose"] === YES) + [self _detachSheetWindow]; + } + else + { + // sheet is closed and not visible + [self _cleanupSheetWindow]; + } +} + +- (void)_setUpMasksForView:(CPView)aView +{ + var views = [aView subviews]; + + [views addObject:aView]; + + for (var i = 0, count = [views count]; i < count; i++) + { + var view = [views objectAtIndex:i], + mask = [view autoresizingMask], + maskToAdd = (mask & CPViewMinYMargin) ? 128 : CPViewMinYMargin; + + [view setAutoresizingMask:(mask | maskToAdd)]; + } +} + +- (void)_restoreMasksForView:(CPView)aView +{ + var views = [aView subviews]; + + [views addObject:aView]; + + for (var i = 0, count = [views count]; i < count; i++) + { + var view = [views objectAtIndex:i], + mask = [view autoresizingMask], + maskToRemove = (mask & 128) ? 128 : CPViewMinYMargin; + + [view setAutoresizingMask:(mask & (~ maskToRemove))]; + } +} + +/*! + Returns the window's attached sheet. +*/ +- (CPWindow)attachedSheet +{ + if (_sheetContext === nil) + return nil; + + return _sheetContext["sheet"]; +} + +/*! + Returns \c YES if the window has ever run as a sheet. +*/ +- (BOOL)isSheet +{ + return _isSheet; +} + +// +/* + Used privately. + @ignore +*/ +- (BOOL)becomesKeyOnlyIfNeeded +{ + return NO; +} + +/*! + Returns \c YES if the receiver is able to receive input events + even when a modal session is active. +*/ +- (BOOL)worksWhenModal +{ + return NO; +} + +- (BOOL)performKeyEquivalent:(CPEvent)anEvent +{ + // FIXME: should we be starting at the root, in other words _windowView? + // The evidence seems to point to no... + return [[self contentView] performKeyEquivalent:anEvent]; +} + +- (void)keyDown:(CPEvent)anEvent +{ + // It's not clear why we do performKeyEquivalent again here... + // Perhaps to allow something to happen between sendEvent: and keyDown:? + if ([anEvent _couldBeKeyEquivalent] && [self performKeyEquivalent:anEvent]) + return; + + // Apple's documentation is inconsistent with their behavior here. According to the docs + // an event going of the responder chain is passed to the input system as a last resort. + // However, the only methods I could get Cocoa to call automatically are + // moveUp: moveDown: moveLeft: moveRight: pageUp: pageDown: and complete: + // Unhandled events just travel further up the responder chain _past_ the window. + if (![self _processKeyboardUIKey:anEvent]) + [super keyDown:anEvent]; +} + +/* + @ignore + Interprets the key event for action messages and sends the action message down the responder chain + Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages. + We deviate from this by sending (the default) scrollPageUp:, scrollPageDown:, scrollToBeginningOfDocument: and scrollToEndOfDocument: for pageUp, pageDown, home and end keys. + @param anEvent the event to handle. + @return YES if the key event was handled, NO if no responder handled the key event +*/ +- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent +{ + var character = [anEvent charactersIgnoringModifiers]; + + if (![CPWindowActionMessageKeys containsObject:character]) + return NO; + + var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0]; + + if ([selectors count] <= 0) + return NO; + + if (character !== CPEscapeFunctionKey) + { + var selector = [selectors objectAtIndex:0]; + return [[self firstResponder] tryToPerform:selector with:self]; + } + else + { + // Cocoa sends complete: for the escape key (in stead of the default cancelOperation:) + // This is also the only action that is not sent directly to the first responder, but through doCommandBySelector. + // The difference is that doCommandBySelector: will also send the action to the window and application delegates. + [[self firstResponder] doCommandBySelector:@selector(complete:)]; + } + + return NO; +} + +- (void)_dirtyKeyViewLoop +{ + if (_autorecalculatesKeyViewLoop) + _keyViewLoopIsDirty = YES; +} + +- (BOOL)_hasKeyViewLoop +{ + var views = allViews(self), + index = [views count]; + + while (index--) + if ([views[index] nextKeyView]) + return YES; + + return NO; +} + +- (void)recalculateKeyViewLoop +{ + var views = allViews(self); + + [views sortUsingFunction:keyViewComparator context:nil]; + + for (var index = 0, count = [views count]; index < count; ++index) + [views[index] setNextKeyView:views[(index + 1) % count]]; + + _keyViewLoopIsDirty = NO; +} + +- (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate +{ + if (_autorecalculatesKeyViewLoop === shouldRecalculate) + return; + + _autorecalculatesKeyViewLoop = shouldRecalculate; + + if (_autorecalculatesKeyViewLoop) + [self _dirtyKeyViewLoop]; +} + +- (BOOL)autorecalculatesKeyViewLoop +{ + return _autorecalculatesKeyViewLoop; +} + +- (void)selectNextKeyView:(id)sender +{ + if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) + [self recalculateKeyViewLoop]; + + var nextValidKeyView = nil; + + if ([_firstResponder isKindOfClass:[CPView class]]) + nextValidKeyView = [_firstResponder nextValidKeyView]; + + if (!nextValidKeyView) + { + var initialFirstResponder = _initialFirstResponder; + + if ([initialFirstResponder acceptsFirstResponder]) + nextValidKeyView = initialFirstResponder; + else + nextValidKeyView = [initialFirstResponder nextValidKeyView]; + } + + [self makeFirstResponder:nextValidKeyView]; +} + +- (void)selectPreviousKeyView:(id)sender +{ + if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) + [self recalculateKeyViewLoop]; + + var previousValidKeyView = nil; + + if ([_firstResponder isKindOfClass:[CPView class]]) + previousValidKeyView = [_firstResponder previousValidKeyView]; + + if (!previousValidKeyView) + { + var initialFirstResponder = _initialFirstResponder; + + if ([initialFirstResponder acceptsFirstResponder]) + previousValidKeyView = initialFirstResponder; + else + previousValidKeyView = [initialFirstResponder previousValidKeyView]; + } + + [self makeFirstResponder:previousValidKeyView]; +} + +- (void)selectKeyViewFollowingView:(CPView)aView +{ + if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) + [self recalculateKeyViewLoop]; + + var nextValidKeyView = [aView nextValidKeyView]; + + if ([nextValidKeyView isKindOfClass:[CPView class]]) + [self makeFirstResponder:nextValidKeyView]; +} + +- (void)selectKeyViewPrecedingView:(CPView)aView +{ + if (_keyViewLoopIsDirty && [self autorecalculatesKeyViewLoop]) + [self recalculateKeyViewLoop]; + + var previousValidKeyView = [aView previousValidKeyView]; + + if ([previousValidKeyView isKindOfClass:[CPView class]]) + [self makeFirstResponder:previousValidKeyView]; +} + +/*! + Sets the default button for the window. + Note: this method is deprecated use setDefaultButton: instead. + @param aButton - The button that should become default. +*/ +- (void)setDefaultButtonCell:(CPButton)aButton +{ + [self setDefaultButton:aButton]; +} + +/*! + Returns the default button of the receiver. + NOTE: This method is deprecated. Use defaultButton instead. +*/ +- (CPButton)defaultButtonCell +{ + return [self defaultButton]; +} + +/*! + Sets the default button for the window. + This is equivalent to setting the the key equivalent of the button to "return". + Additionally this will turn your button blue (with the Aristo theme). + @param aButton - The button that should become default. +*/ +- (void)setDefaultButton:(CPButton)aButton +{ + if (_defaultButton === aButton) + return; + + if ([_defaultButton keyEquivalent] === CPCarriageReturnCharacter) + [_defaultButton setKeyEquivalent:nil]; + + _defaultButton = aButton; + + if ([_defaultButton keyEquivalent] !== CPCarriageReturnCharacter) + [_defaultButton setKeyEquivalent:CPCarriageReturnCharacter]; +} + +/*! + Returns the default button of the receiver. +*/ +- (CPButton)defaultButton +{ + return _defaultButton; +} + +/*! + Sets the default button key equivalent to "return". +*/ +- (void)enableKeyEquivalentForDefaultButton +{ + _defaultButtonEnabled = YES; +} + +/*! + Sets the default button key equivalent to "return". + NOTE: this method is deprecated. Use enableKeyEquivalentForDefaultButton instead. +*/ +- (void)enableKeyEquivalentForDefaultButtonCell +{ + [self enableKeyEquivalentForDefaultButton]; +} + +/*! + Removes the key equivalent for the default button. +*/ +- (void)disableKeyEquivalentForDefaultButton +{ + _defaultButtonEnabled = NO; +} + +/*! + Removes the key equivalent for the default button. + Note: this method is deprecated. Use disableKeyEquivalentForDefaultButton instead. +*/ +- (void)disableKeyEquivalentForDefaultButtonCell +{ + [self disableKeyEquivalentForDefaultButton]; +} + +@end + +var allViews = function(aWindow) +{ + var views = [CPArray arrayWithObject:[aWindow contentView]]; + + [views addObjectsFromArray:[[aWindow contentView] subviews]]; + + // Start from index 1 because index 0 is the contentView and its subviews have already been added + for (var index = 1; index < views.length; ++index) + views = views.concat([views[index] subviews]); + + return views; +}; + +var keyViewComparator = function(lhs, rhs, context) +{ + var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil], + rhsBounds = [rhs convertRect:[rhs bounds] toView:nil], + lhsY = _CGRectGetMinY(lhsBounds), + rhsY = _CGRectGetMinY(rhsBounds), + lhsX = _CGRectGetMinX(lhsBounds), + rhsX = _CGRectGetMinX(rhsBounds), + intersectsVertically = MIN(_CGRectGetMaxY(lhsBounds), _CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY); + + // If two views are "on the same line" (intersect vertically), then rely on the x comparison. + if (intersectsVertically > 0) + { + if (lhsX < rhsX) + return CPOrderedAscending; + + if (lhsX === rhsX) + return CPOrderedSame; + + return CPOrderedDescending; + } + + if (lhsY < rhsY) + return CPOrderedAscending; + + if (lhsY === rhsY) + return CPOrderedSame; + + return CPOrderedDescending; +}; + +@implementation CPWindow (MenuBar) + +- (void)_synchronizeMenuBarTitleWithWindowTitle +{ + // Windows with Documents automatically update the native window title and the menu bar title. + if (![_windowController document] || ![self isMainWindow]) + return; + + [CPMenu setMenuBarTitle:_title]; +} + +@end + +@implementation CPWindow (BridgeSupport) + +/* + @ignore +*/ +- (void)resizeWithOldPlatformWindowSize:(CGSize)aSize +{ + if ([self isFullPlatformWindow]) + return [self setFrame:[_platformWindow visibleFrame]]; + + if (_autoresizingMask == CPWindowNotSizable) + return; + + var frame = [_platformWindow contentBounds], + newFrame = CGRectMakeCopy(_frame), + dX = (CGRectGetWidth(frame) - aSize.width) / + (((_autoresizingMask & CPWindowMinXMargin) ? 1 : 0) + (_autoresizingMask & CPWindowWidthSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxXMargin ? 1 : 0)), + dY = (CGRectGetHeight(frame) - aSize.height) / + ((_autoresizingMask & CPWindowMinYMargin ? 1 : 0) + (_autoresizingMask & CPWindowHeightSizable ? 1 : 0) + (_autoresizingMask & CPWindowMaxYMargin ? 1 : 0)); + + if (_autoresizingMask & CPWindowMinXMargin) + newFrame.origin.x += dX; + if (_autoresizingMask & CPWindowWidthSizable) + newFrame.size.width += dX; + + if (_autoresizingMask & CPWindowMinYMargin) + newFrame.origin.y += dY; + if (_autoresizingMask & CPWindowHeightSizable) + newFrame.size.height += dY; + + [self setFrame:newFrame]; +} + +/* + @ignore +*/ +- (void)setAutoresizingMask:(unsigned)anAutoresizingMask +{ + _autoresizingMask = anAutoresizingMask; +} + +/* + @ignore +*/ +- (unsigned)autoresizingMask +{ + return _autoresizingMask; +} + +/*! + Converts aPoint from the window coordinate system to the global coordinate system. +*/ +- (CGPoint)convertBaseToGlobal:(CGPoint)aPoint +{ + return [CPPlatform isBrowser] ? [self convertBaseToPlatformWindow:aPoint] : [self convertBaseToScreen:aPoint]; +} + +/*! + Converts aPoint from the global coordinate system to the window coordinate system. +*/ +- (CGPoint)convertGlobalToBase:(CGPoint)aPoint +{ + return [CPPlatform isBrowser] ? [self convertPlatformWindowToBase:aPoint] : [self convertScreenToBase:aPoint]; +} + +/*! + Converts aPoint from the window coordinate system to the coordinate system of the parent platform window. +*/ +- (CGPoint)convertBaseToPlatformWindow:(CGPoint)aPoint +{ + if ([self _sharesChromeWithPlatformWindow]) + return _CGPointMakeCopy(aPoint); + + var origin = [self frame].origin; + + return _CGPointMake(aPoint.x + origin.x, aPoint.y + origin.y); +} + +/*! + Converts aPoint from the parent platform window coordinate system to the window's coordinate system. +*/ +- (CGPoint)convertPlatformWindowToBase:(CGPoint)aPoint +{ + if ([self _sharesChromeWithPlatformWindow]) + return _CGPointMakeCopy(aPoint); + + var origin = [self frame].origin; + + return _CGPointMake(aPoint.x - origin.x, aPoint.y - origin.y); +} + +- (CGPoint)convertScreenToBase:(CGPoint)aPoint +{ + return [self convertPlatformWindowToBase:[_platformWindow convertScreenToBase:aPoint]]; +} + +- (CGPoint)convertBaseToScreen:(CGPoint)aPoint +{ + return [_platformWindow convertBaseToScreen:[self convertBaseToPlatformWindow:aPoint]]; +} + +- (void)_setSharesChromeWithPlatformWindow:(BOOL)shouldShareFrameWithPlatformWindow +{ + // We canna' do it captain! We just don't have the power! + if (shouldShareFrameWithPlatformWindow && [CPPlatform isBrowser]) + return; + + _sharesChromeWithPlatformWindow = shouldShareFrameWithPlatformWindow; + + [self _updateShadow]; +} + +- (BOOL)_sharesChromeWithPlatformWindow +{ + return _sharesChromeWithPlatformWindow; +} + +// Undo and Redo Support +/*! + Returns the window's undo manager. +*/ +- (CPUndoManager)undoManager +{ + // If we've ever created an undo manager, return it. + if (_undoManager) + return _undoManager; + + // If not, check to see if the document has one. + var documentUndoManager = [[_windowController document] undoManager]; + + if (documentUndoManager) + return documentUndoManager; + + // If not, check to see if the delegate has one. + if (_delegateRespondsToWindowWillReturnUndoManagerSelector) + return [_delegate windowWillReturnUndoManager:self]; + + // If not, create one. + if (!_undoManager) + _undoManager = [[CPUndoManager alloc] init]; + + return _undoManager; +} + +/*! + Sends the undo manager an \c -undo: message. + @param aSender the object requesting this +*/ +- (void)undo:(id)aSender +{ + [[self undoManager] undo]; +} + +/*! + Sends the undo manager a \c -redo: message. + @param aSender the object requesting this +*/ +- (void)redo:(id)aSender +{ + [[self undoManager] redo]; +} + +- (BOOL)containsPoint:(CGPoint)aPoint +{ + return CGRectContainsPoint(_frame, aPoint); +} + +@end + +@implementation CPWindow (Deprecated) +/*! + Sets the CPWindow to fill the whole browser window. + NOTE: this method has been deprecated in favor of setFullPlatformWindow: +*/ +- (void)setFullBridge:(BOOL)shouldBeFullBridge +{ + [self setFullPlatformWindow:shouldBeFullBridge]; +} + +/*! + Returns YES if the window fills the full browser window, otherwise NO. + NOTE: this method has been deprecated in favor of isFullPlatformWindow. +*/ +- (BOOL)isFullBridge +{ + return [self isFullPlatformWindow]; +} + +/* + @ignore +*/ +- (CGPoint)convertBaseToBridge:(CGPoint)aPoint +{ + return [self convertBaseToPlatformWindow:aPoint]; +} + +/* + @ignore +*/ +- (CGPoint)convertBridgeToBase:(CGPoint)aPoint +{ + return [self convertPlatformWindowToBase:aPoint]; +} + +@end + +var interpolate = function(fromValue, toValue, progress) +{ + return fromValue + (toValue - fromValue) * progress; +}; + +/* @ignore */ +@implementation _CPWindowFrameAnimation : CPAnimation +{ + CPWindow _window; + + CGRect _startFrame; + CGRect _targetFrame; +} + +- (id)initWithWindow:(CPWindow)aWindow targetFrame:(CGRect)aTargetFrame +{ + self = [super initWithDuration:[aWindow animationResizeTime:aTargetFrame] animationCurve:CPAnimationLinear]; + + if (self) + { + _window = aWindow; + + _targetFrame = CGRectMakeCopy(aTargetFrame); + _startFrame = CGRectMakeCopy([_window frame]); + } + + return self; +} + +- (void)startAnimation +{ + [super startAnimation]; + + _window._isAnimating = YES; +} + +- (void)setCurrentProgress:(float)aProgress +{ + [super setCurrentProgress:aProgress]; + + var value = [self currentValue]; + + if (value == 1.0) + _window._isAnimating = NO; + + var newFrame = CGRectMake(interpolate(CGRectGetMinX(_startFrame), CGRectGetMinX(_targetFrame), value), + interpolate(CGRectGetMinY(_startFrame), CGRectGetMinY(_targetFrame), value), + interpolate(CGRectGetWidth(_startFrame), CGRectGetWidth(_targetFrame), value), + interpolate(CGRectGetHeight(_startFrame), CGRectGetHeight(_targetFrame), value)); + + [_window setFrame:newFrame display:YES animate:NO]; +} + +@end + +function _CPWindowFullPlatformWindowSessionMake(aWindowView, aContentRect, hasShadow, aLevel) +{ + return { windowView:aWindowView, contentRect:aContentRect, hasShadow:hasShadow, level:aLevel }; +} + +CPStandardWindowShadowStyle = 0; +CPMenuWindowShadowStyle = 1; +CPPanelWindowShadowStyle = 2; +CPCustomWindowShadowStyle = 3; + + +/*@import "_CPWindowView.j" +@import "_CPStandardWindowView.j" +@import "_CPDocModalWindowView.j" +@import "_CPToolTipWindowView.j" +@import "_CPHUDWindowView.j" +@import "_CPBorderlessWindowView.j" +@import "_CPBorderlessBridgeWindowView.j" +@import "_CPAttachedWindowView.j" +@import "CPDragServer.j" +@import "CPView.j"*/ diff --git a/AppKit/Cib/_CPCibObjectData.j b/AppKit/Cib/_CPCibObjectData.j index 87d079ec8..2d1eecf95 100644 --- a/AppKit/Cib/_CPCibObjectData.j +++ b/AppKit/Cib/_CPCibObjectData.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import @import diff --git a/AppKit/Platform/DOM/CPDOMWindowLayer.j b/AppKit/Platform/DOM/CPDOMWindowLayer.j index 5b8a0fa73..a919dcff6 100644 --- a/AppKit/Platform/DOM/CPDOMWindowLayer.j +++ b/AppKit/Platform/DOM/CPDOMWindowLayer.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import +@import @import diff --git a/Foundation/CPArray+KVO.j b/Foundation/CPArray+KVO.j index a5b52bf9c..fc65294ef 100644 --- a/Foundation/CPArray+KVO.j +++ b/Foundation/CPArray+KVO.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "_CPJavaScriptArray.j" +@import "CPArray.j" @import "CPNull.j" @import "_CPCollectionKVCOperators.j" diff --git a/Foundation/CPArray/CPArray.j b/Foundation/CPArray/CPArray.j old mode 100755 new mode 100644 index 2f38e3faf..5d6505c36 --- a/Foundation/CPArray/CPArray.j +++ b/Foundation/CPArray/CPArray.j @@ -20,999 +20,5 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPEnumerator.j" -@import "CPException.j" -@import "CPObject.j" -@import "CPRange.j" -@import "CPSortDescriptor.j" - - -CPEnumerationNormal = 0; -CPEnumerationConcurrent = 1 << 0; -CPEnumerationReverse = 1 << 1; - -CPBinarySearchingFirstEqual = 1 << 8; -CPBinarySearchingLastEqual = 1 << 9; -CPBinarySearchingInsertionIndex = 1 << 10; - -var concat = Array.prototype.concat, - join = Array.prototype.join, - push = Array.prototype.push; - -#define FORWARD_TO_CONCRETE_CLASS()\ - if (self === _CPSharedPlaceholderArray)\ - {\ - arguments[0] = [_CPJavaScriptArray alloc];\ - return objj_msgSend.apply(this, arguments);\ - }\ - return [super init]; - -/*! - @class CPArray - @brief A mutable array backed by a JavaScript Array. - @ingroup foundation - - A mutable array class backed by a JavaScript Array. - There is also a CPMutableArray class, - but it is just a child class of this class with an - empty implementation. All mutable functionality is - implemented directly in CPArray. -*/ -@implementation CPArray : CPObject - -/*! - Returns a new uninitialized CPArray. -*/ -+ (id)alloc -{ - if (self === CPArray || self === CPMutableArray) - return [_CPPlaceholderArray alloc]; - - return [super alloc]; -} - -/*! - Returns a new initialized CPArray. -*/ -+ (id)array -{ - return [[self alloc] init]; -} - -/*! - Creates a new array containing the objects in \c anArray. - @param anArray Objects in this array will be added to the new array - @return a new CPArray of the provided objects -*/ -+ (id)arrayWithArray:(CPArray)anArray -{ - return [[self alloc] initWithArray:anArray]; -} - -/*! - Creates a new array with \c anObject in it. - @param anObject the object to be added to the array - @return a new CPArray containing a single object -*/ -+ (id)arrayWithObject:(id)anObject -{ - return [[self alloc] initWithObjects:anObject]; -} - -/*! - Creates a new CPArray containing all the objects passed as arguments to the method. - @param anObject the objects that will be added to the new array - @return a new CPArray containing the argument objects -*/ -+ (id)arrayWithObjects:(id)anObject, ... -{ - arguments[0] = [self alloc]; - arguments[1] = @selector(initWithObjects:); - - return objj_msgSend.apply(this, arguments); -} - -/*! - Creates a CPArray from a JavaScript array of objects. - @param objects the JavaScript Array - @param aCount the number of objects in the JS Array - @return a new CPArray containing the specified objects -*/ -+ (id)arrayWithObjects:(id)objects count:(unsigned)aCount -{ - return [[self alloc] initWithObjects:objects count:aCount]; -} - -/*! - Initializes the CPArray. - @return the initialized array -*/ -- (id)init -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -// Creating an Array -/*! - Creates a new CPArray from \c anArray. - @param anArray objects in this array will be added to the new array - @return a new CPArray containing the objects of \c anArray -*/ -- (id)initWithArray:(CPArray)anArray -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -/*! - Initializes a the array with the contents of \c anArray - and optionally performs a deep copy of the objects based on \c copyItems. - @param anArray the array to copy the data from - @param shouldCopyItems if \c YES, each object will be copied by having a \c -copy message - sent to it, and the returned object will be added to the receiver. Otherwise, no copying will be performed. - @return the initialized array of objects -*/ -- (id)initWithArray:(CPArray)anArray copyItems:(BOOL)shouldCopyItems -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -/*! - initializes an array with the contents of anArray -*/ -- (id)initWithObjects:(id)anObject, ... -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -/*! - Initializes the array with a JavaScript array of objects. - @param objects the array of objects to add to the receiver - @param aCount the number of objects in \c objects - @return the initialized CPArray -*/ -- (id)initWithObjects:(id)objects count:(unsigned)aCount -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -// FIXME: This should be defined in CPMutableArray, not here. -- (id)initWithCapacity:(unsigned)aCapacity -{ - FORWARD_TO_CONCRETE_CLASS(); -} - -// Querying an array -/*! - Returns \c YES if the array contains \c anObject. Otherwise, it returns \c NO. - @param anObject the method checks if this object is already in the array -*/ -- (BOOL)containsObject:(id)anObject -{ - return [self indexOfObject:anObject] !== CPNotFound; -} - -- (BOOL)containsObjectIdenticalTo:(id)anObject -{ - return [self indexOfObjectIdenticalTo:anObject] !== CPNotFound; -} - -/*! - Returns the number of elements in the array -*/ -- (int)count -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); -} - -/*! - Returns the first object in the array. If the array is empty, returns \c nil -*/ -- (id)firstObject -{ - var count = [self count]; - - if (count > 0) - return [self objectAtIndex:0]; - - return nil; -} - -/*! - Returns the last object in the array. If the array is empty, returns \c nil -*/ -- (id)lastObject -{ - var count = [self count]; - - if (count <= 0) - return nil; - - return [self objectAtIndex:count - 1]; -} - -/*! - Returns the object at index \c anIndex. - @throws CPRangeException if \c anIndex is out of bounds -*/ -- (id)objectAtIndex:(int)anIndex -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); -} - -/*! - Returns the objects at \c indexes in a new CPArray. - @param indexes the set of indices - @throws CPRangeException if any of the indices is greater than or equal to the length of the array -*/ -- (CPArray)objectsAtIndexes:(CPIndexSet)indexes -{ - var index = CPNotFound, - objects = []; - - while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound) - objects.push([self objectAtIndex:index]); - - return objects; -} - -/*! - Returns an enumerator describing the array sequentially - from the first to the last element. You should not modify - the array during enumeration. -*/ -- (CPEnumerator)objectEnumerator -{ - return [[_CPArrayEnumerator alloc] initWithArray:self]; -} - -/*! - Returns an enumerator describing the array sequentially - from the last to the first element. You should not modify - the array during enumeration. -*/ -- (CPEnumerator)reverseObjectEnumerator -{ - return [[_CPReverseArrayEnumerator alloc] initWithArray:self]; -} - -/*! - Returns the index of \c anObject in this array. - If the object is not in the array, - returns \c CPNotFound. It first attempts to find - a match using \c -isEqual:, then \c ===. - @param anObject the object to search for -*/ -- (CPUInteger)indexOfObject:(id)anObject -{ - return [self indexOfObject:anObject inRange:nil]; -} - -/*! - Returns the index of \c anObject in the array - within \c aRange. It first attempts to find - a match using \c -isEqual:, then \c ===. - @param anObject the object to search for - @param aRange the range to search within - @return the index of the object, or \c CPNotFound if it was not found. -*/ -- (CPUInteger)indexOfObject:(id)anObject inRange:(CPRange)aRange -{ - // Only use isEqual: if our object is a CPObject. - if (anObject && anObject.isa) - { - var index = aRange ? aRange.location : 0, - count = aRange ? CPMaxRange(aRange) : [self count]; - - for (; index < count; ++index) - if ([[self objectAtIndex:index] isEqual:anObject]) - return index; - - return CPNotFound; - } - - return [self indexOfObjectIdenticalTo:anObject inRange:aRange]; -} - -/*! - Returns the index of \c anObject in the array. The test for equality is done using only \c ===. - @param anObject the object to search for - @return the index of the object in the array. \c CPNotFound if the object is not in the array. -*/ -- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject -{ - return [self indexOfObjectIdenticalTo:anObject inRange:nil]; -} - -/*! - Returns the index of \c anObject in the array - within \c aRange. The test for equality is - done using only \c ==. - @param anObject the object to search for - @param aRange the range to search within - @return the index of the object, or \c CPNotFound if it was not found. -*/ -- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange -{ - var index = aRange ? aRange.location : 0, - count = aRange ? CPMaxRange(aRange) : [self count]; - - for (; index < count; ++index) - if ([self objectAtIndex:index] === anObject) - return index; - - return CPNotFound; -} - -/*! - Returns the index of the first object in the receiver that passes a test in a given Javascript function. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return \c CPNotFound to the sender. - @return The index of the first matching object, or \c CPNotFound if there is no matching object. -*/ -- (unsigned)indexOfObjectPassingTest:(Function /*(id anObject, int idx)*/)aPredicate -{ - return [self indexOfObjectWithOptions:CPEnumerationNormal passingTest:aPredicate context:undefined]; -} - -/*! - Returns the index of the first object in the receiver that passes a test in a given Javascript function. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index, context) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return \c CPNotFound to the sender. - @param context An object that contains context information you want passed to the predicate function. - @return The index of the first matching object, or \c CPNotFound if there is no matching object. -*/ -- (unsigned)indexOfObjectPassingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext -{ - return [self indexOfObjectWithOptions:CPEnumerationNormal passingTest:aPredicate context:aContext]; -} - -/*! - Returns the index of the first object in the receiver that passes a test in a given Javascript function. - @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards - or CPEnumerationReverse to search in reverse. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return CPNotFound to the sender. - @return The index of the first matching object, or \c CPNotFound if there is no matching object. -*/ -- (unsigned)indexOfObjectWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx)*/)aPredicate -{ - return [self indexOfObjectWithOptions:options passingTest:aPredicate context:undefined]; -} - -/*! - Returns the index of the first object in the receiver that passes a test in a given Javascript function. - @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards - or CPEnumerationReverse to search in reverse. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index, context) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return CPNotFound to the sender. - @param context An object that contains context information you want passed to the predicate function. - @return The index of the first matching object, or \c CPNotFound if there is no matching object. -*/ -- (unsigned)indexOfObjectWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext -{ - // We don't use an enumerator because they return nil to indicate end of enumeration, - // but nil may actually be the value we are looking for, so we have to loop over the array. - if (options & CPEnumerationReverse) - { - var index = [self count] - 1, - stop = -1, - increment = -1; - } - else - { - var index = 0, - stop = [self count], - increment = 1; - } - - for (; index !== stop; index += increment) - if (aPredicate([self objectAtIndex:index], index, aContext)) - return index; - - return CPNotFound; -} - -- (CPUInteger)indexOfObject:(id)anObject - inSortedRange:(CPRange)aRange - options:(CPBinarySearchingOptions)options - usingComparator:(Function)aComparator -{ - // FIXME: comparator is not a function - if (!aComparator) - _CPRaiseInvalidArgumentException(self, _cmd, "comparator is nil"); - - if ((options & CPBinarySearchingFirstEqual) && (options & CPBinarySearchingLastEqual)) - _CPRaiseInvalidArgumentException(self, _cmd, - "both CPBinarySearchingFirstEqual and CPBinarySearchingLastEqual options cannot be specified"); - - var count = [self count]; - - if (count <= 0) - return (options & CPBinarySearchingInsertionIndex) ? 0 : CPNotFound; - - var first = aRange ? aRange.location : 0, - last = (aRange ? CPMaxRange(aRange) : [self count]) - 1; - - if (first < 0) - _CPRaiseRangeException(self, _cmd, first, count); - - if (last >= count) - _CPRaiseRangeException(self, _cmd, last, count); - - while (first <= last) - { - var middle = FLOOR((first + last) / 2), - result = aComparator(anObject, [self objectAtIndex:middle]); - - if (result > 0) - first = middle + 1; - - else if (result < 0) - last = middle - 1; - - else - { - if (options & CPBinarySearchingFirstEqual) - while (middle > first && aComparator(anObject, [self objectAtIndex:middle - 1]) === CPOrderedSame) - --middle; - - else if (options & CPBinarySearchingLastEqual) - { - while (middle < last && aComparator(anObject, [self objectAtIndex:middle + 1]) === CPOrderedSame) - ++middle; - - if (options & CPBinarySearchingInsertionIndex) - ++middle; - } - - return middle; - } - } - - if (options & CPBinarySearchingInsertionIndex) - return MAX(first, 0); - - return CPNotFound; -} - -/*! - Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return \c CPNotFound to the sender. - @return A CPIndexSet of the matching object indexes. -*/ -- (CPIndexSet)indexesOfObjectsPassingTest:(Function /*(id anObject, int idx)*/)aPredicate -{ - return [self indexesOfObjectsWithOptions:CPEnumerationNormal passingTest:aPredicate context:undefined]; -} - -/*! - Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index, context) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return \c CPNotFound to the sender. - @param context An object that contains context information you want passed to the predicate function. - @return A CPIndexSet of the matching object indexes. -*/ -- (CPIndexSet)indexesOfObjectsPassingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext -{ - return [self indexesOfObjectsWithOptions:CPEnumerationNormal passingTest:aPredicate context:aContext]; -} - -/*! - Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. - @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards - or CPEnumerationReverse to search in reverse. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return CPNotFound to the sender. - @return A CPIndexSet of the matching object indexes. -*/ -- (CPIndexSet)indexesOfObjectsWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx)*/)aPredicate -{ - return [self indexesOfObjectsWithOptions:options passingTest:aPredicate context:undefined]; -} - -/*! - Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. - @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards - or CPEnumerationReverse to search in reverse. - @param predicate The function to apply to objects of the array. The function should have the signature: - @code function(object, index, context) @endcode - The predicate function should either return a Boolean value that indicates whether the object passed the test, - or nil to stop the search, which will return CPNotFound to the sender. - @param context An object that contains context information you want passed to the predicate function. - @return A CPIndexSet of the matching object indexes. -*/ -- (CPIndexSet)indexesOfObjectsWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext -{ - // We don't use an enumerator because they return nil to indicate end of enumeration, - // but nil may actually be the value we are looking for, so we have to loop over the array. - if (options & CPEnumerationReverse) - { - var index = [self count] - 1, - stop = -1, - increment = -1; - } - else - { - var index = 0, - stop = [self count], - increment = 1; - } - - var indexes = [CPIndexSet indexSet]; - - for (; index !== stop; index += increment) - if (aPredicate([self objectAtIndex:index], index, aContext)) - [indexes addIndex:index]; - - return indexes; -} - -// Sending messages to elements -/*! - Sends each element in the array a message. - @param aSelector the selector of the message to send - @throws CPInvalidArgumentException if \c aSelector is \c nil -*/ -- (void)makeObjectsPerformSelector:(SEL)aSelector -{ - [self makeObjectsPerformSelector:aSelector withObjects:nil]; -} - -/*! - Sends each element in the array a message with an argument. - @param aSelector the selector of the message to send - @param anObject the first argument of the message - @throws CPInvalidArgumentException if \c aSelector is \c nil -*/ -- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject -{ - return [self makeObjectsPerformSelector:aSelector withObjects:[anObject]]; -} - -- (void)makeObjectsPerformSelector:(SEL)aSelector withObjects:(CPArray)objects -{ - if (!aSelector) - [CPException raise:CPInvalidArgumentException - reason:"makeObjectsPerformSelector:withObjects: 'aSelector' can't be nil"]; - - var index = 0, - count = [self count]; - - if ([objects count]) - { - var argumentsArray = [[nil, aSelector] arrayByAddingObjectsFromArray:objects]; - - for (; index < count; ++index) - { - argumentsArray[0] = [self objectAtIndex:index]; - objj_msgSend.apply(this, argumentsArray); - } - } - - else - for (; index < count; ++index) - objj_msgSend([self objectAtIndex:index], aSelector); -} - -- (void)enumerateObjectsUsingBlock:(Function /*(id anObject, int idx, @ref BOOL stop)*/)aFunction -{ - // This could have been [self enumerateObjectsWithOptions:CPEnumerationNormal usingBlock:aFunction] - // but this method should be as fast as possible. - var index = 0, - count = [self count], - shouldStop = NO, - shouldStopRef = AT_REF(shouldStop); - - for (; index < count; ++index) - { - aFunction([self objectAtIndex:index], index, shouldStopRef); - if (shouldStop) - return; - } -} - -- (void)enumerateObjectsWithOptions:(CPEnumerationOptions)options usingBlock:(Function /*(id anObject, int idx, @ref BOOL stop)*/)aFunction -{ - var shouldStop = NO; - - if (options & CPEnumerationReverse) - { - var index = [self count] - 1, - stop = -1, - increment = -1; - } - else - { - var index = 0, - stop = [self count], - increment = 1; - } - - for (; index !== stop; index += increment) - { - aFunction([self objectAtIndex:index], index, AT_REF(shouldStop)); - if (shouldStop) - return; - } -} - -// Comparing arrays -/*! - Returns the first object found in the receiver (starting at index 0) which is present in the - \c otherArray as determined by using the \c -containsObject: method. - @return the first object found, or \c nil if no common object was found. -*/ -- (id)firstObjectCommonWithArray:(CPArray)anArray -{ - var count = [self count]; - - if (![anArray count] || !count) - return nil; - - var index = 0; - - for (; index < count; ++index) - { - var object = [self objectAtIndex:index]; - - if ([anArray containsObject:object]) - return object; - } - - return nil; -} - -/*! - Returns true if anArray contains exactly the same objects as the receiver. -*/ -- (BOOL)isEqualToArray:(id)anArray -{ - if (self === anArray) - return YES; - - if (![anArray isKindOfClass:CPArray]) - return NO; - - var count = [self count], - otherCount = [anArray count]; - - if (anArray === nil || count !== otherCount) - return NO; - - var index = 0; - - for (; index < count; ++index) - { - var lhs = [self objectAtIndex:index], - rhs = [anArray objectAtIndex:index]; - - // If they're not equal, and either doesn't have an isa, or they're !isEqual (not isEqual) - if (lhs !== rhs && (lhs && !lhs.isa || rhs && !rhs.isa || ![lhs isEqual:rhs])) - return NO; - } - - return YES; -} - -- (BOOL)isEqual:(id)anObject -{ - return (self === anObject) || [self isEqualToArray:anObject]; -} - -- (Array)_javaScriptArrayCopy -{ - var index = 0, - count = [self count], - copy = []; - - for (; index < count; ++index) - push.call(copy, [self objectAtIndex:index]); - - return copy; -} - -// Deriving new arrays -/*! - Returns a copy of this array plus \c anObject inside the copy. - @param anObject the object to be added to the array copy - @throws CPInvalidArgumentException if \c anObject is \c nil - @return a new array that should be n+1 in size compared to the receiver. -*/ -- (CPArray)arrayByAddingObject:(id)anObject -{ - var argumentArray = [self _javaScriptArrayCopy]; - - // We push instead of concat,because concat flattens arrays, so if the object - // passed in is an array, we end up with its contents added instead of itself. - push.call(argumentArray, anObject); - - return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); -} - -/*! - Returns a new array which is the concatenation of \c self and otherArray (in this precise order). - @param anArray the array that will be concatenated to the receiver's copy -*/ -- (CPArray)arrayByAddingObjectsFromArray:(CPArray)anArray -{ - if (!anArray) - return [self copy]; - - var anArray = anArray.isa === _CPJavaScriptArray ? anArray : [anArray _javaScriptArrayCopy], - argumentArray = concat.call([self _javaScriptArrayCopy], anArray); - - return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); -} - -/* -- (CPArray)filteredArrayUsingPredicate:(CPPredicate)aPredicate -{ - var i= 0, - count = [self count], - array = [CPArray array]; - - for (; i self.length) - [CPException raise:CPRangeException reason:"subarrayWithRange: aRange out of bounds"]; - - var index = aRange.location, - count = CPMaxRange(aRange), - argumentArray = []; - - for (; index < count; ++index) - push.call(argumentArray, [self objectAtIndex:index]); - - return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); -} - -// Sorting arrays -/* - Not yet described. -*/ -- (CPArray)sortedArrayUsingDescriptors:(CPArray)descriptors -{ - var sorted = [self copy]; - - [sorted sortUsingDescriptors:descriptors]; - - return sorted; -} - -/*! - Return a copy of the receiver sorted using the function passed into the first parameter. -*/ -- (CPArray)sortedArrayUsingFunction:(Function)aFunction -{ - return [self sortedArrayUsingFunction:aFunction context:nil]; -} - -/*! - Returns an array in which the objects are ordered according - to a sort with \c aFunction. This invokes - \c -sortUsingFunction:context. - @param aFunction a JavaScript 'Function' type that compares objects - @param aContext context information - @return a new sorted array -*/ -- (CPArray)sortedArrayUsingFunction:(Function)aFunction context:(id)aContext -{ - var sorted = [self copy]; - - [sorted sortUsingFunction:aFunction context:aContext]; - - return sorted; -} - -/*! - Returns a new array in which the objects are ordered according to a sort with \c aSelector. - @param aSelector the selector that will perform object comparisons -*/ -- (CPArray)sortedArrayUsingSelector:(SEL)aSelector -{ - var sorted = [self copy]; - - [sorted sortUsingSelector:aSelector]; - - return sorted; -} - -// Working with string elements - -/*! - Returns a string formed by concatenating the objects in the - receiver, with the specified separator string inserted between each part. - If the element is a Objective-J object, then the \c -description - of that object will be used, otherwise the default JavaScript representation will be used. - @param aString the separator that will separate each object string - @return the string representation of the array -*/ -- (CPString)componentsJoinedByString:(CPString)aString -{ - return join.call([self _javaScriptArrayCopy], aString); -} - -// Creating a description of the array - -/*! - Returns a human readable description of this array and it's elements. -*/ -- (CPString)description -{ - var index = 0, - count = [self count], - description = "@["; - - for (; index < count; ++index) - { - if (index === 0) - description += "\n\t"; - - var object = [self objectAtIndex:index]; - description += CPDescriptionOfObject(object); - - if (index !== count - 1) - description += ",\n\t"; - else - description += "\n"; - } - - return description + "]"; -} - -// Collecting paths -/*! - Returns a new array subset formed by selecting the elements that have - filename extensions from \c filterTypes. Only elements - that are of type CPString are candidates for inclusion in the returned array. - @param filterTypes an array of CPString objects that contain file extensions (without the '.') - @return a new array with matching paths -*/ -- (CPArray)pathsMatchingExtensions:(CPArray)filterTypes -{ - var index = 0, - count = [self count], - array = []; - - for (; index < count; ++index) - if (self[index].isa && [self[index] isKindOfClass:[CPString class]] && [filterTypes containsObject:[self[index] pathExtension]]) - array.push(self[index]); - - return array; -} - -// Copying arrays - -/*! - Makes a copy of the receiver. - @return a new CPArray copy -*/ -- (id)copy -{ - return [[self class] arrayWithArray:self]; -} - -@end - -@implementation CPArray (CPCoding) - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [aCoder decodeObjectForKey:@"CP.objects"]; -} - -- (void)encodeWithCoder:(CPCoder)aCoder -{ - [aCoder _encodeArrayOfObjects:self forKey:@"CP.objects"]; -} - -@end - -/* @ignore */ -@implementation _CPArrayEnumerator : CPEnumerator -{ - CPArray _array; - int _index; -} - -- (id)initWithArray:(CPArray)anArray -{ - self = [super init]; - - if (self) - { - _array = anArray; - _index = -1; - } - - return self; -} - -- (id)nextObject -{ - if (++_index >= [_array count]) - return nil; - - return [_array objectAtIndex:_index]; -} - -@end - -/* @ignore */ -@implementation _CPReverseArrayEnumerator : CPEnumerator -{ - CPArray _array; - int _index; -} - -- (id)initWithArray:(CPArray)anArray -{ - self = [super init]; - - if (self) - { - _array = anArray; - _index = [_array count]; - } - - return self; -} - -- (id)nextObject -{ - if (--_index < 0) - return nil; - - return [_array objectAtIndex:_index]; -} - -@end - -var _CPSharedPlaceholderArray = nil; - -@implementation _CPPlaceholderArray : CPArray -{ -} - -+ (id)alloc -{ - if (!_CPSharedPlaceholderArray) - _CPSharedPlaceholderArray = [super alloc]; - - return _CPSharedPlaceholderArray; -} - -@end - -//@import "_CPJavaScriptArray.j" +@import "_CPArray.j" +@import "_CPJavaScriptArray.j" diff --git a/Foundation/CPArray/CPMutableArray.j b/Foundation/CPArray/CPMutableArray.j index 30621c022..f950e3a6a 100644 --- a/Foundation/CPArray/CPMutableArray.j +++ b/Foundation/CPArray/CPMutableArray.j @@ -1,5 +1,5 @@ -@import "CPArray.j" +@import "_CPArray.j" /*! diff --git a/Foundation/CPArray/_CPArray.j b/Foundation/CPArray/_CPArray.j new file mode 100755 index 000000000..2f38e3faf --- /dev/null +++ b/Foundation/CPArray/_CPArray.j @@ -0,0 +1,1018 @@ +/* + * CPArray.j + * Foundation + * + * Created by Francisco Tolmasky. + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import "CPEnumerator.j" +@import "CPException.j" +@import "CPObject.j" +@import "CPRange.j" +@import "CPSortDescriptor.j" + + +CPEnumerationNormal = 0; +CPEnumerationConcurrent = 1 << 0; +CPEnumerationReverse = 1 << 1; + +CPBinarySearchingFirstEqual = 1 << 8; +CPBinarySearchingLastEqual = 1 << 9; +CPBinarySearchingInsertionIndex = 1 << 10; + +var concat = Array.prototype.concat, + join = Array.prototype.join, + push = Array.prototype.push; + +#define FORWARD_TO_CONCRETE_CLASS()\ + if (self === _CPSharedPlaceholderArray)\ + {\ + arguments[0] = [_CPJavaScriptArray alloc];\ + return objj_msgSend.apply(this, arguments);\ + }\ + return [super init]; + +/*! + @class CPArray + @brief A mutable array backed by a JavaScript Array. + @ingroup foundation + + A mutable array class backed by a JavaScript Array. + There is also a CPMutableArray class, + but it is just a child class of this class with an + empty implementation. All mutable functionality is + implemented directly in CPArray. +*/ +@implementation CPArray : CPObject + +/*! + Returns a new uninitialized CPArray. +*/ ++ (id)alloc +{ + if (self === CPArray || self === CPMutableArray) + return [_CPPlaceholderArray alloc]; + + return [super alloc]; +} + +/*! + Returns a new initialized CPArray. +*/ ++ (id)array +{ + return [[self alloc] init]; +} + +/*! + Creates a new array containing the objects in \c anArray. + @param anArray Objects in this array will be added to the new array + @return a new CPArray of the provided objects +*/ ++ (id)arrayWithArray:(CPArray)anArray +{ + return [[self alloc] initWithArray:anArray]; +} + +/*! + Creates a new array with \c anObject in it. + @param anObject the object to be added to the array + @return a new CPArray containing a single object +*/ ++ (id)arrayWithObject:(id)anObject +{ + return [[self alloc] initWithObjects:anObject]; +} + +/*! + Creates a new CPArray containing all the objects passed as arguments to the method. + @param anObject the objects that will be added to the new array + @return a new CPArray containing the argument objects +*/ ++ (id)arrayWithObjects:(id)anObject, ... +{ + arguments[0] = [self alloc]; + arguments[1] = @selector(initWithObjects:); + + return objj_msgSend.apply(this, arguments); +} + +/*! + Creates a CPArray from a JavaScript array of objects. + @param objects the JavaScript Array + @param aCount the number of objects in the JS Array + @return a new CPArray containing the specified objects +*/ ++ (id)arrayWithObjects:(id)objects count:(unsigned)aCount +{ + return [[self alloc] initWithObjects:objects count:aCount]; +} + +/*! + Initializes the CPArray. + @return the initialized array +*/ +- (id)init +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +// Creating an Array +/*! + Creates a new CPArray from \c anArray. + @param anArray objects in this array will be added to the new array + @return a new CPArray containing the objects of \c anArray +*/ +- (id)initWithArray:(CPArray)anArray +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +/*! + Initializes a the array with the contents of \c anArray + and optionally performs a deep copy of the objects based on \c copyItems. + @param anArray the array to copy the data from + @param shouldCopyItems if \c YES, each object will be copied by having a \c -copy message + sent to it, and the returned object will be added to the receiver. Otherwise, no copying will be performed. + @return the initialized array of objects +*/ +- (id)initWithArray:(CPArray)anArray copyItems:(BOOL)shouldCopyItems +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +/*! + initializes an array with the contents of anArray +*/ +- (id)initWithObjects:(id)anObject, ... +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +/*! + Initializes the array with a JavaScript array of objects. + @param objects the array of objects to add to the receiver + @param aCount the number of objects in \c objects + @return the initialized CPArray +*/ +- (id)initWithObjects:(id)objects count:(unsigned)aCount +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +// FIXME: This should be defined in CPMutableArray, not here. +- (id)initWithCapacity:(unsigned)aCapacity +{ + FORWARD_TO_CONCRETE_CLASS(); +} + +// Querying an array +/*! + Returns \c YES if the array contains \c anObject. Otherwise, it returns \c NO. + @param anObject the method checks if this object is already in the array +*/ +- (BOOL)containsObject:(id)anObject +{ + return [self indexOfObject:anObject] !== CPNotFound; +} + +- (BOOL)containsObjectIdenticalTo:(id)anObject +{ + return [self indexOfObjectIdenticalTo:anObject] !== CPNotFound; +} + +/*! + Returns the number of elements in the array +*/ +- (int)count +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); +} + +/*! + Returns the first object in the array. If the array is empty, returns \c nil +*/ +- (id)firstObject +{ + var count = [self count]; + + if (count > 0) + return [self objectAtIndex:0]; + + return nil; +} + +/*! + Returns the last object in the array. If the array is empty, returns \c nil +*/ +- (id)lastObject +{ + var count = [self count]; + + if (count <= 0) + return nil; + + return [self objectAtIndex:count - 1]; +} + +/*! + Returns the object at index \c anIndex. + @throws CPRangeException if \c anIndex is out of bounds +*/ +- (id)objectAtIndex:(int)anIndex +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); +} + +/*! + Returns the objects at \c indexes in a new CPArray. + @param indexes the set of indices + @throws CPRangeException if any of the indices is greater than or equal to the length of the array +*/ +- (CPArray)objectsAtIndexes:(CPIndexSet)indexes +{ + var index = CPNotFound, + objects = []; + + while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound) + objects.push([self objectAtIndex:index]); + + return objects; +} + +/*! + Returns an enumerator describing the array sequentially + from the first to the last element. You should not modify + the array during enumeration. +*/ +- (CPEnumerator)objectEnumerator +{ + return [[_CPArrayEnumerator alloc] initWithArray:self]; +} + +/*! + Returns an enumerator describing the array sequentially + from the last to the first element. You should not modify + the array during enumeration. +*/ +- (CPEnumerator)reverseObjectEnumerator +{ + return [[_CPReverseArrayEnumerator alloc] initWithArray:self]; +} + +/*! + Returns the index of \c anObject in this array. + If the object is not in the array, + returns \c CPNotFound. It first attempts to find + a match using \c -isEqual:, then \c ===. + @param anObject the object to search for +*/ +- (CPUInteger)indexOfObject:(id)anObject +{ + return [self indexOfObject:anObject inRange:nil]; +} + +/*! + Returns the index of \c anObject in the array + within \c aRange. It first attempts to find + a match using \c -isEqual:, then \c ===. + @param anObject the object to search for + @param aRange the range to search within + @return the index of the object, or \c CPNotFound if it was not found. +*/ +- (CPUInteger)indexOfObject:(id)anObject inRange:(CPRange)aRange +{ + // Only use isEqual: if our object is a CPObject. + if (anObject && anObject.isa) + { + var index = aRange ? aRange.location : 0, + count = aRange ? CPMaxRange(aRange) : [self count]; + + for (; index < count; ++index) + if ([[self objectAtIndex:index] isEqual:anObject]) + return index; + + return CPNotFound; + } + + return [self indexOfObjectIdenticalTo:anObject inRange:aRange]; +} + +/*! + Returns the index of \c anObject in the array. The test for equality is done using only \c ===. + @param anObject the object to search for + @return the index of the object in the array. \c CPNotFound if the object is not in the array. +*/ +- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject +{ + return [self indexOfObjectIdenticalTo:anObject inRange:nil]; +} + +/*! + Returns the index of \c anObject in the array + within \c aRange. The test for equality is + done using only \c ==. + @param anObject the object to search for + @param aRange the range to search within + @return the index of the object, or \c CPNotFound if it was not found. +*/ +- (CPUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(CPRange)aRange +{ + var index = aRange ? aRange.location : 0, + count = aRange ? CPMaxRange(aRange) : [self count]; + + for (; index < count; ++index) + if ([self objectAtIndex:index] === anObject) + return index; + + return CPNotFound; +} + +/*! + Returns the index of the first object in the receiver that passes a test in a given Javascript function. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return \c CPNotFound to the sender. + @return The index of the first matching object, or \c CPNotFound if there is no matching object. +*/ +- (unsigned)indexOfObjectPassingTest:(Function /*(id anObject, int idx)*/)aPredicate +{ + return [self indexOfObjectWithOptions:CPEnumerationNormal passingTest:aPredicate context:undefined]; +} + +/*! + Returns the index of the first object in the receiver that passes a test in a given Javascript function. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index, context) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return \c CPNotFound to the sender. + @param context An object that contains context information you want passed to the predicate function. + @return The index of the first matching object, or \c CPNotFound if there is no matching object. +*/ +- (unsigned)indexOfObjectPassingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext +{ + return [self indexOfObjectWithOptions:CPEnumerationNormal passingTest:aPredicate context:aContext]; +} + +/*! + Returns the index of the first object in the receiver that passes a test in a given Javascript function. + @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards + or CPEnumerationReverse to search in reverse. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return CPNotFound to the sender. + @return The index of the first matching object, or \c CPNotFound if there is no matching object. +*/ +- (unsigned)indexOfObjectWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx)*/)aPredicate +{ + return [self indexOfObjectWithOptions:options passingTest:aPredicate context:undefined]; +} + +/*! + Returns the index of the first object in the receiver that passes a test in a given Javascript function. + @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards + or CPEnumerationReverse to search in reverse. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index, context) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return CPNotFound to the sender. + @param context An object that contains context information you want passed to the predicate function. + @return The index of the first matching object, or \c CPNotFound if there is no matching object. +*/ +- (unsigned)indexOfObjectWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext +{ + // We don't use an enumerator because they return nil to indicate end of enumeration, + // but nil may actually be the value we are looking for, so we have to loop over the array. + if (options & CPEnumerationReverse) + { + var index = [self count] - 1, + stop = -1, + increment = -1; + } + else + { + var index = 0, + stop = [self count], + increment = 1; + } + + for (; index !== stop; index += increment) + if (aPredicate([self objectAtIndex:index], index, aContext)) + return index; + + return CPNotFound; +} + +- (CPUInteger)indexOfObject:(id)anObject + inSortedRange:(CPRange)aRange + options:(CPBinarySearchingOptions)options + usingComparator:(Function)aComparator +{ + // FIXME: comparator is not a function + if (!aComparator) + _CPRaiseInvalidArgumentException(self, _cmd, "comparator is nil"); + + if ((options & CPBinarySearchingFirstEqual) && (options & CPBinarySearchingLastEqual)) + _CPRaiseInvalidArgumentException(self, _cmd, + "both CPBinarySearchingFirstEqual and CPBinarySearchingLastEqual options cannot be specified"); + + var count = [self count]; + + if (count <= 0) + return (options & CPBinarySearchingInsertionIndex) ? 0 : CPNotFound; + + var first = aRange ? aRange.location : 0, + last = (aRange ? CPMaxRange(aRange) : [self count]) - 1; + + if (first < 0) + _CPRaiseRangeException(self, _cmd, first, count); + + if (last >= count) + _CPRaiseRangeException(self, _cmd, last, count); + + while (first <= last) + { + var middle = FLOOR((first + last) / 2), + result = aComparator(anObject, [self objectAtIndex:middle]); + + if (result > 0) + first = middle + 1; + + else if (result < 0) + last = middle - 1; + + else + { + if (options & CPBinarySearchingFirstEqual) + while (middle > first && aComparator(anObject, [self objectAtIndex:middle - 1]) === CPOrderedSame) + --middle; + + else if (options & CPBinarySearchingLastEqual) + { + while (middle < last && aComparator(anObject, [self objectAtIndex:middle + 1]) === CPOrderedSame) + ++middle; + + if (options & CPBinarySearchingInsertionIndex) + ++middle; + } + + return middle; + } + } + + if (options & CPBinarySearchingInsertionIndex) + return MAX(first, 0); + + return CPNotFound; +} + +/*! + Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return \c CPNotFound to the sender. + @return A CPIndexSet of the matching object indexes. +*/ +- (CPIndexSet)indexesOfObjectsPassingTest:(Function /*(id anObject, int idx)*/)aPredicate +{ + return [self indexesOfObjectsWithOptions:CPEnumerationNormal passingTest:aPredicate context:undefined]; +} + +/*! + Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index, context) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return \c CPNotFound to the sender. + @param context An object that contains context information you want passed to the predicate function. + @return A CPIndexSet of the matching object indexes. +*/ +- (CPIndexSet)indexesOfObjectsPassingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext +{ + return [self indexesOfObjectsWithOptions:CPEnumerationNormal passingTest:aPredicate context:aContext]; +} + +/*! + Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. + @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards + or CPEnumerationReverse to search in reverse. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return CPNotFound to the sender. + @return A CPIndexSet of the matching object indexes. +*/ +- (CPIndexSet)indexesOfObjectsWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx)*/)aPredicate +{ + return [self indexesOfObjectsWithOptions:options passingTest:aPredicate context:undefined]; +} + +/*! + Returns the indexes of the objects in the receiver that pass a test in a given Javascript function. + @param options Specifies the direction in which the array is searched. Pass CPEnumerationNormal to search forwards + or CPEnumerationReverse to search in reverse. + @param predicate The function to apply to objects of the array. The function should have the signature: + @code function(object, index, context) @endcode + The predicate function should either return a Boolean value that indicates whether the object passed the test, + or nil to stop the search, which will return CPNotFound to the sender. + @param context An object that contains context information you want passed to the predicate function. + @return A CPIndexSet of the matching object indexes. +*/ +- (CPIndexSet)indexesOfObjectsWithOptions:(CPEnumerationOptions)options passingTest:(Function /*(id anObject, int idx, id context)*/)aPredicate context:(id)aContext +{ + // We don't use an enumerator because they return nil to indicate end of enumeration, + // but nil may actually be the value we are looking for, so we have to loop over the array. + if (options & CPEnumerationReverse) + { + var index = [self count] - 1, + stop = -1, + increment = -1; + } + else + { + var index = 0, + stop = [self count], + increment = 1; + } + + var indexes = [CPIndexSet indexSet]; + + for (; index !== stop; index += increment) + if (aPredicate([self objectAtIndex:index], index, aContext)) + [indexes addIndex:index]; + + return indexes; +} + +// Sending messages to elements +/*! + Sends each element in the array a message. + @param aSelector the selector of the message to send + @throws CPInvalidArgumentException if \c aSelector is \c nil +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector +{ + [self makeObjectsPerformSelector:aSelector withObjects:nil]; +} + +/*! + Sends each element in the array a message with an argument. + @param aSelector the selector of the message to send + @param anObject the first argument of the message + @throws CPInvalidArgumentException if \c aSelector is \c nil +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject +{ + return [self makeObjectsPerformSelector:aSelector withObjects:[anObject]]; +} + +- (void)makeObjectsPerformSelector:(SEL)aSelector withObjects:(CPArray)objects +{ + if (!aSelector) + [CPException raise:CPInvalidArgumentException + reason:"makeObjectsPerformSelector:withObjects: 'aSelector' can't be nil"]; + + var index = 0, + count = [self count]; + + if ([objects count]) + { + var argumentsArray = [[nil, aSelector] arrayByAddingObjectsFromArray:objects]; + + for (; index < count; ++index) + { + argumentsArray[0] = [self objectAtIndex:index]; + objj_msgSend.apply(this, argumentsArray); + } + } + + else + for (; index < count; ++index) + objj_msgSend([self objectAtIndex:index], aSelector); +} + +- (void)enumerateObjectsUsingBlock:(Function /*(id anObject, int idx, @ref BOOL stop)*/)aFunction +{ + // This could have been [self enumerateObjectsWithOptions:CPEnumerationNormal usingBlock:aFunction] + // but this method should be as fast as possible. + var index = 0, + count = [self count], + shouldStop = NO, + shouldStopRef = AT_REF(shouldStop); + + for (; index < count; ++index) + { + aFunction([self objectAtIndex:index], index, shouldStopRef); + if (shouldStop) + return; + } +} + +- (void)enumerateObjectsWithOptions:(CPEnumerationOptions)options usingBlock:(Function /*(id anObject, int idx, @ref BOOL stop)*/)aFunction +{ + var shouldStop = NO; + + if (options & CPEnumerationReverse) + { + var index = [self count] - 1, + stop = -1, + increment = -1; + } + else + { + var index = 0, + stop = [self count], + increment = 1; + } + + for (; index !== stop; index += increment) + { + aFunction([self objectAtIndex:index], index, AT_REF(shouldStop)); + if (shouldStop) + return; + } +} + +// Comparing arrays +/*! + Returns the first object found in the receiver (starting at index 0) which is present in the + \c otherArray as determined by using the \c -containsObject: method. + @return the first object found, or \c nil if no common object was found. +*/ +- (id)firstObjectCommonWithArray:(CPArray)anArray +{ + var count = [self count]; + + if (![anArray count] || !count) + return nil; + + var index = 0; + + for (; index < count; ++index) + { + var object = [self objectAtIndex:index]; + + if ([anArray containsObject:object]) + return object; + } + + return nil; +} + +/*! + Returns true if anArray contains exactly the same objects as the receiver. +*/ +- (BOOL)isEqualToArray:(id)anArray +{ + if (self === anArray) + return YES; + + if (![anArray isKindOfClass:CPArray]) + return NO; + + var count = [self count], + otherCount = [anArray count]; + + if (anArray === nil || count !== otherCount) + return NO; + + var index = 0; + + for (; index < count; ++index) + { + var lhs = [self objectAtIndex:index], + rhs = [anArray objectAtIndex:index]; + + // If they're not equal, and either doesn't have an isa, or they're !isEqual (not isEqual) + if (lhs !== rhs && (lhs && !lhs.isa || rhs && !rhs.isa || ![lhs isEqual:rhs])) + return NO; + } + + return YES; +} + +- (BOOL)isEqual:(id)anObject +{ + return (self === anObject) || [self isEqualToArray:anObject]; +} + +- (Array)_javaScriptArrayCopy +{ + var index = 0, + count = [self count], + copy = []; + + for (; index < count; ++index) + push.call(copy, [self objectAtIndex:index]); + + return copy; +} + +// Deriving new arrays +/*! + Returns a copy of this array plus \c anObject inside the copy. + @param anObject the object to be added to the array copy + @throws CPInvalidArgumentException if \c anObject is \c nil + @return a new array that should be n+1 in size compared to the receiver. +*/ +- (CPArray)arrayByAddingObject:(id)anObject +{ + var argumentArray = [self _javaScriptArrayCopy]; + + // We push instead of concat,because concat flattens arrays, so if the object + // passed in is an array, we end up with its contents added instead of itself. + push.call(argumentArray, anObject); + + return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); +} + +/*! + Returns a new array which is the concatenation of \c self and otherArray (in this precise order). + @param anArray the array that will be concatenated to the receiver's copy +*/ +- (CPArray)arrayByAddingObjectsFromArray:(CPArray)anArray +{ + if (!anArray) + return [self copy]; + + var anArray = anArray.isa === _CPJavaScriptArray ? anArray : [anArray _javaScriptArrayCopy], + argumentArray = concat.call([self _javaScriptArrayCopy], anArray); + + return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); +} + +/* +- (CPArray)filteredArrayUsingPredicate:(CPPredicate)aPredicate +{ + var i= 0, + count = [self count], + array = [CPArray array]; + + for (; i self.length) + [CPException raise:CPRangeException reason:"subarrayWithRange: aRange out of bounds"]; + + var index = aRange.location, + count = CPMaxRange(aRange), + argumentArray = []; + + for (; index < count; ++index) + push.call(argumentArray, [self objectAtIndex:index]); + + return objj_msgSend([self class], @selector(arrayWithArray:), argumentArray); +} + +// Sorting arrays +/* + Not yet described. +*/ +- (CPArray)sortedArrayUsingDescriptors:(CPArray)descriptors +{ + var sorted = [self copy]; + + [sorted sortUsingDescriptors:descriptors]; + + return sorted; +} + +/*! + Return a copy of the receiver sorted using the function passed into the first parameter. +*/ +- (CPArray)sortedArrayUsingFunction:(Function)aFunction +{ + return [self sortedArrayUsingFunction:aFunction context:nil]; +} + +/*! + Returns an array in which the objects are ordered according + to a sort with \c aFunction. This invokes + \c -sortUsingFunction:context. + @param aFunction a JavaScript 'Function' type that compares objects + @param aContext context information + @return a new sorted array +*/ +- (CPArray)sortedArrayUsingFunction:(Function)aFunction context:(id)aContext +{ + var sorted = [self copy]; + + [sorted sortUsingFunction:aFunction context:aContext]; + + return sorted; +} + +/*! + Returns a new array in which the objects are ordered according to a sort with \c aSelector. + @param aSelector the selector that will perform object comparisons +*/ +- (CPArray)sortedArrayUsingSelector:(SEL)aSelector +{ + var sorted = [self copy]; + + [sorted sortUsingSelector:aSelector]; + + return sorted; +} + +// Working with string elements + +/*! + Returns a string formed by concatenating the objects in the + receiver, with the specified separator string inserted between each part. + If the element is a Objective-J object, then the \c -description + of that object will be used, otherwise the default JavaScript representation will be used. + @param aString the separator that will separate each object string + @return the string representation of the array +*/ +- (CPString)componentsJoinedByString:(CPString)aString +{ + return join.call([self _javaScriptArrayCopy], aString); +} + +// Creating a description of the array + +/*! + Returns a human readable description of this array and it's elements. +*/ +- (CPString)description +{ + var index = 0, + count = [self count], + description = "@["; + + for (; index < count; ++index) + { + if (index === 0) + description += "\n\t"; + + var object = [self objectAtIndex:index]; + description += CPDescriptionOfObject(object); + + if (index !== count - 1) + description += ",\n\t"; + else + description += "\n"; + } + + return description + "]"; +} + +// Collecting paths +/*! + Returns a new array subset formed by selecting the elements that have + filename extensions from \c filterTypes. Only elements + that are of type CPString are candidates for inclusion in the returned array. + @param filterTypes an array of CPString objects that contain file extensions (without the '.') + @return a new array with matching paths +*/ +- (CPArray)pathsMatchingExtensions:(CPArray)filterTypes +{ + var index = 0, + count = [self count], + array = []; + + for (; index < count; ++index) + if (self[index].isa && [self[index] isKindOfClass:[CPString class]] && [filterTypes containsObject:[self[index] pathExtension]]) + array.push(self[index]); + + return array; +} + +// Copying arrays + +/*! + Makes a copy of the receiver. + @return a new CPArray copy +*/ +- (id)copy +{ + return [[self class] arrayWithArray:self]; +} + +@end + +@implementation CPArray (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [aCoder decodeObjectForKey:@"CP.objects"]; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [aCoder _encodeArrayOfObjects:self forKey:@"CP.objects"]; +} + +@end + +/* @ignore */ +@implementation _CPArrayEnumerator : CPEnumerator +{ + CPArray _array; + int _index; +} + +- (id)initWithArray:(CPArray)anArray +{ + self = [super init]; + + if (self) + { + _array = anArray; + _index = -1; + } + + return self; +} + +- (id)nextObject +{ + if (++_index >= [_array count]) + return nil; + + return [_array objectAtIndex:_index]; +} + +@end + +/* @ignore */ +@implementation _CPReverseArrayEnumerator : CPEnumerator +{ + CPArray _array; + int _index; +} + +- (id)initWithArray:(CPArray)anArray +{ + self = [super init]; + + if (self) + { + _array = anArray; + _index = [_array count]; + } + + return self; +} + +- (id)nextObject +{ + if (--_index < 0) + return nil; + + return [_array objectAtIndex:_index]; +} + +@end + +var _CPSharedPlaceholderArray = nil; + +@implementation _CPPlaceholderArray : CPArray +{ +} + ++ (id)alloc +{ + if (!_CPSharedPlaceholderArray) + _CPSharedPlaceholderArray = [super alloc]; + + return _CPSharedPlaceholderArray; +} + +@end + +//@import "_CPJavaScriptArray.j" diff --git a/Foundation/CPDictionary.j b/Foundation/CPDictionary.j index 05933558a..2e600d463 100755 --- a/Foundation/CPDictionary.j +++ b/Foundation/CPDictionary.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "_CPJavaScriptArray.j" +@import "CPArray.j" @import "CPEnumerator.j" @import "CPException.j" @import "CPNull.j" @@ -646,7 +646,7 @@ for (; index < count; ++index) { var key = keys[index], - value = valueForKey(key); + value = self.valueForKey(key); string += "\t" + key + ": " + CPDescriptionOfObject(value).split('\n').join("\n\t") + ",\n"; } @@ -670,7 +670,7 @@ for (var index = 0; index < count; index++) { var key = keys[index], - value = valueForKey(key); + value = self.valueForKey(key); aFunction(key, value, shouldStopRef); diff --git a/Foundation/CPPredicate/CPExpression.j b/Foundation/CPPredicate/CPExpression.j index 5a9561cb7..06ed6b0ba 100644 --- a/Foundation/CPPredicate/CPExpression.j +++ b/Foundation/CPPredicate/CPExpression.j @@ -19,379 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPArray.j" -@import "CPDictionary.j" -@import "CPKeyValueCoding.j" -@import "CPObject.j" -@import "CPString.j" - -/*! - An expression that always returns the same value. -*/ -CPConstantValueExpressionType = 0; -/*! - An expression that always returns the parameter object itself. -*/ -CPEvaluatedObjectExpressionType = 1; -/*! - An expression that always returns whatever value is associated with the key specified by ‘variable’ in the bindings dictionary. -*/ -CPVariableExpressionType = 2; -/*! - An expression that returns something that can be used as a key path. -*/ -CPKeyPathExpressionType = 3; -/*! - An expression that returns the result of evaluating a function. -*/ -CPFunctionExpressionType = 4; -/*! - An expression that defines an aggregate of CPExpression objects. -*/ -CPAggregateExpressionType = 5; -/*! - An expression that filters a collection using a subpredicate. -*/ -CPSubqueryExpressionType = 6; -/*! - An expression that creates a union of the results of two nested expressions. -*/ -CPUnionSetExpressionType = 7; -/*! - An expression that creates an intersection of the results of two nested expressions. -*/ -CPIntersectSetExpressionType = 8; -/*! - An expression that combines two nested expression results by set subtraction. -*/ -CPMinusSetExpressionType = 9; - -/*! - @ingroup foundation - @class CPExpression - @brief CPExpression is used to represent expressions in a predicate. - - Comparison operations in an CPPredicate are based on two expressions, as represented by instances of the CPExpression class. - Expressions are created for constant values, key paths, and so on. - - Generally, anywhere in the CPExpression class hierarchy where there is composite API and subtypes - that may only reasonably respond to a subset of that API, invoking a method that does not make sense - for that subtype will cause an exception to be thrown. -*/ - -@implementation CPExpression : CPObject -{ - int _type; -} - -// Initializing an Expression -/*! - Initializes the receiver with the specified expression type. - @param type The type of the new expression, as defined by CPExpressionType. - @return An initialized CPExpression object of the type type. -*/ -- (id)initWithExpressionType:(int)type -{ - _type = type; - - return self; -} - -//Creating an Expression for a Value -/*! - Returns a new expression that represents a given constant value. - @param value The constant value the new expression is to represent. - @return A new expression that represents the constant value. -*/ -+ (CPExpression)expressionForConstantValue:(id)value -{ - return [[_CPConstantValueExpression alloc] initWithValue:value]; -} - -/*! - Returns a new expression that represents the object being evaluated. - @return A new expression that represents the object being evaluated. -*/ -+ (CPExpression)expressionForEvaluatedObject -{ - return [_CPSelfExpression evaluatedObject]; -} - -/*! - Returns a new expression that extracts a value from the variable bindings dictionary for a given key. - @param string The key for the variable to extract from the variable bindings dictionary. - @return A new expression that extracts from the variable bindings dictionary the value for the key string. -*/ -+ (CPExpression)expressionForVariable:(CPString)string -{ - return [[_CPVariableExpression alloc] initWithVariable:string]; -} - -/*! - Returns a new expression that invokes valueForKeyPath: with a given key path. - @param keyPath The key path that the new expression should evaluate. - @return A new expression that invokes valueForKeyPath: with keyPath. -*/ -+ (CPExpression)expressionForKeyPath:(CPString)keyPath -{ - return [[_CPKeyPathExpression alloc] initWithKeyPath:keyPath]; -} - -/*! - Returns a new aggregate expression for a given collection. - @param collection A collection object (an instance of CPArray, CPSet, or CPDictionary) that contains further expressions. - @return A new expression that contains the expressions in collection. -*/ -+ (CPExpression)expressionForAggregate:(CPArray)collection -{ - return [[_CPAggregateExpression alloc] initWithAggregate:collection]; -} - -/*! - Returns a new CPExpression object that represent the union of a given set and collection. - @param left An expression that evaluates to a CPSet object. - @param right An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). - @return A new CPExpression object that represents the union of left and right. -*/ -+ (CPExpression)expressionForUnionSet:(CPExpression)left with:(CPExpression)right -{ - return [[_CPSetExpression alloc] initWithType:CPUnionSetExpressionType left:left right:right]; -} - -/*! - Returns a new CPExpression object that represent the intersection of a given set and collection. - @param left An expression that evaluates to a CPSet object. - @param right An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). - @return A new CPExpression object that represents the intersection of left and right. -*/ -+ (CPExpression)expressionForIntersectSet:(CPExpression)left with:(CPExpression)right -{ - return [[_CPSetExpression alloc] initWithType:CPIntersectSetExpressionType left:left right:right]; -} - -/*! - Returns a new CPExpression object that represent the subtraction of a given collection from a given set. - @param left An expression that evaluates to a CPSet object. - @param left An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). - @return A new CPExpression object that represents the subtraction of right from left. -*/ -+ (CPExpression)expressionForMinusSet:(CPExpression)left with:(CPExpression)right -{ - return [[_CPSetExpression alloc] initWithType:CPMinusSetExpressionType left:left right:right]; -} - -// Creating an Expression for a Function -/*! - Returns a new expression that will invoke one of the predefined functions. - @param function_name The name of the function to invoke. - @param parameters An array containing CPExpression objects that will be used as parameters during the invocation of selector. - @return A new expression that invokes the function name using the parameters in parameters. - - For a selector taking no parameters, the array should be empty. For a selector taking one or more parameters, - the array should contain one CPExpression object which will evaluate to an instance of the appropriate type for each parameter. - - If there is a mismatch between the number of parameters expected and the number you provide during evaluation, - an exception may be raised or missing parameters may simply be replaced by nil (which occurs depends on how many - parameters are provided, and whether you have over- or underflow). - - The name parameter can be one of the following predefined functions: - @verbatim - name parameter array contents returns - ------------------------------------------------------------------------------------------------------------------------------------- - sum: CPExpression instances representing numbers CPNumber - count: CPExpression instances representing numbers CPNumber - min: CPExpression instances representing numbers CPNumber - max: CPExpression instances representing numbers CPNumber - average: CPExpression instances representing numbers CPNumber - median: CPExpression instances representing numbers CPNumber - mode: CPExpression instances representing numbers CPArray (returned array will contain all occurrences of the mode) - stddev: CPExpression instances representing numbers CPNumber - add:to: CPExpression instances representing numbers CPNumber - from:subtract: two CPExpression instances representing numbers CPNumber - multiply:by: two CPExpression instances representing numbers CPNumber - divide:by: two CPExpression instances representing numbers CPNumber - modulus:by: two CPExpression instances representing numbers CPNumber - sqrt: one CPExpression instance representing numbers CPNumber - log: one CPExpression instance representing a number CPNumber - ln: one CPExpression instance representing a number CPNumber - raise:toPower: one CPExpression instance representing a number CPNumber - exp: one CPExpression instance representing a number CPNumber - floor: one CPExpression instance representing a number CPNumber - ceiling: one CPExpression instance representing a number CPNumber - abs: one CPExpression instance representing a number CPNumber - trunc: one CPExpression instance representing a number CPNumber - uppercase: one CPExpression instance representing a string CPString - lowercase: one CPExpression instance representing a string CPString - random: one CPExpression instance representing a number CPNumber (integer) such that 0 <= rand < param - now: none [CPDate now] - - This method raises an exception immediately if the selector is invalid; it raises an exception at runtime if the parameters are incorrect. -@endverbatim -*/ -+ (CPExpression)expressionForFunction:(CPString)function_name arguments:(CPArray)parameters -{ - return [[_CPFunctionExpression alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters]; -} - -/*! - Returns an expression which will return the result of invoking on a given target a selector with a given name using given arguments. - @param target A CPExpression object which will evaluate an object on which the selector identified by name may be invoked. - @param selectorName The name of the method to be invoked. - @param parameters An array containing CPExpression objects which can be evaluated to provide parameters for the method specified by name. - @return An expression which will return the result of invoking the selector named name on the result of evaluating the target expression with the parameters specified by evaluating the elements of parameters. - - See the description of \c expressionForFunction:arguments: for examples of how to construct the parameter array. -*/ -+ (CPExpression)expressionForFunction:(CPExpression)target selectorName:(CPString)selectorName arguments:(CPArray)parameters -{ - return [[_CPFunctionExpression alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters]; -} - -/*! - Returns an expression that filters a collection by storing elements in the collection in a given variable and keeping the elements for which qualifier returns true. - @param expression A CPExpression that evaluates to a collection. - @param variable Used as a local variable, and will shadow any instances of variable in the bindings dictionary. The variable is removed or the old value replaced once evaluation completes. - @param predicate The predicate used to determine whether the element belongs in the result collection. - @return An expression that filters a collection by storing elements in the collection in the variable variable and keeping the elements for which qualifier returns true. -*/ -+ (CPExpression)expressionForSubquery:(CPExpression)expression usingIteratorVariable:(CPString)variable predicate:(CPPredicate)predicate -{ - return [[_CPSubqueryExpression alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate]; -} - -// Getting Information About an Expression -/*! - Returns the expression type for the receiver. - @return The expression type for the receiver. - This method raises an exception if it is not applicable to the receiver. -*/ -- (int)expressionType -{ - return _type; -} - -/*! - Returns the constant value of the receiver. - @return The constant value of the receiver. - This method raises an exception if it is not applicable to the receiver. -*/ -- (id)constantValue -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the variable for the receiver. - @return The variable for the receiver. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPString)variable -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the key path for the receiver. - @return The key path for the receiver. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPString)keyPath -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the function for the receiver. - @return The function for the receiver. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPString)function -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the arguments for the receiver. - @return The arguments for the receiver—that is, the array of expressions that will be passed as parameters during invocation of the selector on the operand of a function expression. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPArray)arguments -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the collection of expressions in an aggregate expression, or the collection element of a subquery expression. - @return The collection of expressions in an aggregate expression, or the collection element of a subquery expression. - This method raises an exception if it is not applicable to the receiver. -*/ -- (id)collection -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the predicate in a subquery expression. - @return The predicate in a subquery expression.. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPPredicate)predicate -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the operand for the receiver. - @return The operand for the receiver—that is, the object on which the selector will be invoked. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPExpression)operand -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the left expression of a set expression. - @return The left expression of a set expression. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPExpression)leftExpression -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -/*! - Returns the right expression of a set expression. - @return The right expression of a set expression. - This method raises an exception if it is not applicable to the receiver. -*/ -- (CPExpression)rightExpression -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); - return nil; -} - -- (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables -{ - return self; -} - -@end - -//@import "_CPConstantValueExpression.j" -//@import "_CPSelfExpression.j" -//@import "_CPVariableExpression.j" -//@import "_CPKeyPathExpression.j" -//@import "_CPFunctionExpression.j" -//@import "_CPAggregateExpression.j" -//@import "_CPSetExpression.j" -//@import "_CPSubqueryExpression.j" +@import "_CPExpression.j" +@import "_CPConstantValueExpression.j" +@import "_CPSelfExpression.j" +@import "_CPVariableExpression.j" +@import "_CPKeyPathExpression.j" +@import "_CPFunctionExpression.j" +@import "_CPAggregateExpression.j" +@import "_CPSetExpression.j" +@import "_CPSubqueryExpression.j" diff --git a/Foundation/CPPredicate/CPPredicate.j b/Foundation/CPPredicate/CPPredicate.j index 3a97a1a1c..b0a9c984f 100644 --- a/Foundation/CPPredicate/CPPredicate.j +++ b/Foundation/CPPredicate/CPPredicate.j @@ -225,7 +225,7 @@ while (count--) { if (![predicate evaluateWithObject:[self objectAtIndex:count]]) - splice(count, 1); + self.splice(count, 1); } } diff --git a/Foundation/CPPredicate/_CPExpression.j b/Foundation/CPPredicate/_CPExpression.j new file mode 100644 index 000000000..5a9561cb7 --- /dev/null +++ b/Foundation/CPPredicate/_CPExpression.j @@ -0,0 +1,397 @@ +/* + * CPExpression.j + * + * Created by cacaodev. + * Copyright 2010. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import "CPArray.j" +@import "CPDictionary.j" +@import "CPKeyValueCoding.j" +@import "CPObject.j" +@import "CPString.j" + +/*! + An expression that always returns the same value. +*/ +CPConstantValueExpressionType = 0; +/*! + An expression that always returns the parameter object itself. +*/ +CPEvaluatedObjectExpressionType = 1; +/*! + An expression that always returns whatever value is associated with the key specified by ‘variable’ in the bindings dictionary. +*/ +CPVariableExpressionType = 2; +/*! + An expression that returns something that can be used as a key path. +*/ +CPKeyPathExpressionType = 3; +/*! + An expression that returns the result of evaluating a function. +*/ +CPFunctionExpressionType = 4; +/*! + An expression that defines an aggregate of CPExpression objects. +*/ +CPAggregateExpressionType = 5; +/*! + An expression that filters a collection using a subpredicate. +*/ +CPSubqueryExpressionType = 6; +/*! + An expression that creates a union of the results of two nested expressions. +*/ +CPUnionSetExpressionType = 7; +/*! + An expression that creates an intersection of the results of two nested expressions. +*/ +CPIntersectSetExpressionType = 8; +/*! + An expression that combines two nested expression results by set subtraction. +*/ +CPMinusSetExpressionType = 9; + +/*! + @ingroup foundation + @class CPExpression + @brief CPExpression is used to represent expressions in a predicate. + + Comparison operations in an CPPredicate are based on two expressions, as represented by instances of the CPExpression class. + Expressions are created for constant values, key paths, and so on. + + Generally, anywhere in the CPExpression class hierarchy where there is composite API and subtypes + that may only reasonably respond to a subset of that API, invoking a method that does not make sense + for that subtype will cause an exception to be thrown. +*/ + +@implementation CPExpression : CPObject +{ + int _type; +} + +// Initializing an Expression +/*! + Initializes the receiver with the specified expression type. + @param type The type of the new expression, as defined by CPExpressionType. + @return An initialized CPExpression object of the type type. +*/ +- (id)initWithExpressionType:(int)type +{ + _type = type; + + return self; +} + +//Creating an Expression for a Value +/*! + Returns a new expression that represents a given constant value. + @param value The constant value the new expression is to represent. + @return A new expression that represents the constant value. +*/ ++ (CPExpression)expressionForConstantValue:(id)value +{ + return [[_CPConstantValueExpression alloc] initWithValue:value]; +} + +/*! + Returns a new expression that represents the object being evaluated. + @return A new expression that represents the object being evaluated. +*/ ++ (CPExpression)expressionForEvaluatedObject +{ + return [_CPSelfExpression evaluatedObject]; +} + +/*! + Returns a new expression that extracts a value from the variable bindings dictionary for a given key. + @param string The key for the variable to extract from the variable bindings dictionary. + @return A new expression that extracts from the variable bindings dictionary the value for the key string. +*/ ++ (CPExpression)expressionForVariable:(CPString)string +{ + return [[_CPVariableExpression alloc] initWithVariable:string]; +} + +/*! + Returns a new expression that invokes valueForKeyPath: with a given key path. + @param keyPath The key path that the new expression should evaluate. + @return A new expression that invokes valueForKeyPath: with keyPath. +*/ ++ (CPExpression)expressionForKeyPath:(CPString)keyPath +{ + return [[_CPKeyPathExpression alloc] initWithKeyPath:keyPath]; +} + +/*! + Returns a new aggregate expression for a given collection. + @param collection A collection object (an instance of CPArray, CPSet, or CPDictionary) that contains further expressions. + @return A new expression that contains the expressions in collection. +*/ ++ (CPExpression)expressionForAggregate:(CPArray)collection +{ + return [[_CPAggregateExpression alloc] initWithAggregate:collection]; +} + +/*! + Returns a new CPExpression object that represent the union of a given set and collection. + @param left An expression that evaluates to a CPSet object. + @param right An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). + @return A new CPExpression object that represents the union of left and right. +*/ ++ (CPExpression)expressionForUnionSet:(CPExpression)left with:(CPExpression)right +{ + return [[_CPSetExpression alloc] initWithType:CPUnionSetExpressionType left:left right:right]; +} + +/*! + Returns a new CPExpression object that represent the intersection of a given set and collection. + @param left An expression that evaluates to a CPSet object. + @param right An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). + @return A new CPExpression object that represents the intersection of left and right. +*/ ++ (CPExpression)expressionForIntersectSet:(CPExpression)left with:(CPExpression)right +{ + return [[_CPSetExpression alloc] initWithType:CPIntersectSetExpressionType left:left right:right]; +} + +/*! + Returns a new CPExpression object that represent the subtraction of a given collection from a given set. + @param left An expression that evaluates to a CPSet object. + @param left An expression that evaluates to a collection object (an instance of CPArray, CPSet, or CPDictionary). + @return A new CPExpression object that represents the subtraction of right from left. +*/ ++ (CPExpression)expressionForMinusSet:(CPExpression)left with:(CPExpression)right +{ + return [[_CPSetExpression alloc] initWithType:CPMinusSetExpressionType left:left right:right]; +} + +// Creating an Expression for a Function +/*! + Returns a new expression that will invoke one of the predefined functions. + @param function_name The name of the function to invoke. + @param parameters An array containing CPExpression objects that will be used as parameters during the invocation of selector. + @return A new expression that invokes the function name using the parameters in parameters. + + For a selector taking no parameters, the array should be empty. For a selector taking one or more parameters, + the array should contain one CPExpression object which will evaluate to an instance of the appropriate type for each parameter. + + If there is a mismatch between the number of parameters expected and the number you provide during evaluation, + an exception may be raised or missing parameters may simply be replaced by nil (which occurs depends on how many + parameters are provided, and whether you have over- or underflow). + + The name parameter can be one of the following predefined functions: + @verbatim + name parameter array contents returns + ------------------------------------------------------------------------------------------------------------------------------------- + sum: CPExpression instances representing numbers CPNumber + count: CPExpression instances representing numbers CPNumber + min: CPExpression instances representing numbers CPNumber + max: CPExpression instances representing numbers CPNumber + average: CPExpression instances representing numbers CPNumber + median: CPExpression instances representing numbers CPNumber + mode: CPExpression instances representing numbers CPArray (returned array will contain all occurrences of the mode) + stddev: CPExpression instances representing numbers CPNumber + add:to: CPExpression instances representing numbers CPNumber + from:subtract: two CPExpression instances representing numbers CPNumber + multiply:by: two CPExpression instances representing numbers CPNumber + divide:by: two CPExpression instances representing numbers CPNumber + modulus:by: two CPExpression instances representing numbers CPNumber + sqrt: one CPExpression instance representing numbers CPNumber + log: one CPExpression instance representing a number CPNumber + ln: one CPExpression instance representing a number CPNumber + raise:toPower: one CPExpression instance representing a number CPNumber + exp: one CPExpression instance representing a number CPNumber + floor: one CPExpression instance representing a number CPNumber + ceiling: one CPExpression instance representing a number CPNumber + abs: one CPExpression instance representing a number CPNumber + trunc: one CPExpression instance representing a number CPNumber + uppercase: one CPExpression instance representing a string CPString + lowercase: one CPExpression instance representing a string CPString + random: one CPExpression instance representing a number CPNumber (integer) such that 0 <= rand < param + now: none [CPDate now] + + This method raises an exception immediately if the selector is invalid; it raises an exception at runtime if the parameters are incorrect. +@endverbatim +*/ ++ (CPExpression)expressionForFunction:(CPString)function_name arguments:(CPArray)parameters +{ + return [[_CPFunctionExpression alloc] initWithSelector:CPSelectorFromString(function_name) arguments:parameters]; +} + +/*! + Returns an expression which will return the result of invoking on a given target a selector with a given name using given arguments. + @param target A CPExpression object which will evaluate an object on which the selector identified by name may be invoked. + @param selectorName The name of the method to be invoked. + @param parameters An array containing CPExpression objects which can be evaluated to provide parameters for the method specified by name. + @return An expression which will return the result of invoking the selector named name on the result of evaluating the target expression with the parameters specified by evaluating the elements of parameters. + + See the description of \c expressionForFunction:arguments: for examples of how to construct the parameter array. +*/ ++ (CPExpression)expressionForFunction:(CPExpression)target selectorName:(CPString)selectorName arguments:(CPArray)parameters +{ + return [[_CPFunctionExpression alloc] initWithTarget:target selector:CPSelectorFromString(selectorName) arguments:parameters]; +} + +/*! + Returns an expression that filters a collection by storing elements in the collection in a given variable and keeping the elements for which qualifier returns true. + @param expression A CPExpression that evaluates to a collection. + @param variable Used as a local variable, and will shadow any instances of variable in the bindings dictionary. The variable is removed or the old value replaced once evaluation completes. + @param predicate The predicate used to determine whether the element belongs in the result collection. + @return An expression that filters a collection by storing elements in the collection in the variable variable and keeping the elements for which qualifier returns true. +*/ ++ (CPExpression)expressionForSubquery:(CPExpression)expression usingIteratorVariable:(CPString)variable predicate:(CPPredicate)predicate +{ + return [[_CPSubqueryExpression alloc] initWithExpression:expression usingIteratorVariable:variable predicate:predicate]; +} + +// Getting Information About an Expression +/*! + Returns the expression type for the receiver. + @return The expression type for the receiver. + This method raises an exception if it is not applicable to the receiver. +*/ +- (int)expressionType +{ + return _type; +} + +/*! + Returns the constant value of the receiver. + @return The constant value of the receiver. + This method raises an exception if it is not applicable to the receiver. +*/ +- (id)constantValue +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the variable for the receiver. + @return The variable for the receiver. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPString)variable +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the key path for the receiver. + @return The key path for the receiver. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPString)keyPath +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the function for the receiver. + @return The function for the receiver. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPString)function +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the arguments for the receiver. + @return The arguments for the receiver—that is, the array of expressions that will be passed as parameters during invocation of the selector on the operand of a function expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPArray)arguments +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the collection of expressions in an aggregate expression, or the collection element of a subquery expression. + @return The collection of expressions in an aggregate expression, or the collection element of a subquery expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (id)collection +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the predicate in a subquery expression. + @return The predicate in a subquery expression.. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPPredicate)predicate +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the operand for the receiver. + @return The operand for the receiver—that is, the object on which the selector will be invoked. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPExpression)operand +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the left expression of a set expression. + @return The left expression of a set expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPExpression)leftExpression +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the right expression of a set expression. + @return The right expression of a set expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPExpression)rightExpression +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +- (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables +{ + return self; +} + +@end + +//@import "_CPConstantValueExpression.j" +//@import "_CPSelfExpression.j" +//@import "_CPVariableExpression.j" +//@import "_CPKeyPathExpression.j" +//@import "_CPFunctionExpression.j" +//@import "_CPAggregateExpression.j" +//@import "_CPSetExpression.j" +//@import "_CPSubqueryExpression.j" diff --git a/Foundation/CPString.j b/Foundation/CPString.j index fc9427369..8ab93f840 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -710,7 +710,7 @@ var CPStringUIDs = new CFMutableDictionary(), */ - (CPArray)pathComponents { - if (length === 0) + if (self.length === 0) return [""]; if (self === "/") diff --git a/Foundation/Foundation.j b/Foundation/Foundation.j index be4f44fde..422501616 100755 --- a/Foundation/Foundation.j +++ b/Foundation/Foundation.j @@ -75,8 +75,6 @@ @import "CPValue.j" @import "CPValueTransformer.j" -@import "_CPJavaScriptArray.j" - /*! @mainpage Cappuccino is distributed under the @ref license "GNU LGPL". diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index 87d2d8970..2e7f268b8 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -479,17 +479,31 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) this.assertNode(astNode, ObjJCompiler.AstNodeFunctionExpression); var children = astNode.children, child = children[2], - offset = 0; + offset = 0, + saveJSBuffer = this._jsBuffer; + this._jsBuffer = null; this.nodeFUNCTION(children[0]); this.nodeUnderline(children[1], true); + var identifier = null; if (child && child.name === ObjJCompiler.AstNodeIdentifier) { - this.nodeIdentifier(child); + identifier = this.nodeIdentifier(child); offset++; } this.nodeUnderline(children[2 + offset], false); - this.nodeWORD(children[3 + offset]); + if (saveJSBuffer) + if (identifier) + { + CONCAT(saveJSBuffer, identifier); + CONCAT(saveJSBuffer, " = function"); + } + else + { + CONCAT(saveJSBuffer, "function"); + } + this._jsBuffer = saveJSBuffer; + this.nodeOpenParenthesis(children[3 + offset]); this.nodeUnderline(children[4 + offset], false); child = children[5 + offset]; @@ -500,7 +514,7 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) offset++; } this.nodeUnderline(children[5 + offset], false); - this.nodeWORD(children[6 + offset]); + this.nodeCloseParenthesis(children[6 + offset]); this.nodeUnderline(children[7 + offset], false); this.nodeOpenBrace(children[8 + offset]); this.nodeUnderline(children[9 + offset], false); diff --git a/Tests/AppKit/CPArrayControllerTest.j b/Tests/AppKit/CPArrayControllerTest.j index 4a1d9756a..b63039b7e 100644 --- a/Tests/AppKit/CPArrayControllerTest.j +++ b/Tests/AppKit/CPArrayControllerTest.j @@ -1,5 +1,5 @@ -@import +@import @import @import diff --git a/Tests/AppKit/CPPredicateEditorTest.j b/Tests/AppKit/CPPredicateEditorTest.j index b94a126ac..7c9b5a56c 100644 --- a/Tests/AppKit/CPPredicateEditorTest.j +++ b/Tests/AppKit/CPPredicateEditorTest.j @@ -1,4 +1,5 @@ @import +@import @implementation CPPredicateEditorTest : OJTestCase { @@ -13,35 +14,35 @@ - (void)testTemplatesMerging { var le1 = [CPExpression expressionForKeyPath:@"keypath1"], - le2 = [CPExpression expressionForKeyPath:@"keypath2"], - le3 = [CPExpression expressionForKeyPath:@"keypath3"]; + le2 = [CPExpression expressionForKeyPath:@"keypath2"], + le3 = [CPExpression expressionForKeyPath:@"keypath3"]; - var lexps1 = [le1, le2], + var lexps1 = [le1, le2], lexps2 = [le2, le3]; - + var ops1 = [CPBeginsWithPredicateOperatorType, CPEndsWithPredicateOperatorType], ops2 = [CPGreaterThanPredicateOperatorType, CPEqualToPredicateOperatorType]; var t1 = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:lexps1 rightExpressionAttributeType:CPStringAttributeType modifier:0 operators:ops1 options:0], t2 = [[CPPredicateEditorRowTemplate alloc] initWithLeftExpressions:lexps2 rightExpressionAttributeType:CPInteger16AttributeType modifier:0 operators:ops2 options:0]; - + var errorFormat = @"The left criterion %@ should have children with the following templates:\n%@\nbut was:\n%@"; - + [_editor setRowTemplates:[t1, t2]]; - + var trees = _editor._rootTrees; var count = [trees count]; // We are expecting 3 criterion on the left. - [self assertTrue:(count == 3) message:"We should have 3 criterion on the left, was " + count]; - + [self assertTrue:(count == 3) message:"We should have 3 criterion on the left, was " + count]; + for (var i = 0; i < count; i++) { var aTree = [trees objectAtIndex:i], title = [aTree title], templates = [[aTree children] valueForKey:@"template"], expected; - + if ([title isEqualToString:@"keypath1"]) expected = [t1, t1]; else if ([title isEqualToString:@"keypath2"]) diff --git a/Tests/AppKit/CPTokenFieldTest.j b/Tests/AppKit/CPTokenFieldTest.j index 14e5440f7..174820192 100644 --- a/Tests/AppKit/CPTokenFieldTest.j +++ b/Tests/AppKit/CPTokenFieldTest.j @@ -1,4 +1,4 @@ -@import +@import [CPApplication sharedApplication]; diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/MyDocument.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/MyDocument.j index b21b77e0a..6abf8445a 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/MyDocument.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/MyDocument.j @@ -174,5 +174,5 @@ @end -@import "TableViewDataSource.j" +//@import "TableViewDataSource.j" diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/TableViewDataSource.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/TableViewDataSource.j index a4cba5084..24a9f8387 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/TableViewDataSource.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/TableViewDataSource.j @@ -23,6 +23,7 @@ */ @import "Bookmark.j" +@import "MyDocument.j" @implementation MyDocument (TableView) diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/WithoutBindingsTest.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/WithoutBindingsTest.j index ecc2edaf3..e5002713b 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/WithoutBindingsTest.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/01_WithoutBindings/WithoutBindingsTest.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "MyDocument.j" +@import "TableViewDataSource.j" /*! Bindings test exercising the functionality seen in the Cocoa example "WithAndWithoutBindings" part 1. Part 1 does in fact not use bindings and serves only as a base line test case. @@ -90,4 +90,4 @@ [self assert:@"http://www.cappuccino.org" equals:[theDocument.selectedBookmarkURLField stringValue]]; } -@end \ No newline at end of file +@end diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark2.j similarity index 97% rename from Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark.j rename to Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark2.j index d20fa5953..9d5ef171f 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Bookmark2.j @@ -22,7 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@implementation Bookmark : CPObject +@implementation Bookmark2 : CPObject { CPString title @accessors; CPDate creationDate @accessors; diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument2.j similarity index 97% rename from Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument.j rename to Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument2.j index e86ab1203..d0307318c 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/MyDocument2.j @@ -22,9 +22,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "Bookmark.j" +@import "Bookmark2.j" -@implementation MyDocument : CPDocument +@implementation MyDocument2 : CPDocument { CPString name @accessors; CPString collectionDescription @accessors; diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Resources/02_WithBindings.xib b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Resources/02_WithBindings.xib index 4a2d898e6..29aa495ac 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Resources/02_WithBindings.xib +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/Resources/02_WithBindings.xib @@ -389,7 +389,7 @@ title URL - Bookmark + Bookmark2 YES YES diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/TableViewDataSource.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/TableViewDataSource.j index c4321f4df..cac1c0706 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/TableViewDataSource.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/TableViewDataSource.j @@ -22,7 +22,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "Bookmark.j" +@import "Bookmark2.j" // In 02 this is a subclass of CPArrayController. @implementation MyArrayController : CPArrayController diff --git a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/WithBindingsTest.j b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/WithBindingsTest.j index 78db62e59..8549fd4c0 100644 --- a/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/WithBindingsTest.j +++ b/Tests/AppKit/WithAndWithoutBindingsIntegration/02_WithBindings/WithBindingsTest.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "MyDocument.j" +@import "MyDocument2.j" @import "StringToURLTransformer.j" /*! @@ -39,7 +39,7 @@ - (void)test { - var theDocument = [MyDocument new], + var theDocument = [MyDocument2 new], cib = [CPBundle loadCibFile:[[CPBundle bundleForClass:WithBindingsTest] pathForResource:"02_WithBindings.cib"] externalNameTable:[CPDictionary dictionaryWithObject:theDocument forKey:CPCibOwner]]; [theDocument windowControllerDidLoadCib:self]; @@ -90,4 +90,4 @@ [self assert:@"http://www.cappuccino.org" equals:[theDocument.selectedBookmarkURLField stringValue]]; } -@end \ No newline at end of file +@end diff --git a/Tests/Foundation/CPArrayPerformanceTest.j b/Tests/Foundation/CPArrayPerformanceTest.j index edad83cf6..61b8265d4 100644 --- a/Tests/Foundation/CPArrayPerformanceTest.j +++ b/Tests/Foundation/CPArrayPerformanceTest.j @@ -1,6 +1,6 @@ var FILE = require("file"); -@import +@import @import @import @import @@ -26,6 +26,7 @@ var ELEMENTS = 100, CPLog.warn("\nNUMERIC ALMOST SORTED"); var a = [self makeUnsorted], sorted = [self sort:a usingSortSelector:@selector(sortedArrayUsingDescriptors:) withObject:descriptors]; + print("a: " + (a == sorted ? "Yes" : "No")); [self checkAlmostSorted:sorted]; } @@ -227,7 +228,7 @@ var ELEMENTS = 100, { var count = [descriptors count]; - sort(function(lhs, rhs) + self.sort(function(lhs, rhs) { var i = 0, result = CPOrderedSame; @@ -251,7 +252,7 @@ var ELEMENTS = 100, - (CPArray)_native_sortUsingSelector:(SEL)aSelector { - sort(function(lhs, rhs) + self.sort(function(lhs, rhs) { return [lhs performSelector:aSelector withObject:rhs]; }); diff --git a/Tests/Foundation/CPAttributedStringTest.j b/Tests/Foundation/CPAttributedStringTest.j index ccf59cd40..0a88f8e06 100644 --- a/Tests/Foundation/CPAttributedStringTest.j +++ b/Tests/Foundation/CPAttributedStringTest.j @@ -600,4 +600,4 @@ function testAttributeAtIndexWithValue(aString, anIndex, aKey, aValue, aSelf) function printRangeEntry(entry) { print("range: " + CPStringFromRange(entry.range) + " " + [entry.attributes description]); -} \ No newline at end of file +} diff --git a/Tests/Foundation/CPDataTest.j b/Tests/Foundation/CPDataTest.j index c0c37c21a..7a97a1850 100644 --- a/Tests/Foundation/CPDataTest.j +++ b/Tests/Foundation/CPDataTest.j @@ -1,4 +1,4 @@ -@import +@import @import @import @import diff --git a/Tests/Foundation/CPInvocationOperationTest.j b/Tests/Foundation/CPInvocationOperationTest.j index a03a16732..54d54e38f 100644 --- a/Tests/Foundation/CPInvocationOperationTest.j +++ b/Tests/Foundation/CPInvocationOperationTest.j @@ -1,6 +1,6 @@ @import -@implementation SomeObject : CPObject +@implementation SomeObject2 : CPObject { CPString result @accessors; } @@ -17,7 +17,7 @@ - (void)testRunInvocation { - var so = [[SomeObject alloc] init], + var so = [[SomeObject2 alloc] init], io = [[CPInvocationOperation alloc] initWithTarget:so selector:@selector(setAString:) object:@"Hello World"]; [io start]; diff --git a/Tests/Foundation/CPKVCArrayTest.j b/Tests/Foundation/CPKVCArrayTest.j index cc96e2ffa..a873d2183 100644 --- a/Tests/Foundation/CPKVCArrayTest.j +++ b/Tests/Foundation/CPKVCArrayTest.j @@ -328,7 +328,7 @@ var COUNTER; [self assert:[two valueForKeyPath:"@max.intValue"] equals:8]; [self assert:[two valueForKeyPath:"@min.intValue"] equals:0]; - var a = [A new]; + var a = [AA new]; [a setValue:one forKey:"b"]; [self assert:[a valueForKeyPath:"b.@count"] equals:8]; [self assert:[a valueForKeyPath:"b.@sum.intValue"] equals:8]; @@ -347,7 +347,7 @@ var COUNTER; @end -@implementation A : CPObject +@implementation AA : CPObject { id b; } diff --git a/Tests/Foundation/CPKVOTest.j b/Tests/Foundation/CPKVOTest.j index 619a0e7f8..86464df1b 100644 --- a/Tests/Foundation/CPKVOTest.j +++ b/Tests/Foundation/CPKVOTest.j @@ -431,7 +431,7 @@ - (void)testDependentKeysPaths { - var object = [[TestObject alloc] init]; + var object = [[TestObject2 alloc] init]; [object addObserver:self forKeyPath:@"key" options:0 context:@"testDependentKeysPaths"]; @@ -879,7 +879,7 @@ } @end -@implementation TestObject : CPObject +@implementation TestObject2 : CPObject { CPString key @accessors; CPString affectingKey @accessors; diff --git a/Tests/Foundation/CPKeyValueCodingTest.j b/Tests/Foundation/CPKeyValueCodingTest.j index fd62a0138..d45f1f096 100644 --- a/Tests/Foundation/CPKeyValueCodingTest.j +++ b/Tests/Foundation/CPKeyValueCodingTest.j @@ -480,8 +480,8 @@ var accessIVARS = YES; - (void)testValueForKeyPath { - var department = [Department departmentWithName:@"Engineering"], - employee = [Employee employeeWithName:@"Klaas Pieter" department:department]; + var department = [Department2 departmentWithName:@"Engineering"], + employee = [Employee2 employeeWithName:@"Klaas Pieter" department:department]; [self assert:department equals:[employee valueForKey:@"department"]]; [self assert:@"Engineering" equals:[employee valueForKeyPath:@"department.name"]]; @@ -489,10 +489,10 @@ var accessIVARS = YES; @end -@implementation Employee : CPObject +@implementation Employee2 : CPObject { CPString _name @accessors(property=name); - Department _department @accessors(property=department); + Department2 _department @accessors(property=department); } + (id)employeeWithName:(CPString)theName department:(Department)theDepartment @@ -513,7 +513,7 @@ var accessIVARS = YES; @end -@implementation Department : CPObject +@implementation Department2 : CPObject { CPString _name @accessors(property=name); } diff --git a/Tests/Foundation/CPOperationTest.j b/Tests/Foundation/CPOperationTest.j index d577a754b..701ef8397 100644 --- a/Tests/Foundation/CPOperationTest.j +++ b/Tests/Foundation/CPOperationTest.j @@ -1,6 +1,6 @@ @import -@implementation TestOperation : CPOperation +@implementation TestOperation2 : CPOperation { CPString name @accessors; CPString value @accessors; @@ -13,7 +13,7 @@ @end -@implementation TestObserver : CPObject +@implementation TestObserver2 : CPObject { CPArray changedKeyPaths @accessors; } @@ -106,7 +106,7 @@ - (void)testCompletionFunction { - var to = [[TestOperation alloc] init]; + var to = [[TestOperation2 alloc] init]; [to setCompletionFunction:function() {[to setValue:@"something"];}]; [to start]; @@ -118,9 +118,9 @@ - (void)testKVO { - var to = [[TestOperation alloc] init], - to2 = [[TestOperation alloc] init], - obs = [[TestObserver alloc] init]; + var to = [[TestOperation2 alloc] init], + to2 = [[TestOperation2 alloc] init], + obs = [[TestObserver2 alloc] init]; [to addObserver:obs forKeyPath:@"isCancelled" diff --git a/Tests/Foundation/SubclassTollFreeTest.j b/Tests/Foundation/SubclassTollFreeTest.j index 48ce95cb7..7e47a51f9 100644 --- a/Tests/Foundation/SubclassTollFreeTest.j +++ b/Tests/Foundation/SubclassTollFreeTest.j @@ -2,14 +2,14 @@ - (void)testThatSubclassTollFreeDoesAllowForSubclassingDictionary { - var target = [[MyDict alloc] init]; + var target = [[MyDict2 alloc] init]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assert:0 equals:[target count]]; } - (void)testThatSubclassTollFreeDoesAllowForSubclassingString { - var target = [[MyString alloc] initWithString:@"adsf"]; + var target = [[MyString2 alloc] initWithString:@"adsf"]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assert:4 equals:[target length]]; @@ -20,42 +20,42 @@ - (void)testThatSubclassTollFreeDoesAllowForSubclassingNumber { - var target = [[MyNum alloc] init]; + var target = [[MyNum2 alloc] init]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assertFalse:[target isEqualToNumber:5]]; } - (void)testThatSubclassTollFreeDoesAllowForSubclassingException { - var target = [[MyException alloc] init]; + var target = [[MyException2 alloc] init]; [OJAssert assert:@"a" equals:[target newMessage]]; // there are no internal properties to test here.. so no need to jimmyrig it. } - (void)testThatSubclassTollFreeDoesAllowForSubclassingArray { - var target = [[MyArray alloc] initWithObjects:@"a"]; + var target = [[MyArray2 alloc] initWithObjects:@"a"]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assert:1 equals:[target count]]; } - (void)testThatSubclassTollFreeDoesAllowForSubclassingDate { - var target = [[MyDate alloc] init]; + var target = [[MyDate2 alloc] init]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assertTrue:[target timeIntervalSince1970] > 0]; } - (void)testThatSubclassTollFreeDoesAllowForSubclassingData { - var target = [[MyData alloc] initWithRawString:@"b"]; + var target = [[MyData2 alloc] initWithRawString:@"b"]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assert:@"b" equals:[target rawString]]; } - (void)testThatSubclassTollFreeDoesAllowForSubclassingURL { - var target = [[MyURL alloc] initWithString:@"http://www.google.com"]; + var target = [[MyURL2 alloc] initWithString:@"http://www.google.com"]; [OJAssert assert:@"a" equals:[target newMessage]]; [OJAssert assert:@"http://www.google.com" equals:[target absoluteString]]; } @@ -65,7 +65,7 @@ @import -@implementation MyDict : CPDictionary +@implementation MyDict2 : CPDictionary - (id)newMessage { @@ -74,7 +74,7 @@ @end -@implementation MyNum : CPNumber +@implementation MyNum2 : CPNumber - (id)newMessage { @@ -83,7 +83,7 @@ @end -@implementation MyString : CPString +@implementation MyString2 : CPString - (id)newMessage { @@ -92,7 +92,7 @@ @end -@implementation MyException : CPException +@implementation MyException2 : CPException - (id)newMessage { @@ -101,7 +101,7 @@ @end -@implementation MyArray : CPArray +@implementation MyArray2 : CPArray { CPArray _storage; } @@ -133,7 +133,7 @@ @end -@implementation MyDate : CPDate +@implementation MyDate2 : CPDate - (id)newMessage { @@ -142,7 +142,7 @@ @end -@implementation MyData : CPData +@implementation MyData2 : CPData - (id)newMessage { @@ -151,7 +151,7 @@ @end -@implementation MyURL : CPURL +@implementation MyURL2 : CPURL - (id)newMessage { diff --git a/Tests/Objective-J/MethodDispatchTest.j b/Tests/Objective-J/MethodDispatchTest.j index 99732d967..377d039eb 100644 --- a/Tests/Objective-J/MethodDispatchTest.j +++ b/Tests/Objective-J/MethodDispatchTest.j @@ -37,6 +37,7 @@ @implementation RootClassWithForwardingTarget { + Class isa; } + (void)initialize From fd59efe41f10d4a9799ff140b4021879441f029e Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 17 Dec 2012 11:15:50 +0100 Subject: [PATCH 05/46] Bug fixes for failing test cases --- Foundation/CPArray+KVO.j | 4 ++-- Tests/Foundation/CPArrayPerformanceTest.j | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Foundation/CPArray+KVO.j b/Foundation/CPArray+KVO.j index fc65294ef..0f6ca990c 100644 --- a/Foundation/CPArray+KVO.j +++ b/Foundation/CPArray+KVO.j @@ -347,7 +347,7 @@ while ((index = [self indexOfObject:theObject inRange:theRange]) !== CPNotFound) { [self removeObjectAtIndex:index]; - theRange = CPIntersectionRange(CPMakeRange(index, length - index), theRange); + theRange = CPIntersectionRange(CPMakeRange(index, self.length - index), theRange); } } } @@ -427,7 +427,7 @@ [CPException raise:CPInvalidArgumentException reason:"called valueForKey: on an array with a complex key (" + aKey + "). use valueForKeyPath:"]; if (aKey === "@count") - return length; + return self.length; return [self valueForUndefinedKey:aKey]; } diff --git a/Tests/Foundation/CPArrayPerformanceTest.j b/Tests/Foundation/CPArrayPerformanceTest.j index 61b8265d4..b80343648 100644 --- a/Tests/Foundation/CPArrayPerformanceTest.j +++ b/Tests/Foundation/CPArrayPerformanceTest.j @@ -15,7 +15,7 @@ var ELEMENTS = 100, - (void)setUp { - var descriptors = [ + descriptors = [ [CPSortDescriptor sortDescriptorWithKey:"a" ascending:NO], [CPSortDescriptor sortDescriptorWithKey:"b" ascending:YES] ]; @@ -26,7 +26,6 @@ var ELEMENTS = 100, CPLog.warn("\nNUMERIC ALMOST SORTED"); var a = [self makeUnsorted], sorted = [self sort:a usingSortSelector:@selector(sortedArrayUsingDescriptors:) withObject:descriptors]; - print("a: " + (a == sorted ? "Yes" : "No")); [self checkAlmostSorted:sorted]; } From 897adf27f0af547fc35987d004483b204e7b1714 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 17 Dec 2012 14:57:18 +0100 Subject: [PATCH 06/46] Fixed import statements in nib2cib, bug in load system and some more fixes to test cases --- Foundation/CPSet/CPMutableSet.j | 2 +- Foundation/CPSet/CPSet.j | 489 +------------------------------ Objective-J/Executable.js | 2 +- Tests/AppKit/CPApplicationTest.j | 2 +- Tools/capp/Configuration.j | 6 +- Tools/nib2cib/Converter.j | 2 +- Tools/nib2cib/Nib2Cib.j | 1 + 7 files changed, 9 insertions(+), 495 deletions(-) diff --git a/Foundation/CPSet/CPMutableSet.j b/Foundation/CPSet/CPMutableSet.j index 0458c636f..a70c74c55 100644 --- a/Foundation/CPSet/CPMutableSet.j +++ b/Foundation/CPSet/CPMutableSet.j @@ -7,7 +7,7 @@ this class only exists for source compatability. */ -@import "CPSet.j" +@import "_CPSet.j" @implementation CPMutableSet : CPSet diff --git a/Foundation/CPSet/CPSet.j b/Foundation/CPSet/CPSet.j index 078e29c34..3e2a88286 100644 --- a/Foundation/CPSet/CPSet.j +++ b/Foundation/CPSet/CPSet.j @@ -24,491 +24,4 @@ * */ -@import "CPArray.j" -@import "CPEnumerator.j" -@import "CPNumber.j" -@import "CPObject.j" - -/*! - @class CPMutableSet - @ingroup Foundation - - CPSet is a data structure for storing an an unordered collection of unique objects. - Sets have O(1) insertion/lookup/deletion time complexity. -*/ - -@implementation CPSet : CPObject -{ -} - -+ (id)alloc -{ - if (self === [CPSet class] || self === [CPMutableSet class]) - return [_CPPlaceholderSet alloc]; - - return [super alloc]; -} - -/*! - Creates and returns an empty set. -*/ -+ (id)set -{ - return [[self alloc] init]; -} - -/*! - Creates and returns a set containing a uniqued collection of those objects contained in a given array. - @param anArray array containing the objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. -*/ -+ (id)setWithArray:(CPArray)anArray -{ - return [[self alloc] initWithArray:anArray]; -} - -/*! - Creates and returns a set that contains a single given object. - @param anObject The object to add to the new set. -*/ -+ (id)setWithObject:(id)anObject -{ - return [[self alloc] initWithObjects:anObject]; -} - -/*! - Creates and returns a set containing a specified number of objects from a given array of objects. - @param objects A array of objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. - @param count The number of objects from objects to add to the new set. -*/ -+ (id)setWithObjects:(id)objects count:(CPUInteger)count -{ - return [[self alloc] initWithObjects:objects count:count]; -} - -/*! - Creates and returns a set containing the objects in a given argument list. - @param anObject The first object to add to the new set. - @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. -*/ -+ (id)setWithObjects:(id)anObject, ... -{ - var argumentsArray = Array.prototype.slice.apply(arguments); - - argumentsArray[0] = [self alloc]; - argumentsArray[1] = @selector(initWithObjects:); - - return objj_msgSend.apply(this, argumentsArray); -} - -/*! - Creates and returns a set containing the objects from another set. - @param aSet A set containing the objects to add to the new set. -*/ -+ (id)setWithSet:(CPSet)set -{ - return [[self alloc] initWithSet:set]; -} - -/*! - Creates and returns a set by adding anObject. - @param anObject to add to the new set. -*/ -- (id)setByAddingObject:(id)anObject -{ - return [[self class] setWithArray:[[self allObjects] arrayByAddingObject:anObject]]; -} - -/*! - Creates and returns a set by adding the objects from another set. - @param aSet to add objects to add to the new set. -*/ -- (id)setByAddingObjectsFromSet:(CPSet)aSet -{ - return [self setByAddingObjectsFromArray:[aSet allObjects]]; -} - -/*! - Creates and returns a set by adding the objects from an array. - @param anArray with objects to add to a new set. -*/ -- (id)setByAddingObjectsFromArray:(CPArray)anArray -{ - return [[self class] setWithArray:[[self allObjects] arrayByAddingObjectsFromArray:anArray]]; -} - -/*! - Basic initializer, returns an empty set. -*/ -- (id)init -{ - return [self initWithObjects:nil count:0]; -} - -/*! - Initializes a newly allocated set with the objects that are contained in a given array. - @param array An array of objects to add to the new set. If the same object appears more than once in array, it is represented only once in the returned set. -*/ -- (id)initWithArray:(CPArray)anArray -{ - return [self initWithObjects:anArray count:[anArray count]]; -} - -/*! - Initializes a newly allocated set with members taken from the specified list of objects. - @param anObject The first object to add to the new set. - @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once in the list, it is represented only once in the returned set. -*/ -- (id)initWithObjects:(id)anObject, ... -{ - var index = 2, - count = arguments.length; - - for (; index < count; ++index) - if (arguments[index] === nil) - break; - - return [self initWithObjects:Array.prototype.slice.call(arguments, 2, index) count:index - 2]; -} - -/*! - Creates and returns a set containing the objects from an array. - @param anArray An array containing the objects to add to the new set. - @param aCount the number of objects in anArray. -*/ -- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount -{ - if (self === _CPSharedPlaceholderSet) - return [[_CPConcreteMutableSet alloc] initWithObjects:objects count:aCount]; - - return [super init]; -} - -/*! - Initializes a newly allocated set and adds to it objects from another given set. - @param aSet a set containing objects to add to the new set. -*/ -- (id)initWithSet:(CPSet)aSet -{ - return [self initWithArray:[aSet allObjects]]; -} - -/*! - Initializes a newly allocated set and adds to it members of another given set. Only included for compatability. - @param aSet a set of objects to add to the new set. - @param shouldCopyItems a boolean value. If YES the objects would be copied, if NO the objects will not be copied. -*/ -- (id)initWithSet:(CPSet)aSet copyItems:(BOOL)shouldCopyItems -{ - if (shouldCopyItems) - return [aSet valueForKey:@"copy"]; - - return [self initWithSet:aSet]; -} - -/*! - Returns the number of members in the receiver. -*/ -- (CPUInteger)count -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); -} - -/*! - Returns an array containing the receiver’s members, or an empty array if the receiver has no members. -*/ -- (CPArray)allObjects -{ - var objects = [], - object, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - objects.push(object); - - return objects; -} - -/*! - Returns one of the objects in the receiver, or nil if the receiver contains no objects. -*/ -- (id)anyObject -{ - return [[self objectEnumerator] nextObject]; -} - -/*! - Returns a Boolean value that indicates whether a given object is present in the receiver. - @param anObject The object for which to test membership of the receiver. -*/ -- (BOOL)containsObject:(id)anObject -{ - return [self member:anObject] !== nil; -} - -/*! - Returns a set filtered using a given predicate. - @prarm aPredicate a CPPredicate object used to filter the objects in the set. -*/ -- (CPSet)filteredSetUsingPredicate:(CPPredicate)aPredicate -{ - var objects = [], - object, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - if ([aPredicate evaluateWithObject:object]) - objects.push(object); - - return [[[self class] alloc] initWithArray:objects]; -} - -/*! - Sends to each object in the receiver a message specified by a given selector. - @param aSelector A selector that specifies the message to send to the members of the receiver. The method must not take any arguments. It should not have the side effect of modifying the receiver. This value must not be NULL. -*/ -- (void)makeObjectsPerformSelector:(SEL)aSelector -{ - [self makeObjectsPerformSelector:aSelector withObjects:nil]; -} - -/*! - Sends to each object in the receiver a message specified by a given selector. - @param aSelector A selector that specifies the message to send to the receiver's members. The method must take a single argument of type id. The method should not, as a side effect, modify the receiver. The value must not be NULL. - @param anObject The object to pass as an argument to the method specified by aSelector. -*/ -- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject -{ - [self makeObjectsPerformSelector:aSelector withObjects:[anObject]]; -} - -/*! - Sends to each object in the receiver a message specified by a given selector. - @param aSelector A selector that specifies the message to send to the receiver's members. The method must take a single argument of type id. The method should not, as a side effect, modify the receiver. The value must not be NULL. - @param objects The objects to pass as an argument to the method specified by aSelector. -*/ -- (void)makeObjectsPerformSelector:(SEL)aSelector withObjects:(CPArray)objects -{ - var object, - objectEnumerator = [self objectEnumerator], - argumentsArray = [nil, aSelector].concat(objects || []); - - while ((object = [objectEnumerator nextObject]) !== nil) - { - argumentsArray[0] = object; - objj_msgSend.apply(this, argumentsArray); - } -} - -/*! - Determines whether the receiver contains an object equal to a given object, and returns that object if it is present. - @param anObject The object for which to test for membership of the receiver. -*/ -- (id)member:(id)anObject -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); -} - -/*! - Returns an object enumerator (CPEnumerator) for the receiver. -*/ -- (CPEnumerator)objectEnumerator -{ - _CPRaiseInvalidAbstractInvocation(self, _cmd); -} - -/*! - Enumberates over the objects in a set using a given function. - @param aFunction a callback for each itteration, should be of the format: function(anObject). -*/ -- (void)enumerateObjectsUsingBlock:(Function)aFunction -{ - var object, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - if (aFunction(object)) - break; -} - -// FIXME: stop is broken. -- (CPSet)objectsPassingTest:(Function)aFunction -{ - var objects = [], - object = nil, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - if (aFunction(object)) - objects.push(object); - - return [[[self class] alloc] initWithArray:objects]; -} - -/*! - Returns a Boolean value that indicates whether every object in the receiver is also present in another given set. - @param set The set with which to compare the receiver. -*/ -- (BOOL)isSubsetOfSet:(CPSet)aSet -{ - var object = nil, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - if (![aSet containsObject:object]) - return NO; - - return YES; -} - -/*! - Returns a Boolean value that indicates whether at least one object in the receiver is also present in another given set. - @param set The set with which to compare the receiver. -*/ -- (BOOL)intersectsSet:(CPSet)aSet -{ - if (self === aSet) - // The empty set intersects nothing - return [self count] > 0; - - var object = nil, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - if ([aSet containsObject:object]) - return YES; - - return NO; -} - -/*! - Returns an array of the set's content sorted as specified by a given array of sort descriptors. - - @param sortDescriptors an array of CPSortDescriptor objects. -*/ -- (CPArray)sortedArrayUsingDescriptors:(CPArray)someSortDescriptors -{ - return [[self allObjects] sortedArrayUsingDescriptors:someSortDescriptors]; -} - -/*! - Compares the receiver to another set. - @param set The set with which to compare the receiver. -*/ -- (BOOL)isEqualToSet:(CPSet)aSet -{ - return [self isEqual:aSet]; -} - -/*! - Returns YES if BOTH sets are a subset of the other. - @param aSet a set of objects -*/ -- (BOOL)isEqual:(CPSet)aSet -{ - // If both are subsets of each other, they are equal - return self === aSet || - [aSet isKindOfClass:[CPSet class]] && - ([self count] === [aSet count] && - [aSet isSubsetOfSet:self]); -} - -- (CPString)description -{ - var string = "{(\n", - objects = [self allObjects], - index = 0, - count = [objects count]; - - for (; index < count; ++index) - { - var object = objects[index]; - - string += "\t" + String(object).split('\n').join("\n\t") + "\n"; - } - - return string + ")}"; -} - -@end - -@implementation CPSet (CPCopying) - -- (id)copy -{ - return [[self class] setWithSet:self]; -} - -- (id)mutableCopy -{ - return [self copy]; -} - -@end - -var CPSetObjectsKey = @"CPSetObjectsKey"; - -@implementation CPSet (CPCoding) - -- (id)initWithCoder:(CPCoder)aCoder -{ - return [self initWithArray:[aCoder decodeObjectForKey:CPSetObjectsKey]]; -} - -- (void)encodeWithCoder:(CPCoder)aCoder -{ - [aCoder encodeObject:[self allObjects] forKey:CPSetObjectsKey]; -} - -@end - -@implementation CPSet (CPKeyValueCoding) - -- (id)valueForKey:(CPString)aKey -{ - if (aKey === "@count") - return [self count]; - - var valueSet = [CPSet set], - object, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - { - var value = [object valueForKey:aKey]; - - [valueSet addObject:value]; - } - - return valueSet; -} - -- (void)setValue:(id)aValue forKey:(CPString)aKey -{ - var object, - objectEnumerator = [self objectEnumerator]; - - while ((object = [objectEnumerator nextObject]) !== nil) - [object setValue:aValue forKey:aKey]; -} - -@end - -var _CPSharedPlaceholderSet = nil; - -@implementation _CPPlaceholderSet : CPSet -{ -} - -+ (id)alloc -{ - if (!_CPSharedPlaceholderSet) - _CPSharedPlaceholderSet = [super alloc]; - - return _CPSharedPlaceholderSet; -} - -@end - -// We actually want _CPConcreteMutableSet, but this introduces the possibility of an invalid @import loop. -// This will be correctly solved when we move to true immutable/mutable pairs. -//@import "CPMutableSet.j" + @import "_CPConcreteMutableSet.j" diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 3885691eb..2793368ff 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -468,7 +468,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) { var referenceURLString = referenceURL.absoluteString(), cachedFileExecutableSearcher = cachedFileExecutableSearchers[referenceURLString], - aFilenameTranslateDictionary = this.filenameTranslateDictionary(); + aFilenameTranslateDictionary = Executable.filenameTranslateDictionary ? Executable.filenameTranslateDictionary() : null; cachedSearchResults = { }; if (!cachedFileExecutableSearcher) diff --git a/Tests/AppKit/CPApplicationTest.j b/Tests/AppKit/CPApplicationTest.j index 5677435a3..be4bfb10f 100644 --- a/Tests/AppKit/CPApplicationTest.j +++ b/Tests/AppKit/CPApplicationTest.j @@ -68,7 +68,7 @@ var globalResults = []; app = [CPApplication sharedApplication]; // fake the window.location.hash - app.window = {location: {hash: "#var1=1/var2=2"}}; + window.location = {hash: "#var1=1/var2=2"}; [app setDelegate:[[MyAppDelegate alloc] init]]; aWindow = [[CPWindow alloc] init]; diff --git a/Tools/capp/Configuration.j b/Tools/capp/Configuration.j index 6419cc209..71c8a7492 100644 --- a/Tools/capp/Configuration.j +++ b/Tools/capp/Configuration.j @@ -124,12 +124,12 @@ var DefaultDictionary = nil, - (void)save { - var path = [self path]; + var aPath = [self path]; - if (!path) + if (!aPath) return; - CFPropertyList.writePropertyListToFile(dictionary, path); + CFPropertyList.writePropertyListToFile(dictionary, aPath); } @end diff --git a/Tools/nib2cib/Converter.j b/Tools/nib2cib/Converter.j index 76ec766c3..096ee34b0 100644 --- a/Tools/nib2cib/Converter.j +++ b/Tools/nib2cib/Converter.j @@ -159,4 +159,4 @@ ConverterConversionException = @"ConverterConversionException"; @end -@import "Converter+Mac.j" +//@import "Converter+Mac.j" diff --git a/Tools/nib2cib/Nib2Cib.j b/Tools/nib2cib/Nib2Cib.j index 76f79db66..c286dde5e 100644 --- a/Tools/nib2cib/Nib2Cib.j +++ b/Tools/nib2cib/Nib2Cib.j @@ -29,6 +29,7 @@ @import "Nib2CibKeyedUnarchiver.j" @import "Converter.j" +@import "Converter+Mac.j" var FILE = require("file"), OS = require("os"), From ca99114b1635d39e9e48843117f5dd4526036b2d Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 17 Dec 2012 15:12:02 +0100 Subject: [PATCH 07/46] Forgot to add one file --- Foundation/CPSet/_CPSet.j | 514 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 514 insertions(+) create mode 100644 Foundation/CPSet/_CPSet.j diff --git a/Foundation/CPSet/_CPSet.j b/Foundation/CPSet/_CPSet.j new file mode 100644 index 000000000..078e29c34 --- /dev/null +++ b/Foundation/CPSet/_CPSet.j @@ -0,0 +1,514 @@ +/* + * CPSet.j + * Foundation + * + * Created by Bailey Carlson + * Extended by Ross Boucher + * Extended by Nabil Elisa + * Rewritten by Francisco Tolmasky + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +@import "CPArray.j" +@import "CPEnumerator.j" +@import "CPNumber.j" +@import "CPObject.j" + +/*! + @class CPMutableSet + @ingroup Foundation + + CPSet is a data structure for storing an an unordered collection of unique objects. + Sets have O(1) insertion/lookup/deletion time complexity. +*/ + +@implementation CPSet : CPObject +{ +} + ++ (id)alloc +{ + if (self === [CPSet class] || self === [CPMutableSet class]) + return [_CPPlaceholderSet alloc]; + + return [super alloc]; +} + +/*! + Creates and returns an empty set. +*/ ++ (id)set +{ + return [[self alloc] init]; +} + +/*! + Creates and returns a set containing a uniqued collection of those objects contained in a given array. + @param anArray array containing the objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. +*/ ++ (id)setWithArray:(CPArray)anArray +{ + return [[self alloc] initWithArray:anArray]; +} + +/*! + Creates and returns a set that contains a single given object. + @param anObject The object to add to the new set. +*/ ++ (id)setWithObject:(id)anObject +{ + return [[self alloc] initWithObjects:anObject]; +} + +/*! + Creates and returns a set containing a specified number of objects from a given array of objects. + @param objects A array of objects to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. + @param count The number of objects from objects to add to the new set. +*/ ++ (id)setWithObjects:(id)objects count:(CPUInteger)count +{ + return [[self alloc] initWithObjects:objects count:count]; +} + +/*! + Creates and returns a set containing the objects in a given argument list. + @param anObject The first object to add to the new set. + @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once objects, it is added only once to the returned set. +*/ ++ (id)setWithObjects:(id)anObject, ... +{ + var argumentsArray = Array.prototype.slice.apply(arguments); + + argumentsArray[0] = [self alloc]; + argumentsArray[1] = @selector(initWithObjects:); + + return objj_msgSend.apply(this, argumentsArray); +} + +/*! + Creates and returns a set containing the objects from another set. + @param aSet A set containing the objects to add to the new set. +*/ ++ (id)setWithSet:(CPSet)set +{ + return [[self alloc] initWithSet:set]; +} + +/*! + Creates and returns a set by adding anObject. + @param anObject to add to the new set. +*/ +- (id)setByAddingObject:(id)anObject +{ + return [[self class] setWithArray:[[self allObjects] arrayByAddingObject:anObject]]; +} + +/*! + Creates and returns a set by adding the objects from another set. + @param aSet to add objects to add to the new set. +*/ +- (id)setByAddingObjectsFromSet:(CPSet)aSet +{ + return [self setByAddingObjectsFromArray:[aSet allObjects]]; +} + +/*! + Creates and returns a set by adding the objects from an array. + @param anArray with objects to add to a new set. +*/ +- (id)setByAddingObjectsFromArray:(CPArray)anArray +{ + return [[self class] setWithArray:[[self allObjects] arrayByAddingObjectsFromArray:anArray]]; +} + +/*! + Basic initializer, returns an empty set. +*/ +- (id)init +{ + return [self initWithObjects:nil count:0]; +} + +/*! + Initializes a newly allocated set with the objects that are contained in a given array. + @param array An array of objects to add to the new set. If the same object appears more than once in array, it is represented only once in the returned set. +*/ +- (id)initWithArray:(CPArray)anArray +{ + return [self initWithObjects:anArray count:[anArray count]]; +} + +/*! + Initializes a newly allocated set with members taken from the specified list of objects. + @param anObject The first object to add to the new set. + @param ... A comma-separated list of objects, ending with nil, to add to the new set. If the same object appears more than once in the list, it is represented only once in the returned set. +*/ +- (id)initWithObjects:(id)anObject, ... +{ + var index = 2, + count = arguments.length; + + for (; index < count; ++index) + if (arguments[index] === nil) + break; + + return [self initWithObjects:Array.prototype.slice.call(arguments, 2, index) count:index - 2]; +} + +/*! + Creates and returns a set containing the objects from an array. + @param anArray An array containing the objects to add to the new set. + @param aCount the number of objects in anArray. +*/ +- (id)initWithObjects:(CPArray)objects count:(CPUInteger)aCount +{ + if (self === _CPSharedPlaceholderSet) + return [[_CPConcreteMutableSet alloc] initWithObjects:objects count:aCount]; + + return [super init]; +} + +/*! + Initializes a newly allocated set and adds to it objects from another given set. + @param aSet a set containing objects to add to the new set. +*/ +- (id)initWithSet:(CPSet)aSet +{ + return [self initWithArray:[aSet allObjects]]; +} + +/*! + Initializes a newly allocated set and adds to it members of another given set. Only included for compatability. + @param aSet a set of objects to add to the new set. + @param shouldCopyItems a boolean value. If YES the objects would be copied, if NO the objects will not be copied. +*/ +- (id)initWithSet:(CPSet)aSet copyItems:(BOOL)shouldCopyItems +{ + if (shouldCopyItems) + return [aSet valueForKey:@"copy"]; + + return [self initWithSet:aSet]; +} + +/*! + Returns the number of members in the receiver. +*/ +- (CPUInteger)count +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); +} + +/*! + Returns an array containing the receiver’s members, or an empty array if the receiver has no members. +*/ +- (CPArray)allObjects +{ + var objects = [], + object, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + objects.push(object); + + return objects; +} + +/*! + Returns one of the objects in the receiver, or nil if the receiver contains no objects. +*/ +- (id)anyObject +{ + return [[self objectEnumerator] nextObject]; +} + +/*! + Returns a Boolean value that indicates whether a given object is present in the receiver. + @param anObject The object for which to test membership of the receiver. +*/ +- (BOOL)containsObject:(id)anObject +{ + return [self member:anObject] !== nil; +} + +/*! + Returns a set filtered using a given predicate. + @prarm aPredicate a CPPredicate object used to filter the objects in the set. +*/ +- (CPSet)filteredSetUsingPredicate:(CPPredicate)aPredicate +{ + var objects = [], + object, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + if ([aPredicate evaluateWithObject:object]) + objects.push(object); + + return [[[self class] alloc] initWithArray:objects]; +} + +/*! + Sends to each object in the receiver a message specified by a given selector. + @param aSelector A selector that specifies the message to send to the members of the receiver. The method must not take any arguments. It should not have the side effect of modifying the receiver. This value must not be NULL. +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector +{ + [self makeObjectsPerformSelector:aSelector withObjects:nil]; +} + +/*! + Sends to each object in the receiver a message specified by a given selector. + @param aSelector A selector that specifies the message to send to the receiver's members. The method must take a single argument of type id. The method should not, as a side effect, modify the receiver. The value must not be NULL. + @param anObject The object to pass as an argument to the method specified by aSelector. +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)anObject +{ + [self makeObjectsPerformSelector:aSelector withObjects:[anObject]]; +} + +/*! + Sends to each object in the receiver a message specified by a given selector. + @param aSelector A selector that specifies the message to send to the receiver's members. The method must take a single argument of type id. The method should not, as a side effect, modify the receiver. The value must not be NULL. + @param objects The objects to pass as an argument to the method specified by aSelector. +*/ +- (void)makeObjectsPerformSelector:(SEL)aSelector withObjects:(CPArray)objects +{ + var object, + objectEnumerator = [self objectEnumerator], + argumentsArray = [nil, aSelector].concat(objects || []); + + while ((object = [objectEnumerator nextObject]) !== nil) + { + argumentsArray[0] = object; + objj_msgSend.apply(this, argumentsArray); + } +} + +/*! + Determines whether the receiver contains an object equal to a given object, and returns that object if it is present. + @param anObject The object for which to test for membership of the receiver. +*/ +- (id)member:(id)anObject +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); +} + +/*! + Returns an object enumerator (CPEnumerator) for the receiver. +*/ +- (CPEnumerator)objectEnumerator +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); +} + +/*! + Enumberates over the objects in a set using a given function. + @param aFunction a callback for each itteration, should be of the format: function(anObject). +*/ +- (void)enumerateObjectsUsingBlock:(Function)aFunction +{ + var object, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + if (aFunction(object)) + break; +} + +// FIXME: stop is broken. +- (CPSet)objectsPassingTest:(Function)aFunction +{ + var objects = [], + object = nil, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + if (aFunction(object)) + objects.push(object); + + return [[[self class] alloc] initWithArray:objects]; +} + +/*! + Returns a Boolean value that indicates whether every object in the receiver is also present in another given set. + @param set The set with which to compare the receiver. +*/ +- (BOOL)isSubsetOfSet:(CPSet)aSet +{ + var object = nil, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + if (![aSet containsObject:object]) + return NO; + + return YES; +} + +/*! + Returns a Boolean value that indicates whether at least one object in the receiver is also present in another given set. + @param set The set with which to compare the receiver. +*/ +- (BOOL)intersectsSet:(CPSet)aSet +{ + if (self === aSet) + // The empty set intersects nothing + return [self count] > 0; + + var object = nil, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + if ([aSet containsObject:object]) + return YES; + + return NO; +} + +/*! + Returns an array of the set's content sorted as specified by a given array of sort descriptors. + + @param sortDescriptors an array of CPSortDescriptor objects. +*/ +- (CPArray)sortedArrayUsingDescriptors:(CPArray)someSortDescriptors +{ + return [[self allObjects] sortedArrayUsingDescriptors:someSortDescriptors]; +} + +/*! + Compares the receiver to another set. + @param set The set with which to compare the receiver. +*/ +- (BOOL)isEqualToSet:(CPSet)aSet +{ + return [self isEqual:aSet]; +} + +/*! + Returns YES if BOTH sets are a subset of the other. + @param aSet a set of objects +*/ +- (BOOL)isEqual:(CPSet)aSet +{ + // If both are subsets of each other, they are equal + return self === aSet || + [aSet isKindOfClass:[CPSet class]] && + ([self count] === [aSet count] && + [aSet isSubsetOfSet:self]); +} + +- (CPString)description +{ + var string = "{(\n", + objects = [self allObjects], + index = 0, + count = [objects count]; + + for (; index < count; ++index) + { + var object = objects[index]; + + string += "\t" + String(object).split('\n').join("\n\t") + "\n"; + } + + return string + ")}"; +} + +@end + +@implementation CPSet (CPCopying) + +- (id)copy +{ + return [[self class] setWithSet:self]; +} + +- (id)mutableCopy +{ + return [self copy]; +} + +@end + +var CPSetObjectsKey = @"CPSetObjectsKey"; + +@implementation CPSet (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + return [self initWithArray:[aCoder decodeObjectForKey:CPSetObjectsKey]]; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [aCoder encodeObject:[self allObjects] forKey:CPSetObjectsKey]; +} + +@end + +@implementation CPSet (CPKeyValueCoding) + +- (id)valueForKey:(CPString)aKey +{ + if (aKey === "@count") + return [self count]; + + var valueSet = [CPSet set], + object, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + { + var value = [object valueForKey:aKey]; + + [valueSet addObject:value]; + } + + return valueSet; +} + +- (void)setValue:(id)aValue forKey:(CPString)aKey +{ + var object, + objectEnumerator = [self objectEnumerator]; + + while ((object = [objectEnumerator nextObject]) !== nil) + [object setValue:aValue forKey:aKey]; +} + +@end + +var _CPSharedPlaceholderSet = nil; + +@implementation _CPPlaceholderSet : CPSet +{ +} + ++ (id)alloc +{ + if (!_CPSharedPlaceholderSet) + _CPSharedPlaceholderSet = [super alloc]; + + return _CPSharedPlaceholderSet; +} + +@end + +// We actually want _CPConcreteMutableSet, but this introduces the possibility of an invalid @import loop. +// This will be correctly solved when we move to true immutable/mutable pairs. +//@import "CPMutableSet.j" From 803c8ce6b544104016a39d8af6f34e915414cb8d Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 17 Dec 2012 17:14:33 +0100 Subject: [PATCH 08/46] A little code clean up. --- Objective-J/FileExecutable.js | 9 +- Objective-J/ObjJCompiler.js | 495 ++++++++++++++++++++++++++++++---- 2 files changed, 444 insertions(+), 60 deletions(-) diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index cb355e031..2acb89300 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -41,13 +41,8 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate if (fileContents.match(/^@STATIC;/)) executable = decompile(fileContents, aURL); - else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) { -// console.log("Compile: " + aURL); -// if (!aURL || aURL.toString().indexOf("Boplats/Office/Applications") === -1) -// executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); -// else - executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); - } + else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) + executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); // FIXME: Include correct flags else executable = new Executable(fileContents, [], aURL); diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index 2e7f268b8..e39354d7a 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -20,42 +20,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -//function FileDependency(/*CFURL*/ aURL, /*BOOL*/ isLocal) -/*{ - this._URL = aURL; - this._isLocal = isLocal; -}*/ - -//var FileDependency = {}; // Dummy declaration !!!!!!! REMOVE!!!!!!!! var ObjJCompiler = { }, currentCompilerFlags = ""; -//(function(global, exports, module) -//{ - -/* function IS_NOT_EMPTY(buffer) {return buffer.atoms.length !== 0;} - - function CONCAT(buffer, atom) - { - if (buffer) - buffer.atoms[buffer.atoms.length] = atom; - } -*/ -/*function StringBuffer() -{ - this.atoms = []; -} - -StringBuffer.prototype.toString = function() -{ - return this.atoms.join(""); -}*/ - -//exports.compile = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -/*{ - return new ObjJCompiler(aString, aURL, flags); -}*/ - exports.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) { return new ObjJCompiler(aString, aURL, flags, 2).executable(); @@ -71,11 +38,6 @@ exports.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, / return new ObjJCompiler(aString, aURL, flags, 1).executable(); } -/*exports.eval = function(aString) -{ - return eval(exports.compile(aString).JSBuffer()); -}*/ - var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) { aString = aString.replace(/^#[^\n]+\n/, "\n"); @@ -88,18 +50,25 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla this._jsBuffer = new StringBuffer(); this._imBuffer = null; this._cmBuffer = null; - var start = new Date().getTime(); - //console.time("Parse - " + aURL); + + //var start = new Date().getTime(); +#ifdef BROWSER + console.time("Parse - " + aURL); +#endif this._tokens = exports.Parser.parse(aString); - var end = new Date().getTime(); - var time = (end - start) / 1000; + //var end = new Date().getTime(); + //var time = (end - start) / 1000; //print("Parse: " + aURL + " in " + time + " seconds"); - //console.timeEnd("Parse - " + aURL); +#ifdef BROWSER + console.timeEnd("Parse - " + aURL); +#endif this._dependencies = []; this._flags = flags | ObjJCompiler.Flags.IncludeDebugSymbols; this._classDefs = {}; - var start = new Date().getTime(); -// console.time("Compile" + pass + " - " + aURL); + //var start = new Date().getTime(); +#ifdef BROWSER + console.time("Compile pass " + pass + " - " + aURL); +#endif try { this.nodeDocument(this._tokens); } @@ -107,10 +76,12 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla print("Error: " + e + ", file content: " + aString); throw e; } - var end = new Date().getTime(); - var time = (end - start) / 1000; + //var end = new Date().getTime(); + //var time = (end - start) / 1000; //print("Compile pass 1: " + aURL + " in " + time + " seconds"); -// console.timeEnd("Compile" + pass + " - " + aURL); +#ifdef BROWSER + console.timeEnd("Compile pass " + pass + " - " + aURL); +#endif // console.log("JS: " + this._jsBuffer); } @@ -119,13 +90,17 @@ ObjJCompiler.prototype.compilePass2 = function() this._pass = 2; this._jsBuffer = new StringBuffer(); //print("Start Compile2: " + this._URL); - var start = new Date().getTime(); -// console.time("Compile" + this._pass + " - " + this._URL); + //var start = new Date().getTime(); +#ifdef BROWSER + console.time("Compile pass 2" + this._pass + " - " + this._URL); +#endif this.nodeDocument(this._tokens); - var end = new Date().getTime(); - var time = (end - start) / 1000; + //var end = new Date().getTime(); + //var time = (end - start) / 1000; //print("Compile pass 2: " + this._URL + " in " + time + " seconds"); -// console.timeEnd("Compile" + this._pass + " - " + this._URL); +#ifdef BROWSER + console.timeEnd("Compile" + this._pass + " - " + this._URL); +#endif return this._jsBuffer.toString(); } @@ -361,6 +336,7 @@ ObjJCompiler.AstNodeFINALLY = "FINALLY"; ObjJCompiler.AstNodeTRY = "TRY"; ObjJCompiler.AstNodeWITH = "WITH"; +#if DEBUG ObjJCompiler.prototype.assertNode = function(/*SyntaxNode*/ astNode, /*String*/ astNodeName) { if (!astNode || astNode.name !== astNodeName) @@ -369,16 +345,21 @@ ObjJCompiler.prototype.assertNode = function(/*SyntaxNode*/ astNode, /*String*/ throw new SyntaxError(this.error_message("Expected node " + astNodeName + " but got " + (astNode ? astNode.name : astNode), astNode)); } } +#endif ObjJCompiler.prototype.nodeDocument = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDocument); +#endif this.nodeStart(astNode.children[0]); } ObjJCompiler.prototype.nodeStart = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeStart); +#endif var children = astNode.children; this.nodeUnderline(children[0], false); @@ -393,7 +374,9 @@ ObjJCompiler.prototype.nodeStart = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeFunctionBody = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFunctionBody); +#endif var children = astNode.children; this.nodeUnderline(children[0], false); @@ -408,7 +391,9 @@ ObjJCompiler.prototype.nodeFunctionBody = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSourceElements = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSourceElements); +#endif var children = astNode.children; this.nodeSourceElement(children[0]); @@ -422,7 +407,9 @@ ObjJCompiler.prototype.nodeSourceElements = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSourceElement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSourceElement); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeStatement) @@ -439,7 +426,9 @@ ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode // Safari can't handle function declarations of the form function [name]([arguments]) { } // in evals. It requires them to be in the form [name] = function([arguments]) { }. So we // need format them like that. +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFunctionDeclaration); +#endif var children = astNode.children, child = children[6], offset = 0, @@ -476,7 +465,9 @@ ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFunctionExpression); +#endif var children = astNode.children, child = children[2], offset = 0, @@ -525,7 +516,9 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeFormalParameterList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFormalParameterList); +#endif var children = astNode.children; this.nodeIdentifier(children[0]); @@ -540,7 +533,9 @@ ObjJCompiler.prototype.nodeFormalParameterList = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeStatementList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeStatementList); +#endif var children = astNode.children; this.nodeStatement(children[0]); @@ -641,7 +636,9 @@ ObjJCompiler.prototype.nodeStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeBlock = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBlock); +#endif var children = astNode.children; this.nodeOpenBrace(children[0]); @@ -659,7 +656,9 @@ ObjJCompiler.prototype.nodeBlock = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeVariableStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVariableStatement); +#endif var children = astNode.children; this.nodeVAR(children[0]); @@ -678,7 +677,9 @@ ObjJCompiler.prototype.nodeVariableStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeVariableDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclaration); +#endif var children = astNode.children, identifier = this.nodeIdentifier(children[0]); @@ -695,7 +696,9 @@ ObjJCompiler.prototype.nodeVariableDeclaration = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeVariableDeclarationNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationNoIn); +#endif var children = astNode.children, identifier = this.nodeIdentifier(children[0]); @@ -712,7 +715,9 @@ ObjJCompiler.prototype.nodeVariableDeclarationNoIn = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeVariableDeclarationListNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationListNoIn); +#endif var children = astNode.children; this.nodeVariableDeclarationNoIn(children[0]); @@ -728,14 +733,18 @@ ObjJCompiler.prototype.nodeVariableDeclarationListNoIn = function(/*SyntaxNode*/ ObjJCompiler.prototype.nodeEmptyStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEmptyStatement); +#endif this.nodeWORD(astNode.children[0]); // ";" } ObjJCompiler.prototype.nodeExpressionStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeExpressionStatement); +#endif var children = astNode.children; this.nodeExpression(children[0]); @@ -744,7 +753,9 @@ ObjJCompiler.prototype.nodeExpressionStatement = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeIfStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIfStatement); +#endif var children = astNode.children; this.nodeIF(children[0]); @@ -768,7 +779,9 @@ ObjJCompiler.prototype.nodeIfStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIterationStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIterationStatement); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -796,7 +809,9 @@ ObjJCompiler.prototype.nodeIterationStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDoWhileStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDoWhileStatement); +#endif var children = astNode.children; this.nodeDO(children[0]); @@ -815,7 +830,9 @@ ObjJCompiler.prototype.nodeDoWhileStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeWhileStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeWhileStatement); +#endif var children = astNode.children; this.nodeWHILE(children[0]); @@ -831,7 +848,9 @@ ObjJCompiler.prototype.nodeWhileStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeForStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeForStatement); +#endif var children = astNode.children, child = children[4]; @@ -871,7 +890,9 @@ ObjJCompiler.prototype.nodeForStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeForFirstExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeForFirstExpression); +#endif var children = astNode.children, child = children[0]; @@ -887,7 +908,9 @@ ObjJCompiler.prototype.nodeForFirstExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeForInStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeForInStatement); +#endif var children = astNode.children; this.nodeFOR(children[0]); @@ -907,7 +930,9 @@ ObjJCompiler.prototype.nodeForInStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeForInFirstExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeForInFirstExpression); +#endif var children = astNode.children, child = children[0]; @@ -923,7 +948,9 @@ ObjJCompiler.prototype.nodeForInFirstExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeEachStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEachStatement); +#endif var children = astNode.children; this.nodeEACH(children[0]); @@ -943,7 +970,9 @@ ObjJCompiler.prototype.nodeEachStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeContinueStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeContinueStatement); +#endif var children = astNode.children, child = children[2]; @@ -960,7 +989,9 @@ ObjJCompiler.prototype.nodeContinueStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeBreakStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBreakStatement); +#endif var children = astNode.children, child = children[2]; @@ -977,7 +1008,9 @@ ObjJCompiler.prototype.nodeBreakStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeReturnStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeReturnStatement); +#endif var children = astNode.children, child = children[2]; @@ -994,7 +1027,9 @@ ObjJCompiler.prototype.nodeReturnStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeWithStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeWithStatement); +#endif var children = astNode.children; this.nodeWITH(children[0]); @@ -1010,7 +1045,9 @@ ObjJCompiler.prototype.nodeWithStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSwitchStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSwitchStatement); +#endif var children = astNode.children; this.nodeSWITCH(children[0]); @@ -1026,7 +1063,9 @@ ObjJCompiler.prototype.nodeSwitchStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCaseBlock = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCaseBlock); +#endif var children = astNode.children, child = children[2]; @@ -1058,7 +1097,9 @@ ObjJCompiler.prototype.nodeCaseBlock = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCaseClauses = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCaseClauses); +#endif var children = astNode.children; this.nodeCaseClause(children[0]); @@ -1072,7 +1113,9 @@ ObjJCompiler.prototype.nodeCaseClauses = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCaseClause = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCaseClause); +#endif var children = astNode.children, child = children[5]; @@ -1090,7 +1133,9 @@ ObjJCompiler.prototype.nodeCaseClause = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDefaultClause = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDefaultClause); +#endif var children = astNode.children, child = children[3]; @@ -1106,7 +1151,9 @@ ObjJCompiler.prototype.nodeDefaultClause = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeLabelledStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLabelledStatement); +#endif var children = astNode.children; this.nodeIdentifier(children[0]); @@ -1118,7 +1165,9 @@ ObjJCompiler.prototype.nodeLabelledStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeThrowStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeThrowStatement); +#endif var children = astNode.children, child = children[2]; @@ -1135,7 +1184,9 @@ ObjJCompiler.prototype.nodeThrowStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeTryStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTryStatement); +#endif var children = astNode.children, child = children[4]; @@ -1158,7 +1209,9 @@ ObjJCompiler.prototype.nodeTryStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCatch = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCatch); +#endif var children = astNode.children; this.nodeCATCH(children[0]); @@ -1174,7 +1227,9 @@ ObjJCompiler.prototype.nodeCatch = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeFinally = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFinally); +#endif var children = astNode.children; this.nodeFINALLY(children[0]); @@ -1184,7 +1239,9 @@ ObjJCompiler.prototype.nodeFinally = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDebuggerStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDebuggerStatement); +#endif var children = astNode.children; this.nodeDEBUGGER(children[0]); @@ -1193,7 +1250,9 @@ ObjJCompiler.prototype.nodeDebuggerStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeImportStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeImportStatement); +#endif var children = astNode.children, child = children[2], isQuoted = null, @@ -1228,14 +1287,18 @@ ObjJCompiler.prototype.nodeImportStatement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeLocalFilePath = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLocalFilePath); +#endif return this.nodeStringLiteral(astNode.children[0]); } ObjJCompiler.prototype.nodeStandardFilePath = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeStandardFilePath); +#endif var children = astNode.children, size = children.length, string = ""; @@ -1254,7 +1317,9 @@ ObjJCompiler.prototype.nodeStandardFilePath = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeClassDeclarationStatement); +#endif var children = astNode.children, child = children[4], offset = 0, @@ -1480,7 +1545,9 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeSuperclassDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSuperclassDeclaration); +#endif var children = astNode.children; this.nodeCOLON(children[0]); @@ -1490,7 +1557,9 @@ ObjJCompiler.prototype.nodeSuperclassDeclaration = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeCategoryDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCategoryDeclaration); +#endif var children = astNode.children; this.nodeOpenParenthesis(children[0]); @@ -1502,7 +1571,9 @@ ObjJCompiler.prototype.nodeCategoryDeclaration = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeCompoundIvarDeclaration = function(/*SyntaxNode*/ astNode, classDefIvars) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCompoundIvarDeclaration); +#endif var children = astNode.children, type = this.nodeIvarType(children[0]); @@ -1534,7 +1605,9 @@ ObjJCompiler.prototype.nodeCompoundIvarDeclaration = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeIvarType = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarType); +#endif var children = astNode.children, type = ""; @@ -1557,7 +1630,9 @@ ObjJCompiler.prototype.nodeIvarType = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIvarTypeElement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarTypeElement); +#endif var children = astNode.children, child = children[0]; @@ -1569,7 +1644,9 @@ ObjJCompiler.prototype.nodeIvarTypeElement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIvarDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarDeclaration); +#endif var children = astNode.children, child = children[2], ivar = {}; @@ -1584,7 +1661,9 @@ ObjJCompiler.prototype.nodeIvarDeclaration = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeAccessors = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAccessors); +#endif var children = astNode.children, size = children.length, accessors = {}; @@ -1617,7 +1696,9 @@ ObjJCompiler.prototype.nodeAccessors = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeAccessorsConfiguration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAccessorsConfiguration); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -1640,7 +1721,9 @@ ObjJCompiler.prototype.nodeAccessorsConfiguration = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeIvarPropertyName = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarPropertyName); +#endif var children = astNode.children; this.nodePROPERTY(children[0]); @@ -1652,7 +1735,9 @@ ObjJCompiler.prototype.nodeIvarPropertyName = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIvarGetterName = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarGetterName); +#endif var children = astNode.children; this.nodeGETTER(children[0]); @@ -1664,7 +1749,9 @@ ObjJCompiler.prototype.nodeIvarGetterName = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIvarSetterName = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIvarSetterName); +#endif var children = astNode.children; this.nodeSETTER(children[0]); @@ -1692,7 +1779,9 @@ ObjJCompiler.prototype.nodeIvarSetterName = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeClassBody = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeClassBody); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeClassElements) @@ -1701,7 +1790,9 @@ ObjJCompiler.prototype.nodeClassBody = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeClassElements = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeClassElements); +#endif var children = astNode.children; this.nodeClassElement(children[0]); @@ -1715,7 +1806,9 @@ ObjJCompiler.prototype.nodeClassElements = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeClassElement = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeClassElement); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -1745,7 +1838,9 @@ ObjJCompiler.prototype.nodeClassElement = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeClassMethodDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeClassMethodDeclaration); +#endif this.nodePLUS(astNode.children[0]); this._classMethod = true; this.genericMethodDeclaration(astNode, this._cmBuffer); @@ -1753,7 +1848,9 @@ ObjJCompiler.prototype.nodeClassMethodDeclaration = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeInstanceMethodDeclaration = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeInstanceMethodDeclaration); +#endif this.nodeMINUS(astNode.children[0]); this._classMethod = false; this.genericMethodDeclaration(astNode, this._imBuffer); @@ -1840,7 +1937,9 @@ ObjJCompiler.prototype.genericMethodDeclaration = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeMethodSelector = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMethodSelector); +#endif var children = astNode.children, child = children[0], size = children.length; @@ -1864,13 +1963,17 @@ ObjJCompiler.prototype.nodeMethodSelector = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeUnarySelector = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnarySelector); +#endif return this.nodeSelector(astNode.children[0]); } ObjJCompiler.prototype.nodeKeywordSelector = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelector); +#endif var children = astNode.children, keywordDecl = this.nodeKeywordDeclarator(children[0]), typeAndIndentifier = {"type": keywordDecl.methodType, "identifier": keywordDecl.identifier}, @@ -1891,7 +1994,9 @@ ObjJCompiler.prototype.nodeKeywordSelector = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeKeywordDeclarator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeKeywordDeclarator); +#endif var children = astNode.children, child = children[0], offset = 0, @@ -1923,13 +2028,17 @@ ObjJCompiler.prototype.nodeKeywordDeclarator = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSelector = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSelector); +#endif return this.nodeIdentifierName(astNode.children[0]); } ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMethodType); +#endif var children = astNode.children, child = children[2], size = children.length, @@ -1984,13 +2093,17 @@ ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeACTION = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeACTION); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeExpression); +#endif var children = astNode.children, size = children.length; @@ -2007,7 +2120,9 @@ ObjJCompiler.prototype.nodeExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2024,7 +2139,9 @@ ObjJCompiler.prototype.nodeExpressionNoIn = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeAssignmentExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpression); +#endif var children = astNode.children, child = children[0]; @@ -2042,7 +2159,9 @@ ObjJCompiler.prototype.nodeAssignmentExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeAssignmentExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpressionNoIn); +#endif var children = astNode.children, child = children[0]; @@ -2060,13 +2179,17 @@ ObjJCompiler.prototype.nodeAssignmentExpressionNoIn = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeAssignmentOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentOperator); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeConditionalExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpression); +#endif var children = astNode.children, child = children[1]; @@ -2086,7 +2209,9 @@ ObjJCompiler.prototype.nodeConditionalExpression = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeConditionalExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpressionNoIn); +#endif var children = astNode.children, child = children[1]; @@ -2106,7 +2231,9 @@ ObjJCompiler.prototype.nodeConditionalExpressionNoIn = function(/*SyntaxNode*/ a ObjJCompiler.prototype.nodeLogicalOrExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpression); +#endif var children = astNode.children, size = children.length; @@ -2123,7 +2250,9 @@ ObjJCompiler.prototype.nodeLogicalOrExpression = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeLogicalOrExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2140,7 +2269,9 @@ ObjJCompiler.prototype.nodeLogicalOrExpressionNoIn = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeLogicalAndExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpression); +#endif var children = astNode.children, size = children.length; @@ -2157,7 +2288,9 @@ ObjJCompiler.prototype.nodeLogicalAndExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeLogicalAndExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2174,7 +2307,9 @@ ObjJCompiler.prototype.nodeLogicalAndExpressionNoIn = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeBitwiseOrExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpression); +#endif var children = astNode.children, size = children.length; @@ -2191,7 +2326,9 @@ ObjJCompiler.prototype.nodeBitwiseOrExpression = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeBitwiseOrExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2208,7 +2345,9 @@ ObjJCompiler.prototype.nodeBitwiseOrExpressionNoIn = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeBitwiseXOrExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpression); +#endif var children = astNode.children, size = children.length; @@ -2225,7 +2364,9 @@ ObjJCompiler.prototype.nodeBitwiseXOrExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeBitwiseXOrExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2242,7 +2383,9 @@ ObjJCompiler.prototype.nodeBitwiseXOrExpressionNoIn = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeBitwiseAndExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpression); +#endif var children = astNode.children, size = children.length; @@ -2259,7 +2402,9 @@ ObjJCompiler.prototype.nodeBitwiseAndExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeBitwiseAndExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2276,7 +2421,9 @@ ObjJCompiler.prototype.nodeBitwiseAndExpressionNoIn = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeEqualityExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpression); +#endif var children = astNode.children, size = children.length; @@ -2293,7 +2440,9 @@ ObjJCompiler.prototype.nodeEqualityExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeEqualityExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2310,13 +2459,17 @@ ObjJCompiler.prototype.nodeEqualityExpressionNoIn = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeEqualityOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEqualityOperator); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeRelationalExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpression); +#endif var children = astNode.children, size = children.length; @@ -2333,7 +2486,9 @@ ObjJCompiler.prototype.nodeRelationalExpression = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeRelationalOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperator); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -2352,7 +2507,9 @@ ObjJCompiler.prototype.nodeRelationalOperator = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeRelationalExpressionNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpressionNoIn); +#endif var children = astNode.children, size = children.length; @@ -2369,7 +2526,9 @@ ObjJCompiler.prototype.nodeRelationalExpressionNoIn = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeRelationalOperatorNoIn = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperatorNoIn); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -2385,7 +2544,9 @@ ObjJCompiler.prototype.nodeRelationalOperatorNoIn = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeShiftExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeShiftExpression); +#endif var children = astNode.children, size = children.length; @@ -2402,13 +2563,17 @@ ObjJCompiler.prototype.nodeShiftExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeShiftOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeShiftOperator); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeAdditiveExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveExpression); +#endif var children = astNode.children, size = children.length; @@ -2425,13 +2590,17 @@ ObjJCompiler.prototype.nodeAdditiveExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeAdditiveOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveOperator); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeMultiplicativeExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeExpression); +#endif var children = astNode.children, size = children.length; @@ -2448,13 +2617,17 @@ ObjJCompiler.prototype.nodeMultiplicativeExpression = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeMultiplicativeOperator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeOperator); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeUnaryExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnaryExpression); +#endif var children = astNode.children, child = astNode.children[0], name = child ? child.name : null; @@ -2488,7 +2661,9 @@ ObjJCompiler.prototype.nodeUnaryExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePostfixExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePostfixExpression); +#endif var children = astNode.children; this.nodeLeftHandSideExpression(children[0]); @@ -2502,7 +2677,9 @@ ObjJCompiler.prototype.nodePostfixExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeLeftHandSideExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLeftHandSideExpression); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeCallExpression) @@ -2513,7 +2690,9 @@ ObjJCompiler.prototype.nodeLeftHandSideExpression = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeNewExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNewExpression); +#endif var children = astNode.children, child = children[0]; @@ -2529,7 +2708,9 @@ ObjJCompiler.prototype.nodeNewExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCallExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCallExpression); +#endif var children = astNode.children, size = children.length; @@ -2562,7 +2743,9 @@ ObjJCompiler.prototype.nodeCallExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeMemberExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMemberExpression); +#endif var children = astNode.children, size = children.length, child = children[0], @@ -2610,7 +2793,9 @@ ObjJCompiler.prototype.nodeMemberExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeBracketedAccessor = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBracketedAccessor); +#endif var children = astNode.children; this.nodeOpenBracket(children[0]); @@ -2622,7 +2807,9 @@ ObjJCompiler.prototype.nodeBracketedAccessor = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDotAccessor = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDotAccessor); +#endif var children = astNode.children; this.nodeDOT(children[0]); @@ -2632,7 +2819,9 @@ ObjJCompiler.prototype.nodeDotAccessor = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeArguments = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeArguments); +#endif var children = astNode.children, child = children[2], offset = 0; @@ -2650,7 +2839,9 @@ ObjJCompiler.prototype.nodeArguments = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeArgumentList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeArgumentList); +#endif var children = astNode.children, size = children.length; @@ -2667,7 +2858,9 @@ ObjJCompiler.prototype.nodeArgumentList = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePrimaryExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePrimaryExpression); +#endif var children = astNode.children, child = children[0], name = child ? child.name : null; @@ -2718,7 +2911,9 @@ ObjJCompiler.prototype.nodePrimaryExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeMessageExpression = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMessageExpression); +#endif var children = astNode.children, child = children[2], saveJSBuffer = this._jsBuffer; @@ -2773,7 +2968,9 @@ ObjJCompiler.prototype.nodeMessageExpression = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSelectorCall = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSelectorCall); +#endif var children = astNode.children, size = children.length, child = children[0], @@ -2802,7 +2999,9 @@ ObjJCompiler.prototype.nodeSelectorCall = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeKeywordSelectorCall = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelectorCall); +#endif var children = astNode.children, size = children.length; @@ -2822,7 +3021,9 @@ ObjJCompiler.prototype.nodeKeywordSelectorCall = function(/*SyntaxNode*/ astNode ObjJCompiler.prototype.nodeKeywordCall = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeKeywordCall); +#endif var children = astNode.children, child = children[0], offset = 0, @@ -2845,7 +3046,9 @@ ObjJCompiler.prototype.nodeKeywordCall = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeArrayLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeArrayLiteral); +#endif var children = astNode.children; this.nodeOpenBracket(children[0]); @@ -2857,7 +3060,9 @@ ObjJCompiler.prototype.nodeArrayLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeElementList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeElementList); +#endif var children = astNode.children, offset = 0; @@ -2884,7 +3089,9 @@ ObjJCompiler.prototype.nodeElementList = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeObjectLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeObjectLiteral); +#endif var children = astNode.children, child = children[2], offset = 2; @@ -2904,7 +3111,9 @@ ObjJCompiler.prototype.nodeObjectLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePropertyNameAndValueList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertyNameAndValueList); +#endif var children = astNode.children, size = children.length; @@ -2921,7 +3130,9 @@ ObjJCompiler.prototype.nodePropertyNameAndValueList = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodePropertyAssignment = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertyAssignment); +#endif var children = astNode.children, child = children[4], name = child ? child.name : null; @@ -2949,7 +3160,9 @@ ObjJCompiler.prototype.nodePropertyAssignment = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePropertyGetter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); +#endif var children = astNode.children, child = children[4]; @@ -2970,7 +3183,9 @@ ObjJCompiler.prototype.nodePropertyGetter = function(/*SyntaxNode*/ astNode) function PropertySetter(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); +#endif var children = astNode.children, child = children[4]; @@ -2993,7 +3208,9 @@ function PropertySetter(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePropertyName = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertyName); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3015,14 +3232,18 @@ ObjJCompiler.prototype.nodePropertyName = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodePropertySetParameterList = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodePropertySetParameterList); +#endif this.nodeIdentifier(astNode.children[0]); } ObjJCompiler.prototype.nodeLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLiteral); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3053,7 +3274,9 @@ ObjJCompiler.prototype.nodeLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSelectorLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteral); +#endif var children = astNode.children, saveJSBuffer = this._jsBuffer, selectorBuffer = new StringBuffer(); @@ -3078,7 +3301,9 @@ ObjJCompiler.prototype.nodeSelectorLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSelectorLiteralContents = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteralContents); +#endif var children = astNode.children, child = children[0]; @@ -3103,14 +3328,18 @@ ObjJCompiler.prototype.nodeSelectorLiteralContents = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeNullLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNullLiteral); +#endif this.nodeNULL(astNode.children[0]); } ObjJCompiler.prototype.nodeBooleanLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBooleanLiteral); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeTRUE) @@ -3121,7 +3350,9 @@ ObjJCompiler.prototype.nodeBooleanLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeNumericLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNumericLiteral); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeHexIntegerLiteral) @@ -3132,7 +3363,9 @@ ObjJCompiler.prototype.nodeNumericLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDecimalLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDecimalLiteral); +#endif var children = astNode.children, offset = 0, number = "", @@ -3162,7 +3395,9 @@ ObjJCompiler.prototype.nodeDecimalLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDecimalIntegerLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDecimalIntegerLiteral); +#endif var children = astNode.children, offset = 1, number = ""; @@ -3187,14 +3422,18 @@ ObjJCompiler.prototype.nodeDecimalIntegerLiteral = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeDecimalDigit = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDecimalDigit); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeExponentPart = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeExponentPart); +#endif var children = astNode.children; return this.nodeWORD(children[0]) + this.nodeSignedInteger(children[1]); @@ -3202,7 +3441,9 @@ ObjJCompiler.prototype.nodeExponentPart = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSignedInteger = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSignedInteger); +#endif var children = astNode.children, offset = 1, number = "", @@ -3225,7 +3466,9 @@ ObjJCompiler.prototype.nodeSignedInteger = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeHexIntegerLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeHexIntegerLiteral); +#endif var children = astNode.children, offset = 2, hex = this.nodeWORD(children[0]); @@ -3245,14 +3488,18 @@ ObjJCompiler.prototype.nodeHexIntegerLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeHexDigit = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeHexDigit); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeStringLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeStringLiteral); +#endif var children = astNode.children, offset = 0, string = ""; @@ -3289,7 +3536,9 @@ ObjJCompiler.prototype.nodeStringLiteral = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeDoubleStringCharacter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDoubleStringCharacter); +#endif var children = astNode.children, child = children[0]; @@ -3303,7 +3552,9 @@ ObjJCompiler.prototype.nodeDoubleStringCharacter = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeSingleStringCharacter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSingleStringCharacter); +#endif var children = astNode.children, child = children[0]; @@ -3317,7 +3568,9 @@ ObjJCompiler.prototype.nodeSingleStringCharacter = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeLineContinuation = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLineContinuation); +#endif var children = astNode.children; return this.nodeWORD(children[0]) + nodeLineTerminatorSequence(children[1]); @@ -3325,7 +3578,9 @@ ObjJCompiler.prototype.nodeLineContinuation = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeEscapeSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEscapeSequence); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3344,7 +3599,9 @@ ObjJCompiler.prototype.nodeEscapeSequence = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeCharacterEscapeSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCharacterEscapeSequence); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeSingleEscapeCharacter) @@ -3355,21 +3612,27 @@ ObjJCompiler.prototype.nodeCharacterEscapeSequence = function(/*SyntaxNode*/ ast ObjJCompiler.prototype.nodeSingleEscapeCharacter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSingleEscapeCharacter); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeNonEscapeCharacter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNonEscapeCharacter); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeHexEscapeSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeHexEscapeSequence); +#endif var children = astNode.children; return children[0] + this.nodeHexDigit(children[1]) + nodeHexDigit(children[2]); @@ -3377,7 +3640,9 @@ ObjJCompiler.prototype.nodeHexEscapeSequence = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeUnicodeEscapeSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeEscapeSequence); +#endif var children = astNode.children; return this.nodeWORD(children[0]) + this.nodeHexDigit(children[1]) + this.nodeHexDigit(children[2]) + this.nodeHexDigit(children[3]) + this.nodeHexDigit(children[4]); @@ -3385,7 +3650,9 @@ ObjJCompiler.prototype.nodeUnicodeEscapeSequence = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeRegularExpressionLiteral = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionLiteral); +#endif var children = astNode.children; return this.nodeWORD(children[0]) + this.nodeRegularExpressionBody(children[1]) + this.nodeWORD(children[2]) + this.nodeRegularExpressionFlags(children[3]); @@ -3393,7 +3660,9 @@ ObjJCompiler.prototype.nodeRegularExpressionLiteral = function(/*SyntaxNode*/ as ObjJCompiler.prototype.nodeRegularExpressionBody = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBody); +#endif var children = astNode.children, regString = this.nodeRegularExpressionFirstChar(children[0]), offset = 1, @@ -3409,7 +3678,9 @@ ObjJCompiler.prototype.nodeRegularExpressionBody = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeRegularExpressionFirstChar = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFirstChar); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3428,7 +3699,9 @@ ObjJCompiler.prototype.nodeRegularExpressionFirstChar = function(/*SyntaxNode*/ ObjJCompiler.prototype.nodeRegularExpressionChar = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionChar); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3447,7 +3720,9 @@ ObjJCompiler.prototype.nodeRegularExpressionChar = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeRegularExpressionBackslashSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBackslashSequence); +#endif var children = astNode.children; return this.nodeWORD(children[0]) + this.nodeRegularExpressionNonTerminator(children[1]); @@ -3455,14 +3730,18 @@ ObjJCompiler.prototype.nodeRegularExpressionBackslashSequence = function(/*Synta ObjJCompiler.prototype.nodeRegularExpressionNonTerminator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionNonTerminator); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeRegularExpressionClass = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClass); +#endif var children = astNode.children, offset = 1, regString = this.nodeWORD(children[0]), @@ -3479,7 +3758,9 @@ ObjJCompiler.prototype.nodeRegularExpressionClass = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeRegularExpressionClassChar = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClassChar); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeRegularExpressionNonTerminator) @@ -3490,7 +3771,9 @@ ObjJCompiler.prototype.nodeRegularExpressionClassChar = function(/*SyntaxNode*/ ObjJCompiler.prototype.nodeRegularExpressionFlags = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFlags); +#endif var children = astNode.children, offset = 0, regString = "", @@ -3507,7 +3790,9 @@ ObjJCompiler.prototype.nodeRegularExpressionFlags = function(/*SyntaxNode*/ astN ObjJCompiler.prototype.nodeUnderline = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnderline); +#endif var children = astNode.children, size = children.length; string = ""; @@ -3537,7 +3822,9 @@ ObjJCompiler.prototype.nodeUnderline = function(/*SyntaxNode*/ astNode, /*boolea ObjJCompiler.prototype.nodeUnderlineNoLineBreak = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnderlineNoLineBreak); +#endif var children = astNode.children, size = children.length; string = ""; @@ -3567,28 +3854,36 @@ ObjJCompiler.prototype.nodeUnderlineNoLineBreak = function(/*SyntaxNode*/ astNod ObjJCompiler.prototype.nodeWhiteSpace = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeWhiteSpace); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeLineTerminator = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminator); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeLineTerminatorSequence = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminatorSequence); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeComment = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeComment); +#endif var child = astNode.children[0]; if (child && child.name === ObjJCompiler.AstNodeMultiLineComment) @@ -3599,7 +3894,9 @@ ObjJCompiler.prototype.nodeComment = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeMultiLineComment = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeMultiLineComment); +#endif var children = astNode.children, size = children.length; string = ""; @@ -3614,7 +3911,9 @@ ObjJCompiler.prototype.nodeMultiLineComment = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSingleLineMultiLineComment = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineMultiLineComment); +#endif var children = astNode.children, size = children.length, string = ""; @@ -3629,7 +3928,9 @@ ObjJCompiler.prototype.nodeSingleLineMultiLineComment = function(/*SyntaxNode*/ ObjJCompiler.prototype.nodeSingleLineComment = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineComment); +#endif var children = astNode.children, size = children.length, string = children[0]; @@ -3645,14 +3946,18 @@ ObjJCompiler.prototype.nodeSingleLineComment = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSingleLineCommentChar = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineCommentChar); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeEOS = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEOS); +#endif var children = astNode.children, child = children[0]; @@ -3675,7 +3980,9 @@ ObjJCompiler.prototype.nodeEOS = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeSemicolonInsertionEOS = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSemicolonInsertionEOS); +#endif var children = astNode.children, child = children[1]; @@ -3690,19 +3997,25 @@ ObjJCompiler.prototype.nodeSemicolonInsertionEOS = function(/*SyntaxNode*/ astNo ObjJCompiler.prototype.nodeEOF = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeEOF); +#endif } ObjJCompiler.prototype.nodeIdentifier = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIdentifier); +#endif return this.nodeIdentifierName(astNode.children[0]); } ObjJCompiler.prototype.nodeIdentifierName = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierName); +#endif var children = astNode.children, size = children.length, string = this.nodeIdentifierStart(children[0]); @@ -3717,7 +4030,9 @@ ObjJCompiler.prototype.nodeIdentifierName = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIdentifierStart = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierStart); +#endif var children = astNode.children, child = children[0]; @@ -3731,7 +4046,9 @@ ObjJCompiler.prototype.nodeIdentifierStart = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeIdentifierPart = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierPart); +#endif var child = astNode.children[0], name = child ? child.name : null; @@ -3756,252 +4073,324 @@ ObjJCompiler.prototype.nodeIdentifierPart = function(/*SyntaxNode*/ astNode) ObjJCompiler.prototype.nodeZWNJ = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeZWNJ); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeZWJ = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeZWJ); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeUnicodeLetter = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeLetter); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeUnicodeCombiningMark = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeCombiningMark); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeUnicodeDigit = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeDigit); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeUnicodeConnectorPunctuation = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeConnectorPunctuation); +#endif return this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeFALSE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFALSE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeTRUE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTRUE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeNULL = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNULL); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeBREAK = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeBREAK); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeCONTINUE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCONTINUE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeDEBUGGER = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDEBUGGER); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeIN = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIN); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeINSTANCEOF = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeINSTANCEOF); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeDELETE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDELETE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeFUNCTION = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFUNCTION); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeNEW = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeNEW); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeTHIS = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTHIS); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeTYPEOF = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTYPEOF); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeVOID = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVOID); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeIF = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeIF); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeELSE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeELSE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeDO = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDO); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeWHILE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeWHILE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeFOR = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFOR); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeVAR = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeVAR); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeRETURN = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeRETURN); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeCASE = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCASE); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeDEFAULT = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeDEFAULT); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeSWITCH = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSWITCH); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeTHROW = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTHROW); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeCATCH = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeCATCH); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeFINALLY = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFINALLY); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeTRY = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeTRY); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeWITH = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeWITH); +#endif this.nodeWORD(astNode.children[0]); } ObjJCompiler.prototype.nodeSUPER = function(/*SyntaxNode*/ astNode) { +#if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeSUPER); +#endif this.nodeWORD(astNode.children[0]); } From 982da962e54d64d321890ad9116d96806b56d4dd Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 19 Dec 2012 23:51:42 +0100 Subject: [PATCH 09/46] Fixed problems due to the removal of with(self) --- Foundation/CPNumber.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/CPNumber.j b/Foundation/CPNumber.j index 1373a025a..2035efce0 100644 --- a/Foundation/CPNumber.j +++ b/Foundation/CPNumber.j @@ -223,7 +223,7 @@ FIXME: Do we need this? - (CPString)descriptionWithLocale:(CPDictionary)aDictionary { if (!aDictionary) - return toString(); + return self.toString(); throw new Error("descriptionWithLocale: NOT YET IMPLEMENTED"); } @@ -277,7 +277,7 @@ FIXME: Do we need this? - (CPString)stringValue { - return toString(); + return self.toString(); } - (unsigned char)unsignedCharValue From b1cec9480e27cc099ae726aeeb336077ad0b4b00 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 09:37:52 +0100 Subject: [PATCH 10/46] New test cases to test ivar handling in new compiler --- .../Preprocessor/BehaviorTests/IvarTest.j | 63 +++++++++++++++++-- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j b/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j index 443ea10a4..fe4d770b5 100644 --- a/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j +++ b/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j @@ -41,6 +41,31 @@ self.ivar1 = ivar1; } +- (void)returnShadowingLocalVariable +{ + var ivar1 = 2; + + return ivar1; +} + +- (void)returnShadowingHoistedLocalVariable +{ + return ivar1; + + var ivar1; +} + +- (void)returnFunctionWithShadowingFunctionParameter +{ + return function(ivar1) { return ivar1 }; +} + +- (void)returnFunctionWithShadowingHoistedLocalVariable +{ + return function() { return ivar1; } + var ivar1; +} + @end @implementation IvarTest : OJTestCase @@ -78,15 +103,12 @@ [self assert:5 equals:testClass.ivar1]; } -/* -TODO Reactivate this test after issue #498 is resolved. - - (void)testIvarShadowing { [self assert:nil equals:testClass.ivar1]; [testClass setIvar1UsingAShadowingLocalVariable:5]; [self assert:5 equals:testClass.ivar1]; -}*/ +} - (void)testAccessorGeneration { @@ -117,4 +139,37 @@ TODO Reactivate this test after issue #498 is resolved. [self assert:nil equals:testClass.ivar3]; } +- (void)testShadowingLocalVariable +{ + [self assert:nil equals:testClass.ivar1]; + testClass.ivar1 = 99; + var x = [testClass returnShadowingLocalVariable]; + [self assert:2 equals:x]; +} + +- (void)testShadowingHoistedLocalVariable +{ + [self assert:nil equals:testClass.ivar1]; + testClass.ivar1 = 99; + var x = [testClass returnShadowingHoistedLocalVariable]; + [self assert:"undefined" equals:typeof x]; +} + +- (void)testFunctionWithShadowingFunctionParameter +{ + [self assert:nil equals:testClass.ivar1]; + testClass.ivar1 = 99; + var f = [testClass returnFunctionWithShadowingFunctionParameter]; + [self assert:8 equals:f(8)]; +} + +- (void)testFunctionWithShadowingHoistedLocalVariable +{ + [self assert:nil equals:testClass.ivar1]; + testClass.ivar1 = 99; + var f = [testClass returnFunctionWithShadowingHoistedLocalVariable]; + + [self assert:"undefined" equals:typeof f()]; +} + @end From 227c696750d3a19d4c3aa7468e1d28f5b6a07439 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 14:22:09 +0100 Subject: [PATCH 11/46] Removed circular imports in CPToolbarItem.j --- AppKit/CPToolbarItem.j | 639 +------------------------- AppKit/_CPToolbarFlexibleSpaceItem.j | 2 +- AppKit/_CPToolbarItem.j | 662 +++++++++++++++++++++++++++ AppKit/_CPToolbarSeparatorItem.j | 2 +- AppKit/_CPToolbarShowColorsItem.j | 2 +- AppKit/_CPToolbarSpaceItem.j | 2 +- 6 files changed, 669 insertions(+), 640 deletions(-) create mode 100644 AppKit/_CPToolbarItem.j diff --git a/AppKit/CPToolbarItem.j b/AppKit/CPToolbarItem.j index 4f6f23a25..c70590151 100644 --- a/AppKit/CPToolbarItem.j +++ b/AppKit/CPToolbarItem.j @@ -20,643 +20,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import -@import -@import "CPImage.j" -@import "CPView.j" - - -CPToolbarItemVisibilityPriorityStandard = 0; -CPToolbarItemVisibilityPriorityLow = -1000; -CPToolbarItemVisibilityPriorityHigh = 1000; -CPToolbarItemVisibilityPriorityUser = 2000; - -CPToolbarSeparatorItemIdentifier = @"CPToolbarSeparatorItem"; -CPToolbarSpaceItemIdentifier = @"CPToolbarSpaceItem"; -CPToolbarFlexibleSpaceItemIdentifier = @"CPToolbarFlexibleSpaceItem"; -CPToolbarShowColorsItemIdentifier = @"CPToolbarShowColorsItem"; -CPToolbarShowFontsItemIdentifier = @"CPToolbarShowFontsItem"; -CPToolbarCustomizeToolbarItemIdentifier = @"CPToolbarCustomizeToolbarItem"; -CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem"; - -/*! - @ingroup appkit - @class CPToolbarItem - - A representation of an item in a CPToolbar. -*/ -@implementation CPToolbarItem : CPObject -{ - CPString _itemIdentifier; - - CPToolbar _toolbar; - - CPString _label; - CPString _paletteLabel; - CPString _toolTip; - int _tag; - id _target; - SEL _action; - BOOL _isEnabled; - CPImage _image; - CPImage _alternateImage; - - CPView _view; - - CGSize _minSize; - CGSize _maxSize; - - int _visibilityPriority; - - BOOL _autovalidates; -} - -- (id)init -{ - return [self initWithItemIdentifier:@""]; -} - -// Creating a Toolbar Item -/*! - Initializes the toolbar item with a specified identifier. - @param anItemIdentifier the item's identifier - @return the initialized toolbar item -*/ -- (id)initWithItemIdentifier:(CPString)anItemIdentifier -{ - self = [super init]; - - if (self) - { - _itemIdentifier = anItemIdentifier; - - _tag = 0; - _isEnabled = YES; - - _minSize = CGSizeMakeZero(); - _maxSize = CGSizeMakeZero(); - - _visibilityPriority = CPToolbarItemVisibilityPriorityStandard; - _autovalidates = YES; - } - - return self; -} - -// Managing Attributes -/*! - Returns the item's identifier. -*/ -- (CPString)itemIdentifier -{ - return _itemIdentifier; -} - -/*! - Returns the toolbar of which this item is a part. -*/ -- (CPToolbar)toolbar -{ - return _toolbar; -} - -/* @ignore */ -- (void)_setToolbar:(CPToolbar)aToolbar -{ - _toolbar = aToolbar; -} - -/*! - Returns the item's label -*/ -- (CPString)label -{ - return _label; -} - -/*! - Sets the item's label. - @param aLabel the new label for the item -*/ -- (void)setLabel:(CPString)aLabel -{ - _label = aLabel; -} - -/*! - Returns the palette label. -*/ -- (CPString)paletteLabel -{ - return _paletteLabel; -} - -/*! - Sets the palette label - @param aPaletteLabel the new palette label -*/ -- (void)setPaletteLabel:(CPString)aPaletteLabel -{ - _paletteLabel = aPaletteLabel; -} - -/*! - Returns the item's tooltip. A tooltip pops up - next to the cursor when the user hovers over - the item with the mouse. -*/ -- (CPString)toolTip -{ - if ([_view respondsToSelector:@selector(toolTip)]) - return [_view toolTip]; - - return _toolTip; -} - -/*! - Sets the item's tooltip. A tooltip pops up next to the cursor when the user hovers over the item with the mouse. - @param aToolTip the new item tool tip -*/ -- (void)setToolTip:(CPString)aToolTip -{ - if ([_view respondsToSelector:@selector(setToolTip:)]) - [_view setToolTip:aToolTip]; - - _toolTip = aToolTip; -} - -/*! - Returns the item's tag. -*/ -- (int)tag -{ - if ([_view respondsToSelector:@selector(tag)]) - return [_view tag]; - - return _tag; -} - -/*! - Sets the item's tag. - @param aTag the new tag for the item -*/ -- (void)setTag:(int)aTag -{ - if ([_view respondsToSelector:@selector(setTag:)]) - [_view setTag:aTag]; - - _tag = aTag; -} - -/*! - Returns the item's action target. -*/ -- (id)target -{ - if (_view) - return [_view respondsToSelector:@selector(target)] ? [_view target] : nil; - - return _target; -} - -/*! - Sets the target of the action that is triggered when the user clicks this item. \c nil will cause - the action to be passed on to the first responder. - @param aTarget the new target -*/ -- (void)setTarget:(id)aTarget -{ - if (!_view) - _target = aTarget; - - else if ([_view respondsToSelector:@selector(setTarget:)]) - [_view setTarget:aTarget]; -} - -/*! - Returns the action that is triggered when the user clicks this item. -*/ -- (SEL)action -{ - if (_view) - return [_view respondsToSelector:@selector(action)] ? [_view action] : nil; - - return _action; -} - -/*! - Sets the action that is triggered when the user clicks this item. - @param anAction the new action -*/ -- (void)setAction:(SEL)anAction -{ - if (!_view) - _action = anAction; - - else if ([_view respondsToSelector:@selector(setAction:)]) - [_view setAction:anAction]; -} - -/*! - Returns \c YES if the item is enabled. -*/ -- (BOOL)isEnabled -{ - if ([_view respondsToSelector:@selector(isEnabled)]) - return [_view isEnabled]; - - return _isEnabled; -} - -/*! - Sets whether the item is enabled. - @param aFlag \c YES enables the item -*/ -- (void)setEnabled:(BOOL)shouldBeEnabled -{ - if (_isEnabled === shouldBeEnabled) - return; - - if ([_view respondsToSelector:@selector(setEnabled:)]) - [_view setEnabled:shouldBeEnabled]; - - _isEnabled = shouldBeEnabled; -} - -/*! - Returns the item's image -*/ -- (CPImage)image -{ - if ([_view respondsToSelector:@selector(image)]) - return [_view image]; - - return _image; -} - -/*! - Sets the item's image. - @param anImage the new item image -*/ -- (void)setImage:(CPImage)anImage -{ - if ([_view respondsToSelector:@selector(setImage:)]) - [_view setImage:anImage]; - - _image = anImage; - - if (!_image) - return; - - if (_minSize.width === 0 && _minSize.height === 0 && - _maxSize.width === 0 && _maxSize.height === 0) - { - var imageSize = [_image size]; - - if (imageSize.width > 0 || imageSize.height > 0) - { - [self setMinSize:imageSize]; - [self setMaxSize:imageSize]; - } - } -} - -/*! - Sets the alternate image. This image is displayed on the item when the user is clicking it. - @param anImage the new alternate image -*/ -- (void)setAlternateImage:(CPImage)anImage -{ - if ([_view respondsToSelector:@selector(setAlternateImage:)]) - [_view setAlternateImage:anImage]; - - _alternateImage = anImage; -} - -/*! - Returns the alternate image. This image is displayed on the item when the user is clicking it. -*/ -- (CPImage)alternateImage -{ - if ([_view respondsToSelector:@selector(alternateIamge)]) - return [_view alternateImage]; - - return _alternateImage; -} - -/*! - Returns the item's view. -*/ -- (CPView)view -{ - return _view; -} - -/*! - Sets the item's view - @param aView the item's new view -*/ -- (void)setView:(CPView)aView -{ - if (_view == aView) - return; - - _view = aView; - - if (_view) - { - // Tags get forwarded. - if (_tag !== 0 && [_view respondsToSelector:@selector(setTag:)]) - [_view setTag:_tag]; - - _target = nil; - _action = nil; - } -} - -/*! - Returns the item's minimum size. -*/ -- (CGSize)minSize -{ - return _minSize; -} - -/*! - Sets the item's minimum size. - @param aMinSize the new minimum size -*/ -- (void)setMinSize:(CGSize)aMinSize -{ - if (!aMinSize.height || !aMinSize.width) - return; - - _minSize = CGSizeMakeCopy(aMinSize); - - // Try to provide some sanity: Make maxSize >= minSize - _maxSize = CGSizeMake(MAX(_minSize.width, _maxSize.width), MAX(_minSize.height, _maxSize.height)); -} - -/*! - Returns the item's maximum size. -*/ -- (CGSize)maxSize -{ - return _maxSize; -} - -/*! - Sets the item's new maximum size. - @param aMaxSize the new maximum size -*/ -- (void)setMaxSize:(CGSize)aMaxSize -{ - if (!aMaxSize.height || !aMaxSize.width) - return; - - _maxSize = CGSizeMakeCopy(aMaxSize); - - // Try to provide some sanity: Make minSize <= maxSize - _minSize = CGSizeMake(MIN(_minSize.width, _maxSize.width), MIN(_minSize.height, _maxSize.height)); -} - -// Visibility Priority -/*! - Returns the item's visibility priority. The value will be one of: -
-CPToolbarItemVisibilityPriorityStandard
-CPToolbarItemVisibilityPriorityLow
-CPToolbarItemVisibilityPriorityHigh
-CPToolbarItemVisibilityPriorityUser
-
-*/ -- (int)visibilityPriority -{ - return _visibilityPriority; -} - -/*! - Sets the item's visibility priority. The value must be one of: -
-CPToolbarItemVisibilityPriorityStandard
-CPToolbarItemVisibilityPriorityLow
-CPToolbarItemVisibilityPriorityHigh
-CPToolbarItemVisibilityPriorityUser
-
- @param aVisiblityPriority the priority -*/ -- (void)setVisibilityPriority:(int)aVisibilityPriority -{ - _visibilityPriority = aVisibilityPriority; -} - -- (void)validate -{ - var action = [self action], - target = [self target]; - - // View items do not do any target-action analysis. - if (_view) - { - if ([target respondsToSelector:@selector(validateToolbarItem:)]) - { - var shouldBeEnabled = [target validateToolbarItem:self]; - if (_isEnabled !== shouldBeEnabled) - [self setEnabled:shouldBeEnabled]; - } - - return; - } - - if (!action) - { - if (_isEnabled) - return [self setEnabled:NO]; - return; - } - - if (target && ![target respondsToSelector:action]) - { - if (_isEnabled) - return [self setEnabled:NO]; - return; - } - - target = [CPApp targetForAction:action to:target from:self]; - - if (!target) - { - if (_isEnabled) - return [self setEnabled:NO]; - return; - } - - if ([target respondsToSelector:@selector(validateToolbarItem:)]) - { - var shouldBeEnabled = [target validateToolbarItem:self]; - if (_isEnabled !== shouldBeEnabled) - [self setEnabled:shouldBeEnabled]; - } - else - { - if (!_isEnabled) - [self setEnabled:YES]; - } -} - -- (BOOL)autovalidates -{ - return _autovalidates; -} - -- (void)setAutovalidates:(BOOL)shouldAutovalidate -{ - _autovalidates = !!shouldAutovalidate; -} - -@end - -var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey", - CPToolbarItemLabelKey = @"CPToolbarItemLabelKey", - CPToolbarItemPaletteLabelKey = @"CPToolbarItemPaletteLabelKey", - CPToolbarItemToolTipKey = @"CPToolbarItemToolTipKey", - CPToolbarItemTagKey = @"CPToolbarItemTagKey", - CPToolbarItemTargetKey = @"CPToolbarItemTargetKey", - CPToolbarItemActionKey = @"CPToolbarItemActionKey", - CPToolbarItemEnabledKey = @"CPToolbarItemEnabledKey", - CPToolbarItemImageKey = @"CPToolbarItemImageKey", - CPToolbarItemAlternateImageKey = @"CPToolbarItemAlternateImageKey", - CPToolbarItemViewKey = @"CPToolbarItemViewKey", - CPToolbarItemMinSizeKey = @"CPToolbarItemMinSizeKey", - CPToolbarItemMaxSizeKey = @"CPToolbarItemMaxSizeKey", - CPToolbarItemVisibilityPriorityKey = @"CPToolbarItemVisibilityPriorityKey", - CPToolbarItemAutovalidatesKey = @"CPToolbarItemAutovalidatesKey"; - -@implementation CPToolbarItem (CPCoding) - -- (id)initWithCoder:(CPCoder)aCoder -{ - self = [super init]; - - if (self) - { - _itemIdentifier = [aCoder decodeObjectForKey:CPToolbarItemItemIdentifierKey]; - - _minSize = [aCoder decodeSizeForKey:CPToolbarItemMinSizeKey]; - _maxSize = [aCoder decodeSizeForKey:CPToolbarItemMaxSizeKey]; - - [self setLabel:[aCoder decodeObjectForKey:CPToolbarItemLabelKey]]; - [self setPaletteLabel:[aCoder decodeObjectForKey:CPToolbarItemPaletteLabelKey]]; - [self setToolTip:[aCoder decodeObjectForKey:CPToolbarItemToolTipKey]]; - - [self setTag:[aCoder decodeObjectForKey:CPToolbarItemTagKey]]; - [self setTarget:[aCoder decodeObjectForKey:CPToolbarItemTargetKey]]; - [self setAction:CPSelectorFromString([aCoder decodeObjectForKey:CPToolbarItemActionKey])]; - - [self setEnabled:[aCoder decodeBoolForKey:CPToolbarItemEnabledKey]]; - - [self setImage:[aCoder decodeObjectForKey:CPToolbarItemImageKey]]; - [self setAlternateImage:[aCoder decodeObjectForKey:CPToolbarItemAlternateImageKey]]; - - [self setView:[aCoder decodeObjectForKey:CPToolbarItemViewKey]]; - - [self setVisibilityPriority:[aCoder decodeIntForKey:CPToolbarItemVisibilityPriorityKey]]; - [self setAutovalidates:[aCoder decodeBoolForKey:CPToolbarItemAutovalidatesKey]]; - } - - return self; -} - -- (void)encodeWithCoder:(CPCoder)aCoder -{ - [aCoder encodeObject:_itemIdentifier forKey:CPToolbarItemItemIdentifierKey]; - - [aCoder encodeObject:[self label] forKey:CPToolbarItemLabelKey]; - [aCoder encodeObject:[self paletteLabel] forKey:CPToolbarItemPaletteLabelKey]; - - [aCoder encodeObject:[self toolTip] forKey:CPToolbarItemToolTipKey]; - - [aCoder encodeObject:[self tag] forKey:CPToolbarItemTagKey]; - [aCoder encodeObject:[self target] forKey:CPToolbarItemTargetKey]; - [aCoder encodeObject:[self action] forKey:CPToolbarItemActionKey]; - - [aCoder encodeObject:[self isEnabled] forKey:CPToolbarItemEnabledKey]; - - [aCoder encodeObject:[self image] forKey:CPToolbarItemImageKey]; - [aCoder encodeObject:[self alternateImage] forKey:CPToolbarItemAlternateImageKey]; - - [aCoder encodeObject:[self view] forKey:CPToolbarItemViewKey]; - - [aCoder encodeSize:[self minSize] forKey:CPToolbarItemMinSizeKey]; - [aCoder encodeSize:[self maxSize] forKey:CPToolbarItemMaxSizeKey]; - - [aCoder encodeObject:[self visibilityPriority] forKey:CPToolbarItemVisibilityPriorityKey]; - [aCoder encodeBool:[self autovalidates] forKey:CPToolbarItemAutovalidatesKey]; -} - -@end - -@implementation CPToolbarItem (CPCopying) - -- (id)copy -{ - var copy = [[[self class] alloc] initWithItemIdentifier:_itemIdentifier]; - - if (_view) - [copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]]; - - [copy _setToolbar:_toolbar]; - - [copy setLabel:_label]; - [copy setPaletteLabel:_paletteLabel]; - [copy setToolTip:[self toolTip]]; - - [copy setTag:[self tag]]; - [copy setTarget:[self target]]; - [copy setAction:[self action]]; - - [copy setEnabled:[self isEnabled]]; - - [copy setImage:[self image]]; - [copy setAlternateImage:[self alternateImage]]; - - [copy setMinSize:_minSize]; - [copy setMaxSize:_maxSize]; - - [copy setVisibilityPriority:[self visibilityPriority]]; - [copy setAutovalidates:[self autovalidates]]; - - return copy; -} - -@end - -// Standard toolbar identifiers - -@implementation CPToolbarItem (Standard) - -/* @ignore */ -+ (CPToolbarItem)_standardItemWithItemIdentifier:(CPString)anItemIdentifier -{ - switch (anItemIdentifier) - { - case CPToolbarSeparatorItemIdentifier: return [_CPToolbarSeparatorItem new]; - case CPToolbarSpaceItemIdentifier: return [_CPToolbarSpaceItem new]; - case CPToolbarFlexibleSpaceItemIdentifier: return [_CPToolbarFlexibleSpaceItem new]; - case CPToolbarShowColorsItemIdentifier: return [_CPToolbarShowColorsItem new]; - case CPToolbarShowFontsItemIdentifier: return nil; - case CPToolbarCustomizeToolbarItemIdentifier: return nil; - case CPToolbarPrintItemIdentifier: return nil; - } - - return nil; -} - -@end - -/*@import "_CPToolbarFlexibleSpaceItem.j" +@import "_CPToolbarItem.j" +@import "_CPToolbarFlexibleSpaceItem.j" @import "_CPToolbarShowColorsItem.j" @import "_CPToolbarSeparatorItem.j" @import "_CPToolbarSpaceItem.j" -*/ + diff --git a/AppKit/_CPToolbarFlexibleSpaceItem.j b/AppKit/_CPToolbarFlexibleSpaceItem.j index 777743535..0a67081bf 100644 --- a/AppKit/_CPToolbarFlexibleSpaceItem.j +++ b/AppKit/_CPToolbarFlexibleSpaceItem.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPToolbarItem.j" +@import "_CPToolbarItem.j" @implementation _CPToolbarFlexibleSpaceItem : CPToolbarItem diff --git a/AppKit/_CPToolbarItem.j b/AppKit/_CPToolbarItem.j new file mode 100644 index 000000000..4f6f23a25 --- /dev/null +++ b/AppKit/_CPToolbarItem.j @@ -0,0 +1,662 @@ +/* + * CPToolbarItem.j + * AppKit + * + * Created by Francisco Tolmasky. + * Copyright 2008, 280 North, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +@import +@import + +@import "CPImage.j" +@import "CPView.j" + + +CPToolbarItemVisibilityPriorityStandard = 0; +CPToolbarItemVisibilityPriorityLow = -1000; +CPToolbarItemVisibilityPriorityHigh = 1000; +CPToolbarItemVisibilityPriorityUser = 2000; + +CPToolbarSeparatorItemIdentifier = @"CPToolbarSeparatorItem"; +CPToolbarSpaceItemIdentifier = @"CPToolbarSpaceItem"; +CPToolbarFlexibleSpaceItemIdentifier = @"CPToolbarFlexibleSpaceItem"; +CPToolbarShowColorsItemIdentifier = @"CPToolbarShowColorsItem"; +CPToolbarShowFontsItemIdentifier = @"CPToolbarShowFontsItem"; +CPToolbarCustomizeToolbarItemIdentifier = @"CPToolbarCustomizeToolbarItem"; +CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem"; + +/*! + @ingroup appkit + @class CPToolbarItem + + A representation of an item in a CPToolbar. +*/ +@implementation CPToolbarItem : CPObject +{ + CPString _itemIdentifier; + + CPToolbar _toolbar; + + CPString _label; + CPString _paletteLabel; + CPString _toolTip; + int _tag; + id _target; + SEL _action; + BOOL _isEnabled; + CPImage _image; + CPImage _alternateImage; + + CPView _view; + + CGSize _minSize; + CGSize _maxSize; + + int _visibilityPriority; + + BOOL _autovalidates; +} + +- (id)init +{ + return [self initWithItemIdentifier:@""]; +} + +// Creating a Toolbar Item +/*! + Initializes the toolbar item with a specified identifier. + @param anItemIdentifier the item's identifier + @return the initialized toolbar item +*/ +- (id)initWithItemIdentifier:(CPString)anItemIdentifier +{ + self = [super init]; + + if (self) + { + _itemIdentifier = anItemIdentifier; + + _tag = 0; + _isEnabled = YES; + + _minSize = CGSizeMakeZero(); + _maxSize = CGSizeMakeZero(); + + _visibilityPriority = CPToolbarItemVisibilityPriorityStandard; + _autovalidates = YES; + } + + return self; +} + +// Managing Attributes +/*! + Returns the item's identifier. +*/ +- (CPString)itemIdentifier +{ + return _itemIdentifier; +} + +/*! + Returns the toolbar of which this item is a part. +*/ +- (CPToolbar)toolbar +{ + return _toolbar; +} + +/* @ignore */ +- (void)_setToolbar:(CPToolbar)aToolbar +{ + _toolbar = aToolbar; +} + +/*! + Returns the item's label +*/ +- (CPString)label +{ + return _label; +} + +/*! + Sets the item's label. + @param aLabel the new label for the item +*/ +- (void)setLabel:(CPString)aLabel +{ + _label = aLabel; +} + +/*! + Returns the palette label. +*/ +- (CPString)paletteLabel +{ + return _paletteLabel; +} + +/*! + Sets the palette label + @param aPaletteLabel the new palette label +*/ +- (void)setPaletteLabel:(CPString)aPaletteLabel +{ + _paletteLabel = aPaletteLabel; +} + +/*! + Returns the item's tooltip. A tooltip pops up + next to the cursor when the user hovers over + the item with the mouse. +*/ +- (CPString)toolTip +{ + if ([_view respondsToSelector:@selector(toolTip)]) + return [_view toolTip]; + + return _toolTip; +} + +/*! + Sets the item's tooltip. A tooltip pops up next to the cursor when the user hovers over the item with the mouse. + @param aToolTip the new item tool tip +*/ +- (void)setToolTip:(CPString)aToolTip +{ + if ([_view respondsToSelector:@selector(setToolTip:)]) + [_view setToolTip:aToolTip]; + + _toolTip = aToolTip; +} + +/*! + Returns the item's tag. +*/ +- (int)tag +{ + if ([_view respondsToSelector:@selector(tag)]) + return [_view tag]; + + return _tag; +} + +/*! + Sets the item's tag. + @param aTag the new tag for the item +*/ +- (void)setTag:(int)aTag +{ + if ([_view respondsToSelector:@selector(setTag:)]) + [_view setTag:aTag]; + + _tag = aTag; +} + +/*! + Returns the item's action target. +*/ +- (id)target +{ + if (_view) + return [_view respondsToSelector:@selector(target)] ? [_view target] : nil; + + return _target; +} + +/*! + Sets the target of the action that is triggered when the user clicks this item. \c nil will cause + the action to be passed on to the first responder. + @param aTarget the new target +*/ +- (void)setTarget:(id)aTarget +{ + if (!_view) + _target = aTarget; + + else if ([_view respondsToSelector:@selector(setTarget:)]) + [_view setTarget:aTarget]; +} + +/*! + Returns the action that is triggered when the user clicks this item. +*/ +- (SEL)action +{ + if (_view) + return [_view respondsToSelector:@selector(action)] ? [_view action] : nil; + + return _action; +} + +/*! + Sets the action that is triggered when the user clicks this item. + @param anAction the new action +*/ +- (void)setAction:(SEL)anAction +{ + if (!_view) + _action = anAction; + + else if ([_view respondsToSelector:@selector(setAction:)]) + [_view setAction:anAction]; +} + +/*! + Returns \c YES if the item is enabled. +*/ +- (BOOL)isEnabled +{ + if ([_view respondsToSelector:@selector(isEnabled)]) + return [_view isEnabled]; + + return _isEnabled; +} + +/*! + Sets whether the item is enabled. + @param aFlag \c YES enables the item +*/ +- (void)setEnabled:(BOOL)shouldBeEnabled +{ + if (_isEnabled === shouldBeEnabled) + return; + + if ([_view respondsToSelector:@selector(setEnabled:)]) + [_view setEnabled:shouldBeEnabled]; + + _isEnabled = shouldBeEnabled; +} + +/*! + Returns the item's image +*/ +- (CPImage)image +{ + if ([_view respondsToSelector:@selector(image)]) + return [_view image]; + + return _image; +} + +/*! + Sets the item's image. + @param anImage the new item image +*/ +- (void)setImage:(CPImage)anImage +{ + if ([_view respondsToSelector:@selector(setImage:)]) + [_view setImage:anImage]; + + _image = anImage; + + if (!_image) + return; + + if (_minSize.width === 0 && _minSize.height === 0 && + _maxSize.width === 0 && _maxSize.height === 0) + { + var imageSize = [_image size]; + + if (imageSize.width > 0 || imageSize.height > 0) + { + [self setMinSize:imageSize]; + [self setMaxSize:imageSize]; + } + } +} + +/*! + Sets the alternate image. This image is displayed on the item when the user is clicking it. + @param anImage the new alternate image +*/ +- (void)setAlternateImage:(CPImage)anImage +{ + if ([_view respondsToSelector:@selector(setAlternateImage:)]) + [_view setAlternateImage:anImage]; + + _alternateImage = anImage; +} + +/*! + Returns the alternate image. This image is displayed on the item when the user is clicking it. +*/ +- (CPImage)alternateImage +{ + if ([_view respondsToSelector:@selector(alternateIamge)]) + return [_view alternateImage]; + + return _alternateImage; +} + +/*! + Returns the item's view. +*/ +- (CPView)view +{ + return _view; +} + +/*! + Sets the item's view + @param aView the item's new view +*/ +- (void)setView:(CPView)aView +{ + if (_view == aView) + return; + + _view = aView; + + if (_view) + { + // Tags get forwarded. + if (_tag !== 0 && [_view respondsToSelector:@selector(setTag:)]) + [_view setTag:_tag]; + + _target = nil; + _action = nil; + } +} + +/*! + Returns the item's minimum size. +*/ +- (CGSize)minSize +{ + return _minSize; +} + +/*! + Sets the item's minimum size. + @param aMinSize the new minimum size +*/ +- (void)setMinSize:(CGSize)aMinSize +{ + if (!aMinSize.height || !aMinSize.width) + return; + + _minSize = CGSizeMakeCopy(aMinSize); + + // Try to provide some sanity: Make maxSize >= minSize + _maxSize = CGSizeMake(MAX(_minSize.width, _maxSize.width), MAX(_minSize.height, _maxSize.height)); +} + +/*! + Returns the item's maximum size. +*/ +- (CGSize)maxSize +{ + return _maxSize; +} + +/*! + Sets the item's new maximum size. + @param aMaxSize the new maximum size +*/ +- (void)setMaxSize:(CGSize)aMaxSize +{ + if (!aMaxSize.height || !aMaxSize.width) + return; + + _maxSize = CGSizeMakeCopy(aMaxSize); + + // Try to provide some sanity: Make minSize <= maxSize + _minSize = CGSizeMake(MIN(_minSize.width, _maxSize.width), MIN(_minSize.height, _maxSize.height)); +} + +// Visibility Priority +/*! + Returns the item's visibility priority. The value will be one of: +
+CPToolbarItemVisibilityPriorityStandard
+CPToolbarItemVisibilityPriorityLow
+CPToolbarItemVisibilityPriorityHigh
+CPToolbarItemVisibilityPriorityUser
+
+*/ +- (int)visibilityPriority +{ + return _visibilityPriority; +} + +/*! + Sets the item's visibility priority. The value must be one of: +
+CPToolbarItemVisibilityPriorityStandard
+CPToolbarItemVisibilityPriorityLow
+CPToolbarItemVisibilityPriorityHigh
+CPToolbarItemVisibilityPriorityUser
+
+ @param aVisiblityPriority the priority +*/ +- (void)setVisibilityPriority:(int)aVisibilityPriority +{ + _visibilityPriority = aVisibilityPriority; +} + +- (void)validate +{ + var action = [self action], + target = [self target]; + + // View items do not do any target-action analysis. + if (_view) + { + if ([target respondsToSelector:@selector(validateToolbarItem:)]) + { + var shouldBeEnabled = [target validateToolbarItem:self]; + if (_isEnabled !== shouldBeEnabled) + [self setEnabled:shouldBeEnabled]; + } + + return; + } + + if (!action) + { + if (_isEnabled) + return [self setEnabled:NO]; + return; + } + + if (target && ![target respondsToSelector:action]) + { + if (_isEnabled) + return [self setEnabled:NO]; + return; + } + + target = [CPApp targetForAction:action to:target from:self]; + + if (!target) + { + if (_isEnabled) + return [self setEnabled:NO]; + return; + } + + if ([target respondsToSelector:@selector(validateToolbarItem:)]) + { + var shouldBeEnabled = [target validateToolbarItem:self]; + if (_isEnabled !== shouldBeEnabled) + [self setEnabled:shouldBeEnabled]; + } + else + { + if (!_isEnabled) + [self setEnabled:YES]; + } +} + +- (BOOL)autovalidates +{ + return _autovalidates; +} + +- (void)setAutovalidates:(BOOL)shouldAutovalidate +{ + _autovalidates = !!shouldAutovalidate; +} + +@end + +var CPToolbarItemItemIdentifierKey = @"CPToolbarItemItemIdentifierKey", + CPToolbarItemLabelKey = @"CPToolbarItemLabelKey", + CPToolbarItemPaletteLabelKey = @"CPToolbarItemPaletteLabelKey", + CPToolbarItemToolTipKey = @"CPToolbarItemToolTipKey", + CPToolbarItemTagKey = @"CPToolbarItemTagKey", + CPToolbarItemTargetKey = @"CPToolbarItemTargetKey", + CPToolbarItemActionKey = @"CPToolbarItemActionKey", + CPToolbarItemEnabledKey = @"CPToolbarItemEnabledKey", + CPToolbarItemImageKey = @"CPToolbarItemImageKey", + CPToolbarItemAlternateImageKey = @"CPToolbarItemAlternateImageKey", + CPToolbarItemViewKey = @"CPToolbarItemViewKey", + CPToolbarItemMinSizeKey = @"CPToolbarItemMinSizeKey", + CPToolbarItemMaxSizeKey = @"CPToolbarItemMaxSizeKey", + CPToolbarItemVisibilityPriorityKey = @"CPToolbarItemVisibilityPriorityKey", + CPToolbarItemAutovalidatesKey = @"CPToolbarItemAutovalidatesKey"; + +@implementation CPToolbarItem (CPCoding) + +- (id)initWithCoder:(CPCoder)aCoder +{ + self = [super init]; + + if (self) + { + _itemIdentifier = [aCoder decodeObjectForKey:CPToolbarItemItemIdentifierKey]; + + _minSize = [aCoder decodeSizeForKey:CPToolbarItemMinSizeKey]; + _maxSize = [aCoder decodeSizeForKey:CPToolbarItemMaxSizeKey]; + + [self setLabel:[aCoder decodeObjectForKey:CPToolbarItemLabelKey]]; + [self setPaletteLabel:[aCoder decodeObjectForKey:CPToolbarItemPaletteLabelKey]]; + [self setToolTip:[aCoder decodeObjectForKey:CPToolbarItemToolTipKey]]; + + [self setTag:[aCoder decodeObjectForKey:CPToolbarItemTagKey]]; + [self setTarget:[aCoder decodeObjectForKey:CPToolbarItemTargetKey]]; + [self setAction:CPSelectorFromString([aCoder decodeObjectForKey:CPToolbarItemActionKey])]; + + [self setEnabled:[aCoder decodeBoolForKey:CPToolbarItemEnabledKey]]; + + [self setImage:[aCoder decodeObjectForKey:CPToolbarItemImageKey]]; + [self setAlternateImage:[aCoder decodeObjectForKey:CPToolbarItemAlternateImageKey]]; + + [self setView:[aCoder decodeObjectForKey:CPToolbarItemViewKey]]; + + [self setVisibilityPriority:[aCoder decodeIntForKey:CPToolbarItemVisibilityPriorityKey]]; + [self setAutovalidates:[aCoder decodeBoolForKey:CPToolbarItemAutovalidatesKey]]; + } + + return self; +} + +- (void)encodeWithCoder:(CPCoder)aCoder +{ + [aCoder encodeObject:_itemIdentifier forKey:CPToolbarItemItemIdentifierKey]; + + [aCoder encodeObject:[self label] forKey:CPToolbarItemLabelKey]; + [aCoder encodeObject:[self paletteLabel] forKey:CPToolbarItemPaletteLabelKey]; + + [aCoder encodeObject:[self toolTip] forKey:CPToolbarItemToolTipKey]; + + [aCoder encodeObject:[self tag] forKey:CPToolbarItemTagKey]; + [aCoder encodeObject:[self target] forKey:CPToolbarItemTargetKey]; + [aCoder encodeObject:[self action] forKey:CPToolbarItemActionKey]; + + [aCoder encodeObject:[self isEnabled] forKey:CPToolbarItemEnabledKey]; + + [aCoder encodeObject:[self image] forKey:CPToolbarItemImageKey]; + [aCoder encodeObject:[self alternateImage] forKey:CPToolbarItemAlternateImageKey]; + + [aCoder encodeObject:[self view] forKey:CPToolbarItemViewKey]; + + [aCoder encodeSize:[self minSize] forKey:CPToolbarItemMinSizeKey]; + [aCoder encodeSize:[self maxSize] forKey:CPToolbarItemMaxSizeKey]; + + [aCoder encodeObject:[self visibilityPriority] forKey:CPToolbarItemVisibilityPriorityKey]; + [aCoder encodeBool:[self autovalidates] forKey:CPToolbarItemAutovalidatesKey]; +} + +@end + +@implementation CPToolbarItem (CPCopying) + +- (id)copy +{ + var copy = [[[self class] alloc] initWithItemIdentifier:_itemIdentifier]; + + if (_view) + [copy setView:[CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:_view]]]; + + [copy _setToolbar:_toolbar]; + + [copy setLabel:_label]; + [copy setPaletteLabel:_paletteLabel]; + [copy setToolTip:[self toolTip]]; + + [copy setTag:[self tag]]; + [copy setTarget:[self target]]; + [copy setAction:[self action]]; + + [copy setEnabled:[self isEnabled]]; + + [copy setImage:[self image]]; + [copy setAlternateImage:[self alternateImage]]; + + [copy setMinSize:_minSize]; + [copy setMaxSize:_maxSize]; + + [copy setVisibilityPriority:[self visibilityPriority]]; + [copy setAutovalidates:[self autovalidates]]; + + return copy; +} + +@end + +// Standard toolbar identifiers + +@implementation CPToolbarItem (Standard) + +/* @ignore */ ++ (CPToolbarItem)_standardItemWithItemIdentifier:(CPString)anItemIdentifier +{ + switch (anItemIdentifier) + { + case CPToolbarSeparatorItemIdentifier: return [_CPToolbarSeparatorItem new]; + case CPToolbarSpaceItemIdentifier: return [_CPToolbarSpaceItem new]; + case CPToolbarFlexibleSpaceItemIdentifier: return [_CPToolbarFlexibleSpaceItem new]; + case CPToolbarShowColorsItemIdentifier: return [_CPToolbarShowColorsItem new]; + case CPToolbarShowFontsItemIdentifier: return nil; + case CPToolbarCustomizeToolbarItemIdentifier: return nil; + case CPToolbarPrintItemIdentifier: return nil; + } + + return nil; +} + +@end + +/*@import "_CPToolbarFlexibleSpaceItem.j" +@import "_CPToolbarShowColorsItem.j" +@import "_CPToolbarSeparatorItem.j" +@import "_CPToolbarSpaceItem.j" +*/ diff --git a/AppKit/_CPToolbarSeparatorItem.j b/AppKit/_CPToolbarSeparatorItem.j index 7b4059565..4b50ba17f 100644 --- a/AppKit/_CPToolbarSeparatorItem.j +++ b/AppKit/_CPToolbarSeparatorItem.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPToolbarItem.j" +@import "_CPToolbarItem.j" @implementation _CPToolbarSeparatorItem : CPToolbarItem diff --git a/AppKit/_CPToolbarShowColorsItem.j b/AppKit/_CPToolbarShowColorsItem.j index 42c76ecf2..012ea37c5 100644 --- a/AppKit/_CPToolbarShowColorsItem.j +++ b/AppKit/_CPToolbarShowColorsItem.j @@ -21,7 +21,7 @@ */ @import "CPApplication.j" -@import "CPToolbarItem.j" +@import "_CPToolbarItem.j" @implementation _CPToolbarShowColorsItem : CPToolbarItem diff --git a/AppKit/_CPToolbarSpaceItem.j b/AppKit/_CPToolbarSpaceItem.j index a77454d15..efa587351 100644 --- a/AppKit/_CPToolbarSpaceItem.j +++ b/AppKit/_CPToolbarSpaceItem.j @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPToolbarItem.j" +@import "_CPToolbarItem.j" @implementation _CPToolbarSpaceItem : CPToolbarItem From 26be5bf26410055a3530b32628c63d56471cae2e Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 14:23:54 +0100 Subject: [PATCH 12/46] Better error message when importing file that is not found --- Objective-J/Executable.js | 5 ++++- Objective-J/ObjJCompiler.js | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 2793368ff..8a90209f3 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -496,7 +496,10 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) function completed(/*StaticResource*/ aStaticResource) { if (!aStaticResource) - throw new Error("Could not load file at " + aURL); + { + var compilingFileUrl = ObjJCompiler && ObjJCompiler.currentCompileFile ? ObjJCompiler.currentCompileFile : null; + throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : " Martin")); + } cachedFileExecutableSearchResults[cacheUID] = aStaticResource; diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index e39354d7a..95c89d3f8 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -25,6 +25,7 @@ var ObjJCompiler = { }, exports.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) { + ObjJCompiler.currentCompileFile = aURL; return new ObjJCompiler(aString, aURL, flags, 2).executable(); } @@ -35,6 +36,7 @@ exports.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsig exports.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) { + ObjJCompiler.currentCompileFile = aURL; return new ObjJCompiler(aString, aURL, flags, 1).executable(); } @@ -87,6 +89,7 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla ObjJCompiler.prototype.compilePass2 = function() { + ObjJCompiler.currentCompileFile = this._URL; this._pass = 2; this._jsBuffer = new StringBuffer(); //print("Start Compile2: " + this._URL); From 0f3d5f4b10c75cd2c1408e0112e252c4420af88b Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 14:26:49 +0100 Subject: [PATCH 13/46] Added support to choose which compiler should be used when compiling in the browser. Default is old compiler but add "ObjJCompilerSetUsedVersion("objj_compiler2");" in the index.html (and/or index-debug.html) to use new compiler in browser. --- Objective-J/Executable.js | 28 ++++++++++++++-------------- Objective-J/FileExecutable.js | 9 ++++++++- Objective-J/ObjJCompiler.js | 10 ++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 8a90209f3..6baaca567 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -151,22 +151,22 @@ Executable.prototype.execute = function() CPLog("EXECUTION: " + this.URL()); #endif - var fileDependencies = this.fileDependencies(), - index = 0, - count = fileDependencies.length; - - for (; index < count; ++index) - { - var fileDependency = fileDependencies[index], - isQuoted = fileDependency.isLocal(), - URL = fileDependency.URL(); - - this.fileExecuter()(URL, isQuoted); - } - if (this._compiler) { - this.setCode(this._compiler.compilePass2()); + var fileDependencies = this.fileDependencies(), + index = 0, + count = fileDependencies.length; + + for (; index < count; ++index) + { + var fileDependency = fileDependencies[index], + isQuoted = fileDependency.isLocal(), + URL = fileDependency.URL(); + + this.fileExecuter()(URL, isQuoted); + } + + this.setCode(this._compiler.compilePass2()); this._compiler = null; } diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 2acb89300..2081daba6 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -42,7 +42,14 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate executable = decompile(fileContents, aURL); else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) - executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); // FIXME: Include correct flags + { + if (!exports.ObjJCompiler.usedVersion || exports.ObjJCompiler.usedVersion === "preprocessor") + executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); + else if (exports.ObjJCompiler.usedVersion === "objj_compiler2") + executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); + else + throw new Error("Compiler to use is set to " + exports.ObjJCompiler.usedVersion + " but we only support 'preprocessor' (old compiler) and 'objj_compiler2' (new compiler)"); + } else executable = new Executable(fileContents, [], aURL); diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index 95c89d3f8..ca25a2f42 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -109,6 +109,16 @@ ObjJCompiler.prototype.compilePass2 = function() exports.ObjJCompiler = ObjJCompiler; +// This will set the compiler version to use. +// These version works: +// "preprocessor" -> Old Cappuccino compiler +// "objj_compiler2" -> New Cappuccino compiler + +GLOBAL(ObjJCompilerSetUsedVersion) = function(version) +{ + ObjJCompiler.usedVersion = version; +} + exports.setCurrentCompilerFlags = function(/*String*/ compilerFlags) { currentCompilerFlags = compilerFlags; From 619f90c6778b1873438f38116b9d4e18b43e418c Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 15:20:12 +0100 Subject: [PATCH 14/46] Removed debug stuff --- Objective-J/Executable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 6baaca567..15647ac04 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -498,7 +498,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) if (!aStaticResource) { var compilingFileUrl = ObjJCompiler && ObjJCompiler.currentCompileFile ? ObjJCompiler.currentCompileFile : null; - throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : " Martin")); + throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : "")); } cachedFileExecutableSearchResults[cacheUID] = aStaticResource; From ac3a399df324b83c606ff52cfcf33b18f706aacb Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 15:20:38 +0100 Subject: [PATCH 15/46] Set to use new compiler when compiling with jake --- Objective-J/CommonJS/lib/objective-j/jake/bundletask.js | 4 +++- Objective-J/ObjJCompiler.js | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index eb73ef14b..2fe448cda 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -803,7 +803,9 @@ BundleTask.prototype.defineStaticTask = function() BundleTask.prototype.defineSourceTasks = function() { - var sources = this.sources(); + // Use new compiler + require("objective-j").ObjJCompiler.setCurrentUsedVersion("objj_compiler2"); + var sources = this.sources(); if (!sources) return; diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index ca25a2f42..aa06bf8c5 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -119,6 +119,11 @@ GLOBAL(ObjJCompilerSetUsedVersion) = function(version) ObjJCompiler.usedVersion = version; } +ObjJCompiler.setCurrentUsedVersion = function(version) +{ + ObjJCompiler.usedVersion = version; +} + exports.setCurrentCompilerFlags = function(/*String*/ compilerFlags) { currentCompilerFlags = compilerFlags; From ed81d75815a0c5a3e64ea71c0aa497f3c7cd3445 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 17:49:23 +0100 Subject: [PATCH 16/46] Removes #pragma lines --- Objective-J/ObjJCompiler.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index aa06bf8c5..a21019cab 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -42,7 +42,7 @@ exports.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, / var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) { - aString = aString.replace(/^#[^\n]+\n/, "\n"); + aString = aString.replace(/^\#.*/gm, ""); this._URL = new CFURL(aURL); this._pass = pass; // If this is pass one we should not save anything in javascript buffer @@ -72,10 +72,14 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla console.time("Compile pass " + pass + " - " + aURL); #endif try { - this.nodeDocument(this._tokens); + this.nodeDocument(this._tokens); } catch (e) { - print("Error: " + e + ", file content: " + aString); + #ifdef BROWSER + //console.log("Error: " + e + ", file content: " + aString); + #else + //print("Error: " + e + ", file content: " + aString); + #endif throw e; } //var end = new Date().getTime(); @@ -102,7 +106,7 @@ ObjJCompiler.prototype.compilePass2 = function() //var time = (end - start) / 1000; //print("Compile pass 2: " + this._URL + " in " + time + " seconds"); #ifdef BROWSER - console.timeEnd("Compile" + this._pass + " - " + this._URL); + console.timeEnd("Compile pass 2" + this._pass + " - " + this._URL); #endif return this._jsBuffer.toString(); } From 78b2d30905975c26762e28876cbd13371c2873ce Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 18:01:47 +0100 Subject: [PATCH 17/46] Added better support for scope --- Objective-J/ObjJCompiler.js | 61 ++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index a21019cab..a298efaab 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -382,10 +382,11 @@ ObjJCompiler.prototype.nodeStart = function(/*SyntaxNode*/ astNode) #if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeStart); #endif - var children = astNode.children; + var children = astNode.children, + lastUnderlineIndex = 1; this.nodeUnderline(children[0], false); - var lastUnderlineIndex = 1; + if (children.length === 3) { this.nodeSourceElements(children[1]); @@ -399,10 +400,11 @@ ObjJCompiler.prototype.nodeFunctionBody = function(/*SyntaxNode*/ astNode) #if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFunctionBody); #endif - var children = astNode.children; + var children = astNode.children, + lastUnderlineIndex = 1; this.nodeUnderline(children[0], false); - var lastUnderlineIndex = 1; + if (children.length === 3) { this.nodeSourceElements(children[1]); @@ -454,7 +456,8 @@ ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode var children = astNode.children, child = children[6], offset = 0, - saveJSBuffer = this._jsBuffer; + saveJSBuffer = this._jsBuffer, + parameterList; this._jsBuffer = null; this.nodeFUNCTION(children[0]); @@ -470,9 +473,9 @@ ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode this.nodeOpenParenthesis(children[4]); this.nodeUnderline(children[5], false); - if (child && child.name ===ObjJCompiler.AstNodeFormalParameterList) + if (child && child.name === ObjJCompiler.AstNodeFormalParameterList) { - this.nodeFormalParameterList(children[6]); + parameterList = this.nodeFormalParameterList(children[6]); offset++; } this.nodeUnderline(children[6 + offset], false); @@ -480,7 +483,16 @@ ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode this.nodeUnderline(children[8 + offset], false); this.nodeOpenBrace(children[9 + offset]); this.nodeUnderline(children[10 + offset], false); + var currentClassMethods = this._currentMethod; + + if (currentClassMethods) + { + // If we have a parameter list push those otherwise an empty dictionary + currentClassMethods.lvarStack.push(parameterList ? parameterList : {}); + } this.nodeFunctionBody(children[11 + offset]); + if (currentClassMethods) + currentClassMethods.lvarStack.pop(); this.nodeUnderline(children[12 + offset], false); this.nodeCloseBrace(children[13 + offset]); } @@ -493,7 +505,8 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) var children = astNode.children, child = children[2], offset = 0, - saveJSBuffer = this._jsBuffer; + saveJSBuffer = this._jsBuffer, + parameterList; this._jsBuffer = null; this.nodeFUNCTION(children[0]); @@ -523,7 +536,7 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) if (child && child.name ===ObjJCompiler.AstNodeFormalParameterList) { - this.nodeFormalParameterList(child); + parameterList = this.nodeFormalParameterList(child); offset++; } this.nodeUnderline(children[5 + offset], false); @@ -531,7 +544,15 @@ ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) this.nodeUnderline(children[7 + offset], false); this.nodeOpenBrace(children[8 + offset]); this.nodeUnderline(children[9 + offset], false); + var currentClassMethods = this._currentMethod; + + if (currentClassMethods) + { + currentClassMethods.lvarStack.push(parameterList ? parameterList : {}); + } this.nodeFunctionBody(children[10 + offset]); + if (currentClassMethods) + currentClassMethods.lvarStack.pop(); this.nodeUnderline(children[11 + offset], false); this.nodeCloseBrace(children[12 + offset]); } @@ -541,16 +562,23 @@ ObjJCompiler.prototype.nodeFormalParameterList = function(/*SyntaxNode*/ astNode #if DEBUG this.assertNode(astNode, ObjJCompiler.AstNodeFormalParameterList); #endif - var children = astNode.children; + var children = astNode.children, + parameterList = {}; + + var identifier = this.nodeIdentifier(children[0]); + + parameterList[identifier] = {"identifier": identifier}; - this.nodeIdentifier(children[0]); for (var i = 1; i + 3 < children.length; i += 4) { this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); + this.nodeCOMMA(children[i + 1]); this.nodeUnderline(children[i + 2], false); - this.nodeIdentifier(children[i + 3]); + identifier = this.nodeIdentifier(children[i + 3]); + parameterList[identifier] = {"identifier": identifier}; } + + return parameterList; } ObjJCompiler.prototype.nodeStatementList = function(/*SyntaxNode*/ astNode) @@ -1929,6 +1957,7 @@ ObjJCompiler.prototype.genericMethodDeclaration = function(/*SyntaxNode*/ astNod // Method already declared. May be a warning? } currentClassMethods[methodSelector.selector] = methodSelector; + methodSelector.lvarStack = [{}]; this._currentMethod = methodSelector; } @@ -2905,10 +2934,14 @@ ObjJCompiler.prototype.nodePrimaryExpression = function(/*SyntaxNode*/ astNode) ivar = this.getIvarForCurrentClass(identifier); if (ivar) + { if (lvar) 0 == 0; // Warning: Local declaration of 'identifier' hides instance variable else - CONCAT(saveJSBuffer, "self."); + { + CONCAT(saveJSBuffer, "self."); + } + } CONCAT(saveJSBuffer, identifier); } From 2277fb04b9413b9df46b573e875d9430ada28266 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 18:19:39 +0100 Subject: [PATCH 18/46] Missed to commit some stuff for scope handling --- Objective-J/ObjJCompiler.js | 46 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index a298efaab..ffb93e4e4 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -4637,19 +4637,27 @@ ObjJCompiler.prototype.getIvarForCurrentClass = function(/* String */ ivarName) ObjJCompiler.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) { - var currentMethod = this._currentMethod; + var currentClassMethods = this._currentMethod; - if (currentMethod) - { - var ivars = currentMethod.lvars; - if (ivars && ivars[lvarName]) - { - return ivars[lvarName]; - } - // TODO: check the parameters in the method declaration - } + if (currentClassMethods) + { + var lvarStack = currentClassMethods.lvarStack; - return null; + for (var i = lvarStack.length - 1; i >= 0; i--) + { + var lvars = lvarStack[i]; + + if (lvars && lvars[lvarName]) + { + return lvars[lvarName]; + } + } + // Check the parameters in the method declaration + if (currentClassMethods.parameters && currentClassMethods.parameters[lvarName]) + return currentClassMethods.parameters[lvarName]; + } + + return null; } ObjJCompiler.prototype.createLocalVariable = function(/*Variable*/ variable) @@ -4658,20 +4666,16 @@ ObjJCompiler.prototype.createLocalVariable = function(/*Variable*/ variable) if (currentClassMethods) { - var lvars = currentClassMethods.lvars; - if (!lvars) - { - lvars = {}; - currentClassMethods.lvars = lvars; - } - - if (lvars[variable.identifier]) + var declaredVariable = lvars[variable.identifier]; + if (declaredVariable) { // Local variable already declared! Maybe a warning? } - - lvars[variable.identifier] = variable; + else + { + lvars[variable.identifier] = variable; + } } } From d5748474d05c3c2b8b4d999c1aab023df3cca4e8 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 20 Dec 2012 22:55:58 +0100 Subject: [PATCH 19/46] Forgot some more lines --- Objective-J/ObjJCompiler.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index ffb93e4e4..d9aceee93 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -4666,6 +4666,8 @@ ObjJCompiler.prototype.createLocalVariable = function(/*Variable*/ variable) if (currentClassMethods) { + var lvarStack = currentClassMethods.lvarStack; + var lvars = lvarStack[lvarStack.length - 1]; // Get last var declaredVariable = lvars[variable.identifier]; if (declaredVariable) From 140cf0debec893124d63434eb0075f3b243d83ff Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 09:55:12 +0100 Subject: [PATCH 20/46] Code cleanup --- Objective-J/CFHTTPRequest.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Objective-J/CFHTTPRequest.js b/Objective-J/CFHTTPRequest.js index ceb61120e..5ba2725bc 100644 --- a/Objective-J/CFHTTPRequest.js +++ b/Objective-J/CFHTTPRequest.js @@ -303,13 +303,9 @@ function FileRequest(/*CFURL*/ aURL, onsuccess, onfailure) #if COMMONJS if (aURL.pathExtension() === "j") { - var FILE = require("file"), - FileList = require("jake").FileList, - aFilePath = aURL.toString().substring(5); - - var OS = require("os"), + var aFilePath = aURL.toString().substring(5), + OS = require("os"), gccFlags = require("objective-j").currentCompilerFlags(), -// gcc = OS.popen("gcc -E -x c -P -DPLATFORM_COMMONJS " + INCLUDES + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), gcc = OS.popen("gcc -E -x c -P " + (gccFlags ? gccFlags : "") + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), chunk, fileContents = ""; From 9cb14d6db3b0cd3b64e2ca604b9c635166478ee1 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 09:59:10 +0100 Subject: [PATCH 21/46] Added new faster compiler based on acorn parser --- .../lib/objective-j/jake/bundletask.js | 3 +- Objective-J/Executable.js | 2 +- Objective-J/FileExecutable.js | 14 +- Objective-J/Includes.js | 3 + Objective-J/ObjJAcornCompiler.js | 732 ++++++ Objective-J/ObjJCompiler.js | 47 +- Objective-J/acorn.js | 2063 +++++++++++++++++ Objective-J/acornLICENSE | 23 + Objective-J/acornwalk.js | 254 ++ 9 files changed, 3111 insertions(+), 30 deletions(-) create mode 100644 Objective-J/ObjJAcornCompiler.js create mode 100644 Objective-J/acorn.js create mode 100644 Objective-J/acornLICENSE create mode 100644 Objective-J/acornwalk.js diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 2fe448cda..45021f9c4 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -804,7 +804,8 @@ BundleTask.prototype.defineStaticTask = function() BundleTask.prototype.defineSourceTasks = function() { // Use new compiler - require("objective-j").ObjJCompiler.setCurrentUsedVersion("objj_compiler2"); + //require("objective-j").ObjJCompiler.setCurrentUsedVersion("acorn"); + //require("objective-j").ObjJCompiler.setCurrentUsedVersion("objj_compiler2"); var sources = this.sources(); if (!sources) diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 15647ac04..6fd3fd57c 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -497,7 +497,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) { if (!aStaticResource) { - var compilingFileUrl = ObjJCompiler && ObjJCompiler.currentCompileFile ? ObjJCompiler.currentCompileFile : null; + var compilingFileUrl = ObjJCompiler && ObjJCompiler.currentCompileFile ? ObjJCompiler.currentCompileFile : ObjJAcornCompiler ? ObjJAcornCompiler.currentCompileFile : null; throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : "")); } diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 2081daba6..52173dce6 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -43,12 +43,18 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) { - if (!exports.ObjJCompiler.usedVersion || exports.ObjJCompiler.usedVersion === "preprocessor") - executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); + var start = new Date().getTime(); + if (!exports.ObjJCompiler.usedVersion || exports.ObjJCompiler.usedVersion === "acorn") + executable = exports.ObjJAcornCompiler.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); else if (exports.ObjJCompiler.usedVersion === "objj_compiler2") - executable = exports.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); + executable = exports.ObjJCompiler.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); + else if (exports.ObjJCompiler.usedVersion === "preprocessor") + executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); else - throw new Error("Compiler to use is set to " + exports.ObjJCompiler.usedVersion + " but we only support 'preprocessor' (old compiler) and 'objj_compiler2' (new compiler)"); + throw new Error("Compiler to use is set to " + exports.ObjJCompiler.usedVersion + " but we only support 'preprocessor' (old compiler), 'objj_compiler2' and 'acorn'"); + + var time = (new Date().getTime() - start) / 1000; + //print("Compile '" + (exports.ObjJCompiler.usedVersion || "preprocessor") + "' " + aURL + " in " + time + " seconds"); } else executable = new Executable(fileContents, [], aURL); diff --git a/Objective-J/Includes.js b/Objective-J/Includes.js index f133c41bc..f9026cad1 100644 --- a/Objective-J/Includes.js +++ b/Objective-J/Includes.js @@ -45,6 +45,9 @@ #include "Preprocessor.js" #include "Parser.js" #include "ObjJCompiler.js" +#include "acorn.js" +#include "acornwalk.js" +#include "ObjJAcornCompiler.js" #include "FileDependency.js" #include "Executable.js" #include "FileExecutable.js" diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js new file mode 100644 index 000000000..941005aa3 --- /dev/null +++ b/Objective-J/ObjJAcornCompiler.js @@ -0,0 +1,732 @@ +/* + * ObjJAcornCompiler.js + * Objective-J + * + * Created by Martin Carlberg. + * Copyright 2013, Martin Carlberg. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +var Scope = function(prev, base) +{ + this.vars = Object.create(null); + if (base) for (var key in base) this[key] = base[key]; + this.prev = prev; + if (prev) this.compiler = prev.compiler; +} + +Scope.prototype.compiler = function() +{ + return this.compiler; +} + +Scope.prototype.currentClassName = function() +{ + return this.classDef ? this.classDef.className : this.prev ? this.prev.currentClassName() : null; +} + +Scope.prototype.getIvarForCurrentClass = function(/* String */ ivarName) +{ + if (this.ivars) + { + var ivar = this.ivars[ivarName]; + if (ivar) + return ivar; + } + + var prev = this.prev; + + // Stop at the class declaration + if (prev && !this.classDef) + return prev.getIvarForCurrentClass(ivarName); + + return null; +} + +Scope.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) +{ + if (this.vars) + { + var lvar = this.vars[lvarName]; + if (lvar) + return lvar; + } + + var prev = this.prev; + + // Stop at the method declaration + if (prev && !this.methodtype) + return prev.getLvarForCurrentMethod(lvarName); + + return null; +} + +Scope.prototype.currentMethodType = function() +{ + return this.methodType ? this.methodType : this.prev ? this.prev.currentMethodType() : null; +} + +var currentCompilerFlags = ""; + +var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) +{ + this.source = aString; + this.URL = new CFURL(aURL); + this.pass = pass; + this.jsBuffer = new StringBuffer(); + this.imBuffer = null; + this.cmBuffer = null; + this.warnings = []; + + var start = new Date().getTime(); +#ifdef BROWSER + console.time("Parse with Acorn - " + aURL); +#endif + try { + this.tokens = exports.acorn.parse(aString); + } + catch (e) { + if (e.lineStart) + { + var message = this.prettifyMessage(e, "ERROR"); +#ifdef BROWSER + console.log(message); +#else + print(message); +#endif + } + throw e; + } + var end = new Date().getTime(); + var time = (end - start) / 1000; + //print("Parse with Acorn: " + aURL + " in " + time + " seconds"); +#ifdef BROWSER + console.timeEnd("Parse with Acorn - " + aURL); +#endif + this.dependencies = []; + this.flags = flags | ObjJAcornCompiler.Flags.IncludeDebugSymbols; + this.classDefs = Object.create(null); + this.lastPos = 0; + //var start = new Date().getTime(); +#ifdef BROWSER + console.time("Compile pass " + pass + " - " + aURL); +#endif + try { + compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); + } + catch (e) { + #ifdef BROWSER + //console.log("Error: " + e + ", file content: " + aString); + #else + //print("Error: " + e + ", file content: " + aString); + #endif + throw e; + } + //var end = new Date().getTime(); + //var time = (end - start) / 1000; + //print("Compile pass 1: " + aURL + " in " + time + " seconds"); +#ifdef BROWSER + console.timeEnd("Compile pass " + pass + " - " + aURL); +#endif +// console.log("JS: " + this.jsBuffer); +} + +exports.ObjJAcornCompiler = ObjJAcornCompiler; + +exports.ObjJAcornCompiler.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + ObjJAcornCompiler.currentCompileFile = aURL; + return new ObjJAcornCompiler(aString, aURL, flags, 2).executable(); +} + +exports.ObjJAcornCompiler.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + return new ObjJAcornCompiler(aString, aURL, flags, 2).IMBuffer(); +} + +exports.ObjJAcornCompiler.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + ObjJAcornCompiler.currentCompileFile = aURL; + return new ObjJAcornCompiler(aString, aURL, flags, 1).executable(); +} + +ObjJAcornCompiler.prototype.compilePass2 = function() +{ + ObjJAcornCompiler.currentCompileFile = this.URL; + this.pass = 2; + this.jsBuffer = new StringBuffer(); + this.warnings = []; + //print("Start Compile2: " + this.URL); + //var start = new Date().getTime(); +#ifdef BROWSER + console.time("Compile pass 2" + this.pass + " - " + this.URL); +#endif + compile(this.tokens, new Scope(null ,{ compiler: this }), pass2); + //var end = new Date().getTime(); + //var time = (end - start) / 1000; + //print("Compile pass 2: " + this.URL + " in " + time + " seconds"); +#ifdef BROWSER + console.timeEnd("Compile pass 2" + this.pass + " - " + this.URL); +#endif + //print("Compiled: \n" + this.jsBuffer.toString()); + + for (var i = 0; i < this.warnings.length; i++) + { + var message = this.prettifyMessage(this.warnings[i], "WARNING"); +#ifdef BROWSER + console.log(message); +#else + print(message); +#endif + } + + return this.jsBuffer.toString(); +} + +ObjJAcornCompiler.Flags = { }; + +ObjJAcornCompiler.Flags.IncludeDebugSymbols = 1 << 0; +ObjJAcornCompiler.Flags.IncludeTypeSignatures = 1 << 1; + +ObjJAcornCompiler.prototype.addWarning = function(/* Warning */ aWarning) +{ + this.warnings.push(aWarning); +} + +ObjJAcornCompiler.prototype.getIvarForClass = function(/* String */ ivarName, /* Scope */ scope) +{ + var ivar = scope.getIvarForCurrentClass(ivarName); + + if (ivar) + return ivar; + + var c = this.getClassDef(scope.currentClassName()); + + while (c) + { + var ivars = c.ivars; + if (ivars) + { + var ivarDef = ivars[ivarName]; + if (ivarDef) + return ivarDef; + } + c = this.getClassDef(c.superClassName); + } +} + +ObjJAcornCompiler.prototype.getClassDef = function(/* String */ aClassName) +{ + if (!aClassName) return null; + + var c = this.classDefs[aClassName]; + + if (c) return c; + + if (objj_getClass) + { + var aClass = objj_getClass(aClassName); + if (aClass) + { + var ivars = class_copyIvarList(aClass), + ivarSize = ivars.length, + myIvars = Object.create(null), + superClass = aClass.super_class; + + for (var i = 0; i < ivarSize; i++) + { + var ivar = ivars[i]; + + myIvars[ivar.name] = {"type": ivar.type, "name": ivar.name}; + } + c = {"className": aClassName, "ivars": myIvars}; + + if (superClass) + c.superClassName = superClass.name; + this.classDefs[aClassName] = c; + return c; + } + } + + return null; +// classDef = {"className": className, "superClassName": superClassName, "ivars": Object.create(null), "methods": Object.create(null)}; +} + +ObjJAcornCompiler.prototype.executable = function() +{ + if (!this._executable) + this._executable = new Executable(this.jsBuffer ? this.jsBuffer.toString() : null, this.dependencies, this.URL, null, this); + return this._executable; +} + +ObjJAcornCompiler.prototype.IMBuffer = function() +{ + return this.imBuffer; +} + +ObjJAcornCompiler.prototype.JSBuffer = function() +{ + return this.jsBuffer; +} + +ObjJAcornCompiler.prototype.prettifyMessage = function(/* Message */ aMessage, /* String */ messageType) +{ + var line = this.source.substring(aMessage.lineStart, aMessage.lineEnd); + var message = "\n" + line; + //print("e: " + e + ", e.lineStart: " + e.lineStart + ", e.lineEnd: " + e.lineEnd + ", e.column: " + e.column); + + message += (new Array(aMessage.column + 1)).join(" "); + message += (new Array(Math.min(1, line.length) + 1)).join("^") + "\n"; + message += messageType + " line " + aMessage.line + " in " + this.URL + ": " + aMessage.message; + + return message; +} + +ObjJAcornCompiler.prototype.error_message = function(errorMessage, astNode) +{ + return errorMessage + " "; +} + +function createMessage(/* String */ aMessage, /* SpiderMonkey AST node */ node, /* String */ code) +{ + var message = exports.acorn.getLineInfo(code, node.start); + message.message = aMessage; + + return message; +} + +function compile(node, state, visitor) { + function c(node, st, override) { + visitor[override || node.type](node, st, c); + } + c(node, state); +}; + +var pass1 = exports.acorn.walk.make({ +ImportStatement: function(node, st, c) { + var urlString = node.filename.value; + + st.compiler.dependencies.push(new FileDependency(new CFURL(urlString), node.localfilepath)); +} +}); + +var pass2 = exports.acorn.walk.make({ +Program: function(node, st, c) { + for (var i = 0; i < node.body.length; ++i) { + c(node.body[i], st, "Statement"); + } + CONCAT(st.compiler.jsBuffer,st.compiler.source.substring(st.compiler.lastPos, node.end)); +}, +Function: function(node, scope, c) { + var inner = new Scope(scope); + for (var i = 0; i < node.params.length; ++i) + inner.vars[node.params[i].name] = {type: "argument", node: node.params[i]}; + if (node.id) { + var decl = node.type == "FunctionDeclaration"; + (decl ? scope : inner).vars[node.id.name] = + {type: decl ? "function" : "function name", node: node.id}; + CONCAT(scope.compiler.jsBuffer,scope.compiler.source.substring(scope.compiler.lastPos, node.start)); + CONCAT(scope.compiler.jsBuffer, node.id.name); + CONCAT(scope.compiler.jsBuffer, " = function"); + scope.compiler.lastPos = node.id.end; + } + c(node.body, inner, "ScopeBody"); +}, +TryStatement: function(node, scope, c) { + c(node.block, scope, "Statement"); + for (var i = 0; i < node.handlers.length; ++i) { + var handler = node.handlers[i], inner = new Scope(scope); + inner.vars[handler.param.name] = {type: "catch clause", node: handler.param}; + c(handler.body, inner, "ScopeBody"); + } + if (node.finalizer) c(node.finalizer, scope, "Statement"); +}, +VariableDeclaration: function(node, scope, c) { + for (var i = 0; i < node.declarations.length; ++i) { + var decl = node.declarations[i]; + scope.vars[decl.id.name] = {type: "var", node: decl.id}; + if (decl.init) c(decl.init, scope, "Expression"); + } +}, +MemberExpression: function(node, st, c) { + c(node.object, st, "Expression"); + st.secondMemberExpression = !node.computed; + c(node.property, st, "Expression"); + st.secondMemberExpression = false; +}, +ImportStatement: function(node, st, c) { + var buffer = st.compiler.jsBuffer; + + if (!buffer) return; + CONCAT(buffer,st.compiler.source.substring(st.compiler.lastPos, node.start)); + CONCAT(buffer, "objj_executeFile(\""); + CONCAT(buffer, node.filename.value); + CONCAT(buffer, node.localfilepath ? "\", YES);" : "\", NO);"); + st.compiler.lastPos = node.end; +}, +ClassDeclarationStatement: function(node, st, c) { + var classDef, + saveJSBuffer = st.compiler.jsBuffer, + className = node.classname.name, + classScope = new Scope(st); + + st.compiler.imBuffer = new StringBuffer(); + st.compiler.cmBuffer = new StringBuffer(); + st.compiler.classBodyBuffer = new StringBuffer(); // TODO: Check if this is needed + + CONCAT(saveJSBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + + // First we declare the class + if (node.superclassname) + { + if (st.compiler.getClassDef(className)) + throw new SyntaxError(st.compiler.error_message("Duplicate class " + className, node.classname)); + if (!st.compiler.getClassDef(node.superclassname.name)) + throw new SyntaxError(st.compiler.error_message("Can't find superclass " + node.superclassname.name, node.superclassname)); + + classDef = {"className": className, "superClassName": node.superclassname.name, "ivars": Object.create(null), "methods": Object.create(null)}; + st.compiler.classDefs[className] = classDef; + + CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(" + node.superclassname.name + ", \"" + className + "\"),\nmeta_class = the_class.isa;"); + } + else if (node.categoryname) + { + classDef = st.compiler.getClassDef(className); + if (!classDef) + throw new SyntaxError(st.compiler.error_message("Class " + className + " not found ", node.classname)); + + CONCAT(saveJSBuffer, "{\nvar the_class = objj_getClass(\"" + className + "\")\n"); + CONCAT(saveJSBuffer, "if(!the_class) throw new SyntaxError(\"*** Could not find definition for class \\\"" + className + "\\\"\");\n"); + CONCAT(saveJSBuffer, "var meta_class = the_class.isa;"); + } + else + { + classDef = {"className": className, "superClassName": null, "ivars": Object.create(null), "methods": Object.create(null)}; + st.compiler.classDefs[className] = classDef; + + CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(Nil, \"" + className + "\"),\nmeta_class = the_class.isa;"); + } + + classScope.classDef = classDef; + st.compiler.currentSuperClass = "objj_getClass(\"" + className + "\").super_class"; + st.compiler.currentSuperMetaClass = "objj_getMetaClass(\"" + className + "\").super_class"; + + var firstIvarDeclaration = true, + hasAccessors = false; + + // Then we add all ivars + if (node.ivardeclarations) for (var i = 0; i < node.ivardeclarations.length; ++i) + { + var ivarDecl = node.ivardeclarations[i], + ivarType = ivarDecl.ivartype ? ivarDecl.ivartype.name : null, + ivarName = ivarDecl.id.name, + ivar = {"type": ivarType, "name": ivarName}; + + if (firstIvarDeclaration) + { + firstIvarDeclaration = false; + CONCAT(saveJSBuffer, "class_addIvars(the_class, ["); + } + else + CONCAT(saveJSBuffer, ", "); + + if (st.compiler.flags & ObjJAcornCompiler.Flags.IncludeTypeSignatures) + CONCAT(saveJSBuffer, "new objj_ivar(\"" + ivarName + "\", \"" + ivarType + "\")"); + else + CONCAT(saveJSBuffer, "new objj_ivar(\"" + ivarName + "\")"); + + if (ivarDecl.outlet) + ivar.outlet = true; + classDef.ivars[ivarName] = ivar; + if (!classScope.ivars) + classScope.ivars = Object.create(null); + classScope.ivars[ivarName] = {type: "ivar", name: ivarName, node: ivarDecl.id, ivar: ivar}; + + if (!hasAccessors && ivarDecl.accessors) + hasAccessors = true; + } + + if (!firstIvarDeclaration) + CONCAT(saveJSBuffer, "]);"); + + // If we have accessors add get and set methods for them + if (hasAccessors) + { + var getterSetterBuffer = new StringBuffer(); + + // Add the class declaration to compile accessors correctly + CONCAT(getterSetterBuffer, st.compiler.source.substring(node.start, node.endOfIvars)); + CONCAT(getterSetterBuffer, "\n"); + + for (var i = 0; i < node.ivardeclarations.length; ++i) + { + var ivarDecl = node.ivardeclarations[i], + ivarType = ivarDecl.ivartype ? ivarDecl.ivartype.name : null, + ivarName = ivarDecl.id.name, + accessors = ivarDecl.accessors; + + if (!accessors) + continue; + + var property = (accessors.property && accessors.property.name) || ivarName, + getterName = (accessors.getter && accessors.getter.name) || property, + getterCode = "- (" + (ivarType ? ivarType : "id") + ")" + getterName + "\n{\nreturn " + ivarName + ";\n}\n"; + + CONCAT(getterSetterBuffer, getterCode); + + if (accessors.readonly) + continue; + + var setterName = accessors.setter ? accessors.setter.name : null; + + if (!setterName) + { + var start = property.charAt(0) == '_' ? 1 : 0; + + setterName = (start ? "_" : "") + "set" + property.substr(start, 1).toUpperCase() + property.substring(start + 1) + ":"; + } + + var setterCode = "- (void)" + setterName + "(" + (ivarType ? ivarType : "id") + ")newValue\n{\n"; + + if (accessors.copy) + setterCode += "if (" + ivarName + " !== newValue)\n" + ivarName + " = [newValue copy];\n}\n"; + else + setterCode += ivarName + " = newValue;\n}\n"; + + CONCAT(getterSetterBuffer, setterCode); + } + + CONCAT(getterSetterBuffer, "\n@end"); + + // Remove all @accessors or we will get a recursive loop in infinity + var b = getterSetterBuffer.toString().replace(/@accessors(\(.*\))?/g, ""); + var imBuffer = ObjJAcornCompiler.compileToIMBuffer(b, "Accessors", st.compiler.flags); + + // Add the accessors methods first to instance method buffer. + // This will allow manually added set and get methods to override the compiler generated + CONCAT(st.compiler.imBuffer, imBuffer); + } + + if (node.body.length > 0) + { + st.compiler.lastPos = node.body[0].start; + + // And last add methods and other statements + for (var i = 0; i < node.body.length; ++i) { + var body = node.body[i]; + c(body, classScope, "Statement"); + } + CONCAT(saveJSBuffer, st.compiler.source.substring(st.compiler.lastPos, body.end)); + } + + // We must make a new class object for our class definition if it's not a category + if (!node.categoryname) { + CONCAT(saveJSBuffer, "objj_registerClassPair(the_class);\n"); + } + + // Add instance methods + if (IS_NOT_EMPTY(st.compiler.imBuffer)) + { + CONCAT(saveJSBuffer, "class_addMethods(the_class, ["); + saveJSBuffer.atoms.push.apply(saveJSBuffer.atoms, st.compiler.imBuffer.atoms); // FIXME: Move this append to StringBuffer + CONCAT(saveJSBuffer, "]);\n"); + } + + // Add class methods + if (IS_NOT_EMPTY(st.compiler.cmBuffer)) + { + CONCAT(saveJSBuffer, "class_addMethods(meta_class, ["); + saveJSBuffer.atoms.push.apply(saveJSBuffer.atoms, st.compiler.cmBuffer.atoms); // FIXME: Move this append to StringBuffer + CONCAT(saveJSBuffer, "]);\n"); + } + + CONCAT(saveJSBuffer, "}"); + + st.compiler.jsBuffer = saveJSBuffer; + + // Skip the "@end" + st.compiler.lastPos = node.end; +}, +MethodDeclarationStatement: function(node, st, c) { + var saveJSBuffer = st.compiler.jsBuffer, + methodScope = new Scope(st), + selectors = node.selectors, + arguments = node.arguments, + types = [node.returntype ? node.returntype.name : "id"], + selector = selectors[0].name; // There is always at least one selector + + CONCAT(saveJSBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + + st.compiler.jsBuffer = node.methodtype === '-' ? st.compiler.imBuffer : st.compiler.cmBuffer; + + // Put together the selector. Maybe this should be done in the parser... + for (var i = 0; i < arguments.length; i++) { + if (i === 0) + selector += ":"; + else + selector += (selectors[i] ? selectors[i].name : "") + ":"; + } + + if (IS_NOT_EMPTY(st.compiler.jsBuffer)) // Add comma separator if this is not first method in this buffer + CONCAT(st.compiler.jsBuffer, ", "); + CONCAT(st.compiler.jsBuffer, "new objj_method(sel_getUid(\""); + CONCAT(st.compiler.jsBuffer, selector); + CONCAT(st.compiler.jsBuffer, "\"), function"); + +// this.currentSelector = selector; + + if (st.compiler.flags & ObjJAcornCompiler.Flags.IncludeDebugSymbols) + { + CONCAT(st.compiler.jsBuffer, " $" + st.currentClassName() + "__" + selector.replace(/:/g, "_")); + } + + CONCAT(st.compiler.jsBuffer, "(self, _cmd"); + + methodScope.methodType = node.methodtype; + if (arguments) for (var i = 0; i < arguments.length; i++) + { + var argument = arguments[i], + argumentName = argument.identifier.name; + + CONCAT(st.compiler.jsBuffer, ", "); + CONCAT(st.compiler.jsBuffer, argumentName); + types.push(argument.type ? argument.type.name : null); + methodScope.vars[argumentName] = {type: "method argument", node: argument}; + } + + CONCAT(st.compiler.jsBuffer, ")"); + + st.compiler.lastPos = node.startOfBody; + c(node.body, methodScope, "Statement"); + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.body.end)); + + CONCAT(st.compiler.jsBuffer, "\n"); + if (st.compiler.flags & ObjJAcornCompiler.Flags.IncludeDebugSymbols) //flags.IncludeTypeSignatures) + CONCAT(st.compiler.jsBuffer, ","+JSON.stringify(types)); + CONCAT(st.compiler.jsBuffer, ")"); + st.compiler.jsBuffer = saveJSBuffer; + st.compiler.lastPos = node.end; +}, +MessageSendExpression: function(node, st, c) { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + st.compiler.lastPos = node.object ? node.object.start : node.arguments.length ? node.arguments[0].start : node.end; + if (node.superObject) + { + CONCAT(st.compiler.jsBuffer, "objj_msgSendSuper("); + CONCAT(st.compiler.jsBuffer, "{ receiver:self, super_class:" + (st.currentMethodType() === "+" ? st.compiler.currentSuperMetaClass : st.compiler.currentSuperClass ) + " }"); + } + else + { + CONCAT(st.compiler.jsBuffer, "objj_msgSend("); + c(node.object, st, "Expression"); + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.object.end)); + } + + var selectors = node.selectors, + arguments = node.arguments, + selector = selectors[0].name; // There is always at least one selector + + // Put together the selector. Maybe this should be done in the parser... + for (var i = 0; i < arguments.length; i++) + if (i === 0) + selector += ":"; + else + selector += (selectors[i] ? selectors[i].name : "") + ":"; + + CONCAT(st.compiler.jsBuffer, ", \""); + CONCAT(st.compiler.jsBuffer, selector); // FIXME: sel_getUid(selector + "") ? This FIXME is from the old preprocessor compiler + CONCAT(st.compiler.jsBuffer, "\""); + + if (node.arguments) for (var i = 0; i < node.arguments.length; i++) + { + var argument = node.arguments[i]; + + CONCAT(st.compiler.jsBuffer, ", "); + st.compiler.lastPos = argument.start; + c(argument, st, "Expression"); + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, argument.end)); + st.compiler.lastPos = argument.end; + } + + // TODO: Move this 'if' wtih body up inside the node.argument 'if' + if (node.parameters) for (var i = 0; i < node.parameters.length; ++i) + { + var parameter = node.parameters[i]; + + CONCAT(st.compiler.jsBuffer, ", "); + st.compiler.lastPos = parameter.start; + c(parameter, st, "Expression"); + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, parameter.end)); + st.compiler.lastPos = parameter.end; + } + + CONCAT(st.compiler.jsBuffer, ")"); + st.compiler.lastPos = node.end; +}, +Identifier: function(node, st, c) { + if (!st.secondMemberExpression) + { + var identifier = node.name, + lvar = st.getLvarForCurrentMethod(identifier), + ivar = st.compiler.getIvarForClass(identifier, st); + + if (ivar) + { + if (lvar) + st.compiler.addWarning(createMessage("Local declaration of '" + identifier + "' hides instance variable", node, st.compiler.source)); + else + { + var nodeStart = node.start, + compiler = st.compiler; + + do { // The Spider Monkey AST tree includes any parentheses in start and end properties so we have to make sure we skip those + CONCAT(compiler.jsBuffer, compiler.source.substring(compiler.lastPos, nodeStart)); + compiler.lastPos = nodeStart; + } while (compiler.source.substr(nodeStart++, 1) === "(") + CONCAT(compiler.jsBuffer, "self."); + } + } + } +}, +SelectorLiteralExpression: function(node, st, c) { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + CONCAT(st.compiler.jsBuffer, "sel_getUid(\""); + CONCAT(st.compiler.jsBuffer, node.selector); + CONCAT(st.compiler.jsBuffer, "\")"); + st.compiler.lastPos = node.end; +}, +Literal: function(node, st, c) { + if (node.raw && node.raw.charAt(0) === "@") + { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + st.compiler.lastPos = node.start + 1; + } +}, +ObjectExpression: function(node, st, c) { + for (var i = 0; i < node.properties.length; ++i) + { + var prop = node.properties[i]; + if (prop.key.raw && prop.key.raw.charAt(0) === "@") + { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, prop.key.start)); + st.compiler.lastPos = prop.key.start + 1; + } + c(prop.value, st, "Expression"); + } +} +}); diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js index d9aceee93..5b8a73652 100644 --- a/Objective-J/ObjJCompiler.js +++ b/Objective-J/ObjJCompiler.js @@ -20,25 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -var ObjJCompiler = { }, - currentCompilerFlags = ""; - -exports.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - ObjJCompiler.currentCompileFile = aURL; - return new ObjJCompiler(aString, aURL, flags, 2).executable(); -} - -exports.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - return new ObjJCompiler(aString, aURL, flags, 2).IMBuffer(); -} - -exports.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - ObjJCompiler.currentCompileFile = aURL; - return new ObjJCompiler(aString, aURL, flags, 1).executable(); -} +var currentCompilerFlags = ""; var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) { @@ -91,6 +73,25 @@ var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ fla // console.log("JS: " + this._jsBuffer); } +exports.ObjJCompiler = ObjJCompiler; + +exports.ObjJCompiler.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + ObjJCompiler.currentCompileFile = aURL; + return new ObjJCompiler(aString, aURL, flags, 2).executable(); +} + +exports.ObjJCompiler.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + return new ObjJCompiler(aString, aURL, flags, 2).IMBuffer(); +} + +exports.ObjJCompiler.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) +{ + ObjJCompiler.currentCompileFile = aURL; + return new ObjJCompiler(aString, aURL, flags, 1).executable(); +} + ObjJCompiler.prototype.compilePass2 = function() { ObjJCompiler.currentCompileFile = this._URL; @@ -111,12 +112,11 @@ ObjJCompiler.prototype.compilePass2 = function() return this._jsBuffer.toString(); } -exports.ObjJCompiler = ObjJCompiler; - // This will set the compiler version to use. // These version works: // "preprocessor" -> Old Cappuccino compiler // "objj_compiler2" -> New Cappuccino compiler +// "acorn" -> New Cappuccino compiler with acorn parser GLOBAL(ObjJCompilerSetUsedVersion) = function(version) { @@ -1400,7 +1400,7 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast if (this.getClassDef(className)) throw new SyntaxError(this.error_message("Duplicate class " + className, children[2])); if (!this.getClassDef(superClassName)) - throw new SyntaxError(this.error_message("Can't find superclass " + superClassName, child)); + throw new SyntaxError(this.error_message("Can't find superclass " + superClassName, child)); classDef = {"className": className, "superClassName": superClassName, "ivars": {}, "methods": {}}; @@ -1540,7 +1540,7 @@ ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ ast CONCAT(getterSetterBuffer, "\n@end"); // Remove all @accessors or we will get a recursive loop in infinity var b = getterSetterBuffer.toString().replace(/@accessors(\(.*\))?/g, ""); - var imBuffer = exports.compileToIMBuffer(b, "getter", this._flags); + var imBuffer = ObjJCompiler.compileToIMBuffer(b, "getter", this._flags); CONCAT(this._imBuffer, imBuffer); } @@ -4704,4 +4704,3 @@ ObjJCompiler.prototype.error_message = function(errorMessage, astNode) (this._currentClass ? " Class: "+this._currentClass : "") + (this._currentSelector ? " Method: "+this._currentSelector : "") +">"; } -//})(window, ObjJCompiler, { exports: ObjJCompiler }); diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js new file mode 100644 index 000000000..bffdb9c6b --- /dev/null +++ b/Objective-J/acorn.js @@ -0,0 +1,2063 @@ +// Acorn is a tiny, fast JavaScript parser written in JavaScript. +// +// Acorn was written by Marijn Haverbeke and released under an MIT +// license. The Unicode regexps (for identifiers and whitespace) were +// taken from [Esprima](http://esprima.org) by Ariya Hidayat. +// +// Git repositories for Acorn are available at +// +// http://marijnhaverbeke.nl/git/acorn +// https://github.com/marijnh/acorn.git +// +// Please use the [github bug tracker][ghbt] to report issues. +// +// [ghbt]: https://github.com/marijnh/acorn/issues +// +// Objective-J extensions made by Martin Carlberg +// +// Git repositories for Acorn with Objective-J extension is available at +// +// https://github.com/mrcarlberg/acorn.git + +if (!exports.acorn) { + exports.acorn = {}; + exports.acorn.walk = {}; +} + +(function(exports) { + "use strict"; + + exports.version = "0.0.1"; + + // The main exported interface (under `self.acorn` when in the + // browser) is a `parse` function that takes a code string and + // returns an abstract syntax tree as specified by [Mozilla parser + // API][api], with the caveat that the SpiderMonkey-specific syntax + // (`let`, `yield`, inline XML, etc) is not recognized. + // + // [api]: https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API + + var options, input, inputLen, sourceFile; + + exports.parse = function(inpt, opts) { + input = String(inpt); inputLen = input.length; + options = opts || {}; + for (var opt in defaultOptions) if (!options.hasOwnProperty(opt)) + options[opt] = defaultOptions[opt]; + sourceFile = options.sourceFile || null; + return parseTopLevel(options.program); + }; + + // A second optional argument can be given to further configure + // the parser process. These options are recognized: + + var defaultOptions = exports.defaultOptions = { + // `ecmaVersion` indicates the ECMAScript version to parse. Must + // be either 3 or 5. This + // influences support for strict mode, the set of reserved words, and + // support for getters and setter. + ecmaVersion: 5, + // Turn on `strictSemicolons` to prevent the parser from doing + // automatic semicolon insertion. + strictSemicolons: false, + // When `allowTrailingCommas` is false, the parser will not allow + // trailing commas in array and object literals. + allowTrailingCommas: true, + // By default, reserved words are not enforced. Enable + // `forbidReserved` to enforce them. + forbidReserved: false, + // When `trackComments` is turned on, the parser will attach + // `commentsBefore` and `commentsAfter` properties to AST nodes + // holding arrays of strings. A single comment may appear in both + // a `commentsBefore` and `commentsAfter` array (of the nodes + // after and before it), but never twice in the before (or after) + // array of different nodes. + trackComments: false, + // When `locations` is on, `loc` properties holding objects with + // `start` and `end` properties in `{line, column}` form (with + // line being 1-based and column 0-based) will be attached to the + // nodes. + locations: false, + // Nodes have their start and end characters offsets recorded in + // `start` and `end` properties (directly on the node, rather than + // the `loc` object, which holds line/column data. To also add a + // [semi-standardized][range] `range` property holding a `[start, + // end]` array with the same numbers, set the `ranges` option to + // `true`. + // + // [range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678 + ranges: false, + // It is possible to parse multiple files into a single AST by + // passing the tree produced by parsing the first file as + // `program` option in subsequent parses. This will add the + // toplevel forms of the parsed file to the `Program` (top) node + // of an existing parse tree. + program: null, + // When `location` is on, you can pass this to record the source + // file in every node's `loc` object. + sourceFile: null, + // Turn on objj to allow objj systax + objj: true + }; + + // The `getLineInfo` function is mostly useful when the + // `locations` option is off (for performance reasons) and you + // want to find the line/column position for a given character + // offset. `input` should be the code string that the offset refers + // into. + + var getLineInfo = exports.getLineInfo = function(input, offset) { + for (var line = 1, cur = 0;;) { + lineBreak.lastIndex = cur; + var match = lineBreak.exec(input); + if (match && match.index < offset) { + ++line; + cur = match.index + match[0].length; + } else break; + } + return {line: line, column: offset - cur, lineStart: cur, lineEnd: (match ? match.index + match[0].length : input.length)}; + }; + + // Acorn is organized as a tokenizer and a recursive-descent parser. + // Both use (closure-)global variables to keep their state and + // communicate. We already saw the `options`, `input`, and + // `inputLen` variables above (set in `parse`). + + // The current position of the tokenizer in the input. + + var tokPos; + + // The start and end offsets of the current token. + + var tokStart, tokEnd; + + // When `options.locations` is true, these hold objects + // containing the tokens start and end line/column pairs. + + var tokStartLoc, tokEndLoc; + + // The type and value of the current token. Token types are objects, + // named by variables against which they can be compared, and + // holding properties that describe them (indicating, for example, + // the precedence of an infix operator, and the original name of a + // keyword token). The kind of value that's held in `tokVal` depends + // on the type of the token. For literals, it is the literal value, + // for operators, the operator name, and so on. + + var tokType, tokVal; + + // These are used to hold arrays of comments when + // `options.trackComments` is true. + + var tokCommentsBefore, tokCommentsAfter; + + // Interal state for the tokenizer. To distinguish between division + // operators and regular expressions, it remembers whether the last + // token was one that is allowed to be followed by an expression. + // (If it is, a slash is probably a regexp, if it isn't it's a + // division operator. See the `parseStatement` function for a + // caveat.) + + var tokRegexpAllowed, tokComments; + + // When `options.locations` is true, these are used to keep + // track of the current line, and know when a new line has been + // entered. See the `curLineLoc` function. + + var tokCurLine, tokLineStart, tokLineStartNext; + + // These store the position of the previous token, which is useful + // when finishing a node and assigning its `end` position. + + var lastStart, lastEnd, lastEndLoc; + + // This is the tokenizer's state for Objective-J. `afterImport` is used + // to make the part between '<' and '>' to be one token if it comes after + // a @import token. + + var tokAfterImport; + + // This is the tokenizer's state for Objective-J. 'nodeMessageSendObjectExpression' + // is used to store the expression that is already parsed when + + var nodeMessageSendObjectExpression; + + // This is the parser's state. `inFunction` is used to reject + // `return` statements outside of functions, `labels` to verify that + // `break` and `continue` have somewhere to jump to, and `strict` + // indicates whether strict mode is on. + + var inFunction, labels, strict; + + // This function is used to raise exceptions on parse errors. It + // takes either a `{line, column}` object or an offset integer (into + // the current `input`) as `pos` argument. It attaches the position + // to the end of the error message, and then raises a `SyntaxError` + // with that message. + + function raise(pos, message) { + if (typeof pos == "number") pos = getLineInfo(input, pos); + message += " (" + pos.line + ":" + pos.column + ")"; + var syntaxError = new SyntaxError(message); + syntaxError.line = pos.line; + syntaxError.column = pos.column; + syntaxError.lineStart = pos.lineStart; + syntaxError.lineEnd = pos.lineEnd; + + throw syntaxError; + } + + // ## Token types + + // The assignment of fine-grained, information-carrying type objects + // allows the tokenizer to store the information it has about a + // token in a way that is very cheap for the parser to look up. + + // All token type variables start with an underscore, to make them + // easy to recognize. + + // These are the general types. The `type` property is only used to + // make them recognizeable when debugging. + + var _num = {type: "num"}, _regexp = {type: "regexp"}, _string = {type: "string"}; + var _name = {type: "name"}, _eof = {type: "eof"}; + + // Keyword tokens. The `keyword` property (also used in keyword-like + // operators) indicates that the token originated from an + // identifier-like word, which is used when parsing property names. + // + // The `beforeExpr` property is used to disambiguate between regular + // expressions and divisions. It is set on all token types that can + // be followed by an expression (thus, a slash after them would be a + // regular expression). + // + // `isLoop` marks a keyword as starting a loop, which is important + // to know when parsing a label, in order to allow or disallow + // continue jumps to that label. + + var _break = {keyword: "break"}, _case = {keyword: "case", beforeExpr: true}, _catch = {keyword: "catch"}; + var _continue = {keyword: "continue"}, _debugger = {keyword: "debugger"}, _default = {keyword: "default"}; + var _do = {keyword: "do", isLoop: true}, _else = {keyword: "else", beforeExpr: true}; + var _finally = {keyword: "finally"}, _for = {keyword: "for", isLoop: true}, _function = {keyword: "function"}; + var _if = {keyword: "if"}, _return = {keyword: "return", beforeExpr: true}, _switch = {keyword: "switch"}; + var _throw = {keyword: "throw", beforeExpr: true}, _try = {keyword: "try"}, _var = {keyword: "var"}; + var _while = {keyword: "while", isLoop: true}, _with = {keyword: "with"}, _new = {keyword: "new", beforeExpr: true}; + var _this = {keyword: "this"}; + var _void = {keyword: "void", prefix: true}; + + // The keywords that denote values. + + var _null = {keyword: "null", atomValue: null}, _true = {keyword: "true", atomValue: true}; + var _false = {keyword: "false", atomValue: false}; + + // Some keywords are treated as regular operators. `in` sometimes + // (when parsing `for`) needs to be tested against specifically, so + // we assign a variable name to it for quick comparing. + + var _in = {keyword: "in", binop: 7, beforeExpr: true}; + + // Objective-J @ keywords + + var _implementation = {keyword: "implementation"}, _outlet = {keyword: "outlet"}, _accessors = {keyword: "accessors"}; + var _end = {keyword: "end"}, _import = {keyword: "import", afterImport: true}; + var _action = {keyword: "action"}, _selector = {keyword: "selector"}; + + // Objective-J keywords + + var _filename = {keyword: "filename"}, _unsigned = {keyword: "unsigned"}, _signed = {keyword: "signed"}; + var _byte = {keyword: "byte"}, _char = {keyword: "char"}, _short = {keyword: "short"}, _int = {keyword: "int"}, _long = {keyword: "long"}; + + // Map keyword names to token types. + + var keywordTypes = {"break": _break, "case": _case, "catch": _catch, + "continue": _continue, "debugger": _debugger, "default": _default, + "do": _do, "else": _else, "finally": _finally, "for": _for, + "function": _function, "if": _if, "return": _return, "switch": _switch, + "throw": _throw, "try": _try, "var": _var, "while": _while, "with": _with, + "null": _null, "true": _true, "false": _false, "new": _new, "in": _in, + "instanceof": {keyword: "instanceof", binop: 7}, "this": _this, + "typeof": {keyword: "typeof", prefix: true}, + "void": _void, + "delete": {keyword: "delete", prefix: true} }; + + // Map Objective-J keyword names to token types. + + var keywordTypesObjJ = {"IBAction": _action, "unsigned": _unsigned, "signed": _signed, "byte": _byte, "char": _char, + "short": _short, "int": _int, "long": _long }; + + // Map Objective-J "@" keyword names to token types. + + var objJAtKeywordTypes = {"implementation": _implementation, "outlet": _outlet, "accessors": _accessors, "end": _end, + "import": _import, "action": _action, "selector": _selector}; + + // Punctuation token types. Again, the `type` property is purely for debugging. + + var _bracketL = {type: "[", beforeExpr: true}, _bracketR = {type: "]"}, _braceL = {type: "{", beforeExpr: true}; + var _braceR = {type: "}"}, _parenL = {type: "(", beforeExpr: true}, _parenR = {type: ")"}; + var _comma = {type: ",", beforeExpr: true}, _semi = {type: ";", beforeExpr: true}; + var _colon = {type: ":", beforeExpr: true}, _dot = {type: "."}, _question = {type: "?", beforeExpr: true}; + + // Objective-J token types + + var _at = {type: "@"}, _dotdotdot = {type: "..."}, _numberSign = {type: "#"}; + + // Operators. These carry several kinds of properties to help the + // parser use them properly (the presence of these properties is + // what categorizes them as operators). + // + // `binop`, when present, specifies that this operator is a binary + // operator, and will refer to its precedence. + // + // `prefix` and `postfix` mark the operator as a prefix or postfix + // unary operator. `isUpdate` specifies that the node produced by + // the operator should be of type UpdateExpression rather than + // simply UnaryExpression (`++` and `--`). + // + // `isAssign` marks all of `=`, `+=`, `-=` etcetera, which act as + // binary operators with a very low precedence, that should result + // in AssignmentExpression nodes. + + var _slash = {binop: 10, beforeExpr: true}, _eq = {isAssign: true, beforeExpr: true}; + var _assign = {isAssign: true, beforeExpr: true}, _plusmin = {binop: 9, prefix: true, beforeExpr: true}; + var _incdec = {postfix: true, prefix: true, isUpdate: true}, _prefix = {prefix: true, beforeExpr: true}; + var _bin1 = {binop: 1, beforeExpr: true}, _bin2 = {binop: 2, beforeExpr: true}; + var _bin3 = {binop: 3, beforeExpr: true}, _bin4 = {binop: 4, beforeExpr: true}; + var _bin5 = {binop: 5, beforeExpr: true}, _bin6 = {binop: 6, beforeExpr: true}; + var _bin7 = {binop: 7, beforeExpr: true}, _bin8 = {binop: 8, beforeExpr: true}; + var _bin10 = {binop: 10, beforeExpr: true}; + + // This is a trick taken from Esprima. It turns out that, on + // non-Chrome browsers, to check whether a string is in a set, a + // predicate containing a big ugly `switch` statement is faster than + // a regular expression, and on Chrome the two are about on par. + // This function uses `eval` (non-lexical) to produce such a + // predicate from a space-separated string of words. + // + // It starts by sorting the words by length. + + function makePredicate(words) { + words = words.split(" "); + var f = "", cats = []; + out: for (var i = 0; i < words.length; ++i) { + for (var j = 0; j < cats.length; ++j) + if (cats[j][0].length == words[i].length) { + cats[j].push(words[i]); + continue out; + } + cats.push([words[i]]); + } + function compareTo(arr) { + if (arr.length == 1) return f += "return str === " + JSON.stringify(arr[0]) + ";"; + f += "switch(str){"; + for (var i = 0; i < arr.length; ++i) f += "case " + JSON.stringify(arr[i]) + ":"; + f += "return true}return false;"; + } + + // When there are more than three length categories, an outer + // switch first dispatches on the lengths, to save on comparisons. + + if (cats.length > 3) { + cats.sort(function(a, b) {return b.length - a.length;}); + f += "switch(str.length){"; + for (var i = 0; i < cats.length; ++i) { + var cat = cats[i]; + f += "case " + cat[0].length + ":"; + compareTo(cat); + } + f += "}"; + + // Otherwise, simply generate a flat `switch` statement. + + } else { + compareTo(words); + } + return new Function("str", f); + } + + // The ECMAScript 3 reserved word list. + + var isReservedWord3 = makePredicate("abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile"); + + // ECMAScript 5 reserved words. + + var isReservedWord5 = makePredicate("class enum extends super const export import"); + + // The additional reserved words in strict mode. + + var isStrictReservedWord = makePredicate("implements interface let package private protected public static yield"); + + // The forbidden variable names in strict mode. + + var isStrictBadIdWord = makePredicate("eval arguments"); + + // And the keywords. + + var isKeyword = makePredicate("break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"); + + // The Objective-J keywords. + + var isKeywordObjJ = makePredicate("IBAction byte char short int long unsigned signed"); + + // ## Character categories + + // Big ugly regular expressions that match characters in the + // whitespace, identifier, and identifier-start categories. These + // are only applied when a character is found to actually have a + // code point above 128. + + var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/; + var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"; + var nonASCIIidentifierChars = "\u0371-\u0374\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u0620-\u0649\u0672-\u06d3\u06e7-\u06e8\u06fb-\u06fc\u0730-\u074a\u0800-\u0814\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0840-\u0857\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962-\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09d7\u09df-\u09e0\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2-\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b5f-\u0b60\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62-\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2-\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d46-\u0d48\u0d57\u0d62-\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e34-\u0e3a\u0e40-\u0e45\u0e50-\u0e59\u0eb4-\u0eb9\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f41-\u0f47\u0f71-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u1000-\u1029\u1040-\u1049\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u170e-\u1710\u1720-\u1730\u1740-\u1750\u1772\u1773\u1780-\u17b2\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u1920-\u192b\u1930-\u193b\u1951-\u196d\u19b0-\u19c0\u19c8-\u19c9\u19d0-\u19d9\u1a00-\u1a15\u1a20-\u1a53\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b46-\u1b4b\u1b50-\u1b59\u1b6b-\u1b73\u1bb0-\u1bb9\u1be6-\u1bf3\u1c00-\u1c22\u1c40-\u1c49\u1c5b-\u1c7d\u1cd0-\u1cd2\u1d00-\u1dbe\u1e01-\u1f15\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2d81-\u2d96\u2de0-\u2dff\u3021-\u3028\u3099\u309a\ua640-\ua66d\ua674-\ua67d\ua69f\ua6f0-\ua6f1\ua7f8-\ua800\ua806\ua80b\ua823-\ua827\ua880-\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8f3-\ua8f7\ua900-\ua909\ua926-\ua92d\ua930-\ua945\ua980-\ua983\ua9b3-\ua9c0\uaa00-\uaa27\uaa40-\uaa41\uaa4c-\uaa4d\uaa50-\uaa59\uaa7b\uaae0-\uaae9\uaaf2-\uaaf3\uabc0-\uabe1\uabec\uabed\uabf0-\uabf9\ufb20-\ufb28\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"; + var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]"); + var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]"); + + // Whether a single character denotes a newline. + + var newline = /[\n\r\u2028\u2029]/; + + // Matches a whole line break (where CRLF is considered a single + // line break). Used to count lines. + + var lineBreak = /\r\n|[\n\r\u2028\u2029]/g; + + // Test whether a given character code starts an identifier. + + function isIdentifierStart(code) { + if (code < 65) return code === 36; + if (code < 91) return true; + if (code < 97) return code === 95; + if (code < 123)return true; + return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)); + } + + // Test whether a given character is part of an identifier. + + function isIdentifierChar(code) { + if (code < 48) return code === 36; + if (code < 58) return true; + if (code < 65) return false; + if (code < 91) return true; + if (code < 97) return code === 95; + if (code < 123)return true; + return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)); + } + + // ## Tokenizer + + // These are used when `options.locations` is on, in order to track + // the current line number and start of line offset, in order to set + // `tokStartLoc` and `tokEndLoc`. + + function nextLineStart() { + lineBreak.lastIndex = tokLineStart; + var match = lineBreak.exec(input); + return match ? match.index + match[0].length : input.length + 1; + } + + function curLineLoc() { + while (tokLineStartNext <= tokPos) { + ++tokCurLine; + tokLineStart = tokLineStartNext; + tokLineStartNext = nextLineStart(); + } + return {line: tokCurLine, column: tokPos - tokLineStart}; + } + + // Reset the token state. Used at the start of a parse. + + function initTokenState() { + tokCurLine = 1; + tokPos = tokLineStart = 0; + tokLineStartNext = nextLineStart(); + tokRegexpAllowed = true; + tokComments = null; + skipSpace(); + } + + // Called at the end of every token. Sets `tokEnd`, `tokVal`, + // `tokCommentsAfter`, and `tokRegexpAllowed`, and skips the space + // after the token, so that the next one's `tokStart` will point at + // the right position. + + function finishToken(type, val) { + tokEnd = tokPos; + if (options.locations) tokEndLoc = curLineLoc(); + tokType = type; + skipSpace(); + tokVal = val; + tokCommentsAfter = tokComments; + tokRegexpAllowed = type.beforeExpr; + tokAfterImport = type.afterImport; + } + + function skipBlockComment() { + var end = input.indexOf("*/", tokPos += 2); + if (end === -1) raise(tokPos - 2, "Unterminated comment"); + if (options.trackComments) + (tokComments || (tokComments = [])).push(input.slice(tokPos, end)); + tokPos = end + 2; + } + + function skipLineComment(skipCharacters) { + var start = tokPos; + var ch = input.charCodeAt(tokPos+=skipCharacters); + while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) { + ++tokPos; + ch = input.charCodeAt(tokPos); + } + if (options.trackComments) + (tokComments || (tokComments = [])).push(input.slice(start, tokPos)); + } + + // Called at the start of the parse and after every token. Skips + // whitespace and comments, and, if `options.trackComments` is on, + // will store all skipped comments in `tokComments`. + + function skipSpace() { + tokComments = null; + while (tokPos < inputLen) { + var ch = input.charCodeAt(tokPos); + if (ch === 47) { // '/' + var next = input.charCodeAt(tokPos+1); + if (next === 42) { // '*' + skipBlockComment(); + } else if (next === 47) { // '/' + skipLineComment(2); + } else break; + } else if (ch < 14 && ch > 8) { + ++tokPos; + } else if (ch === 32 || ch === 160) { // ' ', '\xa0' + ++tokPos; + } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { + ++tokPos; + } else if (ch === 35 && options.objj) { + skipLineComment(1); + } else { + break; + } + } + } + + // ### Token reading + + // This is the function that is called to fetch the next token. It + // is somewhat obscure, because it works in character codes rather + // than characters, and because operator parsing has been inlined + // into it. + // + // All in the name of speed. + // + // The `forceRegexp` parameter is used in the one case where the + // `tokRegexpAllowed` trick does not work. See `parseStatement`. + + function readToken_dot(code) { + var next = input.charCodeAt(tokPos+1); + if (next >= 48 && next <= 57) return readNumber(String.fromCharCode(code)); + if (next === 46 && options.objj && input.charCodeAt(tokPos+2) === 46) { //'.' + tokPos += 3; + return finishToken(_dotdotdot); + } + ++tokPos; + return finishToken(_dot); + } + + function readToken_slash() { // '/' + var next = input.charCodeAt(tokPos+1); + if (tokRegexpAllowed) {++tokPos; return readRegexp();} + if (next === 61) return finishOp(_assign, 2); + return finishOp(_slash, 1); + } + + function readToken_mult_modulo() { // '%*' + var next = input.charCodeAt(tokPos+1); + if (next === 61) return finishOp(_assign, 2); + return finishOp(_bin10, 1); + } + + function readToken_pipe_amp(code) { // '|&' + var next = input.charCodeAt(tokPos+1); + if (next === code) return finishOp(code === 124 ? _bin1 : _bin2, 2); + if (next === 61) return finishOp(_assign, 2); + return finishOp(code === 124 ? _bin3 : _bin5, 1); + } + + function readToken_caret() { // '^' + var next = input.charCodeAt(tokPos+1); + if (next === 61) return finishOp(_assign, 2); + return finishOp(_bin4, 1); + } + + function readToken_plus_min(code) { // '+-' + var next = input.charCodeAt(tokPos+1); + if (next === code) return finishOp(_incdec, 2); + if (next === 61) return finishOp(_assign, 2); + return finishOp(_plusmin, 1); + } + + function readToken_lt_gt(code) { // '<>' + if (tokAfterImport && options.objj && code === 60) { // '<' + var str = []; + for (;;) { + if (tokPos >= inputLen) raise(tokStart, "Unterminated import statement"); + var ch = input.charCodeAt(++tokPos); + if (ch === 62) { // '>' + ++tokPos; + return finishToken(_filename, String.fromCharCode.apply(null, str)); + } + str.push(ch); + } + } + var next = input.charCodeAt(tokPos+1); + var size = 1; + if (next === code) { + size = code === 62 && input.charCodeAt(tokPos+2) === 62 ? 3 : 2; + if (input.charCodeAt(tokPos + size) === 61) return finishOp(_assign, size + 1); + return finishOp(_bin8, size); + } + if (next === 61) + size = input.charCodeAt(tokPos+2) === 61 ? 3 : 2; + return finishOp(_bin7, size); + } + + function readToken_eq_excl(code) { // '=!' + var next = input.charCodeAt(tokPos+1); + if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2); + return finishOp(code === 61 ? _eq : _prefix, 1); + } + + function readToken_at(code) { // '@' + var next = input.charCodeAt(++tokPos); + if (next === 34 || next === 39) // Read string if "'" or '"' + return readString(next); + var word = readWord1(), + token = objJAtKeywordTypes[word]; + if (!token) raise(tokStart, "Unrecognized Objective-J keyword '@" + word + "'"); + return finishToken(token); + } + + function getTokenFromCode(code) { + switch(code) { + // The interpretation of a dot depends on whether it is followed + // by a digit. + case 46: // '.' + return readToken_dot(code); + + // Punctuation tokens. + case 40: ++tokPos; return finishToken(_parenL); + case 41: ++tokPos; return finishToken(_parenR); + case 59: ++tokPos; return finishToken(_semi); + case 44: ++tokPos; return finishToken(_comma); + case 91: ++tokPos; return finishToken(_bracketL); + case 93: ++tokPos; return finishToken(_bracketR); + case 123: ++tokPos; return finishToken(_braceL); + case 125: ++tokPos; return finishToken(_braceR); + case 58: ++tokPos; return finishToken(_colon); + case 63: ++tokPos; return finishToken(_question); + + // '0x' is a hexadecimal number. + case 48: // '0' + var next = input.charCodeAt(tokPos+1); + if (next === 120 || next === 88) return readHexNumber(); + // Anything else beginning with a digit is an integer, octal + // number, or float. + case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9 + return readNumber(String.fromCharCode(code)); + + // Quotes produce strings. + case 34: case 39: // '"', "'" + return readString(code); + + // Operators are parsed inline in tiny state machines. '=' (61) is + // often referred to. `finishOp` simply skips the amount of + // characters it is given as second argument, and returns a token + // of the type given by its first argument. + + case 47: // '/' + return readToken_slash(code); + + case 37: case 42: // '%*' + return readToken_mult_modulo(); + + case 124: case 38: // '|&' + return readToken_pipe_amp(code); + + case 94: // '^' + return readToken_caret(); + + case 43: case 45: // '+-' + return readToken_plus_min(code); + + case 60: case 62: // '<>' + return readToken_lt_gt(code); + + case 61: case 33: // '=!' + return readToken_eq_excl(code); + + case 64: // '@' + if (options.objj) + return readToken_at(code); + return false; + + case 126: // '~' + return finishOp(_prefix, 1); + } + + return false; + } + + function readToken(forceRegexp) { + tokStart = tokPos; + if (options.locations) tokStartLoc = curLineLoc(); + tokCommentsBefore = tokComments; + if (forceRegexp) return readRegexp(); + if (tokPos >= inputLen) return finishToken(_eof); + + var code = input.charCodeAt(tokPos); + // Identifier or keyword. '\uXXXX' sequences are allowed in + // identifiers, so '\' also dispatches to that. + if (isIdentifierStart(code) || code === 92 /* '\' */) return readWord(); + + var tok = getTokenFromCode(code); + + if(tok === false) { + // If we are here, we either found a non-ASCII identifier + // character, or something that's entirely disallowed. + var ch = String.fromCharCode(code); + if (ch === "\\" || nonASCIIidentifierStart.test(ch)) return readWord(); + raise(tokPos, "Unexpected character '" + ch + "'"); + } + return tok; + } + + function finishOp(type, size) { + var str = input.slice(tokPos, tokPos + size); + tokPos += size; + finishToken(type, str); + } + + // Parse a regular expression. Some context-awareness is necessary, + // since a '/' inside a '[]' set does not end the expression. + + function readRegexp() { + var content = "", escaped, inClass, start = tokPos; + for (;;) { + if (tokPos >= inputLen) raise(start, "Unterminated regular expression"); + var ch = input.charAt(tokPos); + if (newline.test(ch)) raise(start, "Unterminated regular expression"); + if (!escaped) { + if (ch === "[") inClass = true; + else if (ch === "]" && inClass) inClass = false; + else if (ch === "/" && !inClass) break; + escaped = ch === "\\"; + } else escaped = false; + ++tokPos; + } + var content = input.slice(start, tokPos); + ++tokPos; + // Need to use `readWord1` because '\uXXXX' sequences are allowed + // here (don't ask). + var mods = readWord1(); + if (mods && !/^[gmsiy]*$/.test(mods)) raise(start, "Invalid regexp flag"); + return finishToken(_regexp, new RegExp(content, mods)); + } + + // Read an integer in the given radix. Return null if zero digits + // were read, the integer value otherwise. When `len` is given, this + // will return `null` unless the integer has exactly `len` digits. + + function readInt(radix, len) { + var start = tokPos, total = 0; + for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) { + var code = input.charCodeAt(tokPos), val; + if (code >= 97) val = code - 97 + 10; // a + else if (code >= 65) val = code - 65 + 10; // A + else if (code >= 48 && code <= 57) val = code - 48; // 0-9 + else val = Infinity; + if (val >= radix) break; + ++tokPos; + total = total * radix + val; + } + if (tokPos === start || len != null && tokPos - start !== len) return null; + + return total; + } + + function readHexNumber() { + tokPos += 2; // 0x + var val = readInt(16); + if (val == null) raise(tokStart + 2, "Expected hexadecimal number"); + if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number"); + return finishToken(_num, val); + } + + // Read an integer, octal integer, or floating-point number. + + function readNumber(ch) { + var start = tokPos, isFloat = ch === "."; + if (!isFloat && readInt(10) == null) raise(start, "Invalid number"); + if (isFloat || input.charAt(tokPos) === ".") { + var next = input.charAt(++tokPos); + if (next === "-" || next === "+") ++tokPos; + if (readInt(10) === null && ch === ".") raise(start, "Invalid number"); + isFloat = true; + } + if (/e/i.test(input.charAt(tokPos))) { + var next = input.charAt(++tokPos); + if (next === "-" || next === "+") ++tokPos; + if (readInt(10) === null) raise(start, "Invalid number") + isFloat = true; + } + if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number"); + + var str = input.slice(start, tokPos), val; + if (isFloat) val = parseFloat(str); + else if (ch !== "0" || str.length === 1) val = parseInt(str, 10); + else if (/[89]/.test(str) || strict) raise(start, "Invalid number"); + else val = parseInt(str, 8); + return finishToken(_num, val); + } + + // Read a string value, interpreting backslash-escapes. + + function readString(quote) { + tokPos++; + var str = []; + for (;;) { + if (tokPos >= inputLen) raise(tokStart, "Unterminated string constant"); + var ch = input.charCodeAt(tokPos); + if (ch === quote) { + ++tokPos; + return finishToken(_string, String.fromCharCode.apply(null, str)); + } + if (ch === 92) { // '\' + ch = input.charCodeAt(++tokPos); + var octal = /^[0-7]+/.exec(input.slice(tokPos, tokPos + 3)); + if (octal) octal = octal[0]; + while (octal && parseInt(octal, 8) > 255) octal = octal.slice(0, octal.length - 1); + if (octal === "0") octal = null; + ++tokPos; + if (octal) { + if (strict) raise(tokPos - 2, "Octal literal in strict mode"); + str.push(parseInt(octal, 8)); + tokPos += octal.length - 1; + } else { + switch (ch) { + case 110: str.push(10); break; // 'n' -> '\n' + case 114: str.push(13); break; // 'r' -> '\r' + case 120: str.push(readHexChar(2)); break; // 'x' + case 117: str.push(readHexChar(4)); break; // 'u' + case 85: str.push(readHexChar(8)); break; // 'U' + case 116: str.push(9); break; // 't' -> '\t' + case 98: str.push(8); break; // 'b' -> '\b' + case 118: str.push(11); break; // 'v' -> '\u000b' + case 102: str.push(12); break; // 'f' -> '\f' + case 48: str.push(0); break; // 0 -> '\0' + case 13: if (input.charCodeAt(tokPos) === 10) ++tokPos; // '\r\n' + case 10: break; // ' \n' + default: str.push(ch); break; + } + } + } else { + if (ch === 13 || ch === 10 || ch === 8232 || ch === 8329) raise(tokStart, "Unterminated string constant"); + if (ch !== 92) str.push(ch); // '\' // This 'if' seems useless as the same thing is checked above..... - Martin + ++tokPos; + } + } + } + + // Used to read character escape sequences ('\x', '\u', '\U'). + + function readHexChar(len) { + var n = readInt(16, len); + if (n === null) raise(tokStart, "Bad character escape sequence"); + return n; + } + + // Used to signal to callers of `readWord1` whether the word + // contained any escape sequences. This is needed because words with + // escape sequences must not be interpreted as keywords. + + var containsEsc; + + // Read an identifier, and return it as a string. Sets `containsEsc` + // to whether the word contained a '\u' escape. + // + // Only builds up the word character-by-character when it actually + // containeds an escape, as a micro-optimization. + + function readWord1() { + containsEsc = false; + var word, first = true, start = tokPos; + for (;;) { + var ch = input.charCodeAt(tokPos); + if (isIdentifierChar(ch)) { + if (containsEsc) word += input.charAt(tokPos); + ++tokPos; + } else if (ch === 92) { // "\" + if (!containsEsc) word = input.slice(start, tokPos); + containsEsc = true; + if (input.charCodeAt(++tokPos) != 117) // "u" + raise(tokPos, "Expecting Unicode escape sequence \\uXXXX"); + ++tokPos; + var esc = readHexChar(4); + var escStr = String.fromCharCode(esc); + if (!escStr) raise(tokPos - 1, "Invalid Unicode escape"); + if (!(first ? isIdentifierStart(esc) : isIdentifierChar(esc))) + raise(tokPos - 4, "Invalid Unicode escape"); + word += escStr; + } else { + break; + } + first = false; + } + return containsEsc ? word : input.slice(start, tokPos); + } + + // Read an identifier or keyword token. Will check for reserved + // words when necessary. + + function readWord() { + var word = readWord1(); + var type = _name; + if (!containsEsc) { + if (isKeyword(word)) type = keywordTypes[word]; + else if (options.objj && isKeywordObjJ(word)) type = keywordTypesObjJ[word]; + else if (options.forbidReserved && + (options.ecmaVersion === 3 ? isReservedWord3 : isReservedWord5)(word) || + strict && isStrictReservedWord(word)) + raise(tokStart, "The keyword '" + word + "' is reserved"); + } + return finishToken(type, word); + } + + // ## Parser + + // A recursive descent parser operates by defining functions for all + // syntactic elements, and recursively calling those, each function + // advancing the input stream and returning an AST node. Precedence + // of constructs (for example, the fact that `!x[1]` means `!(x[1])` + // instead of `(!x)[1]` is handled by the fact that the parser + // function that parses unary prefix operators is called first, and + // in turn calls the function that parses `[]` subscripts — that + // way, it'll receive the node for `x[1]` already parsed, and wraps + // *that* in the unary operator node. + // + // Acorn uses an [operator precedence parser][opp] to handle binary + // operator precedence, because it is much more compact than using + // the technique outlined above, which uses different, nesting + // functions to specify precedence, for all of the ten binary + // precedence levels that JavaScript defines. + // + // [opp]: http://en.wikipedia.org/wiki/Operator-precedence_parser + + // ### Parser utilities + + // Continue to the next token. + + function next() { + lastStart = tokStart; + lastEnd = tokEnd; + lastEndLoc = tokEndLoc; + nodeMessageSendObjectExpression = null; + readToken(); + } + + // Enter strict mode. Re-reads the next token to please pedantic + // tests ("use strict"; 010; -- should fail). + + function setStrict(strct) { + strict = strct; + tokPos = lastEnd; + skipSpace(); + readToken(); + } + + // Start an AST node, attaching a start offset and optionally a + // `commentsBefore` property to it. + + function startNode() { + var node = {type: null, start: tokStart, end: null}; + if (options.trackComments && tokCommentsBefore) { + node.commentsBefore = tokCommentsBefore; + tokCommentsBefore = null; + } + if (options.locations) + node.loc = {start: tokStartLoc, end: null, source: sourceFile}; + if (options.ranges) + node.range = [tokStart, 0]; + return node; + } + + // Start a node whose start offset/comments information should be + // based on the start of another node. For example, a binary + // operator node is only started after its left-hand side has + // already been parsed. + + function startNodeFrom(other) { + var node = {type: null, start: other.start}; + if (other.commentsBefore) { + node.commentsBefore = other.commentsBefore; + other.commentsBefore = null; + } + if (options.locations) + node.loc = {start: other.loc.start, end: null, source: other.loc.source}; + if (options.ranges) + node.range = [other.range[0], 0]; + + return node; + } + + // Finish an AST node, adding `type`, `end`, and `commentsAfter` + // properties. + // + // We keep track of the last node that we finished, in order + // 'bubble' `commentsAfter` properties up to the biggest node. I.e. + // in '`1 + 1 // foo', the comment should be attached to the binary + // operator node, not the second literal node. + + var lastFinishedNode; + + function finishNode(node, type) { + node.type = type; + node.end = lastEnd; + if (options.trackComments) { + if (tokCommentsAfter) { + node.commentsAfter = tokCommentsAfter; + tokCommentsAfter = null; + } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && + lastFinishedNode.commentsAfter) { + node.commentsAfter = lastFinishedNode.commentsAfter; + lastFinishedNode.commentsAfter = null; + } + lastFinishedNode = node; + } + if (options.locations) + node.loc.end = lastEndLoc; + if (options.ranges) + node.range[1] = lastEnd; + return node; + } + + // Test whether a statement node is the string literal `"use strict"`. + + function isUseStrict(stmt) { + return options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" && + stmt.expression.type === "Literal" && stmt.expression.value === "use strict"; + } + + // Predicate that tests whether the next token is of the given + // type, and if yes, consumes it as a side effect. + + function eat(type) { + if (tokType === type) { + next(); + return true; + } + } + + // Test whether a semicolon can be inserted at the current position. + + function canInsertSemicolon() { + return !options.strictSemicolons && + (tokType === _eof || tokType === _braceR || newline.test(input.slice(lastEnd, tokStart)) || + (nodeMessageSendObjectExpression && options.objj)); + } + + // Consume a semicolon, or, failing that, see if we are allowed to + // pretend that there is a semicolon at this position. + + function semicolon() { + if (!eat(_semi) && !canInsertSemicolon()) unexpected(); + } + + // Expect a token of a given type. If found, consume it, otherwise, + // raise an unexpected token error. + + function expect(type) { + if (tokType === type) next(); + else unexpected(); + } + + // Raise an unexpected token error. + + function unexpected() { + raise(tokStart, "Unexpected token"); + } + + // Verify that a node is an lval — something that can be assigned + // to. + + function checkLVal(expr) { + if (expr.type !== "Identifier" && expr.type !== "MemberExpression") + raise(expr.start, "Assigning to rvalue"); + if (strict && expr.type === "Identifier" && isStrictBadIdWord(expr.name)) + raise(expr.start, "Assigning to " + expr.name + " in strict mode"); + } + + // ### Statement parsing + + // Parse a program. Initializes the parser, reads any number of + // statements, and wraps them in a Program node. Optionally takes a + // `program` argument. If present, the statements will be appended + // to its body instead of creating a new node. + + function parseTopLevel(program) { + initTokenState(); + lastStart = lastEnd = tokPos; + if (options.locations) lastEndLoc = curLineLoc(); + inFunction = strict = null; + labels = []; + readToken(); + + var node = program || startNode(), first = true; + if (!program) node.body = []; + while (tokType !== _eof) { + var stmt = parseStatement(); + node.body.push(stmt); + if (first && isUseStrict(stmt)) setStrict(true); + first = false; + } + return finishNode(node, "Program"); + }; + + var loopLabel = {kind: "loop"}, switchLabel = {kind: "switch"}; + + // Parse a single statement. + // + // If expecting a statement and finding a slash operator, parse a + // regular expression literal. This is to handle cases like + // `if (foo) /blah/.exec(foo);`, where looking at the previous token + // does not help. + + function parseStatement() { + if (nodeMessageSendObjectExpression) + return parseMessageSendExpression(nodeMessageSendObjectExpression, nodeMessageSendObjectExpression.object); + + if (tokType === _slash) + readToken(true); + + var starttype = tokType, node = startNode(); + + // Most types of statements are recognized by the keyword they + // start with. Many are trivial to parse, some require a bit of + // complexity. + + switch (starttype) { + case _break: case _continue: + next(); + var isBreak = starttype === _break; + if (eat(_semi) || canInsertSemicolon()) node.label = null; + else if (tokType !== _name) unexpected(); + else { + node.label = parseIdent(); + semicolon(); + } + + // Verify that there is an actual destination to break or + // continue to. + for (var i = 0; i < labels.length; ++i) { + var lab = labels[i]; + if (node.label == null || lab.name === node.label.name) { + if (lab.kind != null && (isBreak || lab.kind === "loop")) break; + if (node.label && isBreak) break; + } + } + if (i === labels.length) raise(node.start, "Unsyntactic " + starttype.keyword); + return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); + + case _debugger: + next(); + semicolon(); + return finishNode(node, "DebuggerStatement"); + + case _do: + next(); + labels.push(loopLabel); + node.body = parseStatement(); + labels.pop(); + expect(_while); + node.test = parseParenExpression(); + semicolon(); + return finishNode(node, "DoWhileStatement"); + + // Disambiguating between a `for` and a `for`/`in` loop is + // non-trivial. Basically, we have to parse the init `var` + // statement or expression, disallowing the `in` operator (see + // the second parameter to `parseExpression`), and then check + // whether the next token is `in`. When there is no init part + // (semicolon immediately after the opening parenthesis), it is + // a regular `for` loop. + + case _for: + next(); + labels.push(loopLabel); + expect(_parenL); + if (tokType === _semi) return parseFor(node, null); + if (tokType === _var) { + var init = startNode(); + next(); + parseVar(init, true); + if (init.declarations.length === 1 && eat(_in)) + return parseForIn(node, init); + return parseFor(node, init); + } + var init = parseExpression(false, true); + if (eat(_in)) {checkLVal(init); return parseForIn(node, init);} + return parseFor(node, init); + + case _function: + next(); + return parseFunction(node, true); + + case _if: + next(); + node.test = parseParenExpression(); + node.consequent = parseStatement(); + node.alternate = eat(_else) ? parseStatement() : null; + return finishNode(node, "IfStatement"); + + case _return: + if (!inFunction) raise(tokStart, "'return' outside of function"); + next(); + + // In `return` (and `break`/`continue`), the keywords with + // optional arguments, we eagerly look for a semicolon or the + // possibility to insert one. + + if (eat(_semi) || canInsertSemicolon()) node.argument = null; + else { node.argument = parseExpression(); semicolon(); } + return finishNode(node, "ReturnStatement"); + + case _switch: + next(); + node.discriminant = parseParenExpression(); + node.cases = []; + expect(_braceL); + labels.push(switchLabel); + + // Statements under must be grouped (by label) in SwitchCase + // nodes. `cur` is used to keep the node that we are currently + // adding statements to. + + for (var cur, sawDefault; tokType != _braceR;) { + if (tokType === _case || tokType === _default) { + var isCase = tokType === _case; + if (cur) finishNode(cur, "SwitchCase"); + node.cases.push(cur = startNode()); + cur.consequent = []; + next(); + if (isCase) cur.test = parseExpression(); + else { + if (sawDefault) raise(lastStart, "Multiple default clauses"); sawDefault = true; + cur.test = null; + } + expect(_colon); + } else { + if (!cur) unexpected(); + cur.consequent.push(parseStatement()); + } + } + if (cur) finishNode(cur, "SwitchCase"); + next(); // Closing brace + labels.pop(); + return finishNode(node, "SwitchStatement"); + + case _throw: + next(); + if (newline.test(input.slice(lastEnd, tokStart))) + raise(lastEnd, "Illegal newline after throw"); + node.argument = parseExpression(); + semicolon(); + return finishNode(node, "ThrowStatement"); + + case _try: + next(); + node.block = parseBlock(); + node.handlers = []; + while (tokType === _catch) { + var clause = startNode(); + next(); + expect(_parenL); + clause.param = parseIdent(); + if (strict && isStrictBadIdWord(clause.param.name)) + raise(clause.param.start, "Binding " + clause.param.name + " in strict mode"); + expect(_parenR); + clause.guard = null; + clause.body = parseBlock(); + node.handlers.push(finishNode(clause, "CatchClause")); + } + node.finalizer = eat(_finally) ? parseBlock() : null; + if (!node.handlers.length && !node.finalizer) + raise(node.start, "Missing catch or finally clause"); + return finishNode(node, "TryStatement"); + + case _var: + next(); + node = parseVar(node); + semicolon(); + return node; + + case _while: + next(); + node.test = parseParenExpression(); + labels.push(loopLabel); + node.body = parseStatement(); + labels.pop(); + return finishNode(node, "WhileStatement"); + + case _with: + if (strict) raise(tokStart, "'with' in strict mode"); + next(); + node.object = parseParenExpression(); + node.body = parseStatement(); + return finishNode(node, "WithStatement"); + + case _braceL: + return parseBlock(); + + case _semi: + next(); + return finishNode(node, "EmptyStatement"); + + // This is a Objective-J statement + case _implementation: + if (options.objj) { + next(); + node.classname = parseIdent(true); + if (eat(_colon)) + node.superclassname = parseIdent(true); + else if (eat(_parenL)) { + node.categoryname = parseIdent(true); + expect(_parenR); + } + if (eat(_braceL)) { + node.ivardeclarations = []; + for (;;) { + if (eat(_braceR)) break; + parseIvarDeclaration(node); + } + node.endOfIvars = tokStart; + } + node.body = []; + while(!eat(_end)) { + node.body.push(parseClassElement()); + } + } + return finishNode(node, "ClassDeclarationStatement"); + + // This is a Objective-J statement + case _import: + next(); + if (tokType === _string) + node.localfilepath = true; + else if (tokType ===_filename) + node.localfilepath = false; + else + unexpected(); + + node.filename = parseStringNumRegExpLiteral(); + return finishNode(node, "ImportStatement"); + + // If the statement does not start with a statement keyword or a + // brace, it's an ExpressionStatement or LabeledStatement. We + // simply start parsing an expression, and afterwards, if the + // next token is a colon and the expression was a simple + // Identifier node, we switch to interpreting it as a label. + + default: + var maybeName = tokVal, expr = parseExpression(); + if (starttype === _name && expr.type === "Identifier" && eat(_colon)) { + for (var i = 0; i < labels.length; ++i) + if (labels[i].name === maybeName) raise(expr.start, "Label '" + maybeName + "' is already declared"); + var kind = tokType.isLoop ? "loop" : tokType === _switch ? "switch" : null; + labels.push({name: maybeName, kind: kind}); + node.body = parseStatement(); + labels.pop(); + node.label = expr; + return finishNode(node, "LabeledStatement"); + } else { + node.expression = expr; + semicolon(); + return finishNode(node, "ExpressionStatement"); + } + } + } + + // CompoundIvarDeclaration = + // IvarType _ IvarDeclaration (_ "," _ IvarDeclaration)* EOS + + // IvarDeclaration = + // Identifier _ Accessors? + + // Accessors = + // "@accessors" ("(" (AccessorsConfiguration (_ "," _ AccessorsConfiguration)*)? ")")? + + function parseIvarDeclaration(node) { + var outlet; + if (eat(_outlet)) + outlet = true; + var type = parseObjectiveJType(); + if (strict && isStrictBadIdWord(type.name)) + raise(type.start, "Binding " + type.name + " in strict mode"); + for (;;) { + var decl = startNode(); + if (outlet) + decl.outlet = outlet; + decl.ivartype = type; + decl.id = parseIdent(); + if (strict && isStrictBadIdWord(decl.id.name)) + raise(decl.id.start, "Binding " + decl.id.name + " in strict mode"); + if (eat(_accessors)) { + decl.accessors = {}; + if (eat(_parenL)) { + if (!eat(_parenR)) { + for (;;) { + var config = parseIdent(true); + switch(config.name) { + case "property": + case "getter": + expect(_eq); + decl.accessors[config.name] = parseIdent(true); + break; + + case "setter": + expect(_eq); + var setter = parseIdent(true); + decl.accessors[config.name] = setter; + if (eat(_colon)) + setter.end = tokStart; + setter.name += ":" + break; + + case "readwrite": + case "readonly": + case "copy": + decl.accessors[config.name] = true; + break; + + default: + raise(config.start, "Unknown accessors attribute '" + config.name + "'"); + } + if (!eat(_comma)) break; + } + expect(_parenR); + } + } + } + finishNode(decl, "IvarDeclaration") + node.ivardeclarations.push(decl); + if (!eat(_comma)) break; + } + semicolon(); + } + + function parseClassElement() { + var methodType = tokVal, + element = startNode(); + if (eat(_plusmin)) { + element.methodtype = methodType; + // If we find a '(' we have a return type to parse + if (eat(_parenL)) { + if (eat(_action)) + element.action = true; + if (!eat(_parenR)) { + element.returntype = parseObjectiveJType(); + expect(_parenR); + } + } + // Now we parse the selector + var first = true, + selectors = [], + args = []; + element.selectors = selectors; + element.arguments = args; + for (;;) { + if (tokType !== _colon) { + selectors.push(parseIdent(true)); + if (first && tokType !== _colon) break; + } else + selectors.push(null); + expect(_colon); + var argument = {}; + args.push(argument); + if (eat(_parenL)) { + argument.type = parseObjectiveJType(); + expect(_parenR); + } + argument.identifier = parseIdent(false); + if (tokType === _braceL || eat(_semi)) break; + if (eat(_comma)) { + expect(_dotdotdot); + element.parameters = true; + break; + } + first = false; + } + + element.startOfBody = lastEnd; + // Start a new scope with regard to labels and the `inFunction` + // flag (restore them to their old value afterwards). + var oldInFunc = inFunction, oldLabels = labels; + inFunction = true; labels = []; + element.body = parseBlock(true); + inFunction = oldInFunc; labels = oldLabels; + return finishNode(element, "MethodDeclarationStatement"); + } else + return parseStatement(); + } + + // Used for constructs like `switch` and `if` that insist on + // parentheses around their expression. + + function parseParenExpression() { + expect(_parenL); + var val = parseExpression(); + expect(_parenR); + return val; + } + + // Parse a semicolon-enclosed block of statements, handling `"use + // strict"` declarations when `allowStrict` is true (used for + // function bodies). + + function parseBlock(allowStrict) { + var node = startNode(), first = true, strict = false, oldStrict; + node.body = []; + expect(_braceL); + while (!eat(_braceR)) { + var stmt = parseStatement(); + node.body.push(stmt); + if (first && isUseStrict(stmt)) { + oldStrict = strict; + setStrict(strict = true); + } + first = false + } + if (strict && !oldStrict) setStrict(false); + return finishNode(node, "BlockStatement"); + } + + // Parse a regular `for` loop. The disambiguation code in + // `parseStatement` will already have parsed the init statement or + // expression. + + function parseFor(node, init) { + node.init = init; + expect(_semi); + node.test = tokType === _semi ? null : parseExpression(); + expect(_semi); + node.update = tokType === _parenR ? null : parseExpression(); + expect(_parenR); + node.body = parseStatement(); + labels.pop(); + return finishNode(node, "ForStatement"); + } + + // Parse a `for`/`in` loop. + + function parseForIn(node, init) { + node.left = init; + node.right = parseExpression(); + expect(_parenR); + node.body = parseStatement(); + labels.pop(); + return finishNode(node, "ForInStatement"); + } + + // Parse a list of variable declarations. + + function parseVar(node, noIn) { + node.declarations = []; + node.kind = "var"; + for (;;) { + var decl = startNode(); + decl.id = parseIdent(); + if (strict && isStrictBadIdWord(decl.id.name)) + raise(decl.id.start, "Binding " + decl.id.name + " in strict mode"); + decl.init = eat(_eq) ? parseExpression(true, noIn) : null; + node.declarations.push(finishNode(decl, "VariableDeclarator")); + if (!eat(_comma)) break; + } + return finishNode(node, "VariableDeclaration"); + } + + // ### Expression parsing + + // These nest, from the most general expression type at the top to + // 'atomic', nondivisible expression types at the bottom. Most of + // the functions will simply let the function(s) below them parse, + // and, *if* the syntactic construct they handle is present, wrap + // the AST node that the inner parser gave them in another node. + + // Parse a full expression. The arguments are used to forbid comma + // sequences (in argument lists, array literals, or object literals) + // or the `in` operator (in for loops initalization expressions). + + function parseExpression(noComma, noIn) { + var expr = parseMaybeAssign(noIn); + if (!noComma && tokType === _comma) { + var node = startNodeFrom(expr); + node.expressions = [expr]; + while (eat(_comma)) node.expressions.push(parseMaybeAssign(noIn)); + return finishNode(node, "SequenceExpression"); + } + return expr; + } + + // Parse an assignment expression. This includes applications of + // operators like `+=`. + + function parseMaybeAssign(noIn) { + var left = parseMaybeConditional(noIn); + if (tokType.isAssign) { + var node = startNodeFrom(left); + node.operator = tokVal; + node.left = left; + next(); + node.right = parseMaybeAssign(noIn); + checkLVal(left); + return finishNode(node, "AssignmentExpression"); + } + return left; + } + + // Parse a ternary conditional (`?:`) operator. + + function parseMaybeConditional(noIn) { + var expr = parseExprOps(noIn); + if (eat(_question)) { + var node = startNodeFrom(expr); + node.test = expr; + node.consequent = parseExpression(true); + expect(_colon); + node.alternate = parseExpression(true, noIn); + return finishNode(node, "ConditionalExpression"); + } + return expr; + } + + // Start the precedence parser. + + function parseExprOps(noIn) { + return parseExprOp(parseMaybeUnary(noIn), -1, noIn); + } + + // Parse binary operators with the operator precedence parsing + // algorithm. `left` is the left-hand side of the operator. + // `minPrec` provides context that allows the function to stop and + // defer further parser to one of its callers when it encounters an + // operator that has a lower precedence than the set it is parsing. + + function parseExprOp(left, minPrec, noIn) { + var prec = tokType.binop; + if (prec != null && (!noIn || tokType !== _in)) { + if (prec > minPrec) { + var node = startNodeFrom(left); + node.left = left; + node.operator = tokVal; + next(); + node.right = parseExprOp(parseMaybeUnary(noIn), prec, noIn); + var node = finishNode(node, /&&|\|\|/.test(node.operator) ? "LogicalExpression" : "BinaryExpression"); + return parseExprOp(node, minPrec, noIn); + } + } + return left; + } + + // Parse unary operators, both prefix and postfix. + + function parseMaybeUnary(noIn) { + if (tokType.prefix) { + var node = startNode(), update = tokType.isUpdate; + node.operator = tokVal; + node.prefix = true; + next(); + node.argument = parseMaybeUnary(noIn); + if (update) checkLVal(node.argument); + else if (strict && node.operator === "delete" && + node.argument.type === "Identifier") + raise(node.start, "Deleting local variable in strict mode"); + return finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); + } + var expr = parseExprSubscripts(); + while (tokType.postfix && !canInsertSemicolon()) { + var node = startNodeFrom(expr); + node.operator = tokVal; + node.prefix = false; + node.argument = expr; + checkLVal(expr); + next(); + expr = finishNode(node, "UpdateExpression"); + } + return expr; + } + + // Parse call, dot, and `[]`-subscript expressions. + + function parseExprSubscripts() { + return parseSubscripts(parseExprAtom()); + } + + function parseSubscripts(base, noCalls) { + if (eat(_dot)) { + var node = startNodeFrom(base); + node.object = base; + node.property = parseIdent(true); + node.computed = false; + return parseSubscripts(finishNode(node, "MemberExpression"), noCalls); + } else { + if (options.objj) var messageSendNode = startNode(); + if (eat(_bracketL)) { + var expr = parseExpression(); + if (options.objj && tokType !== _bracketR) { + messageSendNode.object = expr; + nodeMessageSendObjectExpression = messageSendNode; + return base; + } + var node = startNodeFrom(base); + node.object = base; + node.property = expr; + node.computed = true; + expect(_bracketR); + return parseSubscripts(finishNode(node, "MemberExpression"), noCalls); + } else if (!noCalls && eat(_parenL)) { + var node = startNodeFrom(base); + node.callee = base; + node.arguments = parseExprList(_parenR, tokType === _parenR ? null : parseExpression(true), false); + return parseSubscripts(finishNode(node, "CallExpression"), noCalls); + } + } + return base; + } + + // Parse an atomic expression — either a single token that is an + // expression, an expression started by a keyword like `function` or + // `new`, or an expression wrapped in punctuation like `()`, `[]`, + // or `{}`. + + function parseExprAtom() { + switch (tokType) { + case _this: + var node = startNode(); + next(); + return finishNode(node, "ThisExpression"); + case _name: + return parseIdent(); + case _num: case _string: case _regexp: + return parseStringNumRegExpLiteral(); + + case _null: case _true: case _false: + var node = startNode(); + node.value = tokType.atomValue; + next(); + return finishNode(node, "Literal"); + + case _parenL: + var tokStartLoc1 = tokStartLoc, tokStart1 = tokStart; + next(); + var val = parseExpression(); + val.start = tokStart1; + val.end = tokEnd; + if (options.locations) { + val.loc.start = tokStartLoc1; + val.loc.end = tokEndLoc; + } + if (options.ranges) + val.range = [tokStart1, tokEnd]; + expect(_parenR); + return val; + + case _bracketL: + var node = startNode(), + firstExpr = null; + next(); + if (tokType !== _comma && tokType !== _bracketR) { + firstExpr = parseExpression(true); + if (tokType !== _comma && tokType !== _bracketR) + return parseMessageSendExpression(node, firstExpr); + } + node.elements = parseExprList(_bracketR, firstExpr, true, true); + return finishNode(node, "ArrayExpression"); + + case _braceL: + return parseObj(); + + case _function: + var node = startNode(); + next(); + return parseFunction(node, false); + + case _new: + return parseNew(); + + case _selector: + var node = startNode(); + next(); + expect(_parenL); + parseSelector(node, _parenR); + expect(_parenR); + return finishNode(node, "SelectorLiteralExpression"); + + default: + unexpected(); + } + } + + function parseMessageSendExpression(node, firstExpr) { + parseSelectorWithArguments(node, _bracketR); + if (firstExpr.type === "Identifier" && firstExpr.name === "super") + node.superObject = true; + else + node.object = firstExpr; + return finishNode(node, "MessageSendExpression"); + } + + function parseSelector(node, close) { + var first = true, + selectors = []; + for (;;) { + if (tokType !== _colon) { + selectors.push(parseIdent(true).name); + if (first && tokType === close) break; + } + expect(_colon); + selectors.push(":"); + if (tokType === close) break; + first = false; + } + node.selector = selectors.join(""); + } + + function parseSelectorWithArguments(node, close) { + var first = true, + selectors = [], + args = [], + parameters = []; + node.selectors = selectors; + node.arguments = args; + for (;;) { + if (tokType !== _colon) { + selectors.push(parseIdent(true)); + if (first && eat(close)) + break; + } else { + selectors.push(null); + } + expect(_colon); + args.push(parseExpression(true)); + if (eat(close)) + break; + if (tokType === _comma) { + node.parameters = []; + while(eat(_comma)) { + node.parameters.push(parseExpression(true)); + } + eat(close); + break; + } + first = false; + } + } + + // New's precedence is slightly tricky. It must allow its argument + // to be a `[]` or dot subscript expression, but not a call — at + // least, not without wrapping it in parentheses. Thus, it uses the + + function parseNew() { + var node = startNode(); + next(); + node.callee = parseSubscripts(parseExprAtom(false), true); + if (eat(_parenL)) + node.arguments = parseExprList(_parenR, tokType === _parenR ? null : parseExpression(true), false); + else node.arguments = []; + return finishNode(node, "NewExpression"); + } + + // Parse an object literal. + + function parseObj() { + var node = startNode(), first = true, sawGetSet = false; + node.properties = []; + next(); + while (!eat(_braceR)) { + if (!first) { + expect(_comma); + if (options.allowTrailingCommas && eat(_braceR)) break; + } else first = false; + + var prop = {key: parsePropertyName()}, isGetSet = false, kind; + if (eat(_colon)) { + prop.value = parseExpression(true); + kind = prop.kind = "init"; + } else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" && + (prop.key.name === "get" || prop.key.name === "set")) { + isGetSet = sawGetSet = true; + kind = prop.kind = prop.key.name; + prop.key = parsePropertyName(); + if (!tokType === _parenL) unexpected(); + prop.value = parseFunction(startNode(), false); + } else unexpected(); + + // getters and setters are not allowed to clash — either with + // each other or with an init property — and in strict mode, + // init properties are also not allowed to be repeated. + + if (prop.key.type === "Identifier" && (strict || sawGetSet)) { + for (var i = 0; i < node.properties.length; ++i) { + var other = node.properties[i]; + if (other.key.name === prop.key.name) { + var conflict = kind == other.kind || isGetSet && other.kind === "init" || + kind === "init" && (other.kind === "get" || other.kind === "set"); + if (conflict && !strict && kind === "init" && other.kind === "init") conflict = false; + if (conflict) raise(prop.key.start, "Redefinition of property"); + } + } + } + node.properties.push(prop); + } + return finishNode(node, "ObjectExpression"); + } + + function parsePropertyName() { + if (tokType === _num || tokType === _string) return parseExprAtom(); + return parseIdent(true); + } + + // Parse a function declaration or literal (depending on the + // `isStatement` parameter). + + function parseFunction(node, isStatement) { + if (tokType === _name) node.id = parseIdent(); + else if (isStatement) unexpected(); + else node.id = null; + node.params = []; + var first = true; + expect(_parenL); + while (!eat(_parenR)) { + if (!first) expect(_comma); else first = false; + node.params.push(parseIdent()); + } + + // Start a new scope with regard to labels and the `inFunction` + // flag (restore them to their old value afterwards). + var oldInFunc = inFunction, oldLabels = labels; + inFunction = true; labels = []; + node.body = parseBlock(true); + inFunction = oldInFunc; labels = oldLabels; + + // If this is a strict mode function, verify that argument names + // are not repeated, and it does not try to bind the words `eval` + // or `arguments`. + if (strict || node.body.body.length && isUseStrict(node.body.body[0])) { + for (var i = node.id ? -1 : 0; i < node.params.length; ++i) { + var id = i < 0 ? node.id : node.params[i]; + if (isStrictReservedWord(id.name) || isStrictBadIdWord(id.name)) + raise(id.start, "Defining '" + id.name + "' in strict mode"); + if (i >= 0) for (var j = 0; j < i; ++j) if (id.name === node.params[j].name) + raise(id.start, "Argument name clash in strict mode"); + } + } + + return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); + } + + // Parses a comma-separated list of expressions, and returns them as + // an array. `close` is the token type that ends the list, and + // `allowEmpty` can be turned on to allow subsequent commas with + // nothing in between them to be parsed as `null` (which is needed + // for array literals). + // This function is modified so the first expression is passed as a + // parameter. This is nessesary cause we need to check if it is a Objective-J + // message send expression ([expr mySelector:param1 withSecondParam:param2]) + + function parseExprList(close, firstExpr, allowTrailingComma, allowEmpty) { + if (firstExpr && eat(close)) + return [firstExpr]; + var elts = [], first = true; + while (!eat(close)) { + if (first) { + first = false; + if (allowEmpty && tokType === _comma && !firstExpr) elts.push(null); + else elts.push(firstExpr); + } else { + expect(_comma); + if (allowTrailingComma && options.allowTrailingCommas && eat(close)) break; + if (allowEmpty && tokType === _comma) elts.push(null); + else elts.push(parseExpression(true)); + } + } + return elts; + } + + // Parse the next token as an identifier. If `liberal` is true (used + // when parsing properties), it will also convert keywords into + // identifiers. + + function parseIdent(liberal) { + var node = startNode(); + node.name = tokType === _name ? tokVal : (liberal && !options.forbidReserved && tokType.keyword) || unexpected(); + next(); + return finishNode(node, "Identifier"); + } + + function parseStringNumRegExpLiteral() { + var node = startNode(); + node.value = tokVal; + node.raw = input.slice(tokStart, tokEnd); + next(); + return finishNode(node, "Literal"); + } + + // Parse the next token as an Objective-J typ. + // It can be an identifier followed by a optional protocol '' + // It can be 'void' + // It can be 'signed' or 'unsigned' followed by an optional 'char', 'byte', 'short', 'int' or 'long' + // It can be 'char', 'byte', 'short', 'int' or 'long' + // 'int' can be followed by an optinal 'long'. 'long' can be followed by an optional extra 'long' + + function parseObjectiveJType() { + var node = startNode(); + if (tokType === _name) { + node.name = tokVal; + next(); + if (tokVal === '<') { + next(); + node.protocol = parseIdent(true); + if (tokVal !== '>') unexpected(); + next(); + } + } else { + node.name = tokType.keyword; + if (!eat(_void)) { + var nextKeyWord; + if (eat(_signed) || eat(_unsigned)) + nextKeyWord = tokType.keyword || true; + if (eat(_char) || eat(_byte) || eat(_short)) { + if (nextKeyWord) + node.name += " " + nextKeyWord; + nextKeyWord = tokType.keyword || true; + } else { + if (eat(_int)) { + if (nextKeyWord) + node.name += " " + nextKeyWord; + nextKeyWord = tokType.keyword || true; + } + if (eat(_long)) { + if (nextKeyWord) + node.name += " " + nextKeyWord; + nextKeyWord = tokType.keyword || true; + if (eat(_long)) { + node.name += " " + nextKeyWord; + } + } + } + if (!nextKeyWord) { + node.name = (!options.forbidReserved && tokType.keyword) || unexpected(); + next(); + } + } + } + return finishNode(node, "ObjectiveJType"); + } + +})(typeof exports === "undefined" ? (self.acorn = {}) : exports.acorn); diff --git a/Objective-J/acornLICENSE b/Objective-J/acornLICENSE new file mode 100644 index 000000000..3916e96b2 --- /dev/null +++ b/Objective-J/acornLICENSE @@ -0,0 +1,23 @@ +Copyright (C) 2012 by Marijn Haverbeke + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +Please note that some subdirectories of the CodeMirror distribution +include their own LICENSE files, and are released under different +licences. diff --git a/Objective-J/acornwalk.js b/Objective-J/acornwalk.js new file mode 100644 index 000000000..09f359827 --- /dev/null +++ b/Objective-J/acornwalk.js @@ -0,0 +1,254 @@ +// AST walker module for Mozilla Parser API compatible trees + +if (!exports.acorn) { + exports.acorn = {}; + exports.acorn.walk = {}; +} + +(function(exports) { + "use strict"; + + // A simple walk is one where you simply specify callbacks to be + // called on specific nodes. The last two arguments are optional. A + // simple use would be + // + // walk.simple(myTree, { + // Expression: function(node) { ... } + // }); + // + // to do something with all expressions. All Parser API node types + // can be used to identify node types, as well as Expression, + // Statement, and ScopeBody, which denote categories of nodes. + // + // The base argument can be used to pass a custom (recursive) + // walker, and state can be used to give this walked an initial + // state. + exports.simple = function(node, visitors, base, state) { + if (!base) base = exports; + function c(node, st, override) { + var type = override || node.type, found = visitors[type]; + if (found) found(node, st); + base[type](node, st, c); + } + c(node, state); + }; + + // A recursive walk is one where your functions override the default + // walkers. They can modify and replace the state parameter that's + // threaded through the walk, and can opt how and whether to walk + // their child nodes (by calling their third argument on these + // nodes). + exports.recursive = function(node, state, funcs, base) { + var visitor = exports.make(funcs, base); + function c(node, st, override) { + visitor[override || node.type](node, st, c); + } + c(node, state); + }; + + // Used to create a custom walker. Will fill in all missing node + // type properties with the defaults. + exports.make = function(funcs, base) { + if (!base) base = exports; + var visitor = {}; + for (var type in base) visitor[type] = base[type]; + for (var type in funcs) visitor[type] = funcs[type]; + return visitor; + }; + + function skipThrough(node, st, c) { c(node, st); } + function ignore(node, st, c) {} + + // Node walkers. + + exports.Program = exports.BlockStatement = function(node, st, c) { + for (var i = 0; i < node.body.length; ++i) { + c(node.body[i], st, "Statement"); + } + }; + exports.Statement = skipThrough; + exports.EmptyStatement = ignore; + exports.ExpressionStatement = function(node, st, c) { + c(node.expression, st, "Expression"); + }; + exports.IfStatement = function(node, st, c) { + c(node.test, st, "Expression"); + c(node.consequent, st, "Statement"); + if (node.alternate) c(node.alternate, st, "Statement"); + }; + exports.LabeledStatement = function(node, st, c) { + c(node.body, st, "Statement"); + }; + exports.BreakStatement = exports.ContinueStatement = ignore; + exports.WithStatement = function(node, st, c) { + c(node.object, st, "Expression"); + c(node.body, st, "Statement"); + }; + exports.SwitchStatement = function(node, st, c) { + c(node.discriminant, st, "Expression"); + for (var i = 0; i < node.cases.length; ++i) { + var cs = node.cases[i]; + if (cs.test) c(cs.test, st, "Expression"); + for (var j = 0; j < cs.consequent.length; ++j) + c(cs.consequent[j], st, "Statement"); + } + }; + exports.ReturnStatement = function(node, st, c) { + if (node.argument) c(node.argument, st, "Expression"); + }; + exports.ThrowStatement = function(node, st, c) { + c(node.argument, st, "Expression"); + }; + exports.TryStatement = function(node, st, c) { + c(node.block, st, "Statement"); + for (var i = 0; i < node.handlers.length; ++i) + c(node.handlers[i].body, st, "ScopeBody"); + if (node.finalizer) c(node.finalizer, st, "Statement"); + }; + exports.WhileStatement = function(node, st, c) { + c(node.test, st, "Expression"); + c(node.body, st, "Statement"); + }; + exports.DoWhileStatement = function(node, st, c) { + c(node.body, st, "Statement"); + c(node.test, st, "Expression"); + }; + exports.ForStatement = function(node, st, c) { + if (node.init) c(node.init, st, "ForInit"); + if (node.test) c(node.test, st, "Expression"); + if (node.update) c(node.update, st, "Expression"); + c(node.body, st, "Statement"); + }; + exports.ForInStatement = function(node, st, c) { + c(node.left, st, "ForInit"); + c(node.right, st, "Expression"); + c(node.body, st, "Statement"); + }; + exports.ForInit = function(node, st, c) { + if (node.type == "VariableDeclaration") c(node, st); + else c(node, st, "Expression"); + }; + exports.DebuggerStatement = ignore; + + exports.FunctionDeclaration = function(node, st, c) { + c(node, st, "Function"); + }; + exports.VariableDeclaration = function(node, st, c) { + for (var i = 0; i < node.declarations.length; ++i) { + var decl = node.declarations[i]; + if (decl.init) c(decl.init, st, "Expression"); + } + }; + + exports.Function = function(node, st, c) { + c(node.body, st, "ScopeBody"); + }; + exports.ScopeBody = function(node, st, c) { + c(node, st, "Statement"); + }; + + exports.Expression = skipThrough; + exports.ThisExpression = ignore; + exports.ArrayExpression = function(node, st, c) { + for (var i = 0; i < node.elements.length; ++i) { + var elt = node.elements[i]; + if (elt) c(elt, st, "Expression"); + } + }; + exports.ObjectExpression = function(node, st, c) { + for (var i = 0; i < node.properties.length; ++i) + c(node.properties[i].value, st, "Expression"); + }; + exports.FunctionExpression = exports.FunctionDeclaration; + exports.SequenceExpression = function(node, st, c) { + for (var i = 0; i < node.expressions.length; ++i) + c(node.expressions[i], st, "Expression"); + }; + exports.UnaryExpression = exports.UpdateExpression = function(node, st, c) { + c(node.argument, st, "Expression"); + }; + exports.BinaryExpression = exports.AssignmentExpression = exports.LogicalExpression = function(node, st, c) { + c(node.left, st, "Expression"); + c(node.right, st, "Expression"); + }; + exports.ConditionalExpression = function(node, st, c) { + c(node.test, st, "Expression"); + c(node.consequent, st, "Expression"); + c(node.alternate, st, "Expression"); + }; + exports.NewExpression = exports.CallExpression = function(node, st, c) { + c(node.callee, st, "Expression"); + if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) + c(node.arguments[i], st, "Expression"); + }; + exports.MemberExpression = function(node, st, c) { + c(node.object, st, "Expression"); + if (node.computed) c(node.property, st, "Expression"); + }; + exports.Identifier = exports.Literal = ignore; + + exports.ClassDeclarationStatement = function(node, st, c) { + if (node.ivardeclarations) for (var i = 0; i < node.ivardeclarations.length; ++i) { + c(node.ivardeclarations[i], st, "IvarDeclaration"); + } + for (var i = 0; i < node.body.length; ++i) { + c(node.body[i], st, "Statement"); + } + } + + exports.ImportStatement = ignore; + + exports.IvarDeclaration = ignore; + + exports.MethodDeclarationStatement = ignore; + + exports.MethodDeclarationStatement = function(node, st, c) { + c(node.body, st, "Statement"); + } + + exports.MessageSendExpression = function(node, st, c) { + if (!node.superObject) c(node.object, st, "Expression"); + if (node.arguments) for (var i = 0; i < node.arguments.length; ++i) + c(node.arguments[i], st, "Expression"); + if (node.parameters) for (var i = 0; i < node.parameters.length; ++i) + c(node.parameters[i], st, "Expression"); + } + + exports.SelectorLiteralExpression = ignore; + + // A custom walker that keeps track of the scope chain and the + // variables defined in it. + function makeScope(prev) { + return {vars: Object.create(null), prev: prev}; + } + exports.scopeVisitor = exports.make({ + Function: function(node, scope, c) { + var inner = makeScope(scope); + for (var i = 0; i < node.params.length; ++i) + inner.vars[node.params[i].name] = {type: "argument", node: node.params[i]}; + if (node.id) { + var decl = node.type == "FunctionDeclaration"; + (decl ? scope : inner).vars[node.id.name] = + {type: decl ? "function" : "function name", node: node.id}; + } + c(node.body, inner, "ScopeBody"); + }, + TryStatement: function(node, scope, c) { + c(node.block, scope, "Statement"); + for (var i = 0; i < node.handlers.length; ++i) { + var handler = node.handlers[i], inner = makeScope(scope); + inner.vars[handler.param.name] = {type: "catch clause", node: handler.param}; + c(handler.body, inner, "ScopeBody"); + } + if (node.finalizer) c(node.finalizer, scope, "Statement"); + }, + VariableDeclaration: function(node, scope, c) { + for (var i = 0; i < node.declarations.length; ++i) { + var decl = node.declarations[i]; + scope.vars[decl.id.name] = {type: "var", node: decl.id}; + if (decl.init) c(decl.init, scope, "Expression"); + } + } + }); + +})(typeof exports == "undefined" ? acorn.walk = {} : exports.acorn.walk); From bf32b907020f26fff2c7281bcc1f5128a191e0f3 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 20:03:47 +0100 Subject: [PATCH 22/46] Allow signed, unsigned, char, short, int and long to be an identifier --- Objective-J/acorn.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index bffdb9c6b..0455cef66 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -264,8 +264,9 @@ if (!exports.acorn) { // Objective-J keywords - var _filename = {keyword: "filename"}, _unsigned = {keyword: "unsigned"}, _signed = {keyword: "signed"}; - var _byte = {keyword: "byte"}, _char = {keyword: "char"}, _short = {keyword: "short"}, _int = {keyword: "int"}, _long = {keyword: "long"}; + var _filename = {keyword: "filename"}, _unsigned = {keyword: "unsigned", okAsIdent: true}, _signed = {keyword: "signed", okAsIdent: true}; + var _byte = {keyword: "byte", okAsIdent: true}, _char = {keyword: "char", okAsIdent: true}, _short = {keyword: "short", okAsIdent: true}; + var _int = {keyword: "int", okAsIdent: true}, _long = {keyword: "long", okAsIdent: true}, _preprocess = {keyword: "#"}; // Map keyword names to token types. @@ -1995,7 +1996,7 @@ if (!exports.acorn) { function parseIdent(liberal) { var node = startNode(); - node.name = tokType === _name ? tokVal : (liberal && !options.forbidReserved && tokType.keyword) || unexpected(); + node.name = tokType === _name ? tokVal : (((liberal && !options.forbidReserved) || tokType.okAsIdent) && tokType.keyword) || unexpected(); next(); return finishNode(node, "Identifier"); } From cfe718f4ef02a3314e308cba57259f6ce9fab803 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 20:05:20 +0100 Subject: [PATCH 23/46] Handle preprocessor lines like "#pragma" --- Objective-J/ObjJAcornCompiler.js | 5 +++++ Objective-J/acorn.js | 17 +++++++++++++++-- Objective-J/acornwalk.js | 2 ++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 941005aa3..d8a67adb0 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -728,5 +728,10 @@ ObjectExpression: function(node, st, c) { } c(prop.value, st, "Expression"); } +}, +PreprocessStatement: function(node, st, c) { + CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.start)); + st.compiler.lastPos = node.start; + CONCAT(st.compiler.jsBuffer, "//"); } }); diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 0455cef66..dffd4c9bc 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -531,8 +531,6 @@ if (!exports.acorn) { ++tokPos; } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { ++tokPos; - } else if (ch === 35 && options.objj) { - skipLineComment(1); } else { break; } @@ -699,6 +697,16 @@ if (!exports.acorn) { return readToken_at(code); return false; + case 35: // '#' + if (options.objj) { + var start = tokPos; + var ch = input.charCodeAt(++tokPos); + while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) // End of line + ch = input.charCodeAt(++tokPos); + return finishToken(_preprocess, input.slice(start, tokPos)); + } + return false; + case 126: // '~' return finishOp(_prefix, 1); } @@ -1359,6 +1367,11 @@ if (!exports.acorn) { node.filename = parseStringNumRegExpLiteral(); return finishNode(node, "ImportStatement"); + // This is a Objective-J statement + case _preprocess: + next(); + return finishNode(node, "PreprocessStatement"); + // If the statement does not start with a statement keyword or a // brace, it's an ExpressionStatement or LabeledStatement. We // simply start parsing an expression, and afterwards, if the diff --git a/Objective-J/acornwalk.js b/Objective-J/acornwalk.js index 09f359827..e03e99e1f 100644 --- a/Objective-J/acornwalk.js +++ b/Objective-J/acornwalk.js @@ -202,6 +202,8 @@ if (!exports.acorn) { exports.MethodDeclarationStatement = ignore; + exports.PreprocessStatement = ignore; + exports.MethodDeclarationStatement = function(node, st, c) { c(node.body, st, "Statement"); } From cf46768ac7e2075228826fd55de60f8c05b68522 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 20:06:09 +0100 Subject: [PATCH 24/46] Removal of logs --- Objective-J/ObjJAcornCompiler.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index d8a67adb0..1eb696877 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -91,9 +91,10 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* this.cmBuffer = null; this.warnings = []; + //console.log("Start Parse: " + aURL); var start = new Date().getTime(); #ifdef BROWSER - console.time("Parse with Acorn - " + aURL); + //console.time("Parse with Acorn - " + aURL); #endif try { this.tokens = exports.acorn.parse(aString); @@ -114,7 +115,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* var time = (end - start) / 1000; //print("Parse with Acorn: " + aURL + " in " + time + " seconds"); #ifdef BROWSER - console.timeEnd("Parse with Acorn - " + aURL); + //console.timeEnd("Parse with Acorn - " + aURL); #endif this.dependencies = []; this.flags = flags | ObjJAcornCompiler.Flags.IncludeDebugSymbols; @@ -122,7 +123,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* this.lastPos = 0; //var start = new Date().getTime(); #ifdef BROWSER - console.time("Compile pass " + pass + " - " + aURL); + //console.time("Compile pass " + pass + " - " + aURL); #endif try { compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); @@ -139,7 +140,7 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* //var time = (end - start) / 1000; //print("Compile pass 1: " + aURL + " in " + time + " seconds"); #ifdef BROWSER - console.timeEnd("Compile pass " + pass + " - " + aURL); + //console.timeEnd("Compile pass " + pass + " - " + aURL); #endif // console.log("JS: " + this.jsBuffer); } @@ -169,17 +170,17 @@ ObjJAcornCompiler.prototype.compilePass2 = function() this.pass = 2; this.jsBuffer = new StringBuffer(); this.warnings = []; - //print("Start Compile2: " + this.URL); + //console.log("Start Compile2: " + this.URL); //var start = new Date().getTime(); #ifdef BROWSER - console.time("Compile pass 2" + this.pass + " - " + this.URL); + //console.time("Compile pass 2" + this.pass + " - " + this.URL); #endif compile(this.tokens, new Scope(null ,{ compiler: this }), pass2); //var end = new Date().getTime(); //var time = (end - start) / 1000; //print("Compile pass 2: " + this.URL + " in " + time + " seconds"); #ifdef BROWSER - console.timeEnd("Compile pass 2" + this.pass + " - " + this.URL); + //console.timeEnd("Compile pass 2" + this.pass + " - " + this.URL); #endif //print("Compiled: \n" + this.jsBuffer.toString()); From d49e78c43e791838cdd43ebb4b3e660e8e1baca9 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 20:13:08 +0100 Subject: [PATCH 25/46] Removal of old compiler --- Objective-J/FileExecutable.js | 16 +- Objective-J/Includes.js | 2 - Objective-J/ObjJAcornCompiler.js | 12 + Objective-J/ObjJCompiler.js | 4706 ------------------------------ Objective-J/Parser.js | 382 --- 5 files changed, 13 insertions(+), 5105 deletions(-) delete mode 100644 Objective-J/ObjJCompiler.js delete mode 100644 Objective-J/Parser.js diff --git a/Objective-J/FileExecutable.js b/Objective-J/FileExecutable.js index 52173dce6..002586f0f 100644 --- a/Objective-J/FileExecutable.js +++ b/Objective-J/FileExecutable.js @@ -40,22 +40,8 @@ function FileExecutable(/*CFURL|String*/ aURL, /*Dictionary*/ aFilenameTranslate if (fileContents.match(/^@STATIC;/)) executable = decompile(fileContents, aURL); - else if ((extension === "j" || !extension) && !fileContents.match(/^{/)) - { - var start = new Date().getTime(); - if (!exports.ObjJCompiler.usedVersion || exports.ObjJCompiler.usedVersion === "acorn") - executable = exports.ObjJAcornCompiler.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); - else if (exports.ObjJCompiler.usedVersion === "objj_compiler2") - executable = exports.ObjJCompiler.compileFileDependencies(fileContents, aURL, ObjJCompiler.Flags.IncludeDebugSymbols); - else if (exports.ObjJCompiler.usedVersion === "preprocessor") - executable = exports.preprocess(fileContents, aURL, Preprocessor.Flags.IncludeDebugSymbols); - else - throw new Error("Compiler to use is set to " + exports.ObjJCompiler.usedVersion + " but we only support 'preprocessor' (old compiler), 'objj_compiler2' and 'acorn'"); - - var time = (new Date().getTime() - start) / 1000; - //print("Compile '" + (exports.ObjJCompiler.usedVersion || "preprocessor") + "' " + aURL + " in " + time + " seconds"); - } + executable = exports.ObjJAcornCompiler.compileFileDependencies(fileContents, aURL, ObjJAcornCompiler.Flags.IncludeDebugSymbols); else executable = new Executable(fileContents, [], aURL); diff --git a/Objective-J/Includes.js b/Objective-J/Includes.js index f9026cad1..4bfcacad4 100644 --- a/Objective-J/Includes.js +++ b/Objective-J/Includes.js @@ -43,8 +43,6 @@ #include "CFBundle.js" #include "StaticResource.js" #include "Preprocessor.js" -#include "Parser.js" -#include "ObjJCompiler.js" #include "acorn.js" #include "acornwalk.js" #include "ObjJAcornCompiler.js" diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 1eb696877..da456cada 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -197,6 +197,18 @@ ObjJAcornCompiler.prototype.compilePass2 = function() return this.jsBuffer.toString(); } +var currentCompilerFlags = ""; + +exports.setCurrentCompilerFlags = function(/*String*/ compilerFlags) +{ + currentCompilerFlags = compilerFlags; +} + +exports.currentCompilerFlags = function(/*String*/ compilerFlags) +{ + return currentCompilerFlags; +} + ObjJAcornCompiler.Flags = { }; ObjJAcornCompiler.Flags.IncludeDebugSymbols = 1 << 0; diff --git a/Objective-J/ObjJCompiler.js b/Objective-J/ObjJCompiler.js deleted file mode 100644 index 5b8a73652..000000000 --- a/Objective-J/ObjJCompiler.js +++ /dev/null @@ -1,4706 +0,0 @@ -/* - * ObjJCompiler.js - * Objective-J - * - * Created by Martin Carlberg. - * Copyright 2012, Martin Carlberg. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -var currentCompilerFlags = ""; - -var ObjJCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) -{ - aString = aString.replace(/^\#.*/gm, ""); - this._URL = new CFURL(aURL); - this._pass = pass; - // If this is pass one we should not save anything in javascript buffer - if (pass === 1) - this._jsBuffer = null; - else - this._jsBuffer = new StringBuffer(); - this._imBuffer = null; - this._cmBuffer = null; - - //var start = new Date().getTime(); -#ifdef BROWSER - console.time("Parse - " + aURL); -#endif - this._tokens = exports.Parser.parse(aString); - //var end = new Date().getTime(); - //var time = (end - start) / 1000; - //print("Parse: " + aURL + " in " + time + " seconds"); -#ifdef BROWSER - console.timeEnd("Parse - " + aURL); -#endif - this._dependencies = []; - this._flags = flags | ObjJCompiler.Flags.IncludeDebugSymbols; - this._classDefs = {}; - //var start = new Date().getTime(); -#ifdef BROWSER - console.time("Compile pass " + pass + " - " + aURL); -#endif - try { - this.nodeDocument(this._tokens); - } - catch (e) { - #ifdef BROWSER - //console.log("Error: " + e + ", file content: " + aString); - #else - //print("Error: " + e + ", file content: " + aString); - #endif - throw e; - } - //var end = new Date().getTime(); - //var time = (end - start) / 1000; - //print("Compile pass 1: " + aURL + " in " + time + " seconds"); -#ifdef BROWSER - console.timeEnd("Compile pass " + pass + " - " + aURL); -#endif -// console.log("JS: " + this._jsBuffer); -} - -exports.ObjJCompiler = ObjJCompiler; - -exports.ObjJCompiler.compileToExecutable = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - ObjJCompiler.currentCompileFile = aURL; - return new ObjJCompiler(aString, aURL, flags, 2).executable(); -} - -exports.ObjJCompiler.compileToIMBuffer = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - return new ObjJCompiler(aString, aURL, flags, 2).IMBuffer(); -} - -exports.ObjJCompiler.compileFileDependencies = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags) -{ - ObjJCompiler.currentCompileFile = aURL; - return new ObjJCompiler(aString, aURL, flags, 1).executable(); -} - -ObjJCompiler.prototype.compilePass2 = function() -{ - ObjJCompiler.currentCompileFile = this._URL; - this._pass = 2; - this._jsBuffer = new StringBuffer(); - //print("Start Compile2: " + this._URL); - //var start = new Date().getTime(); -#ifdef BROWSER - console.time("Compile pass 2" + this._pass + " - " + this._URL); -#endif - this.nodeDocument(this._tokens); - //var end = new Date().getTime(); - //var time = (end - start) / 1000; - //print("Compile pass 2: " + this._URL + " in " + time + " seconds"); -#ifdef BROWSER - console.timeEnd("Compile pass 2" + this._pass + " - " + this._URL); -#endif - return this._jsBuffer.toString(); -} - -// This will set the compiler version to use. -// These version works: -// "preprocessor" -> Old Cappuccino compiler -// "objj_compiler2" -> New Cappuccino compiler -// "acorn" -> New Cappuccino compiler with acorn parser - -GLOBAL(ObjJCompilerSetUsedVersion) = function(version) -{ - ObjJCompiler.usedVersion = version; -} - -ObjJCompiler.setCurrentUsedVersion = function(version) -{ - ObjJCompiler.usedVersion = version; -} - -exports.setCurrentCompilerFlags = function(/*String*/ compilerFlags) -{ - currentCompilerFlags = compilerFlags; -} - -exports.currentCompilerFlags = function(/*String*/ compilerFlags) -{ - return currentCompilerFlags; -} - -ObjJCompiler.Flags = { }; - -ObjJCompiler.Flags.IncludeDebugSymbols = 1 << 0; -ObjJCompiler.Flags.IncludeTypeSignatures = 1 << 1; - -ObjJCompiler.AstNodeDocument = "#document"; -ObjJCompiler.AstNodeStart = "start"; -ObjJCompiler.AstNodeFunctionBody = "FunctionBody"; -ObjJCompiler.AstNodeSourceElements = "SourceElements"; -ObjJCompiler.AstNodeSourceElement = "SourceElement"; -ObjJCompiler.AstNodeFunctionDeclaration = "FunctionDeclaration"; -ObjJCompiler.AstNodeFunctionExpression = "FunctionExpression"; -ObjJCompiler.AstNodeFormalParameterList = "FormalParameterList"; -ObjJCompiler.AstNodeStatementList = "StatementList"; -ObjJCompiler.AstNodeStatement = "Statement"; -ObjJCompiler.AstNodeBlock = "Block"; -ObjJCompiler.AstNodeVariableStatement = "VariableStatement"; -ObjJCompiler.AstNodeEmptyStatement = "EmptyStatement"; -ObjJCompiler.AstNodeExpressionStatement = "ExpressionStatement"; -ObjJCompiler.AstNodeIfStatement = "IfStatement"; -ObjJCompiler.AstNodeIterationStatement = "IterationStatement"; -ObjJCompiler.AstNodeContinueStatement = "ContinueStatement"; -ObjJCompiler.AstNodeBreakStatement = "BreakStatement"; -ObjJCompiler.AstNodeReturnStatement = "ReturnStatement"; -ObjJCompiler.AstNodeWithStatement = "WithStatement"; -ObjJCompiler.AstNodeLabelledStatement = "LabelledStatement"; -ObjJCompiler.AstNodeSwitchStatement = "SwitchStatement"; -ObjJCompiler.AstNodeThrowStatement = "ThrowStatement"; -ObjJCompiler.AstNodeTryStatement = "TryStatement"; -ObjJCompiler.AstNodeDebuggerStatement = "DebuggerStatement"; -ObjJCompiler.AstNodeImportStatement = "ImportStatement"; -ObjJCompiler.AstNodeVariableDeclaration = "VariableDeclaration"; -ObjJCompiler.AstNodeVariableDeclarationNoIn = "VariableDeclarationNoIn"; -ObjJCompiler.AstNodeVariableDeclarationListNoIn = "VariableDeclarationListNoIn"; -ObjJCompiler.AstNodeDoWhileStatement = "DoWhileStatement"; -ObjJCompiler.AstNodeWhileStatement = "WhileStatement"; -ObjJCompiler.AstNodeForStatement = "ForStatement"; -ObjJCompiler.AstNodeForFirstExpression = "ForFirstExpression"; -ObjJCompiler.AstNodeForInStatement = "ForInStatement"; -ObjJCompiler.AstNodeForInFirstExpression = "ForInFirstExpression"; -ObjJCompiler.AstNodeEachStatement = "EachStatement"; -ObjJCompiler.AstNodeCaseBlock = "CaseBlock"; -ObjJCompiler.AstNodeCaseClauses = "CaseClauses"; -ObjJCompiler.AstNodeCaseClause = "CaseClause"; -ObjJCompiler.AstNodeDefaultClause = "DefaultClause"; -ObjJCompiler.AstNodeCatch = "Catch"; -ObjJCompiler.AstNodeFinally = "Finally"; -ObjJCompiler.AstNodeLocalFilePath = "LocalFilePath"; -ObjJCompiler.AstNodeStandardFilePath = "StandardFilePath"; -ObjJCompiler.AstNodeClassDeclarationStatement = "ClassDeclarationStatement"; -ObjJCompiler.AstNodeSuperclassDeclaration = "SuperclassDeclaration"; -ObjJCompiler.AstNodeCategoryDeclaration = "CategoryDeclaration"; -ObjJCompiler.AstNodeCompoundIvarDeclaration = "CompoundIvarDeclaration"; -ObjJCompiler.AstNodeIvarType = "IvarType"; -ObjJCompiler.AstNodeIvarTypeElement = "IvarTypeElement"; -ObjJCompiler.AstNodeIvarDeclaration = "IvarDeclaration"; -ObjJCompiler.AstNodeAccessors = "Accessors"; -ObjJCompiler.AstNodeAccessorsConfiguration = "AccessorsConfiguration"; -ObjJCompiler.AstNodeIvarPropertyName = "IvarPropertyName"; -ObjJCompiler.AstNodeIvarGetterName = "IvarGetterName"; -ObjJCompiler.AstNodeIvarSetterName = "IvarSetterName"; -ObjJCompiler.AstNodeClassBody = "ClassBody"; -ObjJCompiler.AstNodeClassElements = "ClassElements"; -ObjJCompiler.AstNodeClassElement = "ClassElement"; -ObjJCompiler.AstNodeClassMethodDeclaration = "ClassMethodDeclaration"; -ObjJCompiler.AstNodeInstanceMethodDeclaration = "InstanceMethodDeclaration"; -ObjJCompiler.AstNodeMethodSelector = "MethodSelector"; -ObjJCompiler.AstNodeUnarySelector = "UnarySelector"; -ObjJCompiler.AstNodeKeywordSelector = "KeywordSelector"; -ObjJCompiler.AstNodeKeywordDeclarator = "KeywordDeclarator"; -ObjJCompiler.AstNodeSelector = "Selector"; -ObjJCompiler.AstNodeMethodType = "MethodType"; -ObjJCompiler.AstNodeACTION = "ACTION"; -ObjJCompiler.AstNodeExpression = "Expression"; -ObjJCompiler.AstNodeExpressionNoIn = "ExpressionNoIn"; -ObjJCompiler.AstNodeAssignmentExpression = "AssignmentExpression"; -ObjJCompiler.AstNodeAssignmentExpressionNoIn = "AssignmentExpressionNoIn"; -ObjJCompiler.AstNodeAssignmentOperator = "AssignmentOperator"; -ObjJCompiler.AstNodeConditionalExpression = "ConditionalExpression"; -ObjJCompiler.AstNodeConditionalExpressionNoIn = "ConditionalExpressionNoIn"; -ObjJCompiler.AstNodeLogicalOrExpression = "LogicalOrExpression"; -ObjJCompiler.AstNodeLogicalOrExpressionNoIn = "LogicalOrExpressionNoIn"; -ObjJCompiler.AstNodeLogicalAndExpression = "LogicalAndExpression"; -ObjJCompiler.AstNodeLogicalAndExpressionNoIn = "LogicalAndExpressionNoIn"; -ObjJCompiler.AstNodeBitwiseOrExpression = "BitwiseOrExpression"; -ObjJCompiler.AstNodeBitwiseOrExpressionNoIn = "BitwiseOrExpressionNoIn"; -ObjJCompiler.AstNodeBitwiseXOrExpression = "BitwiseXOrExpression"; -ObjJCompiler.AstNodeBitwiseXOrExpressionNoIn = "BitwiseXOrExpressionNoIn"; -ObjJCompiler.AstNodeBitwiseAndExpression = "BitwiseAndExpression"; -ObjJCompiler.AstNodeBitwiseAndExpressionNoIn = "BitwiseAndExpressionNoIn"; -ObjJCompiler.AstNodeEqualityExpression = "EqualityExpression"; -ObjJCompiler.AstNodeEqualityExpressionNoIn = "EqualityExpressionNoIn"; -ObjJCompiler.AstNodeEqualityOperator = "EqualityOperator"; -ObjJCompiler.AstNodeRelationalExpression = "RelationalExpression"; -ObjJCompiler.AstNodeRelationalOperator = "RelationalOperator"; -ObjJCompiler.AstNodeRelationalExpressionNoIn = "RelationalExpressionNoIn"; -ObjJCompiler.AstNodeRelationalOperatorNoIn = "RelationalOperatorNoIn"; -ObjJCompiler.AstNodeShiftExpression = "ShiftExpression"; -ObjJCompiler.AstNodeShiftOperator = "ShiftOperator"; -ObjJCompiler.AstNodeAdditiveExpression = "AdditiveExpression"; -ObjJCompiler.AstNodeAdditiveOperator = "AdditiveOperator"; -ObjJCompiler.AstNodeMultiplicativeExpression = "MultiplicativeExpression"; -ObjJCompiler.AstNodeMultiplicativeOperator = "MultiplicativeOperator"; -ObjJCompiler.AstNodeUnaryExpression = "UnaryExpression"; -ObjJCompiler.AstNodePostfixExpression = "PostfixExpression"; -ObjJCompiler.AstNodeLeftHandSideExpression = "LeftHandSideExpression"; -ObjJCompiler.AstNodeNewExpression = "NewExpression"; -ObjJCompiler.AstNodeCallExpression = "CallExpression"; -ObjJCompiler.AstNodeMemberExpression = "MemberExpression"; -ObjJCompiler.AstNodeBracketedAccessor = "BracketedAccessor"; -ObjJCompiler.AstNodeDotAccessor = "DotAccessor"; -ObjJCompiler.AstNodeArguments = "Arguments"; -ObjJCompiler.AstNodeArgumentList = "ArgumentList"; -ObjJCompiler.AstNodePrimaryExpression = "PrimaryExpression"; -ObjJCompiler.AstNodeMessageExpression = "MessageExpression"; -ObjJCompiler.AstNodeSUPER = "SUPER"; -ObjJCompiler.AstNodeSelectorCall = "SelectorCall"; -ObjJCompiler.AstNodeKeywordSelectorCall = "KeywordSelectorCall"; -ObjJCompiler.AstNodeKeywordCall = "KeywordCall"; -ObjJCompiler.AstNodeArrayLiteral = "ArrayLiteral"; -ObjJCompiler.AstNodeElementList = "ElementList"; -ObjJCompiler.AstNodeObjectLiteral = "ObjectLiteral"; -ObjJCompiler.AstNodePropertyNameAndValueList = "PropertyNameAndValueList"; -ObjJCompiler.AstNodePropertyAssignment = "PropertyAssignment"; -ObjJCompiler.AstNodePropertyGetter = "PropertyGetter"; -ObjJCompiler.AstNodePropertySetter = "PropertySetter"; -ObjJCompiler.AstNodePropertyName = "PropertyName"; -ObjJCompiler.AstNodePropertySetParameterList = "PropertySetParameterList"; -ObjJCompiler.AstNodeLiteral = "Literal"; -ObjJCompiler.AstNodeNullLiteral = "NullLiteral"; -ObjJCompiler.AstNodeBooleanLiteral = "BooleanLiteral"; -ObjJCompiler.AstNodeNumericLiteral = "NumericLiteral"; -ObjJCompiler.AstNodeDecimalLiteral = "DecimalLiteral"; -ObjJCompiler.AstNodeDecimalIntegerLiteral = "DecimalIntegerLiteral"; -ObjJCompiler.AstNodeDecimalDigit = "DecimalDigit"; -ObjJCompiler.AstNodeExponentPart = "ExponentPart"; -ObjJCompiler.AstNodeSignedInteger = "SignedInteger"; -ObjJCompiler.AstNodeHexIntegerLiteral = "HexIntegerLiteral"; -ObjJCompiler.AstNodeHexDigit = "HexDigit"; -ObjJCompiler.AstNodeStringLiteral = "StringLiteral"; -ObjJCompiler.AstNodeDoubleStringCharacter = "DoubleStringCharacter"; -ObjJCompiler.AstNodeSingleStringCharacter = "SingleStringCharacter"; -ObjJCompiler.AstNodeLineContinuation = "LineContinuation"; -ObjJCompiler.AstNodeEscapeSequence = "EscapeSequence"; -ObjJCompiler.AstNodeCharacterEscapeSequence = "CharacterEscapeSequence"; -ObjJCompiler.AstNodeSingleEscapeCharacter = "SingleEscapeCharacter"; -ObjJCompiler.AstNodeNonEscapeCharacter = "NonEscapeCharacter"; -ObjJCompiler.AstNodeEscapeCharacter = "EscapeCharacter"; -ObjJCompiler.AstNodeHexEscapeSequence = "HexEscapeSequence"; -ObjJCompiler.AstNodeUnicodeEscapeSequence = "UnicodeEscapeSequence"; -ObjJCompiler.AstNodeRegularExpressionLiteral = "RegularExpressionLiteral"; -ObjJCompiler.AstNodeRegularExpressionBody = "RegularExpressionBody"; -ObjJCompiler.AstNodeRegularExpressionFirstChar = "RegularExpressionFirstChar"; -ObjJCompiler.AstNodeRegularExpressionChar = "RegularExpressionChar"; -ObjJCompiler.AstNodeRegularExpressionBackslashSequence = "RegularExpressionBackslashSequence"; -ObjJCompiler.AstNodeRegularExpressionNonTerminator = "RegularExpressionNonTerminator"; -ObjJCompiler.AstNodeRegularExpressionClass = "RegularExpressionClass"; -ObjJCompiler.AstNodeRegularExpressionClassChar = "RegularExpressionClassChar"; -ObjJCompiler.AstNodeRegularExpressionFlags = "RegularExpressionFlags"; -ObjJCompiler.AstNodeSelectorLiteral = "SelectorLiteral"; -ObjJCompiler.AstNodeSelectorLiteralContents = "SelectorLiteralContents"; -ObjJCompiler.AstNodeUnderline = "_"; -ObjJCompiler.AstNodeUnderlineNoLineBreak = "__"; -ObjJCompiler.AstNodeWhiteSpace = "WhiteSpace"; -ObjJCompiler.AstNodeLineTerminator = "LineTerminator"; -ObjJCompiler.AstNodeLineTerminatorSequence = "LineTerminatorSequence"; -ObjJCompiler.AstNodeComment = "Comment"; -ObjJCompiler.AstNodeMultiLineComment = "MultiLineComment"; -ObjJCompiler.AstNodeSingleLineMultiLineComment = "SingleLineMultiLineComment"; -ObjJCompiler.AstNodeSingleLineComment = "SingleLineComment"; -ObjJCompiler.AstNodeSingleLineCommentChar = "SingleLineCommentChar"; -ObjJCompiler.AstNodeEOS = "EOS"; -ObjJCompiler.AstNodeSemicolonInsertionEOS = "SemicolonInsertionEOS"; -ObjJCompiler.AstNodeEOF = "EOF"; -ObjJCompiler.AstNodeReservedWord = "ReservedWord"; -ObjJCompiler.AstNodeKeyword = "Keyword"; -ObjJCompiler.AstNodeFutureReservedWord = "FutureReservedWord"; -ObjJCompiler.AstNodeIdentifier = "Identifier"; -ObjJCompiler.AstNodeBadIdentifier = "BadIdentifier"; -ObjJCompiler.AstNodeReservedWordIdentifier = "ReservedWordIdentifier"; -ObjJCompiler.AstNodeDigitIdentifier = "DigitIdentifier"; -ObjJCompiler.AstNodeIdentifierName = "IdentifierName"; -ObjJCompiler.AstNodeIdentifierStart = "IdentifierStart"; -ObjJCompiler.AstNodeIdentifierPart = "IdentifierPart"; -ObjJCompiler.AstNodeUnicodeLetter = "UnicodeLetter"; -ObjJCompiler.AstNodeUnicodeCombiningMark = "UnicodeCombiningMark"; -ObjJCompiler.AstNodeUnicodeDigit = "UnicodeDigit"; -ObjJCompiler.AstNodeUnicodeConnectorPunctuation = "UnicodeConnectorPunctuation"; -ObjJCompiler.AstNodeZWNJ = "ZWNJ"; -ObjJCompiler.AstNodeZWJ = "ZWJ"; -ObjJCompiler.AstNodeFALSE = "FALSE"; -ObjJCompiler.AstNodeTRUE = "TRUE"; -ObjJCompiler.AstNodeNULL = "NULL"; -ObjJCompiler.AstNodeBREAK = "BREAK"; -ObjJCompiler.AstNodeCONTINUE = "CONTINUE"; -ObjJCompiler.AstNodeDEBUGGER = "DEBUGGER"; -ObjJCompiler.AstNodeIN = "IN"; -ObjJCompiler.AstNodeINSTANCEOF = "INSTANCEOF"; -ObjJCompiler.AstNodeDELETE = "DELETE"; -ObjJCompiler.AstNodeFUNCTION = "FUNCTION"; -ObjJCompiler.AstNodeNEW = "NEW"; -ObjJCompiler.AstNodeTHIS = "THIS"; -ObjJCompiler.AstNodeTYPEOF = "TYPEOF"; -ObjJCompiler.AstNodeVOID = "VOID"; -ObjJCompiler.AstNodeIF = "IF"; -ObjJCompiler.AstNodeELSE = "ELSE"; -ObjJCompiler.AstNodeDO = "DO"; -ObjJCompiler.AstNodeWHILE = "WHILE"; -ObjJCompiler.AstNodeFOR = "FOR"; -ObjJCompiler.AstNodeVAR = "VAR"; -ObjJCompiler.AstNodeRETURN = "RETURN"; -ObjJCompiler.AstNodeCASE = "CASE"; -ObjJCompiler.AstNodeDEFAULT = "DEFAULT"; -ObjJCompiler.AstNodeSWITCH = "SWITCH"; -ObjJCompiler.AstNodeTHROW = "THROW"; -ObjJCompiler.AstNodeCATCH = "CATCH"; -ObjJCompiler.AstNodeFINALLY = "FINALLY"; -ObjJCompiler.AstNodeTRY = "TRY"; -ObjJCompiler.AstNodeWITH = "WITH"; - -#if DEBUG -ObjJCompiler.prototype.assertNode = function(/*SyntaxNode*/ astNode, /*String*/ astNodeName) -{ - if (!astNode || astNode.name !== astNodeName) - { -// debugger; - throw new SyntaxError(this.error_message("Expected node " + astNodeName + " but got " + (astNode ? astNode.name : astNode), astNode)); - } -} -#endif - -ObjJCompiler.prototype.nodeDocument = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDocument); -#endif - this.nodeStart(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeStart = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeStart); -#endif - var children = astNode.children, - lastUnderlineIndex = 1; - - this.nodeUnderline(children[0], false); - - if (children.length === 3) - { - this.nodeSourceElements(children[1]); - lastUnderlineIndex++; - } - this.nodeUnderline(children[lastUnderlineIndex], false) -} - -ObjJCompiler.prototype.nodeFunctionBody = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFunctionBody); -#endif - var children = astNode.children, - lastUnderlineIndex = 1; - - this.nodeUnderline(children[0], false); - - if (children.length === 3) - { - this.nodeSourceElements(children[1]); - lastUnderlineIndex++; - } - this.nodeUnderline(children[lastUnderlineIndex], false) -} - -ObjJCompiler.prototype.nodeSourceElements = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSourceElements); -#endif - var children = astNode.children; - - this.nodeSourceElement(children[0]); - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - this.nodeSourceElement(children[i + 1]); - } -} - -ObjJCompiler.prototype.nodeSourceElement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSourceElement); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeStatement) - this.nodeStatement(child); - else if (child && child.name === ObjJCompiler.AstNodeFunctionDeclaration) - if (this._pass === 2) // Skip this if it is the first pass - this.nodeFunctionDeclaration(child); - else - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeStatement + " or " + ObjJCompiler.AstNodeFunctionDeclaration + " but got " + child, child)); -} - -ObjJCompiler.prototype.nodeFunctionDeclaration = function(/*SyntaxNode*/ astNode) -{ - // Safari can't handle function declarations of the form function [name]([arguments]) { } - // in evals. It requires them to be in the form [name] = function([arguments]) { }. So we - // need format them like that. -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFunctionDeclaration); -#endif - var children = astNode.children, - child = children[6], - offset = 0, - saveJSBuffer = this._jsBuffer, - parameterList; - - this._jsBuffer = null; - this.nodeFUNCTION(children[0]); - this.nodeUnderline(children[1], true); - var identifier = this.nodeIdentifier(children[2]); - this.nodeUnderline(children[3], false); - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, identifier); - CONCAT(saveJSBuffer, " = function"); - } - this._jsBuffer = saveJSBuffer; - this.nodeOpenParenthesis(children[4]); - this.nodeUnderline(children[5], false); - - if (child && child.name === ObjJCompiler.AstNodeFormalParameterList) - { - parameterList = this.nodeFormalParameterList(children[6]); - offset++; - } - this.nodeUnderline(children[6 + offset], false); - this.nodeCloseParenthesis(children[7 + offset]); - this.nodeUnderline(children[8 + offset], false); - this.nodeOpenBrace(children[9 + offset]); - this.nodeUnderline(children[10 + offset], false); - var currentClassMethods = this._currentMethod; - - if (currentClassMethods) - { - // If we have a parameter list push those otherwise an empty dictionary - currentClassMethods.lvarStack.push(parameterList ? parameterList : {}); - } - this.nodeFunctionBody(children[11 + offset]); - if (currentClassMethods) - currentClassMethods.lvarStack.pop(); - this.nodeUnderline(children[12 + offset], false); - this.nodeCloseBrace(children[13 + offset]); -} - -ObjJCompiler.prototype.nodeFunctionExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFunctionExpression); -#endif - var children = astNode.children, - child = children[2], - offset = 0, - saveJSBuffer = this._jsBuffer, - parameterList; - - this._jsBuffer = null; - this.nodeFUNCTION(children[0]); - this.nodeUnderline(children[1], true); - var identifier = null; - if (child && child.name === ObjJCompiler.AstNodeIdentifier) - { - identifier = this.nodeIdentifier(child); - offset++; - } - this.nodeUnderline(children[2 + offset], false); - if (saveJSBuffer) - if (identifier) - { - CONCAT(saveJSBuffer, identifier); - CONCAT(saveJSBuffer, " = function"); - } - else - { - CONCAT(saveJSBuffer, "function"); - } - this._jsBuffer = saveJSBuffer; - this.nodeOpenParenthesis(children[3 + offset]); - this.nodeUnderline(children[4 + offset], false); - - child = children[5 + offset]; - - if (child && child.name ===ObjJCompiler.AstNodeFormalParameterList) - { - parameterList = this.nodeFormalParameterList(child); - offset++; - } - this.nodeUnderline(children[5 + offset], false); - this.nodeCloseParenthesis(children[6 + offset]); - this.nodeUnderline(children[7 + offset], false); - this.nodeOpenBrace(children[8 + offset]); - this.nodeUnderline(children[9 + offset], false); - var currentClassMethods = this._currentMethod; - - if (currentClassMethods) - { - currentClassMethods.lvarStack.push(parameterList ? parameterList : {}); - } - this.nodeFunctionBody(children[10 + offset]); - if (currentClassMethods) - currentClassMethods.lvarStack.pop(); - this.nodeUnderline(children[11 + offset], false); - this.nodeCloseBrace(children[12 + offset]); -} - -ObjJCompiler.prototype.nodeFormalParameterList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFormalParameterList); -#endif - var children = astNode.children, - parameterList = {}; - - var identifier = this.nodeIdentifier(children[0]); - - parameterList[identifier] = {"identifier": identifier}; - - for (var i = 1; i + 3 < children.length; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - identifier = this.nodeIdentifier(children[i + 3]); - parameterList[identifier] = {"identifier": identifier}; - } - - return parameterList; -} - -ObjJCompiler.prototype.nodeStatementList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeStatementList); -#endif - var children = astNode.children; - - this.nodeStatement(children[0]); - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - this.nodeStatement(children[i + 1]); - } -} - -ObjJCompiler.prototype.nodeStatement = function(/*SyntaxNode*/ astNode) -{ - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeBlock: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeBlock(child); - break; - case ObjJCompiler.AstNodeVariableStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeVariableStatement(child); - break; - case ObjJCompiler.AstNodeEmptyStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeEmptyStatement(child); - break; - case ObjJCompiler.AstNodeExpressionStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeExpressionStatement(child); - break; - case ObjJCompiler.AstNodeIfStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeIfStatement(child); - break; - case ObjJCompiler.AstNodeIterationStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeIterationStatement(child); - break; - case ObjJCompiler.AstNodeContinueStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeContinueStatement(child); - break; - case ObjJCompiler.AstNodeBreakStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeBreakStatement(child); - break; - case ObjJCompiler.AstNodeReturnStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeReturnStatement(child); - break; - case ObjJCompiler.AstNodeWithStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeWithStatement(child); - break; - case ObjJCompiler.AstNodeLabelledStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeLabelledStatement(child); - break; - case ObjJCompiler.AstNodeSwitchStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeSwitchStatement(child); - break; - case ObjJCompiler.AstNodeThrowStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeThrowStatement(child); - break; - case ObjJCompiler.AstNodeTryStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeTryStatement(child); - break; - case ObjJCompiler.AstNodeDebuggerStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeDebuggerStatement(child); - break; - case ObjJCompiler.AstNodeFunctionDeclaration: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeFunctionDeclaration(child); - break; - case ObjJCompiler.AstNodeFunctionExpression: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeFunctionExpression(child); - break; - case ObjJCompiler.AstNodeImportStatement: - this.nodeImportStatement(child); - break; - case ObjJCompiler.AstNodeClassDeclarationStatement: - if (this._pass === 2) // Skip this if it is the first pass - this.nodeClassDeclationStatement(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeStatement + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeBlock = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBlock); -#endif - var children = astNode.children; - - this.nodeOpenBrace(children[0]); - this.nodeUnderline(children[1], false); - var offset = 0; - if (children.length === 5) - { - this.nodeStatementList(children[2]); - offset++; - } - this.nodeUnderline(children[2 + offset], false); - this.nodeCloseBrace(children[3 + offset]); - // TODO: Handle BadBlock with missing close brace -} - -ObjJCompiler.prototype.nodeVariableStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVariableStatement); -#endif - var children = astNode.children; - - this.nodeVAR(children[0]); - this.nodeUnderline(children[1], true); - this.nodeVariableDeclaration(children[2]); - - for (var i = 3; i + 3 < children.length; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeVariableDeclaration(children[i + 3]); - } - this.nodeEOS(children[i]); -} - -ObjJCompiler.prototype.nodeVariableDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclaration); -#endif - var children = astNode.children, - identifier = this.nodeIdentifier(children[0]); - - if (children.length === 5) - { - this.nodeUnderline(children[1], false); - this.nodeEQUALS(children[2]); - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpression(children[4]); - } - - this.createLocalVariable({"identifier": identifier}); -} - -ObjJCompiler.prototype.nodeVariableDeclarationNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationNoIn); -#endif - var children = astNode.children, - identifier = this.nodeIdentifier(children[0]); - - if (children.length === 5) - { - this.nodeUnderline(children[1], false); - this.nodeEQUALS(children[2]); - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpressionNoIn(children[4]); - } - - this.createLocalVariable({"identifier": identifier}); -} - -ObjJCompiler.prototype.nodeVariableDeclarationListNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVariableDeclarationListNoIn); -#endif - var children = astNode.children; - - this.nodeVariableDeclarationNoIn(children[0]); - - for (var i = 1; i + 3 < children.length; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeVariableDeclarationNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeEmptyStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEmptyStatement); -#endif - - this.nodeWORD(astNode.children[0]); // ";" -} - -ObjJCompiler.prototype.nodeExpressionStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeExpressionStatement); -#endif - var children = astNode.children; - - this.nodeExpression(children[0]); - this.nodeEOS(children[1]); -} - -ObjJCompiler.prototype.nodeIfStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIfStatement); -#endif - var children = astNode.children; - - this.nodeIF(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeExpression(children[4]); - this.nodeUnderline(children[5], false); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeStatement(children[8]); - - if (children.length === 13) - { - this.nodeUnderline(children[9], false); - this.nodeELSE(children[10], false); - this.nodeUnderline(children[11], true); - this.nodeStatement(children[12]); - } -} - -ObjJCompiler.prototype.nodeIterationStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIterationStatement); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeDoWhileStatement: - this.nodeDoWhileStatement(child); - break; - case ObjJCompiler.AstNodeWhileStatement: - this.nodeWhileStatement(child); - break; - case ObjJCompiler.AstNodeForStatement: - this.nodeForStatement(child); - break; - case ObjJCompiler.AstNodeForInStatement: - this.nodeForInStatement(child); - break; - case ObjJCompiler.AstNodeEachStatement: - this.nodeEachStatement(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeIterationStatement + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeDoWhileStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDoWhileStatement); -#endif - var children = astNode.children; - - this.nodeDO(children[0]); - this.nodeUnderline(children[1], true); - this.nodeStatement(children[2]); - this.nodeUnderline(children[3], true); - this.nodeWHILE(children[4]); - this.nodeUnderline(children[5], false); - this.nodeOpenParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeExpression(children[8]); - this.nodeUnderline(children[9], false); - this.nodeCloseParenthesis(children[10]); - this.nodeEOS(children[11]); -} - -ObjJCompiler.prototype.nodeWhileStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeWhileStatement); -#endif - var children = astNode.children; - - this.nodeWHILE(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeExpression(children[4]); - this.nodeUnderline(children[5], false); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeStatement(children[8]); -} - -ObjJCompiler.prototype.nodeForStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeForStatement); -#endif - var children = astNode.children, - child = children[4]; - - this.nodeFOR(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - var offset = 0; - if (!child || child.name !== ObjJCompiler.AstNodeUnderline) - { - this.nodeForFirstExpression(children[4]); - offset++; - } - this.nodeUnderline(children[4 + offset], false); - this.nodeWORD(children[5 + offset]); // ";" - this.nodeUnderline(children[6 + offset], false); - child = children[7 + offset]; - if (!child || child.name !== ObjJCompiler.AstNodeUnderline) - { - this.nodeExpression(child); - offset++; - } - this.nodeUnderline(children[7 + offset], false); - this.nodeWORD(children[8 + offset]); // ";" - this.nodeUnderline(children[9 + offset], false); - child = children[10 + offset]; - if (!child || child.name !== ObjJCompiler.AstNodeUnderline) - { - this.nodeExpression(children[10 + offset]); - offset++; - } - this.nodeUnderline(children[10 + offset], false); - this.nodeCloseParenthesis(children[11 + offset]); - this.nodeUnderline(children[12 + offset], false); - this.nodeStatement(children[13 + offset]); -} - -ObjJCompiler.prototype.nodeForFirstExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeForFirstExpression); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeVAR) - { - this.nodeVAR(child); - this.nodeUnderline(children[1], true); - this.nodeVariableDeclarationListNoIn(children[2]); - } - else - this.nodeExpressionNoIn(children[0]); -} - -ObjJCompiler.prototype.nodeForInStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeForInStatement); -#endif - var children = astNode.children; - - this.nodeFOR(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeForInFirstExpression(children[4]); - this.nodeUnderline(children[5], true); - this.nodeIN(children[6]); - this.nodeUnderline(children[7], true); - this.nodeExpression(children[8]); // ";" - this.nodeUnderline(children[9], false); - this.nodeCloseParenthesis(children[10]); - this.nodeUnderline(children[11], false); - this.nodeStatement(children[12]); -} - -ObjJCompiler.prototype.nodeForInFirstExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeForInFirstExpression); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeVAR) - { - this.nodeVAR(child); - this.nodeUnderline(children[1], true); - this.nodeVariableDeclarationNoIn(children[2]); - } - else - this.nodeLeftHandSideExpression(child); -} - -ObjJCompiler.prototype.nodeEachStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEachStatement); -#endif - var children = astNode.children; - - this.nodeEACH(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeForInFirstExpression(children[4]); - this.nodeUnderline(children[5], true); - this.nodeIN(children[6]); - this.nodeUnderline(children[7], true); - this.nodeExpression(children[8]); // ";" - this.nodeUnderline(children[9], false); - this.nodeCloseParenthesis(children[10]); - this.nodeUnderline(children[11], false); - this.nodeStatement(children[12]); -} - -ObjJCompiler.prototype.nodeContinueStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeContinueStatement); -#endif - var children = astNode.children, - child = children[2]; - - this.nodeCONTINUE(children[0]); - this.nodeUnderlineNoLineBreak(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeIdentifier) - { - this.nodeIdentifier(child); - this.nodeEOS(children[3]); - } - else - this.nodeSemicolonInsertionEOS(children[2]); -} - -ObjJCompiler.prototype.nodeBreakStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBreakStatement); -#endif - var children = astNode.children, - child = children[2]; - - this.nodeBREAK(children[0]); - this.nodeUnderlineNoLineBreak(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeIdentifier) - { - this.nodeIdentifier(child); - this.nodeEOS(children[3]); - } - else - this.nodeSemicolonInsertionEOS(children[2]); -} - -ObjJCompiler.prototype.nodeReturnStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeReturnStatement); -#endif - var children = astNode.children, - child = children[2]; - - this.nodeRETURN(children[0]); - this.nodeUnderlineNoLineBreak(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeExpression) - { - this.nodeExpression(child); - this.nodeEOS(children[3]); - } - else - this.nodeSemicolonInsertionEOS(child); -} - -ObjJCompiler.prototype.nodeWithStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeWithStatement); -#endif - var children = astNode.children; - - this.nodeWITH(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeExpression(children[4]); - this.nodeUnderline(children[5], true); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeStatement(children[8]); -} - -ObjJCompiler.prototype.nodeSwitchStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSwitchStatement); -#endif - var children = astNode.children; - - this.nodeSWITCH(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeExpression(children[4]); - this.nodeUnderline(children[5], true); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeCaseBlock(children[8]); -} - -ObjJCompiler.prototype.nodeCaseBlock = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCaseBlock); -#endif - var children = astNode.children, - child = children[2]; - - this.nodeOpenBrace(children[0]); - this.nodeUnderline(children[1], false); - var offset = 0; - if (child && child.name === ObjJCompiler.AstNodeCaseClauses) - { - this.nodeCaseClauses(child); - offset++; - } - this.nodeUnderline(children[2 + offset], false); - child = children[3 + offset]; - if (child && child.name === ObjJCompiler.AstNodeDefaultClause) - { - this.nodeDefaultClause(child); - offset++; - } - this.nodeUnderline(children[3 + offset], false); - child = children[4 + offset]; - if (child && child.name === ObjJCompiler.AstNodeCaseClauses) - { - this.nodeCaseClauses(child); - offset++; - } - this.nodeUnderline(children[4 + offset], false); - this.nodeCloseBrace(children[5 + offset]); -} - -ObjJCompiler.prototype.nodeCaseClauses = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCaseClauses); -#endif - var children = astNode.children; - - this.nodeCaseClause(children[0]); - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - this.nodeCaseClause(children[i + 1]); - } -} - -ObjJCompiler.prototype.nodeCaseClause = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCaseClause); -#endif - var children = astNode.children, - child = children[5]; - - this.nodeCASE(children[0]); - this.nodeUnderline(children[1], true); - this.nodeExpression(children[2]); - this.nodeUnderline(children[3], false); - this.nodeCOLON(children[4]); - if (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - this.nodeStatementList(children[6]); - } -} - -ObjJCompiler.prototype.nodeDefaultClause = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDefaultClause); -#endif - var children = astNode.children, - child = children[3]; - - this.nodeDEFAULT(children[0]); - this.nodeUnderline(children[1], true); - this.nodeCOLON(children[2]); - if (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - this.nodeStatementList(children[4]); - } -} - -ObjJCompiler.prototype.nodeLabelledStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLabelledStatement); -#endif - var children = astNode.children; - - this.nodeIdentifier(children[0]); - this.nodeUnderline(children[1], true); - this.nodeCOLON(children[2]); - this.nodeUnderline(children[3], false); - this.nodeStatementList(children[4]); -} - -ObjJCompiler.prototype.nodeThrowStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeThrowStatement); -#endif - var children = astNode.children, - child = children[2]; - - this.nodeTHROW(children[0]); - this.nodeUnderlineNoLineBreak(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeExpression) - { - this.nodeExpression(child); - this.nodeEOS(children[3]); - } - else - this.nodeSemicolonInsertionEOS(children[2]); -} - -ObjJCompiler.prototype.nodeTryStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTryStatement); -#endif - var children = astNode.children, - child = children[4]; - - this.nodeTRY(children[0]); - this.nodeUnderline(children[1], false); - this.nodeBlock(children[2]); - this.nodeUnderline(children[3], false); - if (child && child.name === ObjJCompiler.AstNodeCatch) - { - this.nodeCatch(child); - child = children[5]; - if (child && child.name === ObjJCompiler.AstNodeFinally) - { - this.nodeFinally(child); - } - } - else - this.nodeFinally(child); -} - -ObjJCompiler.prototype.nodeCatch = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCatch); -#endif - var children = astNode.children; - - this.nodeCATCH(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - this.nodeIdentifier(children[4]); - this.nodeUnderline(children[5], false); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeBlock(children[8]); -} - -ObjJCompiler.prototype.nodeFinally = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFinally); -#endif - var children = astNode.children; - - this.nodeFINALLY(children[0]); - this.nodeUnderline(children[1], false); - this.nodeBlock(children[2]); -} - -ObjJCompiler.prototype.nodeDebuggerStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDebuggerStatement); -#endif - var children = astNode.children; - - this.nodeDEBUGGER(children[0]); - this.nodeEOS(children[1]); -} - -ObjJCompiler.prototype.nodeImportStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeImportStatement); -#endif - var children = astNode.children, - child = children[2], - isQuoted = null, - urlString = null, - saveJSBuffer = this._jsBuffer; - - this._jsBuffer = null; - this.nodeIMPORT(children[0]); - this.nodeUnderline(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeLocalFilePath) - { - urlString = this.nodeLocalFilePath(child); - isQuoted = true; - } - else - { - urlString = this.nodeStandardFilePath(children[2]); - isQuoted = false; - } - this.nodeEOS(children[3]); - - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, "objj_executeFile(\""); - CONCAT(saveJSBuffer, urlString); - CONCAT(saveJSBuffer, isQuoted ? "\", YES);" : "\", NO);"); - } - - this._dependencies.push(new FileDependency(new CFURL(urlString), isQuoted)); - this._jsBuffer = saveJSBuffer; -} - -ObjJCompiler.prototype.nodeLocalFilePath = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLocalFilePath); -#endif - - return this.nodeStringLiteral(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeStandardFilePath = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeStandardFilePath); -#endif - var children = astNode.children, - size = children.length, - string = ""; - - this.nodeLESSTHEN(children[0]); - this.nodeUnderline(children[1], false); - for (var i = 2; i < size - 2; i++) - { - string += this.nodeWORD(children[i]); - } - this.nodeUnderline(children[size - 2], false); - this.nodeGREATERTHEN(children[size - 1]); - - return string; -} - -ObjJCompiler.prototype.nodeClassDeclationStatement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeClassDeclarationStatement); -#endif - var children = astNode.children, - child = children[4], - offset = 0, - saveJSBuffer = this._jsBuffer, // Save the javascript buffer - saveObjJBuffer = this._objJBuffer, // Save the objJ buffer - classBodyBuffer = new StringBuffer(); // Create a buffer for javascript statements and functions inside the class declaration - - // Make sure nothing is copied to the javascript buffer - this._jsBuffer = null; - // Crate an objJ buffer if we need to create accessors - this._objJBuffer = new StringBuffer(); - - this.nodeIMPLEMENTATION(children[0]); - this.nodeUnderline(children[1], true); - - var className = this.nodeIdentifier(children[2]), - superClassName = null, - classDef = null, - isCategoryDeclaration = false; - - this.nodeUnderline(children[3], false); - - if (child && child.name === ObjJCompiler.AstNodeSuperclassDeclaration) - { - superClassName = this.nodeSuperclassDeclaration(child); - offset++; - - if (this.getClassDef(className)) - throw new SyntaxError(this.error_message("Duplicate class " + className, children[2])); - if (!this.getClassDef(superClassName)) - throw new SyntaxError(this.error_message("Can't find superclass " + superClassName, child)); - - classDef = {"className": className, "superClassName": superClassName, "ivars": {}, "methods": {}}; - - this._classDefs[className] = classDef; - - if (saveJSBuffer) - CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(" + superClassName + ", \"" + className + "\"),\nmeta_class = the_class.isa;"); - } - else if (child && child.name === ObjJCompiler.AstNodeCategoryDeclaration) - { - isCategoryDeclaration = true; - this.nodeCategoryDeclaration(child); - offset++; - - classDef = this.getClassDef(className); - if (!classDef) - throw new SyntaxError(this.error_message("Class " + className + " not found ", children[2])); - - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, "{\nvar the_class = objj_getClass(\"" + className + "\")\n"); - CONCAT(saveJSBuffer, "if(!the_class) throw new SyntaxError(\"*** Could not find definition for class \\\"" + className + "\\\"\");\n"); - CONCAT(saveJSBuffer, "var meta_class = the_class.isa;"); - } - } - else - { - classDef = {"className": className, "superClassName": null, "ivars": {}, "methods": {}}; - - this._classDefs[className] = classDef; - - if (saveJSBuffer) - CONCAT(saveJSBuffer, "{var the_class = objj_allocateClassPair(Nil, \"" + className + "\"),\nmeta_class = the_class.isa;"); - } - - this._currentSuperClass = "objj_getClass(\"" + className + "\").super_class"; - this._currentSuperMetaClass = "objj_getMetaClass(\"" + className + "\").super_class"; - - this.nodeUnderline(children[4 + offset], false); - this._imBuffer = new StringBuffer(); - this._cmBuffer = new StringBuffer(); - this._classBodyBuffer = new StringBuffer(); - child = children[5 + offset]; - - if (!child || child.name !== ObjJCompiler.AstNodeUnderline) - { - this.nodeOpenBrace(child); - offset++; - var firstIvarDeclaration = true, - ivars = classDef.ivars, - hasAccessors = false; - - child = children[6 + offset]; - - while (child && child.name === ObjJCompiler.AstNodeCompoundIvarDeclaration) - { - this.nodeUnderline(children[5 + offset++], false); - - var ivarDeclaration = this.nodeCompoundIvarDeclaration(child, ivars), // This will save the declaration in ivars and return the declaration. - type = ivarDeclaration.type; - - for (var name in ivarDeclaration.ivars) - { - if (firstIvarDeclaration) - { - firstIvarDeclaration = false; - if (saveJSBuffer) - CONCAT(saveJSBuffer, "class_addIvars(the_class, ["); - } - else - if (saveJSBuffer) - CONCAT(saveJSBuffer, ", "); - - if (saveJSBuffer) - if (this._flags & ObjJCompiler.Flags.IncludeTypeSignatures) - CONCAT(saveJSBuffer, "new objj_ivar(\"" + name + "\", \"" + type + "\")"); - else - CONCAT(saveJSBuffer, "new objj_ivar(\"" + name + "\")"); - - if (!hasAccessors && ivarDeclaration.ivars[name].accessors) - hasAccessors = true; - } - - child = children[6 + ++offset]; - } - if (!firstIvarDeclaration) - if (saveJSBuffer) - CONCAT(saveJSBuffer, "]);\n"); - - this.nodeUnderline(children[5 + offset++], false); - this.nodeCloseBrace(children[5 + offset++]); - - if (hasAccessors) - { - var getterSetterBuffer = new StringBuffer(); - - // Add the class declaration to compile accessors correctly - CONCAT(getterSetterBuffer, this._objJBuffer); - CONCAT(getterSetterBuffer, "\n"); - - for (var name in ivars) - { - var ivarDecl = ivars[name], - type = ivarDecl.type, - accessors = ivarDecl.accessors; - - if (!accessors) - continue; - - var property = accessors["property"] || name, - getterName = accessors["getter"] || property, - getterCode = "- (" + (type ? type : "id") + ")" + getterName + "\n{\nreturn " + name + ";\n}\n"; - - CONCAT(getterSetterBuffer, getterCode); - - if (accessors["readonly"]) - continue; - - var setterName = accessors["setter"]; - - if (!setterName) - { - var start = property.charAt(0) == '_' ? 1 : 0; - setterName = (start ? "_" : "") + "set" + property.substr(start, 1).toUpperCase() + property.substring(start + 1) + ":"; - } - - var setterCode = "- (void)" + setterName + "(" + (type ? type : "id") + ")newValue\n{\n"; - - if (accessors["copy"]) - setterCode += "if (" + name + " !== newValue)\n" + name + " = [newValue copy];\n}\n"; - else - setterCode += name + " = newValue;\n}\n"; - - CONCAT(getterSetterBuffer, setterCode); - } - - CONCAT(getterSetterBuffer, "\n@end"); - // Remove all @accessors or we will get a recursive loop in infinity - var b = getterSetterBuffer.toString().replace(/@accessors(\(.*\))?/g, ""); - var imBuffer = ObjJCompiler.compileToIMBuffer(b, "getter", this._flags); - - CONCAT(this._imBuffer, imBuffer); - } - } - this.nodeUnderline(children[5 + offset], false); - this._currentClassDef = classDef; - - this._jsBuffer = classBodyBuffer; - this.nodeClassBody(children[6 + offset]); - this._currentClassDef = null; - this._jsBuffer = null; - - this.nodeUnderline(children[7 + offset], false); - this.nodeEND(children[8 + offset]); - this.nodeEOS(children[9 + offset]); - - if (saveJSBuffer) - { - // We must make a new class object for our class definition. - if (!isCategoryDeclaration) { - CONCAT(saveJSBuffer, "objj_registerClassPair(the_class);\n"); - } - - if (IS_NOT_EMPTY(this._imBuffer)) - { - CONCAT(saveJSBuffer, "class_addMethods(the_class, ["); - CONCAT(saveJSBuffer, this._imBuffer); - CONCAT(saveJSBuffer, "]);\n"); - } - - if (IS_NOT_EMPTY(this._cmBuffer)) - { - CONCAT(saveJSBuffer, "class_addMethods(meta_class, ["); - CONCAT(saveJSBuffer, this._cmBuffer); - CONCAT(saveJSBuffer, "]);\n"); - } - - CONCAT(saveJSBuffer, "}"); - - // FIXME: Maybe we should add this before we add the class implementation? - // We might have variable/function declarations etc that is needed before class declaration? - // Maybe not? Needs some investigation.... - CONCAT(saveJSBuffer, this._classBodyBuffer); - } - // Restore javascript buffer - this._jsBuffer = saveJSBuffer; - // Restore objJ buffer - if (saveObjJBuffer) - CONCAT(saveObjJBuffer, this._objJBuffer); - this._objJBuffer = saveObjJBuffer; -} - -ObjJCompiler.prototype.nodeSuperclassDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSuperclassDeclaration); -#endif - var children = astNode.children; - - this.nodeCOLON(children[0]); - this.nodeUnderline(children[1], false); - return this.nodeIdentifier(children[2]); -} - -ObjJCompiler.prototype.nodeCategoryDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCategoryDeclaration); -#endif - var children = astNode.children; - - this.nodeOpenParenthesis(children[0]); - this.nodeUnderline(children[1], false); - this.nodeIdentifier(children[2]); - this.nodeUnderline(children[3], false); - this.nodeCloseParenthesis(children[4]); -} - -ObjJCompiler.prototype.nodeCompoundIvarDeclaration = function(/*SyntaxNode*/ astNode, classDefIvars) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCompoundIvarDeclaration); -#endif - var children = astNode.children, - type = this.nodeIvarType(children[0]); - - this.nodeUnderline(children[1], true); - var ivar = this.nodeIvarDeclaration(children[2]), - ivars = {}; - - ivars[ivar.identifier] = ivar; - classDefIvars[ivar.identifier] = {"type": type, "name": ivar.identifier, "accessors": ivar.accessors}; - for (var i = 3; i + 3 < children.length; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "," - this.nodeUnderline(children[i + 2], false); - ivar = this.nodeIvarDeclaration(children[i + 3]); - if (classDefIvars[ivar.identifier]) // FIXME: Must look at classes not in this file - throw new SyntaxError(this.error_message("Duplicate member " + ivar.identifier, children[i + 3])); - ivars[ivar.identifier] = ivar; - classDefIvars[ivar.identifier] = {"type": type, "name": ivar.identifier, "accessors": ivar.accessors}; - } - this.nodeEOS(children[i]); - return {"type": type, "ivars": ivars}; -} - -// This grammar is not correct. You should not be able to have multiple IvarTypeElement. -// Maybe should be one type element and one extra @outlet? Or something...... -// IvarType = -// IvarTypeElement (_ IvarTypeElement)* - -ObjJCompiler.prototype.nodeIvarType = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarType); -#endif - var children = astNode.children, - type = ""; - - var newType = this.nodeIvarTypeElement(children[0]); - // Maybe we should return the outlet information and save it along the ivars for the class.... - if (newType !== "@outlet") - type = newType; - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - newType = this.nodeIvarTypeElement(children[i + 1]); - // Maybe we should return the outlet information and save it along the ivars for the class.... - if (newType !== "@outlet") - type += " " + newType; - } - - return type; -} - -ObjJCompiler.prototype.nodeIvarTypeElement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarTypeElement); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeIdentifierName) - return this.nodeIdentifierName(child); - else - return this.nodeOUTLET(child); -} - -ObjJCompiler.prototype.nodeIvarDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarDeclaration); -#endif - var children = astNode.children, - child = children[2], - ivar = {}; - - ivar.identifier = this.nodeIdentifier(children[0]); - this.nodeUnderline(children[1], false); - - if (child && child.name === ObjJCompiler.AstNodeAccessors) - ivar.accessors = this.nodeAccessors(child); - return ivar; -} - -ObjJCompiler.prototype.nodeAccessors = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAccessors); -#endif - var children = astNode.children, - size = children.length, - accessors = {}; - - this.nodeACCESSORS(children[0]); - if (size > 1) - { - this.nodeOpenParenthesis(children[1]); - var offset = 0, - child = children[2]; - if (child && child.name === ObjJCompiler.AstNodeAccessorsConfiguration) - { - accessors = this.nodeAccessorsConfiguration(child); - child = children[2 + ++offset] - while (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(children[2 + offset++], false); - this.nodeWORD(children[2 + offset++]); // "," - this.nodeUnderline(children[2 + offset++], false); - var moreAccessors = this.nodeAccessorsConfiguration(children[2 + offset++]); - for (var attrname in moreAccessors) // Clang takes the last if many exists so just Merge in moreAccessors - accessors[attrname] = moreAccessors[attrname]; - child = children[2 + offset]; - } - } - this.nodeCloseParenthesis(child); - } - return accessors; -} - -ObjJCompiler.prototype.nodeAccessorsConfiguration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAccessorsConfiguration); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeIvarPropertyName: - return {"property": this.nodeIvarPropertyName(child)}; - case ObjJCompiler.AstNodeIvarGetterName: - return {"getter": this.nodeIvarGetterName(child)}; - case ObjJCompiler.AstNodeIvarSetterName: - return {"setter": this.nodeIvarSetterName(child)}; - default: - // Here we accept anything the parser accepts: "readonly", "copy" or "readwrite" - this.nodeWORD(child); - var r = {}; - r[child] = true; - return r; - } -} - -ObjJCompiler.prototype.nodeIvarPropertyName = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarPropertyName); -#endif - var children = astNode.children; - - this.nodePROPERTY(children[0]); - this.nodeUnderline(children[1], false); - this.nodeEQUALS(children[2]); - this.nodeUnderline(children[3], false); - return this.nodeIdentifier(children[4]); -} - -ObjJCompiler.prototype.nodeIvarGetterName = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarGetterName); -#endif - var children = astNode.children; - - this.nodeGETTER(children[0]); - this.nodeUnderline(children[1], false); - this.nodeEQUALS(children[2]); - this.nodeUnderline(children[3], false); - return this.nodeIdentifier(children[4]); -} - -ObjJCompiler.prototype.nodeIvarSetterName = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIvarSetterName); -#endif - var children = astNode.children; - - this.nodeSETTER(children[0]); - this.nodeUnderline(children[1], false); - this.nodeEQUALS(children[2]); - this.nodeUnderline(children[3], false); - var setterName = this.nodeIdentifier(children[4]); - - // I think the grammar is wrong here! You should always include the colon. - // IvarSetterName = - // "setter" _ "=" _ Identifier (_ ":")? - - if (children.length > 6) - { - this.nodeUnderline(children[5], false); - setterName += this.nodeCOLON(children[6]); - } - else - { - setterName += ":"; - } - - return setterName; -} - -ObjJCompiler.prototype.nodeClassBody = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeClassBody); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeClassElements) - this.nodeClassElements(child); -} - -ObjJCompiler.prototype.nodeClassElements = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeClassElements); -#endif - var children = astNode.children; - - this.nodeClassElement(children[0]); - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - this.nodeClassElement(children[i + 1]); - } -} - -ObjJCompiler.prototype.nodeClassElement = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeClassElement); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeClassMethodDeclaration: - this.nodeClassMethodDeclaration(child); - break; - case ObjJCompiler.AstNodeInstanceMethodDeclaration: - this.nodeInstanceMethodDeclaration(child); - break; - case ObjJCompiler.AstNodeStatement: - this._jsBuffer = this._classBodyBuffer; - this.nodeStatement(child); - this._jsBuffer = null; - break; - case ObjJCompiler.AstNodeFunctionDeclaration: - this._jsBuffer = this._classBodyBuffer; - this.nodeFunctionDeclaration(child); - this._jsBuffer = null; - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeClassElement + " but got " + child, child)); - break; - } -} - -ObjJCompiler.prototype.nodeClassMethodDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeClassMethodDeclaration); -#endif - this.nodePLUS(astNode.children[0]); - this._classMethod = true; - this.genericMethodDeclaration(astNode, this._cmBuffer); -} - -ObjJCompiler.prototype.nodeInstanceMethodDeclaration = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeInstanceMethodDeclaration); -#endif - this.nodeMINUS(astNode.children[0]); - this._classMethod = false; - this.genericMethodDeclaration(astNode, this._imBuffer); -} - -ObjJCompiler.prototype.genericMethodDeclaration = function(/*SyntaxNode*/ astNode, /*StringBuffer*/ buffer) -{ - var children = astNode.children, - child = children[2], - offset = 0, - returnTypes = [null], - classDef = this._currentClassDef, - currentClassMethods = classDef ? classDef.methods : null; - - if (child && child.name === ObjJCompiler.AstNodeMethodType) - { - this.nodeUnderline(children[1 + offset++], false); - returnTypes = this.nodeMethodType(children[1 + offset++]); - } - this.nodeUnderline(children[1 + offset], false); - var methodSelector = this.nodeMethodSelector(children[2 + offset]), - selector = methodSelector.selector, - types = [returnTypes[0]]; // First type is return type? We might handle only one type? The grammar MethodType can be many types - - if (IS_NOT_EMPTY(buffer)) // Add comma separator if this is not first method in this buffer - CONCAT(buffer, ", "); - CONCAT(buffer, "new objj_method(sel_getUid(\""); - CONCAT(buffer, selector); - CONCAT(buffer, "\"), function"); - -// this._currentSelector = selector; - - if (this._flags & ObjJCompiler.Flags.IncludeDebugSymbols) - { - CONCAT(buffer, " $" + this._currentClassDef.className + "__" + selector.replace(/:/g, "_")); - } - - CONCAT(buffer, "(self, _cmd"); - - for (var identifier in methodSelector.parameters) - { - var parameter = methodSelector.parameters[identifier]; - - CONCAT(buffer, ", "); - CONCAT(buffer, parameter.identifier); - types.push(parameter.type); - } - - if (currentClassMethods) - { - var currentMethodSelector = currentClassMethods[methodSelector.selector]; - if (currentMethodSelector) - { - // Method already declared. May be a warning? - } - currentClassMethods[methodSelector.selector] = methodSelector; - methodSelector.lvarStack = [{}]; - this._currentMethod = methodSelector; - } - - CONCAT(buffer, ")\n{\n"); - - this.nodeUnderline(children[3 + offset], false); - - child = children[4 + offset]; - if (child && child.name !== ObjJCompiler.AstNodeUnderline) - { - this.nodeSEMICOLON(children[4 + offset++]); - } - this.nodeUnderline(children[4 + offset], false); - this.nodeOpenBrace(children[5 + offset]); - this.nodeUnderline(children[6 + offset], false); - this._jsBuffer = buffer; // Now write the FunctionBody to buffer - this.nodeFunctionBody(children[7 + offset]); - this._jsBuffer = null; // Turn back off again so nothing is written - this.nodeUnderline(children[8 + offset], false); - this.nodeCloseBrace(children[9 + offset]); - CONCAT(buffer, "}\n"); - if (this._flags & ObjJCompiler.Flags.IncludeDebugSymbols) //flags.IncludeTypeSignatures) - CONCAT(buffer, ","+JSON.stringify(types)); - CONCAT(buffer, ")"); - - this._currentMethod = null; -} - -ObjJCompiler.prototype.nodeMethodSelector = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMethodSelector); -#endif - var children = astNode.children, - child = children[0], - size = children.length; - - if (child && child.name === ObjJCompiler.AstNodeKeywordSelector) - { - var keywordSelector = this.nodeKeywordSelector(child); - if (size > 1) - { - this.nodeUnderline(children[1], false); - this.nodeCOMMA(children[2]); - this.nodeUnderline(children[3], false); - // FIXME: Handle argument list. If we need to? - this.nodeWORD(children[4]); // ... - } - return keywordSelector; - } - else - return {"selector": this.nodeUnarySelector(child)}; -} - -ObjJCompiler.prototype.nodeUnarySelector = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnarySelector); -#endif - return this.nodeSelector(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeKeywordSelector = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelector); -#endif - var children = astNode.children, - keywordDecl = this.nodeKeywordDeclarator(children[0]), - typeAndIndentifier = {"type": keywordDecl.methodType, "identifier": keywordDecl.identifier}, - keywordSelector = {"selector": keywordDecl.selector, "parameters":{}}; - - keywordSelector.parameters[keywordDecl.identifier] = typeAndIndentifier; - - for (var i = 1; i + 1 < children.length; i += 2) - { - this.nodeUnderline(children[i], false); - var nextKeywordDecl = this.nodeKeywordDeclarator(children[i + 1]); - - keywordSelector.selector += nextKeywordDecl.selector; - keywordSelector.parameters[nextKeywordDecl.identifier] = {"type": nextKeywordDecl.methodType, "identifier": nextKeywordDecl.identifier}; - } - return keywordSelector; -} - -ObjJCompiler.prototype.nodeKeywordDeclarator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeKeywordDeclarator); -#endif - var children = astNode.children, - child = children[0], - offset = 0, - selector = "", - methodType = null; - - if (child && child.name === ObjJCompiler.AstNodeSelector) - { - selector = this.nodeSelector(children[0 + offset++]); - this.nodeUnderline(children[0 + offset++], false); - } - - this.nodeCOLON(children[0 + offset]); - selector += ":"; - child = children[2 + offset]; - - if (child && child.name === ObjJCompiler.AstNodeMethodType) - { - this.nodeUnderline(children[1 + offset++], false); - // TODO: Parser allows multiple MethodType. Need to find out what to do if we get more then one - methodType = this.nodeMethodType(children[1 + offset++])[0]; - } - - this.nodeUnderline(children[1 + offset], false); - var identifier = this.nodeIdentifier(children[2 + offset]); - - return {"selector": selector, "methodType": methodType, "identifier": identifier}; -} - -ObjJCompiler.prototype.nodeSelector = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSelector); -#endif - return this.nodeIdentifierName(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeMethodType = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMethodType); -#endif - var children = astNode.children, - child = children[2], - size = children.length, - methodTypes = [], - offset = 3; - - this.nodeOpenParenthesis(children[0]); - this.nodeUnderline(children[1], false); - - if (child && child.name === ObjJCompiler.AstNodeACTION) - methodTypes.push(this.nodeACTION(child)); - else - { - methodTypes.push(this.nodeIdentifierName(child)); - if (children[4] === "<") - { - this.nodeUnderline(children[3], false); - this.nodeWORD(children[4]); // "<" - this.nodeUnderline(children[5], false); - this.nodeIdentifierName(children[6]); - this.nodeUnderline(children[7], false); - this.nodeWORD(children[8]); // ">" - offset += 6; - } - } - - for (var i = offset; i + 1 < size - 2; i += 2) - { - this.nodeUnderline(children[i], true); - child = children[i + 1]; - if (child && child.name === ObjJCompiler.AstNodeACTION) - methodTypes.push(this.nodeACTION(child)); - else - { - methodTypes.push(this.nodeIdentifierName(child)); - if (i + 7 < size && children[i + 3] === "<") - { - this.nodeUnderline(children[i++ + 2], false); - this.nodeWORD(children[i++ + 2]); // "<" - this.nodeUnderline(children[i++ + 2], false); - this.nodeIdentifierName(children[i++ + 2]); - this.nodeUnderline(children[i++ + 2], false); - this.nodeWORD(children[i++ + 2]); // ">" - } - } - } - - this.nodeUnderline(children[size - 2], false); - this.nodeCloseParenthesis(children[size - 1]); - return methodTypes; -} - -ObjJCompiler.prototype.nodeACTION = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeACTION); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeAssignmentExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "," - this.nodeUnderline(children[i + 2], false); - this.nodeAssignmentExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeAssignmentExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "," - this.nodeUnderline(children[i + 2], false); - this.nodeAssignmentExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeAssignmentExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpression); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeLeftHandSideExpression) - { - this.nodeLeftHandSideExpression(child); - this.nodeUnderline(children[1], false); - this.nodeAssignmentOperator(children[2]); - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpression(children[4]); - } - else - this.nodeConditionalExpression(child); -} - -ObjJCompiler.prototype.nodeAssignmentExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentExpressionNoIn); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeLeftHandSideExpression) - { - this.nodeLeftHandSideExpression(child); - this.nodeUnderline(children[1], false); - this.nodeAssignmentOperator(children[2]); - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpressionNoIn(children[4]); - } - else - this.nodeConditionalExpressionNoIn(child); -} - -ObjJCompiler.prototype.nodeAssignmentOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAssignmentOperator); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeConditionalExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpression); -#endif - var children = astNode.children, - child = children[1]; - - this.nodeLogicalOrExpression(children[0]); - if (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - this.nodeWORD(children[2]); // "?" - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpression(children[4]); - this.nodeUnderline(children[5], false); - this.nodeWORD(children[6]); // ":" - this.nodeUnderline(children[7], false); - this.nodeAssignmentExpression(children[8]); - } -} - -ObjJCompiler.prototype.nodeConditionalExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeConditionalExpressionNoIn); -#endif - var children = astNode.children, - child = children[1]; - - this.nodeLogicalOrExpressionNoIn(children[0]); - if (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - this.nodeWORD(children[2]); // "?" - this.nodeUnderline(children[3], false); - this.nodeAssignmentExpressionNoIn(children[4]); - this.nodeUnderline(children[5], false); - this.nodeWORD(children[6]); // ":" - this.nodeUnderline(children[7], false); - this.nodeAssignmentExpressionNoIn(children[8]); - } -} - -ObjJCompiler.prototype.nodeLogicalOrExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeLogicalAndExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "||" - this.nodeUnderline(children[i + 2], false); - this.nodeLogicalAndExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeLogicalOrExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLogicalOrExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeLogicalAndExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "||" - this.nodeUnderline(children[i + 2], false); - this.nodeLogicalAndExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeLogicalAndExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseOrExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "&&" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseOrExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeLogicalAndExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLogicalAndExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseOrExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "&&" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseOrExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseOrExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseXOrExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "|" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseXOrExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseOrExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseOrExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseXOrExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "|" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseXOrExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseXOrExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseAndExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "^" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseAndExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseXOrExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseXOrExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeBitwiseAndExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "^" - this.nodeUnderline(children[i + 2], false); - this.nodeBitwiseAndExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseAndExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeEqualityExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "&" - this.nodeUnderline(children[i + 2], false); - this.nodeEqualityExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeBitwiseAndExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBitwiseAndExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeEqualityExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeWORD(children[i + 1]); // "&" - this.nodeUnderline(children[i + 2], false); - this.nodeEqualityExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeEqualityExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeRelationalExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeEqualityOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeRelationalExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeEqualityExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEqualityExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeRelationalExpressionNoIn(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeEqualityOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeRelationalExpressionNoIn(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeEqualityOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEqualityOperator); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeRelationalExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeShiftExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeRelationalOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeShiftExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeRelationalOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperator); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeIN: - this.nodeIN(child); - break; - case ObjJCompiler.AstNodeINSTANCEOF: - this.nodeINSTANCEOF(child); - break; - default: - this.nodeWORD(child); - } -} - -ObjJCompiler.prototype.nodeRelationalExpressionNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRelationalExpressionNoIn); -#endif - var children = astNode.children, - size = children.length; - - this.nodeShiftExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeRelationalOperatorNoIn(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeShiftExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeRelationalOperatorNoIn = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRelationalOperatorNoIn); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeINSTANCEOF: - this.nodeINSTANCEOF(child); - break; - default: - this.nodeWORD(child); - } -} - -ObjJCompiler.prototype.nodeShiftExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeShiftExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeAdditiveExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeShiftOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeAdditiveExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeShiftOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeShiftOperator); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeAdditiveExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeMultiplicativeExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeAdditiveOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeMultiplicativeExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeAdditiveOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeAdditiveOperator); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeMultiplicativeExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeUnaryExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeMultiplicativeOperator(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeUnaryExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodeMultiplicativeOperator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMultiplicativeOperator); -#endif - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeUnaryExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnaryExpression); -#endif - var children = astNode.children, - child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodePostfixExpression: - this.nodePostfixExpression(child); - break; - case ObjJCompiler.AstNodeDELETE: - this.nodeDELETE(child); - this.nodeUnderline(children[1], true); - this.nodeUnaryExpression(children[2]); - break; - case ObjJCompiler.AstNodeVOID: - this.nodeVOID(child); - this.nodeUnderline(children[1], true); - this.nodeUnaryExpression(children[2]); - break; - case ObjJCompiler.AstNodeTYPEOF: - this.nodeTYPEOF(child); - this.nodeUnderline(children[1], true); - this.nodeUnaryExpression(children[2]); - break; - default: - this.nodeWORD(child); - this.nodeUnderline(children[1], false); - this.nodeUnaryExpression(children[2]); - } -} - -ObjJCompiler.prototype.nodePostfixExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePostfixExpression); -#endif - var children = astNode.children; - - this.nodeLeftHandSideExpression(children[0]); - - if (children.length > 1) - { - this.nodeUnderlineNoLineBreak(children[1], false); - this.nodeWORD(children[2]); // "++" or "--" - } -} - -ObjJCompiler.prototype.nodeLeftHandSideExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLeftHandSideExpression); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeCallExpression) - this.nodeCallExpression(child) - else - this.nodeNewExpression(child); -} - -ObjJCompiler.prototype.nodeNewExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNewExpression); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeMemberExpression) - this.nodeMemberExpression(child) - else - { - this.nodeNEW(child); - this.nodeUnderline(children[1], true); - this.nodeNewExpression(children[2]); - } -} - -ObjJCompiler.prototype.nodeCallExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCallExpression); -#endif - var children = astNode.children, - size = children.length; - - this.nodeMemberExpression(children[0]); - this.nodeUnderline(children[1], false); - this.nodeArguments(children[2]); - - for (var i = 3; i + 1 < size; i += 2) - { - this.nodeUnderline(children[i], false); - var child = children[i + 1], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeArguments: - this.nodeArguments(child); - break; - case ObjJCompiler.AstNodeBracketedAccessor: - this.nodeBracketedAccessor(child); - break; - case ObjJCompiler.AstNodeDotAccessor: - this.nodeDotAccessor(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeArguments + ", " + ObjJCompiler.AstNodeBracketedAccessor + " or " + ObjJCompiler.AstNodeDotAccessor + " but got " + child, child)); - } - } -} - -ObjJCompiler.prototype.nodeMemberExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMemberExpression); -#endif - var children = astNode.children, - size = children.length, - child = children[0], - name = child ? child.name : null, - offset = 1; - - switch(name) - { - case ObjJCompiler.AstNodePrimaryExpression: - this.nodePrimaryExpression(child); - break; - case ObjJCompiler.AstNodeFunctionExpression: - this.nodeFunctionExpression(child); - break; - case ObjJCompiler.AstNodeMessageExpression: - this.nodeMessageExpression(child); - break; - default: - this.nodeNEW(child); - this.nodeUnderline(children[offset++], true); - this.nodeMemberExpression(children[offset++]); - this.nodeUnderline(children[offset++], false); - this.nodeArguments(children[offset++]); - } - - for (var i = offset; i + 1 < size; i += 2) - { - this.nodeUnderline(children[i], false); - var child = children[i + 1], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeBracketedAccessor: - this.nodeBracketedAccessor(child); - break; - case ObjJCompiler.AstNodeDotAccessor: - this.nodeDotAccessor(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeBracketedAccessor + " or " + ObjJCompiler.AstNodeDotAccessor + " but got " + child, child)); - } - } -} - -ObjJCompiler.prototype.nodeBracketedAccessor = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBracketedAccessor); -#endif - var children = astNode.children; - - this.nodeOpenBracket(children[0]); - this.nodeUnderline(children[1], false); - this.nodeExpression(children[2]); - this.nodeUnderline(children[3], false); - this.nodeCloseBracket(children[4]); -} - -ObjJCompiler.prototype.nodeDotAccessor = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDotAccessor); -#endif - var children = astNode.children; - - this.nodeDOT(children[0]); - this.nodeUnderline(children[1], false); - this.nodeIdentifierName(children[2]); -} - -ObjJCompiler.prototype.nodeArguments = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeArguments); -#endif - var children = astNode.children, - child = children[2], - offset = 0; - - this.nodeOpenParenthesis(children[0]); - this.nodeUnderline(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeArgumentList) - { - this.nodeArgumentList(child); - offset++; - } - this.nodeUnderline(children[2 + offset], false); - this.nodeCloseParenthesis(children[3 + offset]); -} - -ObjJCompiler.prototype.nodeArgumentList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeArgumentList); -#endif - var children = astNode.children, - size = children.length; - - this.nodeAssignmentExpression(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodeAssignmentExpression(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodePrimaryExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePrimaryExpression); -#endif - var children = astNode.children, - child = children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeTHIS: - this.nodeTHIS(child); - break; - case ObjJCompiler.AstNodeIdentifier: - var saveJSBuffer = this._jsBuffer; - - this._jsBuffer = null; - var identifier = this.nodeIdentifier(child); - this._jsBuffer = saveJSBuffer; - - if (saveJSBuffer) - { - var lvar = this.getLvarForCurrentMethod(identifier), - ivar = this.getIvarForCurrentClass(identifier); - - if (ivar) - { - if (lvar) - 0 == 0; // Warning: Local declaration of 'identifier' hides instance variable - else - { - CONCAT(saveJSBuffer, "self."); - } - } - - CONCAT(saveJSBuffer, identifier); - } - break; - case ObjJCompiler.AstNodeLiteral: - this.nodeLiteral(child); - break; - case ObjJCompiler.AstNodeArrayLiteral: - this.nodeArrayLiteral(child); - break; - case ObjJCompiler.AstNodeObjectLiteral: - this.nodeObjectLiteral(child); - break; - default: - this.nodeOpenParenthesis(child); - this.nodeUnderline(children[1], false); - this.nodeExpression(children[2]); - this.nodeUnderline(children[3], false); - this.nodeCloseParenthesis(children[4]); - } -} - -ObjJCompiler.prototype.nodeMessageExpression = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMessageExpression); -#endif - var children = astNode.children, - child = children[2], - saveJSBuffer = this._jsBuffer; - - this._jsBuffer = null; - this.nodeOpenBracket(children[0]); - this.nodeUnderline(children[1], false); - if (child && child.name === ObjJCompiler.AstNodeExpression) - { - var buffer = new StringBuffer(); - - this._jsBuffer = buffer; - this.nodeExpression(child); - this._jsBuffer = null; - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, "objj_msgSend("); - CONCAT(saveJSBuffer, buffer); - } - } - else - { - this.nodeSUPER(child); - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, "objj_msgSendSuper("); - CONCAT(saveJSBuffer, "{ receiver:self, super_class:" + (this._classMethod ? this._currentSuperMetaClass : this._currentSuperClass ) + " }"); - } - } - - this.nodeUnderline(children[3], false); - var selector = this.nodeSelectorCall(children[4]); - - if (saveJSBuffer) - { - CONCAT(saveJSBuffer, ", \""); - CONCAT(saveJSBuffer, selector.selector); // FIXME: sel_getUid(selector.selector + "") ? - CONCAT(saveJSBuffer, "\""); - - if (selector.expressions) - for (var i = 0; i < selector.expressions.length; i++) - CONCAT(saveJSBuffer, ", " + selector.expressions[i]); - - CONCAT(saveJSBuffer, ")"); - } - - this.nodeUnderline(children[5], false); - this.nodeCloseBracket(children[6]); - - this._jsBuffer = saveJSBuffer; -} - -ObjJCompiler.prototype.nodeSelectorCall = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSelectorCall); -#endif - var children = astNode.children, - size = children.length, - child = children[0], - selector = {}; - - if (child && child.name === ObjJCompiler.AstNodeUnarySelector) - selector.selector = this.nodeUnarySelector(child); - else - { - selector = this.nodeKeywordSelectorCall(child); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - var buffer = new StringBuffer(); - this._jsBuffer = buffer; - this.nodeExpression(children[i + 3]); - selector.parameters.push(buffer.toString()); - this._jsBuffer = null; - } - } - return selector; -} - -ObjJCompiler.prototype.nodeKeywordSelectorCall = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeKeywordSelectorCall); -#endif - var children = astNode.children, - size = children.length; - - var keywordCall = this.nodeKeywordCall(children[0]), - selector = keywordCall.selector, - expressions = [keywordCall.expression]; - - for (var i = 1; i + 1 < size; i += 2) - { - this.nodeUnderline(children[i], false); - keywordCall = this.nodeKeywordCall(children[i + 1]); - selector += keywordCall.selector; - expressions.push(keywordCall.expression); - } - return {"selector": selector, "expressions": expressions}; -} - -ObjJCompiler.prototype.nodeKeywordCall = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeKeywordCall); -#endif - var children = astNode.children, - child = children[0], - offset = 0, - selector = "", - buffer = new StringBuffer(); - - if (child && child.name === ObjJCompiler.AstNodeSelector) - selector += this.nodeSelector(children[offset++]); - - this.nodeUnderline(children[offset++], false); - this.nodeCOLON(children[offset++]); - selector += ":"; - this.nodeUnderline(children[offset++], false); - this._jsBuffer = buffer; - this.nodeExpression(children[offset]); - this._jsBuffer = null; - - return {"selector": selector, "expression": buffer.toString()}; -} - -ObjJCompiler.prototype.nodeArrayLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeArrayLiteral); -#endif - var children = astNode.children; - - this.nodeOpenBracket(children[0]); - this.nodeUnderline(children[1], false); - this.nodeElementList(children[2]); - this.nodeUnderline(children[3], false); - this.nodeCloseBracket(children[4]); -} - -ObjJCompiler.prototype.nodeElementList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeElementList); -#endif - var children = astNode.children, - offset = 0; - - while (children[offset] === ",") - { - this.nodeCOMMA(children[offset++]); - this.nodeUnderline(children[offset++], false); - } - - var child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - child = children[++offset]; - if (child && child.name === ObjJCompiler.AstNodeAssignmentExpression) - this.nodeAssignmentExpression(child); - else if (child === ",") - this.nodeCOMMA(child); - - child = children[++offset]; - } -} - -ObjJCompiler.prototype.nodeObjectLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeObjectLiteral); -#endif - var children = astNode.children, - child = children[2], - offset = 2; - - this.nodeOpenBrace(children[0]); - this.nodeUnderline(children[1], false); - if (child && child.name === ObjJCompiler.AstNodePropertyNameAndValueList) - { - this.nodePropertyNameAndValueList(children[offset++]); - this.nodeUnderline(children[offset++], false); - if (children[offset] === ",") - this.nodeCOMMA(children[offset++]); - } - this.nodeUnderline(children[offset++], false); - this.nodeCloseBrace(children[offset]); -} - -ObjJCompiler.prototype.nodePropertyNameAndValueList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertyNameAndValueList); -#endif - var children = astNode.children, - size = children.length; - - this.nodePropertyAssignment(children[0]); - - for (var i = 1; i + 3 < size; i += 4) - { - this.nodeUnderline(children[i], false); - this.nodeCOMMA(children[i + 1]); - this.nodeUnderline(children[i + 2], false); - this.nodePropertyAssignment(children[i + 3]); - } -} - -ObjJCompiler.prototype.nodePropertyAssignment = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertyAssignment); -#endif - var children = astNode.children, - child = children[4], - name = child ? child.name : null; - - this.nodePropertyName(children[0]); - this.nodeUnderline(children[1], false); - this.nodeCOLON(children[2]); - this.nodeUnderline(children[3], false); - - switch(name) - { - case ObjJCompiler.AstNodeAssignmentExpression: - this.nodeAssignmentExpression(child); - break; - case ObjJCompiler.AstNodePropertyGetter: - this.nodePropertyGetter(child); - break; - case ObjJCompiler.AstNodePropertySetter: - this.nodePropertySetter(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeAssignmentExpression + ", " + ObjJCompiler.AstNodePropertyGetter + " or " + ObjJCompiler.AstNodePropertySetter + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodePropertyGetter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); -#endif - var children = astNode.children, - child = children[4]; - - this.nodeGET(children[0]); - this.nodeUnderline(children[1], true); - this.nodePropertyName(children[2]); - this.nodeUnderline(children[3], false); - this.nodeOpenParenthesis(children[4]); - this.nodeUnderline(children[5], false); - this.nodeCloseParenthesis(children[6]); - this.nodeUnderline(children[7], false); - this.nodeOpenBrace(children[8]); - this.nodeUnderline(children[9], false); - this.nodeFunctionBody(children[10]); - this.nodeUnderline(children[11], false); - this.nodeCloseBrace(children[12]); -} - -function PropertySetter(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertyGetter); -#endif - var children = astNode.children, - child = children[4]; - - this.nodeGET(children[0]); - this.nodeUnderline(children[1], true); - this.nodePropertyName(children[2]); - this.nodeUnderline(children[3], false); - this.nodeOpenParenthesis(children[4]); - this.nodeUnderline(children[5], false); - this.nodePropertySetParameterList(children[6]); - this.nodeUnderline(children[7], false); - this.nodeCloseParenthesis(children[8]); - this.nodeUnderline(children[9], false); - this.nodeOpenBrace(children[10]); - this.nodeUnderline(children[11], false); - this.nodeFunctionBody(children[12]); - this.nodeUnderline(children[13], false); - this.nodeCloseBrace(children[14]); -} - -ObjJCompiler.prototype.nodePropertyName = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertyName); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeIdentifierName: - this.nodeIdentifierName(child); - break; - case ObjJCompiler.AstNodeStringLiteral: - this.nodeStringLiteral(child); - break; - case ObjJCompiler.AstNodeNumericLiteral: - this.nodeNumericLiteral(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeIdentifierName + ", " + ObjJCompiler.AstNodeStringLiteral + " or " + ObjJCompiler.AstNodeNumericLiteral + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodePropertySetParameterList = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodePropertySetParameterList); -#endif - - this.nodeIdentifier(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLiteral); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeNullLiteral: - this.nodeNullLiteral(child); - break; - case ObjJCompiler.AstNodeBooleanLiteral: - this.nodeBooleanLiteral(child); - break; - case ObjJCompiler.AstNodeNumericLiteral: - this.nodeNumericLiteral(child); - break; - case ObjJCompiler.AstNodeStringLiteral: - this.nodeStringLiteral(child); - break; - case ObjJCompiler.AstNodeRegularExpressionLiteral: - this.nodeRegularExpressionLiteral(child); - break; - case ObjJCompiler.AstNodeSelectorLiteral: - this.nodeSelectorLiteral(child); - break; - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeLiteral + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeSelectorLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteral); -#endif - var children = astNode.children, - saveJSBuffer = this._jsBuffer, - selectorBuffer = new StringBuffer(); - - this._jsBuffer = null; - this.nodeSELECTOR(children[0]); - this.nodeUnderline(children[1], false); - this.nodeOpenParenthesis(children[2]); - this.nodeUnderline(children[3], false); - if (saveJSBuffer) - CONCAT(selectorBuffer, "sel_getUid(\""); - this._jsBuffer = selectorBuffer; - this.nodeSelectorLiteralContents(children[4]); - CONCAT(selectorBuffer, "\")"); - this._jsBuffer = null; - this.nodeUnderline(children[5], false); - this.nodeCloseParenthesis(children[6]); - this._jsBuffer = saveJSBuffer; - if (saveJSBuffer) - CONCAT(saveJSBuffer, selectorBuffer); -} - -ObjJCompiler.prototype.nodeSelectorLiteralContents = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSelectorLiteralContents); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeIdentifier) - this.nodeIdentifier(child); - else - { - var size = children.length, - offset = 0; - - while (offset < size) - { - child = children[offset]; - if (child && child.name === ObjJCompiler.AstNodeSelector) - this.nodeSelector(children[offset++]); - this.nodeUnderline(children[offset++], false); - this.nodeCOLON(children[offset++]); - this.nodeUnderline(children[offset++], false); - } - } -} - -ObjJCompiler.prototype.nodeNullLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNullLiteral); -#endif - - this.nodeNULL(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeBooleanLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBooleanLiteral); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeTRUE) - this.nodeTRUE(child); - else - this.nodeFALSE(child); -} - -ObjJCompiler.prototype.nodeNumericLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNumericLiteral); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeHexIntegerLiteral) - this.nodeHexIntegerLiteral(child); - else - this.nodeDecimalLiteral(child); -} - -ObjJCompiler.prototype.nodeDecimalLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDecimalLiteral); -#endif - var children = astNode.children, - offset = 0, - number = "", - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeDecimalIntegerLiteral) - { - number += this.nodeDecimalIntegerLiteral(child); - child = children[++offset]; - } - - if (child === ".") - { - number += this.nodeWORD(child); // "." - child = children[++offset]; - } - - while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) - { - number += this.nodeDecimalDigit(child); - child = children[++offset] - } - - if (child && child.name === ObjJCompiler.AstNodeExponentPart) - number += this.nodeExponentPart(child); -} - -ObjJCompiler.prototype.nodeDecimalIntegerLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDecimalIntegerLiteral); -#endif - var children = astNode.children, - offset = 1, - number = ""; - - if (children[0] === "0") - number = this.nodeWORD(children[0]); - else - { - number = this.nodeWORD(children[0]); - } - - var child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) - { - number += this.nodeDecimalDigit(child); - child = children[++offset] - } - - return number; -} - -ObjJCompiler.prototype.nodeDecimalDigit = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDecimalDigit); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeExponentPart = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeExponentPart); -#endif - var children = astNode.children; - - return this.nodeWORD(children[0]) + this.nodeSignedInteger(children[1]); -} - -ObjJCompiler.prototype.nodeSignedInteger = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSignedInteger); -#endif - var children = astNode.children, - offset = 1, - number = "", - child = children[0]; - - if (child === "+" || child === "-") - { - number = this.nodeWORD(child); - child = children[offset++]; - } - - while (child && child.name === ObjJCompiler.AstNodeDecimalDigit) - { - number += this.nodeDecimalDigit(child); - child = children[offset++]; - } - - return number; -} - -ObjJCompiler.prototype.nodeHexIntegerLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeHexIntegerLiteral); -#endif - var children = astNode.children, - offset = 2, - hex = this.nodeWORD(children[0]); - - hex += this.nodeWORD(children[1]); - - var child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeHexDigit) - { - hex += this.nodeHexDigit(child); - child = children[++offset]; - } - - return hex; -} - -ObjJCompiler.prototype.nodeHexDigit = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeHexDigit); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeStringLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeStringLiteral); -#endif - var children = astNode.children, - offset = 0, - string = ""; - - if (children[0] === "@") - { - var saveJSBuffer = this._jsBuffer; - - this._jsBuffer = null; - this.nodeWORD(children[offset++]); - this._jsBuffer = saveJSBuffer; - this.nodeUnderline(children[offset++], false); - } - - var quoteCharacter = children[offset++], - stringCharacterFunction = null; - - this.nodeWORD(quoteCharacter); - - if (quoteCharacter === '"') - stringCharacterFunction = this.nodeDoubleStringCharacter; - else - stringCharacterFunction = this.nodeSingleStringCharacter; - - while (children[offset] !== quoteCharacter) - { - string += stringCharacterFunction.call(this, children[offset++]); - } - - this.nodeWORD(children[offset]); - - return string; -} - -ObjJCompiler.prototype.nodeDoubleStringCharacter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDoubleStringCharacter); -#endif - var children = astNode.children, - child = children[0]; - - if (child === "\\") - return this.nodeWORD(child) + this.nodeEscapeSequence(children[1]); - else if (child && child.name === ObjJCompiler.AstNodeLineContinuation) - return this.nodeLineContinuation(child); - else - return this.nodeWORD(child); -} - -ObjJCompiler.prototype.nodeSingleStringCharacter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSingleStringCharacter); -#endif - var children = astNode.children, - child = children[0]; - - if (child === "\\") - return this.nodeWORD(child) + this.nodeEscapeSequence(children[1]); - else if (child && child.name === ObjJCompiler.AstNodeLineContinuation) - return this.nodeLineContinuation(child); - else - return this.nodeWORD(child); -} - -ObjJCompiler.prototype.nodeLineContinuation = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLineContinuation); -#endif - var children = astNode.children; - - return this.nodeWORD(children[0]) + nodeLineTerminatorSequence(children[1]); -} - -ObjJCompiler.prototype.nodeEscapeSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEscapeSequence); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeCharacterEscapeSequence: - return this.nodeCharacterEscapeSequence(child); - case ObjJCompiler.AstNodeHexEscapeSequence: - return this.nodeHexEscapeSequence(child); - case ObjJCompiler.AstNodeUnicodeEscapeSequence: - return this.nodeUnicodeEscapeSequence(child); - default: - return this.nodeWORD(child); - } -} - -ObjJCompiler.prototype.nodeCharacterEscapeSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCharacterEscapeSequence); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeSingleEscapeCharacter) - return this.nodeSingleEscapeCharacter(child); - else - return this.nodeNonEscapeCharacter(child); -} - -ObjJCompiler.prototype.nodeSingleEscapeCharacter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSingleEscapeCharacter); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeNonEscapeCharacter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNonEscapeCharacter); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeHexEscapeSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeHexEscapeSequence); -#endif - var children = astNode.children; - - return children[0] + this.nodeHexDigit(children[1]) + nodeHexDigit(children[2]); -} - -ObjJCompiler.prototype.nodeUnicodeEscapeSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeEscapeSequence); -#endif - var children = astNode.children; - - return this.nodeWORD(children[0]) + this.nodeHexDigit(children[1]) + this.nodeHexDigit(children[2]) + this.nodeHexDigit(children[3]) + this.nodeHexDigit(children[4]); -} - -ObjJCompiler.prototype.nodeRegularExpressionLiteral = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionLiteral); -#endif - var children = astNode.children; - - return this.nodeWORD(children[0]) + this.nodeRegularExpressionBody(children[1]) + this.nodeWORD(children[2]) + this.nodeRegularExpressionFlags(children[3]); -} - -ObjJCompiler.prototype.nodeRegularExpressionBody = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBody); -#endif - var children = astNode.children, - regString = this.nodeRegularExpressionFirstChar(children[0]), - offset = 1, - child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeRegularExpressionChar) - { - regString += this.nodeRegularExpressionChar(child); - child = children[++offset]; - } - return regString; -} - -ObjJCompiler.prototype.nodeRegularExpressionFirstChar = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFirstChar); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeRegularExpressionNonTerminator: - return this.nodeRegularExpressionNonTerminator(child); - case ObjJCompiler.AstNodeRegularExpressionBackslashSequence: - return this.nodeRegularExpressionBackslashSequence(child); - case ObjJCompiler.AstNodeRegularExpressionClass: - return this.nodeRegularExpressionClass(child); - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeRegularExpressionNonTerminator + ", " + ObjJCompiler.AstNodeRegularExpressionBackslashSequence + " or " + ObjJCompiler.AstNodeRegularExpressionClass + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeRegularExpressionChar = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionChar); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeRegularExpressionNonTerminator: - return this.nodeRegularExpressionNonTerminator(child); - case ObjJCompiler.AstNodeRegularExpressionBackslashSequence: - return this.nodeRegularExpressionBackslashSequence(child); - case ObjJCompiler.AstNodeRegularExpressionClass: - return this.nodeRegularExpressionClass(child); - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeRegularExpressionNonTerminator + ", " + ObjJCompiler.AstNodeRegularExpressionBackslashSequence + " or " + ObjJCompiler.AstNodeRegularExpressionClass + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeRegularExpressionBackslashSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionBackslashSequence); -#endif - var children = astNode.children; - - return this.nodeWORD(children[0]) + this.nodeRegularExpressionNonTerminator(children[1]); -} - -ObjJCompiler.prototype.nodeRegularExpressionNonTerminator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionNonTerminator); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeRegularExpressionClass = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClass); -#endif - var children = astNode.children, - offset = 1, - regString = this.nodeWORD(children[0]), - child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeRegularExpressionClassChar) - { - regString += this.nodeRegularExpressionClassChar(children[offset++]); - child = children[offset]; - } - - return regString + this.nodeWORD(child); -} - -ObjJCompiler.prototype.nodeRegularExpressionClassChar = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionClassChar); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeRegularExpressionNonTerminator) - return this.nodeRegularExpressionNonTerminator(child); - else - return this.nodeRegularExpressionBackslashSequence(child); -} - -ObjJCompiler.prototype.nodeRegularExpressionFlags = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRegularExpressionFlags); -#endif - var children = astNode.children, - offset = 0, - regString = "", - child = children[offset]; - - while (child && child.name === ObjJCompiler.AstNodeIdentifierPart) - { - regString += this.nodeIdentifierPart(child); - child = children[++offset]; - } - - return regString; -} - -ObjJCompiler.prototype.nodeUnderline = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnderline); -#endif - var children = astNode.children, - size = children.length; - string = ""; - - for (var i = 0; i < size; i++) - { - var child = children[i], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeWhiteSpace: - string += this.nodeWhiteSpace(child); - break; - case ObjJCompiler.AstNodeLineTerminator: - string += this.nodeLineTerminator(child); - break; - case ObjJCompiler.AstNodeComment: - string += this.nodeComment(child); - break - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeWhiteSpace + ", " + ObjJCompiler.AstNodeLineTerminator + " or " + ObjJCompiler.AstNodeComment + " but got " + child.name, child)); - } - } - // FIXME: Do something smart with this..... -} - -ObjJCompiler.prototype.nodeUnderlineNoLineBreak = function(/*SyntaxNode*/ astNode, /*boolean*/ mustHaveOneSpace) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnderlineNoLineBreak); -#endif - var children = astNode.children, - size = children.length; - string = ""; - - for (var i = 0; i < size; i++) - { - var child = children[i], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeWhiteSpace: - string += this.nodeWhiteSpace(child); - break - case ObjJCompiler.AstNodeSingleLineMultiLineComment: - string += this.nodeSingleLineMultiLineComment(child); - break - case AstSingleLineComment: - string += this.nodeSingleLineComment(child); - break - default: - throw new SyntaxError(this.error_message("Expected node " + ObjJCompiler.AstNodeWhiteSpace + ", " + ObjJCompiler.AstNodeSingleLineMultiLineComment + " or " + ObjJCompiler.AstSingleLineComment + " but got " + child.name, child)); - } - } - // FIXME: Do something smart with this..... -} - -ObjJCompiler.prototype.nodeWhiteSpace = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeWhiteSpace); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeLineTerminator = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminator); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeLineTerminatorSequence = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeLineTerminatorSequence); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeComment = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeComment); -#endif - var child = astNode.children[0]; - - if (child && child.name === ObjJCompiler.AstNodeMultiLineComment) - return this.nodeMultiLineComment(child); - else - return this.nodeSingleLineComment(child); -} - -ObjJCompiler.prototype.nodeMultiLineComment = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeMultiLineComment); -#endif - var children = astNode.children, - size = children.length; - string = ""; - - for (var i = 0; i < size; i++) - { - string += this.nodeWORD(children[i]); - } - - return string; -} - -ObjJCompiler.prototype.nodeSingleLineMultiLineComment = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineMultiLineComment); -#endif - var children = astNode.children, - size = children.length, - string = ""; - - for (var i = 0; i < size; i++) - { - string += this.nodeWORD(children[i]); - } - - return string; -} - -ObjJCompiler.prototype.nodeSingleLineComment = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineComment); -#endif - var children = astNode.children, - size = children.length, - string = children[0]; - - this.nodeWORD(string); - for (var i = 1; i < size; i++) - { - string += this.nodeSingleLineCommentChar(children[i]) - } - - return string; -} - -ObjJCompiler.prototype.nodeSingleLineCommentChar = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSingleLineCommentChar); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeEOS = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEOS); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeUnderline) - { - this.nodeUnderline(child, false); - this.nodeSEMICOLON(children[1]); - } - else - { - this.nodeUnderlineNoLineBreak(child, false); - child = children[1]; - - if (child && child.name === ObjJCompiler.AstNodeLineTerminatorSequence) - this.nodeLineTerminatorSequence(child); - else if (child && child.name === ObjJCompiler.AstNodeEOF) - this.nodeEOF(child); - } -} - -ObjJCompiler.prototype.nodeSemicolonInsertionEOS = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSemicolonInsertionEOS); -#endif - var children = astNode.children, - child = children[1]; - - this.nodeUnderlineNoLineBreak(children[0], false) - if (child && child.name === ObjJCompiler.AstNodeLineTerminatorSequence) - this.nodeLineTerminatorSequence(child); - else if (child && child.name === ObjJCompiler.AstNodeEOF) - this.nodeEOF(child); - else if (children.length > 1) - this.nodeSEMICOLON(child); -} - -ObjJCompiler.prototype.nodeEOF = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeEOF); -#endif -} - -ObjJCompiler.prototype.nodeIdentifier = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIdentifier); -#endif - - return this.nodeIdentifierName(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeIdentifierName = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierName); -#endif - var children = astNode.children, - size = children.length, - string = this.nodeIdentifierStart(children[0]); - - for (var i = 1; i < size; i++) - { - string += this.nodeIdentifierPart(children[i]); - } - - return string; -} - -ObjJCompiler.prototype.nodeIdentifierStart = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierStart); -#endif - var children = astNode.children, - child = children[0]; - - if (child && child.name === ObjJCompiler.AstNodeUnicodeLetter) - return this.nodeUnicodeLetter(child); - else if (child === "\\") - return this.nodeWORD(child) + nodeUnicodeEscapeSequence(children[1]); - else - return this.nodeWORD(child); -} - -ObjJCompiler.prototype.nodeIdentifierPart = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIdentifierPart); -#endif - var child = astNode.children[0], - name = child ? child.name : null; - - switch(name) - { - case ObjJCompiler.AstNodeIdentifierStart: - return this.nodeIdentifierStart(child); - case ObjJCompiler.AstNodeUnicodeCombiningMark: - return this.nodeUnicodeCombiningMark(child); - case ObjJCompiler.AstNodeUnicodeDigit: - return this.nodeUnicodeDigit(child); - case ObjJCompiler.AstNodeUnicodeConnectorPunctuation: - return this.nodeUnicodeConnectorPunctuation(child); - case ObjJCompiler.AstNodeZWNJ: - return this.nodeZWNJ(child); - case ObjJCompiler.AstNodeZWJ: - return this.nodeZWJ(child); - default: - throw new SyntaxError(this.error_message("Expected children of " + ObjJCompiler.AstNodeIdentifierPart + " but got " + child, child)); - } -} - -ObjJCompiler.prototype.nodeZWNJ = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeZWNJ); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeZWJ = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeZWJ); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeUnicodeLetter = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeLetter); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeUnicodeCombiningMark = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeCombiningMark); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeUnicodeDigit = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeDigit); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeUnicodeConnectorPunctuation = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeUnicodeConnectorPunctuation); -#endif - - return this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeFALSE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFALSE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeTRUE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTRUE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeNULL = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNULL); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeBREAK = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeBREAK); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeCONTINUE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCONTINUE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeDEBUGGER = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDEBUGGER); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeIN = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIN); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeINSTANCEOF = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeINSTANCEOF); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeDELETE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDELETE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeFUNCTION = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFUNCTION); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeNEW = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeNEW); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeTHIS = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTHIS); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeTYPEOF = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTYPEOF); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeVOID = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVOID); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeIF = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeIF); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeELSE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeELSE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeDO = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDO); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeWHILE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeWHILE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeFOR = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFOR); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeVAR = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeVAR); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeRETURN = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeRETURN); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeCASE = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCASE); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeDEFAULT = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeDEFAULT); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeSWITCH = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSWITCH); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeTHROW = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTHROW); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeCATCH = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeCATCH); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeFINALLY = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeFINALLY); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeTRY = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeTRY); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeWITH = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeWITH); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeSUPER = function(/*SyntaxNode*/ astNode) -{ -#if DEBUG - this.assertNode(astNode, ObjJCompiler.AstNodeSUPER); -#endif - - this.nodeWORD(astNode.children[0]); -} - -ObjJCompiler.prototype.nodeCOMMA = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeCOLON = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeSEMICOLON = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeOpenParenthesis = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeCloseParenthesis = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeOpenBrace = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeCloseBrace = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeOpenBracket = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeCloseBracket = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeDOT = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeIMPLEMENTATION = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeEND = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeIMPORT = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeOUTLET = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeSELECTOR = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeACCESSORS = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodePROPERTY = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeGETTER = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeSETTER = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeLESSTHEN = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeGREATERTHEN = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeEQUALS = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodePLUS = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeMINUS = function(/*SyntaxNode*/ astNode) -{ - return this.nodeWORD(astNode); -} - -ObjJCompiler.prototype.nodeWORD = function(/*SyntaxNode*/ astNode) -{ -// if (typeof astNode !== "string") -// debugger; - if (this._jsBuffer) - CONCAT(this._jsBuffer, astNode); - if (this._objJBuffer) - CONCAT(this._objJBuffer, astNode); - return astNode; -} - -ObjJCompiler.prototype.getClassDef = function(/* String */ aClassName) -{ - var c = this._classDefs[aClassName]; - - if (c) return c; - - if (objj_getClass) - { - var aClass = objj_getClass(aClassName); - if (aClass) - { - var ivars = class_copyIvarList(aClass), - ivarSize = ivars.length, - myIvars = {}, - superClass = aClass.super_class; - - for (var i = 0; i < ivarSize; i++) - { - var ivar = ivars[i]; - - myIvars[ivar.name] = {"type": ivar.type, "name": ivar.name}; - } - c = {"className": aClassName, "ivars": myIvars}; - - if (superClass) - c.superClassName = superClass.name; - this._classDefs[aClassName] = c; - return c; - } - } - - return null; -// classDef = {"className": className, "superClassName": superClassName, "ivars": {}, "methods": {}}; -} - -ObjJCompiler.prototype.getIvarForCurrentClass = function(/* String */ ivarName) -{ - var c = this._currentClassDef; - - while (c) - { - var ivars = c.ivars; - if (ivars) - { - var ivarDef = ivars[ivarName]; - if (ivarDef) - return ivarDef; - } - c = this.getClassDef(c.superClassName); - } - - return null; -} - -ObjJCompiler.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) -{ - var currentClassMethods = this._currentMethod; - - if (currentClassMethods) - { - var lvarStack = currentClassMethods.lvarStack; - - for (var i = lvarStack.length - 1; i >= 0; i--) - { - var lvars = lvarStack[i]; - - if (lvars && lvars[lvarName]) - { - return lvars[lvarName]; - } - } - // Check the parameters in the method declaration - if (currentClassMethods.parameters && currentClassMethods.parameters[lvarName]) - return currentClassMethods.parameters[lvarName]; - } - - return null; -} - -ObjJCompiler.prototype.createLocalVariable = function(/*Variable*/ variable) -{ - var currentClassMethods = this._currentMethod; - - if (currentClassMethods) - { - var lvarStack = currentClassMethods.lvarStack; - var lvars = lvarStack[lvarStack.length - 1]; // Get last - - var declaredVariable = lvars[variable.identifier]; - if (declaredVariable) - { - // Local variable already declared! Maybe a warning? - } - else - { - lvars[variable.identifier] = variable; - } - } -} - -ObjJCompiler.prototype.executable = function() -{ - if (!this._executable) - this._executable = new Executable(this._jsBuffer ? this._jsBuffer.toString() : null, this._dependencies, this._URL, null, this); - return this._executable; -} - -ObjJCompiler.prototype.IMBuffer = function() -{ - return this._imBuffer; -} - -ObjJCompiler.prototype.JSBuffer = function() -{ - return this._jsBuffer; -} - -ObjJCompiler.prototype.error_message = function(errorMessage, astNode) -{ - return errorMessage + " "; -} diff --git a/Objective-J/Parser.js b/Objective-J/Parser.js deleted file mode 100644 index 4859744ba..000000000 --- a/Objective-J/Parser.js +++ /dev/null @@ -1,382 +0,0 @@ - -var Parser = { }; - -var compiledGrammar = {"table":[[0,"source",1],[0,"start",2],[4,3,4,3],[0,"_",5],[8,6],[6,7],[0,"SourceElements",8],[3,9,10,11],[4,12,13],[0,"WhiteSpace",14],[0,"LineTerminator",15],[0,"Comment",16],[0,"SourceElement",17],[6,18],[2,"[\\u0009\\u000B\\u000C\\u0020\\u00A0\\uFEFF\\u1680\\u180E\\u2000-\\u200A\\u202F\\u205F\\u3000]"],[2,"[\\u000A\\u000D\\u2028\\u2029]"],[3,19,20],[3,21,22],[4,3,12],[0,"MultiLineComment",23],[0,"SingleLineComment",24],[0,"Statement",25],[0,"FunctionDeclaration",26],[4,27,28,29],[4,30,31],[3,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,22,47,48,49],[4,50,3,51,3,52,3,53,3,54,3,55,3,56,3,57],[5,"/*"],[6,58],[5,"*/"],[5,"//"],[6,59],[0,"Block",60],[0,"VariableStatement",61],[0,"EmptyStatement",62],[0,"ExpressionStatement",63],[0,"IfStatement",64],[0,"IterationStatement",65],[0,"ContinueStatement",66],[0,"BreakStatement",67],[0,"ReturnStatement",68],[0,"WithStatement",69],[0,"LabelledStatement",70],[0,"SwitchStatement",71],[0,"ThrowStatement",72],[0,"TryStatement",73],[0,"DebuggerStatement",74],[0,"FunctionExpression",75],[0,"ImportStatement",76],[0,"ClassDeclarationStatement",77],[0,"FUNCTION",78],[0,"Identifier",79],[5,"("],[8,80],[5,")"],[5,"{"],[0,"FunctionBody",2],[5,"}"],[4,81,82],[0,"SingleLineCommentChar",83],[4,55,3,84,3,57],[4,85,3,86,87,88],[5,";"],[4,89,90,88],[4,91,3,52,3,90,3,54,3,21,92],[3,93,94,95,96,97],[4,98,99,100],[4,101,99,100],[4,102,99,103],[4,104,3,52,3,90,3,54,3,21],[4,51,3,105,3,21],[4,106,3,52,3,90,3,54,3,107],[4,108,99,103],[4,109,3,32,3,110],[4,111,88],[4,50,3,112,3,52,3,53,3,54,3,55,3,56,3,57],[4,113,3,114,88],[4,115,3,51,3,116,3,117,3,118,3,119,88],[4,120,121],[4,122,123],[0,"FormalParameterList",124],[9,29],[1],[4,125,82],[8,126],[0,"VAR",127],[0,"VariableDeclaration",128],[6,129],[0,"EOS",130],[9,131],[0,"Expression",132],[0,"IF",133],[8,134],[0,"DoWhileStatement",135],[0,"WhileStatement",136],[0,"ForStatement",137],[0,"ForInStatement",138],[0,"EachStatement",139],[0,"CONTINUE",140],[0,"__",141],[3,142,143],[0,"BREAK",144],[0,"RETURN",145],[3,143,146],[0,"WITH",147],[5,":"],[0,"SWITCH",148],[0,"CaseBlock",149],[0,"THROW",150],[0,"TRY",151],[3,152,153],[0,"DEBUGGER",154],[8,51],[5,"@import"],[3,155,156],[5,"@implementation"],[8,157],[8,158],[0,"ClassBody",159],[5,"@end"],[5,"function"],[9,160],[9,161],[0,"IdentifierName",162],[4,51,163],[9,10],[0,"StatementList",164],[4,165,121],[4,51,166],[4,3,167,3,86],[3,168,169,170,171],[3,55,50],[4,172,173],[4,174,121],[4,3,175,3,21],[4,176,3,21,3,177,3,52,3,90,3,54,88],[4,177,3,52,3,90,3,54,3,21],[4,178,3,52,3,179,3,62,3,180,3,62,3,180,3,54,3,21],[4,178,3,52,3,181,3,182,3,90,3,54,3,21],[4,183,3,52,3,181,3,182,3,90,3,54,3,21],[4,184,121],[6,185],[4,51,88],[0,"SemicolonInsertionEOS",186],[4,187,121],[4,188,121],[4,90,88],[4,189,121],[4,190,121],[4,55,3,191,3,192,3,191,3,57],[4,193,121],[4,194,121],[4,195,196],[0,"Finally",197],[4,198,121],[0,"LocalFilePath",199],[0,"StandardFilePath",200],[3,201,202],[4,55,203,3,57],[8,204],[0,"IdentifierPart",205],[4,206,121],[4,207,208],[6,209],[4,21,210],[5,"var"],[8,211],[5,","],[4,3,62],[4,99,212],[4,99,213],[4,99,214],[0,"AssignmentExpression",215],[6,216],[5,"if"],[0,"ELSE",217],[0,"DO",218],[0,"WHILE",219],[0,"FOR",220],[8,221],[8,90],[0,"ForInFirstExpression",222],[0,"IN",223],[5,"@each"],[5,"continue"],[3,9,224,20],[3,225,169,170,171],[5,"break"],[5,"return"],[5,"with"],[5,"switch"],[8,226],[8,227],[5,"throw"],[5,"try"],[0,"Catch",228],[8,229],[4,230,3,32],[5,"debugger"],[0,"StringLiteral",231],[4,232,3,233,3,234],[0,"SuperclassDeclaration",235],[0,"CategoryDeclaration",236],[6,237],[0,"ClassElements",238],[3,207,239,240,241,242,243],[0,"ReservedWord",244],[0,"IdentifierStart",245],[6,160],[4,3,167,3,51],[6,246],[4,3,247,248,3,172],[0,"LineTerminatorSequence",249],[10,57],[0,"EOF",250],[3,251,252],[4,3,167,3,172],[4,253,121],[4,254,121],[4,255,121],[4,256,121],[0,"ForFirstExpression",257],[3,258,259],[4,260,121],[0,"SingleLineMultiLineComment",261],[4,99,62],[0,"CaseClauses",262],[0,"DefaultClause",263],[4,264,3,52,3,51,3,54,3,32],[4,3,153],[0,"FINALLY",265],[3,266,267],[5,"<"],[6,268],[5,">"],[4,105,3,51],[4,52,3,51,3,54],[4,3,269],[4,270,271],[0,"UnicodeCombiningMark",272],[0,"UnicodeDigit",273],[0,"UnicodeConnectorPunctuation",274],[0,"ZWNJ",275],[0,"ZWJ",276],[3,277,278,279,280],[3,281,282,283],[4,3,21],[5,"="],[9,247],[3,284,285,286,287,288],[9,82],[4,258,3,289,3,172],[0,"ConditionalExpression",290],[5,"else"],[5,"do"],[5,"while"],[5,"for"],[3,291,292],[0,"LeftHandSideExpression",293],[4,85,3,294],[5,"in"],[4,27,295,29],[4,296,297],[4,298,3,105,299],[0,"CATCH",300],[4,301,121],[4,302,303,304,303],[4,305,306,305],[3,307,308],[0,"CompoundIvarDeclaration",309],[0,"ClassElement",310],[6,311],[3,312,313,314,315,316,317],[3,318,319,320,321],[2,"[\\u005F\\u203F\\u2040\\u2054\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFF3F]"],[5,"\u200C"],[5,"\u200D"],[0,"Keyword",322],[0,"FutureReservedWord",323],[0,"NullLiteral",324],[0,"BooleanLiteral",325],[0,"UnicodeLetter",326],[2,"[$_]"],[4,327,328],[5,"\n"],[4,288,329],[5,"\u2028"],[5,"\u2029"],[5,"\r"],[0,"AssignmentOperator",330],[4,331,332],[0,"ExpressionNoIn",333],[4,85,3,334],[3,335,336],[0,"VariableDeclarationNoIn",337],[6,338],[0,"CaseClause",339],[6,340],[0,"DEFAULT",341],[8,342],[4,343,121],[5,"finally"],[8,344],[5,"\""],[6,345],[5,"'"],[6,346],[5,"\\>"],[4,347,82],[4,348,3,349,350,88],[3,351,352,21,22],[4,3,270],[2,"[\\u0300-\\u036F\\u0483-\\u0487\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u0610-\\u061A\\u064B-\\u065F\\u0670\\u06D6-\\u06DC\\u06DF-\\u06E4\\u06E7\\u06E8\\u06EA-\\u06ED\\u0711\\u0730-\\u074A\\u07A6-\\u07B0\\u07EB-\\u07F3\\u0816-\\u0819\\u081B-\\u0823\\u0825-\\u0827\\u0829-\\u082D\\u0859-\\u085B\\u0900-\\u0902\\u093A\\u093C\\u0941-\\u0948\\u094D\\u0951-\\u0957\\u0962\\u0963\\u0981\\u09BC\\u09C1-\\u09C4\\u09CD\\u09E2\\u09E3\\u0A01\\u0A02\\u0A3C\\u0A41\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A70\\u0A71\\u0A75\\u0A81\\u0A82\\u0ABC\\u0AC1-\\u0AC5\\u0AC7\\u0AC8\\u0ACD\\u0AE2\\u0AE3\\u0B01\\u0B3C\\u0B3F\\u0B41-\\u0B44\\u0B4D\\u0B56\\u0B62\\u0B63\\u0B82\\u0BC0\\u0BCD\\u0C3E-\\u0C40\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C62\\u0C63\\u0CBC\\u0CBF\\u0CC6\\u0CCC\\u0CCD\\u0CE2\\u0CE3\\u0D41-\\u0D44\\u0D4D\\u0D62\\u0D63\\u0DCA\\u0DD2-\\u0DD4\\u0DD6\\u0E31\\u0E34-\\u0E3A\\u0E47-\\u0E4E\\u0EB1\\u0EB4-\\u0EB9\\u0EBB\\u0EBC\\u0EC8-\\u0ECD\\u0F18\\u0F19\\u0F35\\u0F37\\u0F39\\u0F71-\\u0F7E\\u0F80-\\u0F84\\u0F86\\u0F87\\u0F8D-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u102D-\\u1030\\u1032-\\u1037\\u1039\\u103A\\u103D\\u103E\\u1058\\u1059\\u105E-\\u1060\\u1071-\\u1074\\u1082\\u1085\\u1086\\u108D\\u109D\\u135D-\\u135F\\u1712-\\u1714\\u1732-\\u1734\\u1752\\u1753\\u1772\\u1773\\u17B7-\\u17BD\\u17C6\\u17C9-\\u17D3\\u17DD\\u180B-\\u180D\\u18A9\\u1920-\\u1922\\u1927\\u1928\\u1932\\u1939-\\u193B\\u1A17\\u1A18\\u1A56\\u1A58-\\u1A5E\\u1A60\\u1A62\\u1A65-\\u1A6C\\u1A73-\\u1A7C\\u1A7F\\u1B00-\\u1B03\\u1B34\\u1B36-\\u1B3A\\u1B3C\\u1B42\\u1B6B-\\u1B73\\u1B80\\u1B81\\u1BA2-\\u1BA5\\u1BA8\\u1BA9\\u1BE6\\u1BE8\\u1BE9\\u1BED\\u1BEF-\\u1BF1\\u1C2C-\\u1C33\\u1C36\\u1C37\\u1CD0-\\u1CD2\\u1CD4-\\u1CE0\\u1CE2-\\u1CE8\\u1CED\\u1DC0-\\u1DE6\\u1DFC-\\u1DFF\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2CEF-\\u2CF1\\u2D7F\\u2DE0-\\u2DFF\\u302A-\\u302F\\u3099\\u309A\\uA66F\\uA67C\\uA67D\\uA6F0\\uA6F1\\uA802\\uA806\\uA80B\\uA825\\uA826\\uA8C4\\uA8E0-\\uA8F1\\uA926-\\uA92D\\uA947-\\uA951\\uA980-\\uA982\\uA9B3\\uA9B6-\\uA9B9\\uA9BC\\uAA29-\\uAA2E\\uAA31\\uAA32\\uAA35\\uAA36\\uAA43\\uAA4C\\uAAB0\\uAAB2-\\uAAB4\\uAAB7\\uAAB8\\uAABE\\uAABF\\uAAC1\\uABE5\\uABE8\\uABED\\uFB1E\\uFE00-\\uFE0F\\uFE20-\\uFE26\\u0903\\u093B\\u093E-\\u0940\\u0949-\\u094C\\u094E\\u094F\\u0982\\u0983\\u09BE-\\u09C0\\u09C7\\u09C8\\u09CB\\u09CC\\u09D7\\u0A03\\u0A3E-\\u0A40\\u0A83\\u0ABE-\\u0AC0\\u0AC9\\u0ACB\\u0ACC\\u0B02\\u0B03\\u0B3E\\u0B40\\u0B47\\u0B48\\u0B4B\\u0B4C\\u0B57\\u0BBE\\u0BBF\\u0BC1\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCC\\u0BD7\\u0C01-\\u0C03\\u0C41-\\u0C44\\u0C82\\u0C83\\u0CBE\\u0CC0-\\u0CC4\\u0CC7\\u0CC8\\u0CCA\\u0CCB\\u0CD5\\u0CD6\\u0D02\\u0D03\\u0D3E-\\u0D40\\u0D46-\\u0D48\\u0D4A-\\u0D4C\\u0D57\\u0D82\\u0D83\\u0DCF-\\u0DD1\\u0DD8-\\u0DDF\\u0DF2\\u0DF3\\u0F3E\\u0F3F\\u0F7F\\u102B\\u102C\\u1031\\u1038\\u103B\\u103C\\u1056\\u1057\\u1062-\\u1064\\u1067-\\u106D\\u1083\\u1084\\u1087-\\u108C\\u108F\\u109A-\\u109C\\u17B6\\u17BE-\\u17C5\\u17C7\\u17C8\\u1923-\\u1926\\u1929-\\u192B\\u1930\\u1931\\u1933-\\u1938\\u19B0-\\u19C0\\u19C8\\u19C9\\u1A19-\\u1A1B\\u1A55\\u1A57\\u1A61\\u1A63\\u1A64\\u1A6D-\\u1A72\\u1B04\\u1B35\\u1B3B\\u1B3D-\\u1B41\\u1B43\\u1B44\\u1B82\\u1BA1\\u1BA6\\u1BA7\\u1BAA\\u1BE7\\u1BEA-\\u1BEC\\u1BEE\\u1BF2\\u1BF3\\u1C24-\\u1C2B\\u1C34\\u1C35\\u1CE1\\u1CF2\\uA823\\uA824\\uA827\\uA880\\uA881\\uA8B4-\\uA8C3\\uA952\\uA953\\uA983\\uA9B4\\uA9B5\\uA9BA\\uA9BB\\uA9BD-\\uA9C0\\uAA2F\\uAA30\\uAA33\\uAA34\\uAA4D\\uAA7B\\uABE3\\uABE4\\uABE6\\uABE7\\uABE9\\uABEA\\uABEC]"],[4,353,354],[4,355,356],[4,357,358],[4,359,360],[4,361,362],[2,"[\\u0030-\\u0039\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]"],[4,363,364],[4,357,365],[4,366,367],[3,187,368,343,184,198,369,370,254,253,301,256,120,174,371,260,372,188,190,373,193,194,374,165,375,255,189],[3,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405],[0,"NULL",406],[3,407,408],[3,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426],[5,"\\"],[0,"UnicodeEscapeSequence",427],[8,284],[3,428,429,430,431,432,433,434,435,436,437,438,439],[0,"LogicalOrExpression",440],[8,441],[4,442,443],[0,"VariableDeclarationListNoIn",444],[0,"CallExpression",445],[0,"NewExpression",446],[4,51,447],[4,81,125,82],[4,448,3,90,3,105,299],[4,3,296],[4,369,121],[4,3,126],[5,"catch"],[4,449,3],[0,"DoubleStringCharacter",450],[0,"SingleStringCharacter",451],[9,234],[0,"IvarType",452],[0,"IvarDeclaration",453],[6,454],[0,"ClassMethodDeclaration",455],[0,"InstanceMethodDeclaration",456],[5,"\uDB40"],[2,"[\\uDD00-\\uDDEF]"],[5,"\uD834"],[2,"[\\uDD67-\\uDD69\\uDD7B-\\uDD82\\uDD85-\\uDD8B\\uDDAA-\\uDDAD\\uDE42-\\uDE44\\uDD65\\uDD66\\uDD6D-\\uDD72]"],[5,"\uD804"],[2,"[\\uDC01\\uDC38-\\uDC46\\uDC80\\uDC81\\uDCB3-\\uDCB6\\uDCB9\\uDCBA\\uDC00\\uDC02\\uDC82\\uDCB0-\\uDCB2\\uDCB7\\uDCB8]"],[5,"\uD800"],[2,"[\\uDDFD]"],[5,"\uD802"],[2,"[\\uDE01-\\uDE03\\uDE05\\uDE06\\uDE0C-\\uDE0F\\uDE38-\\uDE3A\\uDE3F]"],[5,"\uD835"],[2,"[\\uDFCE-\\uDFFF]"],[2,"[\\uDC66-\\uDC6F]"],[5,"\uD801"],[2,"[\\uDCA0-\\uDCA9]"],[5,"case"],[5,"default"],[5,"delete"],[5,"instanceof"],[5,"new"],[5,"this"],[5,"typeof"],[5,"void"],[5,"abstract"],[5,"boolean"],[5,"byte"],[5,"char"],[5,"class"],[5,"const"],[5,"double"],[5,"enum"],[5,"export"],[5,"extends"],[5,"final"],[5,"float"],[5,"goto"],[5,"implements"],[5,"import"],[5,"interface"],[5,"int"],[5,"long"],[5,"native"],[5,"package"],[5,"private"],[5,"protected"],[5,"public"],[5,"short"],[5,"static"],[5,"super"],[5,"synchronized"],[5,"throws"],[5,"transient"],[5,"volatile"],[4,457,121],[0,"TRUE",458],[0,"FALSE",459],[2,"[\\u0041-\\u005A\\u00C0-\\u00D6\\u00D8-\\u00DE\\u0100\\u0102\\u0104\\u0106\\u0108\\u010A\\u010C\\u010E\\u0110\\u0112\\u0114\\u0116\\u0118\\u011A\\u011C\\u011E\\u0120\\u0122\\u0124\\u0126\\u0128\\u012A\\u012C\\u012E\\u0130\\u0132\\u0134\\u0136\\u0139\\u013B\\u013D\\u013F\\u0141\\u0143\\u0145\\u0147\\u014A\\u014C\\u014E\\u0150\\u0152\\u0154\\u0156\\u0158\\u015A\\u015C\\u015E\\u0160\\u0162\\u0164\\u0166\\u0168\\u016A\\u016C\\u016E\\u0170\\u0172\\u0174\\u0176\\u0178\\u0179\\u017B\\u017D\\u0181\\u0182\\u0184\\u0186\\u0187\\u0189-\\u018B\\u018E-\\u0191\\u0193\\u0194\\u0196-\\u0198\\u019C\\u019D\\u019F\\u01A0\\u01A2\\u01A4\\u01A6\\u01A7\\u01A9\\u01AC\\u01AE\\u01AF\\u01B1-\\u01B3\\u01B5\\u01B7\\u01B8\\u01BC\\u01C4\\u01C7\\u01CA\\u01CD\\u01CF\\u01D1\\u01D3\\u01D5\\u01D7\\u01D9\\u01DB\\u01DE\\u01E0\\u01E2\\u01E4\\u01E6\\u01E8\\u01EA\\u01EC\\u01EE\\u01F1\\u01F4\\u01F6-\\u01F8\\u01FA\\u01FC\\u01FE\\u0200\\u0202\\u0204\\u0206\\u0208\\u020A\\u020C\\u020E\\u0210\\u0212\\u0214\\u0216\\u0218\\u021A\\u021C\\u021E\\u0220\\u0222\\u0224\\u0226\\u0228\\u022A\\u022C\\u022E\\u0230\\u0232\\u023A\\u023B\\u023D\\u023E\\u0241\\u0243-\\u0246\\u0248\\u024A\\u024C\\u024E\\u0370\\u0372\\u0376\\u0386\\u0388-\\u038A\\u038C\\u038E\\u038F\\u0391-\\u03A1\\u03A3-\\u03AB\\u03CF\\u03D2-\\u03D4\\u03D8\\u03DA\\u03DC\\u03DE\\u03E0\\u03E2\\u03E4\\u03E6\\u03E8\\u03EA\\u03EC\\u03EE\\u03F4\\u03F7\\u03F9\\u03FA\\u03FD-\\u042F\\u0460\\u0462\\u0464\\u0466\\u0468\\u046A\\u046C\\u046E\\u0470\\u0472\\u0474\\u0476\\u0478\\u047A\\u047C\\u047E\\u0480\\u048A\\u048C\\u048E\\u0490\\u0492\\u0494\\u0496\\u0498\\u049A\\u049C\\u049E\\u04A0\\u04A2\\u04A4\\u04A6\\u04A8\\u04AA\\u04AC\\u04AE\\u04B0\\u04B2\\u04B4\\u04B6\\u04B8\\u04BA\\u04BC\\u04BE\\u04C0\\u04C1\\u04C3\\u04C5\\u04C7\\u04C9\\u04CB\\u04CD\\u04D0\\u04D2\\u04D4\\u04D6\\u04D8\\u04DA\\u04DC\\u04DE\\u04E0\\u04E2\\u04E4\\u04E6\\u04E8\\u04EA\\u04EC\\u04EE\\u04F0\\u04F2\\u04F4\\u04F6\\u04F8\\u04FA\\u04FC\\u04FE\\u0500\\u0502\\u0504\\u0506\\u0508\\u050A\\u050C\\u050E\\u0510\\u0512\\u0514\\u0516\\u0518\\u051A\\u051C\\u051E\\u0520\\u0522\\u0524\\u0526\\u0531-\\u0556\\u10A0-\\u10C5\\u1E00\\u1E02\\u1E04\\u1E06\\u1E08\\u1E0A\\u1E0C\\u1E0E\\u1E10\\u1E12\\u1E14\\u1E16\\u1E18\\u1E1A\\u1E1C\\u1E1E\\u1E20\\u1E22\\u1E24\\u1E26\\u1E28\\u1E2A\\u1E2C\\u1E2E\\u1E30\\u1E32\\u1E34\\u1E36\\u1E38\\u1E3A\\u1E3C\\u1E3E\\u1E40\\u1E42\\u1E44\\u1E46\\u1E48\\u1E4A\\u1E4C\\u1E4E\\u1E50\\u1E52\\u1E54\\u1E56\\u1E58\\u1E5A\\u1E5C\\u1E5E\\u1E60\\u1E62\\u1E64\\u1E66\\u1E68\\u1E6A\\u1E6C\\u1E6E\\u1E70\\u1E72\\u1E74\\u1E76\\u1E78\\u1E7A\\u1E7C\\u1E7E\\u1E80\\u1E82\\u1E84\\u1E86\\u1E88\\u1E8A\\u1E8C\\u1E8E\\u1E90\\u1E92\\u1E94\\u1E9E\\u1EA0\\u1EA2\\u1EA4\\u1EA6\\u1EA8\\u1EAA\\u1EAC\\u1EAE\\u1EB0\\u1EB2\\u1EB4\\u1EB6\\u1EB8\\u1EBA\\u1EBC\\u1EBE\\u1EC0\\u1EC2\\u1EC4\\u1EC6\\u1EC8\\u1ECA\\u1ECC\\u1ECE\\u1ED0\\u1ED2\\u1ED4\\u1ED6\\u1ED8\\u1EDA\\u1EDC\\u1EDE\\u1EE0\\u1EE2\\u1EE4\\u1EE6\\u1EE8\\u1EEA\\u1EEC\\u1EEE\\u1EF0\\u1EF2\\u1EF4\\u1EF6\\u1EF8\\u1EFA\\u1EFC\\u1EFE\\u1F08-\\u1F0F\\u1F18-\\u1F1D\\u1F28-\\u1F2F\\u1F38-\\u1F3F\\u1F48-\\u1F4D\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F68-\\u1F6F\\u1FB8-\\u1FBB\\u1FC8-\\u1FCB\\u1FD8-\\u1FDB\\u1FE8-\\u1FEC\\u1FF8-\\u1FFB\\u2102\\u2107\\u210B-\\u210D\\u2110-\\u2112\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u2130-\\u2133\\u213E\\u213F\\u2145\\u2183\\u2C00-\\u2C2E\\u2C60\\u2C62-\\u2C64\\u2C67\\u2C69\\u2C6B\\u2C6D-\\u2C70\\u2C72\\u2C75\\u2C7E-\\u2C80\\u2C82\\u2C84\\u2C86\\u2C88\\u2C8A\\u2C8C\\u2C8E\\u2C90\\u2C92\\u2C94\\u2C96\\u2C98\\u2C9A\\u2C9C\\u2C9E\\u2CA0\\u2CA2\\u2CA4\\u2CA6\\u2CA8\\u2CAA\\u2CAC\\u2CAE\\u2CB0\\u2CB2\\u2CB4\\u2CB6\\u2CB8\\u2CBA\\u2CBC\\u2CBE\\u2CC0\\u2CC2\\u2CC4\\u2CC6\\u2CC8\\u2CCA\\u2CCC\\u2CCE\\u2CD0\\u2CD2\\u2CD4\\u2CD6\\u2CD8\\u2CDA\\u2CDC\\u2CDE\\u2CE0\\u2CE2\\u2CEB\\u2CED\\uA640\\uA642\\uA644\\uA646\\uA648\\uA64A\\uA64C\\uA64E\\uA650\\uA652\\uA654\\uA656\\uA658\\uA65A\\uA65C\\uA65E\\uA660\\uA662\\uA664\\uA666\\uA668\\uA66A\\uA66C\\uA680\\uA682\\uA684\\uA686\\uA688\\uA68A\\uA68C\\uA68E\\uA690\\uA692\\uA694\\uA696\\uA722\\uA724\\uA726\\uA728\\uA72A\\uA72C\\uA72E\\uA732\\uA734\\uA736\\uA738\\uA73A\\uA73C\\uA73E\\uA740\\uA742\\uA744\\uA746\\uA748\\uA74A\\uA74C\\uA74E\\uA750\\uA752\\uA754\\uA756\\uA758\\uA75A\\uA75C\\uA75E\\uA760\\uA762\\uA764\\uA766\\uA768\\uA76A\\uA76C\\uA76E\\uA779\\uA77B\\uA77D\\uA77E\\uA780\\uA782\\uA784\\uA786\\uA78B\\uA78D\\uA790\\uA7A0\\uA7A2\\uA7A4\\uA7A6\\uA7A8\\uFF21-\\uFF3A\\u0061-\\u007A\\u00AA\\u00B5\\u00BA\\u00DF-\\u00F6\\u00F8-\\u00FF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F-\\u0293\\u0295-\\u02AF\\u0371\\u0373\\u0377\\u037B-\\u037D\\u0390\\u03AC-\\u03CE\\u03D0\\u03D1\\u03D5-\\u03D7\\u03D9\\u03DB\\u03DD\\u03DF\\u03E1\\u03E3\\u03E5\\u03E7\\u03E9\\u03EB\\u03ED\\u03EF-\\u03F3\\u03F5\\u03F8\\u03FB\\u03FC\\u0430-\\u045F\\u0461\\u0463\\u0465\\u0467\\u0469\\u046B\\u046D\\u046F\\u0471\\u0473\\u0475\\u0477\\u0479\\u047B\\u047D\\u047F\\u0481\\u048B\\u048D\\u048F\\u0491\\u0493\\u0495\\u0497\\u0499\\u049B\\u049D\\u049F\\u04A1\\u04A3\\u04A5\\u04A7\\u04A9\\u04AB\\u04AD\\u04AF\\u04B1\\u04B3\\u04B5\\u04B7\\u04B9\\u04BB\\u04BD\\u04BF\\u04C2\\u04C4\\u04C6\\u04C8\\u04CA\\u04CC\\u04CE\\u04CF\\u04D1\\u04D3\\u04D5\\u04D7\\u04D9\\u04DB\\u04DD\\u04DF\\u04E1\\u04E3\\u04E5\\u04E7\\u04E9\\u04EB\\u04ED\\u04EF\\u04F1\\u04F3\\u04F5\\u04F7\\u04F9\\u04FB\\u04FD\\u04FF\\u0501\\u0503\\u0505\\u0507\\u0509\\u050B\\u050D\\u050F\\u0511\\u0513\\u0515\\u0517\\u0519\\u051B\\u051D\\u051F\\u0521\\u0523\\u0525\\u0527\\u0561-\\u0587\\u1D00-\\u1D2B\\u1D62-\\u1D77\\u1D79-\\u1D9A\\u1E01\\u1E03\\u1E05\\u1E07\\u1E09\\u1E0B\\u1E0D\\u1E0F\\u1E11\\u1E13\\u1E15\\u1E17\\u1E19\\u1E1B\\u1E1D\\u1E1F\\u1E21\\u1E23\\u1E25\\u1E27\\u1E29\\u1E2B\\u1E2D\\u1E2F\\u1E31\\u1E33\\u1E35\\u1E37\\u1E39\\u1E3B\\u1E3D\\u1E3F\\u1E41\\u1E43\\u1E45\\u1E47\\u1E49\\u1E4B\\u1E4D\\u1E4F\\u1E51\\u1E53\\u1E55\\u1E57\\u1E59\\u1E5B\\u1E5D\\u1E5F\\u1E61\\u1E63\\u1E65\\u1E67\\u1E69\\u1E6B\\u1E6D\\u1E6F\\u1E71\\u1E73\\u1E75\\u1E77\\u1E79\\u1E7B\\u1E7D\\u1E7F\\u1E81\\u1E83\\u1E85\\u1E87\\u1E89\\u1E8B\\u1E8D\\u1E8F\\u1E91\\u1E93\\u1E95-\\u1E9D\\u1E9F\\u1EA1\\u1EA3\\u1EA5\\u1EA7\\u1EA9\\u1EAB\\u1EAD\\u1EAF\\u1EB1\\u1EB3\\u1EB5\\u1EB7\\u1EB9\\u1EBB\\u1EBD\\u1EBF\\u1EC1\\u1EC3\\u1EC5\\u1EC7\\u1EC9\\u1ECB\\u1ECD\\u1ECF\\u1ED1\\u1ED3\\u1ED5\\u1ED7\\u1ED9\\u1EDB\\u1EDD\\u1EDF\\u1EE1\\u1EE3\\u1EE5\\u1EE7\\u1EE9\\u1EEB\\u1EED\\u1EEF\\u1EF1\\u1EF3\\u1EF5\\u1EF7\\u1EF9\\u1EFB\\u1EFD\\u1EFF-\\u1F07\\u1F10-\\u1F15\\u1F20-\\u1F27\\u1F30-\\u1F37\\u1F40-\\u1F45\\u1F50-\\u1F57\\u1F60-\\u1F67\\u1F70-\\u1F7D\\u1F80-\\u1F87\\u1F90-\\u1F97\\u1FA0-\\u1FA7\\u1FB0-\\u1FB4\\u1FB6\\u1FB7\\u1FBE\\u1FC2-\\u1FC4\\u1FC6\\u1FC7\\u1FD0-\\u1FD3\\u1FD6\\u1FD7\\u1FE0-\\u1FE7\\u1FF2-\\u1FF4\\u1FF6\\u1FF7\\u210A\\u210E\\u210F\\u2113\\u212F\\u2134\\u2139\\u213C\\u213D\\u2146-\\u2149\\u214E\\u2184\\u2C30-\\u2C5E\\u2C61\\u2C65\\u2C66\\u2C68\\u2C6A\\u2C6C\\u2C71\\u2C73\\u2C74\\u2C76-\\u2C7C\\u2C81\\u2C83\\u2C85\\u2C87\\u2C89\\u2C8B\\u2C8D\\u2C8F\\u2C91\\u2C93\\u2C95\\u2C97\\u2C99\\u2C9B\\u2C9D\\u2C9F\\u2CA1\\u2CA3\\u2CA5\\u2CA7\\u2CA9\\u2CAB\\u2CAD\\u2CAF\\u2CB1\\u2CB3\\u2CB5\\u2CB7\\u2CB9\\u2CBB\\u2CBD\\u2CBF\\u2CC1\\u2CC3\\u2CC5\\u2CC7\\u2CC9\\u2CCB\\u2CCD\\u2CCF\\u2CD1\\u2CD3\\u2CD5\\u2CD7\\u2CD9\\u2CDB\\u2CDD\\u2CDF\\u2CE1\\u2CE3\\u2CE4\\u2CEC\\u2CEE\\u2D00-\\u2D25\\uA641\\uA643\\uA645\\uA647\\uA649\\uA64B\\uA64D\\uA64F\\uA651\\uA653\\uA655\\uA657\\uA659\\uA65B\\uA65D\\uA65F\\uA661\\uA663\\uA665\\uA667\\uA669\\uA66B\\uA66D\\uA681\\uA683\\uA685\\uA687\\uA689\\uA68B\\uA68D\\uA68F\\uA691\\uA693\\uA695\\uA697\\uA723\\uA725\\uA727\\uA729\\uA72B\\uA72D\\uA72F-\\uA731\\uA733\\uA735\\uA737\\uA739\\uA73B\\uA73D\\uA73F\\uA741\\uA743\\uA745\\uA747\\uA749\\uA74B\\uA74D\\uA74F\\uA751\\uA753\\uA755\\uA757\\uA759\\uA75B\\uA75D\\uA75F\\uA761\\uA763\\uA765\\uA767\\uA769\\uA76B\\uA76D\\uA76F\\uA771-\\uA778\\uA77A\\uA77C\\uA77F\\uA781\\uA783\\uA785\\uA787\\uA78C\\uA78E\\uA791\\uA7A1\\uA7A3\\uA7A5\\uA7A7\\uA7A9\\uA7FA\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFF41-\\uFF5A\\u01C5\\u01C8\\u01CB\\u01F2\\u1F88-\\u1F8F\\u1F98-\\u1F9F\\u1FA8-\\u1FAF\\u1FBC\\u1FCC\\u1FFC\\u02B0-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0374\\u037A\\u0559\\u0640\\u06E5\\u06E6\\u07F4\\u07F5\\u07FA\\u081A\\u0824\\u0828\\u0971\\u0E46\\u0EC6\\u10FC\\u17D7\\u1843\\u1AA7\\u1C78-\\u1C7D\\u1D2C-\\u1D61\\u1D78\\u1D9B-\\u1DBF\\u2071\\u207F\\u2090-\\u209C\\u2C7D\\u2D6F\\u2E2F\\u3005\\u3031-\\u3035\\u303B\\u309D\\u309E\\u30FC-\\u30FE\\uA015\\uA4F8-\\uA4FD\\uA60C\\uA67F\\uA717-\\uA71F\\uA770\\uA788\\uA9CF\\uAA70\\uAADD\\uFF70\\uFF9E\\uFF9F\\u01BB\\u01C0-\\u01C3\\u0294\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u063F\\u0641-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u0800-\\u0815\\u0840-\\u0858\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0972-\\u0977\\u0979-\\u097F\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C33\\u0C35-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E45\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EDC\\u0EDD\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10D0-\\u10FA\\u1100-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17DC\\u1820-\\u1842\\u1844-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191C\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BC0-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C77\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u2135-\\u2138\\u2D30-\\u2D65\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u3006\\u303C\\u3041-\\u3096\\u309F\\u30A1-\\u30FA\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400\\u4DB5\\u4E00\\u9FCB\\uA000-\\uA014\\uA016-\\uA48C\\uA4D0-\\uA4F7\\uA500-\\uA60B\\uA610-\\uA61F\\uA62A\\uA62B\\uA66E\\uA6A0-\\uA6E5\\uA7FB-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA6F\\uAA71-\\uAA76\\uAA7A\\uAA80-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB\\uAADC\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uABC0-\\uABE2\\uAC00\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA2D\\uFA30-\\uFA6D\\uFA70-\\uFAD9\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF66-\\uFF6F\\uFF71-\\uFF9D\\uFFA0-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC\\u16EE-\\u16F0\\u2160-\\u2182\\u2185-\\u2188\\u3007\\u3021-\\u3029\\u3038-\\u303A\\uA6E6-\\uA6EF]"],[4,460,461],[4,462,463],[4,464,465],[4,466,467],[4,363,468],[4,357,469],[4,359,470],[4,471,472],[4,366,473],[4,474,475],[4,476,477],[4,478,479],[4,480,481],[4,482,483],[4,484,485],[4,361,486],[4,487,488],[4,489,490,490,490,490],[4,247,248],[5,"*="],[5,"/="],[5,"%="],[5,"+="],[5,"-="],[5,"<<="],[5,">>="],[5,">>>="],[5,"&="],[5,"^="],[5,"|="],[4,491,492],[4,3,493,3,172,3,105,3,172],[0,"AssignmentExpressionNoIn",494],[6,495],[4,294,496],[4,497,3,498,499],[3,497,500],[8,501],[0,"CASE",502],[5,"@"],[3,503,504,505],[3,506,504,505],[4,507,508],[4,51,3,509],[4,3,167,3,349],[4,510,511,3,512,3,513,3,55,3,56,3,57],[4,514,511,3,512,3,513,3,55,3,56,3,57],[5,"null"],[4,515,121],[4,516,121],[5,"\uD82C"],[2,"[\\uDC00\\uDC01]"],[5,"\uD808"],[2,"[\\uDC00-\\uDF6E]"],[5,"\uD869"],[2,"[\\uDED6\\uDF00]"],[5,"\uD809"],[2,"[\\uDC00-\\uDC62]"],[2,"[\\uDC00-\\uDC19\\uDC34-\\uDC4D\\uDC68-\\uDC81\\uDC9C\\uDC9E\\uDC9F\\uDCA2\\uDCA5\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB5\\uDCD0-\\uDCE9\\uDD04\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD38\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD6C-\\uDD85\\uDDA0-\\uDDB9\\uDDD4-\\uDDED\\uDE08-\\uDE21\\uDE3C-\\uDE55\\uDE70-\\uDE89\\uDEA8-\\uDEC0\\uDEE2-\\uDEFA\\uDF1C-\\uDF34\\uDF56-\\uDF6E\\uDF90-\\uDFA8\\uDFCA\\uDC1A-\\uDC33\\uDC4E-\\uDC54\\uDC56-\\uDC67\\uDC82-\\uDC9B\\uDCB6-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDCEA-\\uDD03\\uDD1E-\\uDD37\\uDD52-\\uDD6B\\uDD86-\\uDD9F\\uDDBA-\\uDDD3\\uDDEE-\\uDE07\\uDE22-\\uDE3B\\uDE56-\\uDE6F\\uDE8A-\\uDEA5\\uDEC2-\\uDEDA\\uDEDC-\\uDEE1\\uDEFC-\\uDF14\\uDF16-\\uDF1B\\uDF36-\\uDF4E\\uDF50-\\uDF55\\uDF70-\\uDF88\\uDF8A-\\uDF8F\\uDFAA-\\uDFC2\\uDFC4-\\uDFC9\\uDFCB]"],[2,"[\\uDC03-\\uDC37\\uDC83-\\uDCAF]"],[2,"[\\uDC00-\\uDC0B\\uDC0D-\\uDC26\\uDC28-\\uDC3A\\uDC3C\\uDC3D\\uDC3F-\\uDC4D\\uDC50-\\uDC5D\\uDC80-\\uDCFA\\uDE80-\\uDE9C\\uDEA0-\\uDED0\\uDF00-\\uDF1E\\uDF30-\\uDF40\\uDF42-\\uDF49\\uDF80-\\uDF9D\\uDFA0-\\uDFC3\\uDFC8-\\uDFCF\\uDD40-\\uDD74\\uDF41\\uDF4A\\uDFD1-\\uDFD5]"],[5,"\uD80C"],[2,"[\\uDC00-\\uDFFF]"],[2,"[\\uDC00-\\uDC9D]"],[5,"\uD86E"],[2,"[\\uDC1D]"],[5,"\uD803"],[2,"[\\uDC00-\\uDC48]"],[5,"\uD840"],[2,"[\\uDC00]"],[5,"\uD87E"],[2,"[\\uDC00-\\uDE1D]"],[5,"\uD86D"],[2,"[\\uDF34\\uDF40]"],[5,"\uD81A"],[2,"[\\uDC00-\\uDE38]"],[2,"[\\uDC00-\\uDC05\\uDC08\\uDC0A-\\uDC35\\uDC37\\uDC38\\uDC3C\\uDC3F-\\uDC55\\uDD00-\\uDD15\\uDD20-\\uDD39\\uDE00\\uDE10-\\uDE13\\uDE15-\\uDE17\\uDE19-\\uDE33\\uDE60-\\uDE7C\\uDF00-\\uDF35\\uDF40-\\uDF55\\uDF60-\\uDF72]"],[5,"\uD80D"],[2,"[\\uDC00-\\uDC2E]"],[5,"u"],[0,"HexDigit",517],[0,"LogicalAndExpression",518],[6,519],[5,"?"],[3,520,521],[4,3,167,3,442],[6,522],[0,"MemberExpression",523],[0,"Arguments",524],[6,525],[4,526,3,336],[4,3,247,248,3,442],[4,368,121],[4,527,82],[4,327,528],[0,"LineContinuation",529],[4,530,82],[0,"IvarTypeElement",531],[6,532],[8,533],[5,"+"],[8,534],[0,"MethodSelector",535],[8,62],[5,"-"],[5,"true"],[5,"false"],[2,"[0-9a-fA-F]"],[4,536,537],[4,3,538,3,491],[4,258,3,289,3,442],[0,"ConditionalExpressionNoIn",539],[4,3,167,3,294],[4,540,541],[4,52,3,542,3,54],[4,3,543],[0,"NEW",544],[9,545],[0,"EscapeSequence",546],[4,327,212],[9,547],[4,548,549],[4,3,507],[0,"Accessors",550],[4,3,551],[3,552,553],[0,"BitwiseOrExpression",554],[6,555],[5,"||"],[4,556,557],[3,558,47,559,560],[6,561],[8,562],[3,498,563,564],[4,372,121],[3,565,327,10],[3,566,567,568,328],[3,569,327,10],[9,570],[3,123,571],[4,572,573],[0,"MethodType",574],[4,575,576],[0,"UnarySelector",577],[4,578,579],[4,3,580,3,536],[0,"LogicalOrExpressionNoIn",581],[8,582],[0,"PrimaryExpression",583],[0,"MessageExpression",584],[4,526,3,497,3,498],[4,3,585],[0,"ArgumentList",132],[0,"BracketedAccessor",586],[0,"DotAccessor",587],[2,"[\"]"],[0,"CharacterEscapeSequence",588],[4,589,590],[0,"HexEscapeSequence",591],[2,"[']"],[4,549,3,592],[5,"@outlet"],[5,"@accessors"],[8,593],[4,52,3,594,595,3,54],[0,"KeywordSelector",596],[8,597],[0,"Selector",123],[0,"BitwiseXOrExpression",598],[6,599],[5,"&&"],[4,600,601],[4,3,493,3,442,3,105,3,442],[3,602,51,603,604,605,606],[4,607,3,608,3,609,3,610],[3,563,564],[4,607,3,90,3,610],[4,611,3,123],[3,612,613],[5,"0"],[9,614],[4,615,490,490],[3,533,88,167],[4,52,616,54],[3,617,618],[6,619],[4,620,621],[4,3,167,3,622],[4,623,624],[4,3,625,248,3,578],[0,"LogicalAndExpressionNoIn",626],[6,627],[0,"THIS",628],[0,"Literal",629],[0,"ArrayLiteral",630],[0,"ObjectLiteral",631],[4,52,3,90,3,54],[5,"["],[3,632,90],[0,"SelectorCall",633],[5,"]"],[5,"."],[0,"SingleEscapeCharacter",634],[0,"NonEscapeCharacter",635],[0,"DecimalDigit",636],[5,"x"],[8,637],[0,"ACTION",638],[4,123,639],[4,3,594],[0,"KeywordDeclarator",640],[6,641],[5,"..."],[0,"BitwiseAndExpression",642],[6,643],[5,"|"],[4,644,645],[4,3,538,3,600],[4,373,121],[3,279,280,646,199,647,648],[4,607,3,649,3,610],[4,55,3,650,3,57],[0,"SUPER",651],[3,652,553],[2,"['\"\\\\bfnrtv]"],[4,125,653,82],[2,"[0-9]"],[4,654,655],[3,656,657],[8,658],[4,659,105,511,3,51],[4,3,620],[4,660,661],[4,3,662,248,3,623],[0,"BitwiseOrExpressionNoIn",663],[6,664],[0,"NumericLiteral",665],[0,"RegularExpressionLiteral",666],[0,"SelectorLiteral",667],[0,"ElementList",668],[8,669],[4,401,121],[4,670,671],[9,672],[0,"AccessorsConfiguration",673],[6,674],[4,675,121],[4,676,121],[4,3,232,3,123,3,234],[8,677],[0,"EqualityExpression",678],[6,679],[5,"^"],[4,680,681],[4,3,580,3,644],[4,682,683],[4,684,685,684,686],[4,687,3,52,3,688,3,54],[4,689,690,3,691],[4,692,3,693],[0,"KeywordSelectorCall",694],[6,695],[0,"EscapeCharacter",696],[3,697,698,699,700,701,702],[4,3,167,3,654],[5,"@action"],[5,"IBAction"],[4,577,3],[4,703,704],[4,3,705,248,3,660],[0,"BitwiseXOrExpressionNoIn",706],[6,707],[3,708,709],[9,207],[5,"/"],[0,"RegularExpressionBody",710],[0,"RegularExpressionFlags",208],[5,"@selector"],[0,"SelectorLiteralContents",711],[6,712],[6,713],[8,172],[0,"PropertyNameAndValueList",714],[8,167],[4,715,716],[4,3,167,3,90],[3,612,614,615,489],[0,"IvarPropertyName",717],[0,"IvarGetterName",718],[0,"IvarSetterName",719],[5,"readonly"],[5,"readwrite"],[5,"copy"],[0,"RelationalExpression",720],[6,721],[5,"&"],[4,722,723],[4,3,625,248,3,680],[0,"HexIntegerLiteral",724],[0,"DecimalLiteral",725],[4,726,727],[3,728,51],[4,167,3],[4,3,172,729],[4,730,731],[0,"KeywordCall",732],[6,733],[4,734,3,247,3,51],[4,735,3,247,3,51],[4,736,3,247,3,51,737],[4,738,739],[4,3,740,3,703],[0,"BitwiseAndExpressionNoIn",741],[6,742],[4,589,743,744],[4,745,746],[0,"RegularExpressionFirstChar",747],[6,748],[7,749],[7,750],[0,"PropertyAssignment",751],[6,752],[4,753,3,105,3,90],[4,3,715],[5,"property"],[5,"getter"],[5,"setter"],[8,754],[0,"ShiftExpression",755],[6,756],[0,"EqualityOperator",757],[4,758,759],[4,3,662,248,3,722],[2,"[Xx]"],[7,490],[3,760,761,762],[8,763],[3,764,765,766],[0,"RegularExpressionChar",767],[4,753,3,105,3],[4,3,167],[3,768,769,770],[4,3,167,3,730],[8,577],[4,3,105],[4,771,772],[4,3,773,3,738],[3,774,775,776,777],[0,"EqualityExpressionNoIn",778],[6,779],[4,762,611,780],[4,611,781],[0,"DecimalIntegerLiteral",782],[0,"ExponentPart",783],[4,784,785],[0,"RegularExpressionBackslashSequence",786],[0,"RegularExpressionClass",787],[3,788,765,766],[4,789,3,105,3,172],[0,"PropertyGetter",790],[0,"PropertySetter",791],[0,"AdditiveExpression",792],[6,793],[0,"RelationalOperator",794],[5,"==="],[5,"!=="],[5,"=="],[5,"!="],[4,795,796],[4,3,705,248,3,758],[6,614],[7,614],[3,589,797],[4,798,799],[9,800],[0,"RegularExpressionNonTerminator",83],[4,327,785],[4,607,801,610],[4,802,785],[0,"PropertyName",803],[4,804,3,789,3,52,3,54,3,55,3,56,3,57],[4,805,3,789,3,52,3,806,3,54,3,55,3,56,3,57],[4,807,808],[4,3,809,3,771],[3,810,811,232,234,812,182],[0,"RelationalExpressionNoIn",813],[6,814],[4,815,780],[2,"[eE]"],[0,"SignedInteger",816],[2,"[*\\u005C/[]"],[6,817],[9,818],[3,123,199,646],[5,"get"],[5,"set"],[0,"PropertySetParameterList",51],[0,"MultiplicativeExpression",819],[6,820],[0,"ShiftOperator",821],[5,"<="],[5,">="],[0,"INSTANCEOF",822],[4,738,823],[4,3,740,3,795],[2,"[1-9]"],[4,824,781],[0,"RegularExpressionClassChar",825],[2,"[\\u005C/[]"],[4,826,827],[4,3,828,3,807],[3,829,830,831],[4,371,121],[6,832],[8,833],[3,834,765],[0,"UnaryExpression",835],[6,836],[0,"AdditiveOperator",837],[5,"<<"],[5,">>"],[5,">>>"],[4,3,838,3,738],[2,"[+-]"],[4,839,785],[3,840,841,842,843,844,845,846,847,848,849],[4,3,850,3,826],[4,851,248],[0,"RelationalOperatorNoIn",852],[9,853],[0,"PostfixExpression",854],[4,855,3,826],[4,856,3,826],[4,857,3,826],[4,858,3,826],[4,859,3,826],[4,510,3,826],[4,514,3,826],[4,860,3,826],[4,861,3,826],[0,"MultiplicativeOperator",862],[3,863,864],[3,810,811,232,234,812],[2,"[\\u005C\\]]"],[4,258,865],[0,"DELETE",866],[0,"VOID",867],[0,"TYPEOF",868],[5,"++"],[5,"--"],[5,"~"],[5,"!"],[4,869,248],[4,510,870],[4,514,871],[8,872],[4,370,121],[4,375,121],[4,374,121],[3,873,684,874],[9,510],[9,514],[4,99,875],[5,"*"],[5,"%"],[3,858,859],[0,"%start",877],[4,878,879,878],[0,"%_",880],[8,881],[6,882],[0,"%SourceElements",883],[3,884,885,886],[4,887,888],[0,"%WhiteSpace",14],[0,"%LineTerminator",15],[0,"%Comment",889],[0,"%SourceElement",890],[6,891],[3,892,893],[3,894,895],[4,878,887],[0,"%MultiLineComment",23],[0,"%SingleLineComment",896],[0,"%Statement",897],[0,"%FunctionDeclaration",898],[4,30,899],[3,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,895,915,916,917],[4,918,878,919,878,52,878,920,878,54,878,55,878,921,878,57],[6,922],[0,"%Block",923],[0,"%VariableStatement",924],[0,"%EmptyStatement",62],[0,"%ExpressionStatement",925],[0,"%IfStatement",926],[0,"%IterationStatement",927],[0,"%ContinueStatement",928],[0,"%BreakStatement",929],[0,"%ReturnStatement",930],[0,"%WithStatement",931],[0,"%LabelledStatement",932],[0,"%SwitchStatement",933],[0,"%ThrowStatement",934],[0,"%TryStatement",935],[0,"%DebuggerStatement",936],[0,"%FunctionExpression",937],[0,"%ImportStatement",938],[0,"%ClassDeclarationStatement",939],[0,"%FUNCTION",940],[0,"%Identifier",941],[8,942],[0,"%FunctionBody",877],[0,"%SingleLineCommentChar",943],[12,944,945],[4,946,878,947,948,949],[4,950,951,949],[4,952,878,52,878,951,878,54,878,894,953],[3,954,955,956,957,958],[4,959,960,961],[4,962,960,961],[4,963,960,964],[4,965,878,52,878,951,878,54,878,894],[4,919,878,105,878,894],[4,966,878,52,878,951,878,54,878,967],[4,968,960,964],[4,969,878,900,878,970],[4,971,949],[4,918,878,972,878,52,878,920,878,54,878,55,878,921,878,57],[4,113,878,973,949],[4,115,878,919,878,974,878,975,878,976,878,119,949],[4,120,977],[12,978,979],[0,"%FormalParameterList",980],[4,981,82],[4,55,878,982,878,57],[11,"%BadBlock",983,"Missing ending brace"],[0,"%VAR",984],[0,"%VariableDeclaration",985],[6,986],[0,"%EOS",987],[9,988],[0,"%Expression",989],[0,"%IF",990],[8,991],[0,"%DoWhileStatement",992],[0,"%WhileStatement",993],[0,"%ForStatement",994],[0,"%ForInStatement",995],[0,"%EachStatement",996],[0,"%CONTINUE",997],[0,"%__",998],[3,999,1000],[0,"%BREAK",1001],[0,"%RETURN",1002],[3,1000,1003],[0,"%WITH",1004],[0,"%SWITCH",1005],[0,"%CaseBlock",1006],[0,"%THROW",1007],[0,"%TRY",1008],[3,1009,1010],[0,"%DEBUGGER",1011],[8,919],[3,1012,1013],[8,1014],[8,1015],[0,"%ClassBody",1016],[9,1017],[4,1018,1019],[0,"%BadIdentifier",1020],[4,919,1021],[9,885],[8,1022],[4,55,878,982,878],[4,165,977],[4,919,1023],[4,878,167,878,947],[3,1024,1025,1026,1027],[3,55,918],[4,1028,1029],[4,174,977],[4,878,1030,878,894],[4,1031,878,894,878,1032,878,52,878,951,878,54,949],[4,1032,878,52,878,951,878,54,878,894],[4,1033,878,52,878,1034,878,62,878,1035,878,62,878,1035,878,54,878,894],[4,1033,878,52,878,1036,878,1037,878,951,878,54,878,894],[4,183,878,52,878,1036,878,1037,878,951,878,54,878,894],[4,184,977],[6,1038],[4,919,949],[0,"%SemicolonInsertionEOS",1039],[4,187,977],[4,188,977],[4,951,949],[4,189,977],[4,190,977],[4,55,878,1040,878,1041,878,1040,878,57],[4,193,977],[4,194,977],[4,1042,1043],[0,"%Finally",1044],[4,198,977],[0,"%LocalFilePath",1045],[0,"%StandardFilePath",1046],[3,1047,1048],[4,55,1049,878,57],[8,1050],[0,"%IdentifierPart",1051],[9,1052],[0,"%IdentifierName",1053],[3,1054,1055],[6,1056],[0,"%StatementList",1057],[8,1058],[4,878,62],[4,960,1059],[4,960,213],[4,960,1060],[0,"%AssignmentExpression",1061],[6,1062],[0,"%ELSE",1063],[0,"%DO",1064],[0,"%WHILE",1065],[0,"%FOR",1066],[8,1067],[8,951],[0,"%ForInFirstExpression",1068],[0,"%IN",1069],[3,884,1070,893],[3,1071,1025,1026,1027],[8,1072],[8,1073],[0,"%Catch",1074],[8,1075],[4,1076,878,900],[0,"%StringLiteral",1077],[4,232,878,233,878,234],[0,"%SuperclassDeclaration",1078],[0,"%CategoryDeclaration",1079],[6,1080],[0,"%ClassElements",1081],[3,1082,1083,1084,1085,1086,1087],[4,1088,977],[4,1082,1089],[11,"%ReservedWordIdentifier",1052,"Identifier cannot be a reserved word"],[11,"%DigitIdentifier",1090,"Identifier cannot start with a digit"],[4,878,167,878,919],[4,894,1091],[4,878,247,248,878,1028],[0,"%LineTerminatorSequence",249],[0,"%EOF",250],[3,1092,1093],[4,878,167,878,1028],[4,253,977],[4,254,977],[4,255,977],[4,256,977],[0,"%ForFirstExpression",1094],[3,1095,1096],[4,260,977],[0,"%SingleLineMultiLineComment",1097],[4,960,62],[0,"%CaseClauses",1098],[0,"%DefaultClause",1099],[4,1100,878,52,878,919,878,54,878,900],[4,878,1010],[0,"%FINALLY",1101],[3,1102,1103],[4,105,878,919],[4,52,878,919,878,54],[4,878,1104],[4,1105,1106],[0,"%IdentifierStart",1107],[0,"%UnicodeCombiningMark",272],[0,"%UnicodeDigit",273],[0,"%UnicodeConnectorPunctuation",274],[0,"%ZWNJ",275],[0,"%ZWJ",276],[0,"%ReservedWord",1108],[6,1017],[4,1084,1109],[6,1110],[4,1095,878,1111,878,1028],[0,"%ConditionalExpression",1112],[3,1113,1114],[0,"%LeftHandSideExpression",1115],[4,946,878,1116],[4,27,1117,29],[4,1118,1119],[4,1120,878,105,1121],[0,"%CATCH",1122],[4,301,977],[4,1123,303,1124,303],[4,305,1125,305],[0,"%CompoundIvarDeclaration",1126],[0,"%ClassElement",1127],[6,1128],[3,1129,282,1130],[3,1131,1132,1133,1134],[7,1017],[4,878,894],[0,"%AssignmentOperator",330],[4,1135,1136],[0,"%ExpressionNoIn",1137],[4,946,878,1138],[3,1139,1140],[0,"%VariableDeclarationNoIn",1141],[6,1142],[0,"%CaseClause",1143],[6,1144],[0,"%DEFAULT",1145],[8,1146],[4,343,977],[8,1147],[6,1148],[6,1149],[4,1150,878,1151,1152,949],[3,1153,1154,894,895],[4,878,1105],[0,"%UnicodeLetter",326],[4,327,1155],[0,"%Keyword",322],[0,"%FutureReservedWord",323],[0,"%NullLiteral",1156],[0,"%BooleanLiteral",1157],[0,"%LogicalOrExpression",1158],[8,1159],[4,1160,1161],[0,"%VariableDeclarationListNoIn",1162],[0,"%CallExpression",1163],[0,"%NewExpression",1164],[4,919,1165],[4,81,981,82],[4,1166,878,951,878,105,1121],[4,878,1118],[4,369,977],[4,878,1022],[4,449,878],[0,"%DoubleStringCharacter",1167],[0,"%SingleStringCharacter",1168],[0,"%IvarType",1169],[0,"%IvarDeclaration",1170],[6,1171],[0,"%ClassMethodDeclaration",1172],[0,"%InstanceMethodDeclaration",1173],[0,"%UnicodeEscapeSequence",1174],[0,"%NULL",1175],[3,1176,1177],[4,1178,1179],[4,878,493,878,1028,878,105,878,1028],[0,"%AssignmentExpressionNoIn",1180],[6,1181],[4,1116,1182],[4,1183,878,1184,1185],[3,1183,1186],[8,1187],[0,"%CASE",1188],[3,1189,1190,1191],[3,1192,1190,1191],[4,1193,1194],[4,919,878,1195],[4,878,167,878,1151],[4,510,1196,878,1197,878,513,878,55,878,921,878,57],[4,514,1196,878,1197,878,513,878,55,878,921,878,57],[4,489,1198,1198,1198,1198],[4,457,977],[0,"%TRUE",1199],[0,"%FALSE",1200],[0,"%LogicalAndExpression",1201],[6,1202],[3,1203,1204],[4,878,167,878,1160],[6,1205],[0,"%MemberExpression",1206],[0,"%Arguments",1207],[6,1208],[4,1209,878,1140],[4,878,247,248,878,1160],[4,368,977],[4,1210,82],[4,327,1211],[0,"%LineContinuation",1212],[4,1213,82],[0,"%IvarTypeElement",1214],[6,1215],[8,1216],[8,1217],[0,"%MethodSelector",1218],[0,"%HexDigit",517],[4,515,977],[4,516,977],[4,1219,1220],[4,878,538,878,1178],[4,1095,878,1111,878,1160],[0,"%ConditionalExpressionNoIn",1221],[4,878,167,878,1116],[4,1222,1223],[4,52,878,1224,878,54],[4,878,1225],[0,"%NEW",1226],[9,1227],[0,"%EscapeSequence",1228],[4,327,1059],[9,1229],[4,1230,1231],[4,878,1193],[0,"%Accessors",1232],[4,878,1233],[3,1234,1235],[0,"%BitwiseOrExpression",1236],[6,1237],[4,1238,1239],[3,1240,915,1241,1242],[6,1243],[8,1244],[3,1184,1245,1246],[4,372,977],[3,565,327,885],[3,1247,1248,1249,1155],[3,569,327,885],[9,1250],[3,1019,571],[4,572,1251],[0,"%MethodType",1252],[4,1253,1254],[0,"%UnarySelector",1255],[4,1256,1257],[4,878,580,878,1219],[0,"%LogicalOrExpressionNoIn",1258],[8,1259],[0,"%PrimaryExpression",1260],[0,"%MessageExpression",1261],[4,1209,878,1183,878,1184],[4,878,1262],[0,"%ArgumentList",989],[0,"%BracketedAccessor",1263],[0,"%DotAccessor",1264],[0,"%CharacterEscapeSequence",1265],[4,589,1266],[0,"%HexEscapeSequence",1267],[4,1231,878,1268],[8,1269],[4,52,878,1270,1271,878,54],[0,"%KeywordSelector",1272],[8,1273],[0,"%Selector",1019],[0,"%BitwiseXOrExpression",1274],[6,1275],[4,1276,1277],[4,878,493,878,1160,878,105,878,1160],[3,1278,919,1279,1280,1281,1282],[4,607,878,1283,878,1284,878,610],[3,1245,1246],[4,607,878,951,878,610],[4,611,878,1019],[3,1285,1286],[9,1287],[4,615,1198,1198],[3,1216,949,167],[4,52,1288,54],[3,1289,1290],[6,1291],[4,1292,1293],[4,878,167,878,622],[4,1294,1295],[4,878,625,248,878,1256],[0,"%LogicalAndExpressionNoIn",1296],[6,1297],[0,"%THIS",1298],[0,"%Literal",1299],[0,"%ArrayLiteral",1300],[0,"%ObjectLiteral",1301],[4,52,878,951,878,54],[3,1302,951],[0,"%SelectorCall",1303],[0,"%SingleEscapeCharacter",634],[0,"%NonEscapeCharacter",1304],[0,"%DecimalDigit",636],[8,1305],[0,"%ACTION",1306],[4,1019,1307],[4,878,1270],[0,"%KeywordDeclarator",1308],[6,1309],[0,"%BitwiseAndExpression",1310],[6,1311],[4,1312,1313],[4,878,538,878,1276],[4,373,977],[3,1133,1134,1314,1045,1315,1316],[4,607,878,1317,878,610],[4,55,878,1318,878,57],[0,"%SUPER",1319],[3,1320,1235],[4,981,1321,82],[4,1322,1323],[3,1324,1325],[8,1326],[4,1327,105,1196,878,919],[4,878,1292],[4,1328,1329],[4,878,662,248,878,1294],[0,"%BitwiseOrExpressionNoIn",1330],[6,1331],[0,"%NumericLiteral",1332],[0,"%RegularExpressionLiteral",1333],[0,"%SelectorLiteral",1334],[0,"%ElementList",1335],[8,1336],[4,401,977],[4,1337,1338],[9,1339],[0,"%AccessorsConfiguration",1340],[6,1341],[4,675,977],[4,676,977],[4,878,232,878,1019,878,234],[8,1342],[0,"%EqualityExpression",1343],[6,1344],[4,1345,1346],[4,878,580,878,1312],[4,1347,1348],[4,684,1349,684,1350],[4,687,878,52,878,1351,878,54],[4,1352,1353,878,1354],[4,1355,878,693],[0,"%KeywordSelectorCall",1356],[6,1357],[0,"%EscapeCharacter",1358],[3,1359,1360,1361,700,701,702],[4,878,167,878,1322],[4,1255,878],[4,1362,1363],[4,878,705,248,878,1328],[0,"%BitwiseXOrExpressionNoIn",1364],[6,1365],[3,1366,1367],[9,1082],[0,"%RegularExpressionBody",1368],[0,"%RegularExpressionFlags",1089],[0,"%SelectorLiteralContents",1369],[6,1370],[6,1371],[8,1028],[0,"%PropertyNameAndValueList",1372],[4,1373,1374],[4,878,167,878,951],[3,1285,1287,615,489],[0,"%IvarPropertyName",1375],[0,"%IvarGetterName",1376],[0,"%IvarSetterName",1377],[0,"%RelationalExpression",1378],[6,1379],[4,1380,1381],[4,878,625,248,878,1345],[0,"%HexIntegerLiteral",1382],[0,"%DecimalLiteral",1383],[4,1384,1385],[3,1386,919],[4,167,878],[4,878,1028,1387],[4,1388,1389],[0,"%KeywordCall",1390],[6,1391],[4,734,878,247,878,919],[4,735,878,247,878,919],[4,736,878,247,878,919,1392],[4,1393,1394],[4,878,1395,878,1362],[0,"%BitwiseAndExpressionNoIn",1396],[6,1397],[4,589,743,1398],[4,1399,1400],[0,"%RegularExpressionFirstChar",1401],[6,1402],[7,1403],[7,1404],[0,"%PropertyAssignment",1405],[6,1406],[4,1407,878,105,878,951],[4,878,1373],[8,1408],[0,"%ShiftExpression",1409],[6,1410],[0,"%EqualityOperator",757],[4,1411,1412],[4,878,662,248,878,1380],[7,1198],[3,1413,1414,1415],[8,1416],[3,1417,1418,1419],[0,"%RegularExpressionChar",1420],[4,1407,878,105,878],[4,878,167],[3,1421,1422,1423],[4,878,167,878,1388],[8,1255],[4,878,105],[4,1424,1425],[4,878,1426,878,1393],[0,"%EqualityExpressionNoIn",1427],[6,1428],[4,1415,611,1429],[4,611,1430],[0,"%DecimalIntegerLiteral",1431],[0,"%ExponentPart",1432],[4,784,1433],[0,"%RegularExpressionBackslashSequence",1434],[0,"%RegularExpressionClass",1435],[3,1436,1418,1419],[4,1437,878,105,878,1028],[0,"%PropertyGetter",1438],[0,"%PropertySetter",1439],[0,"%AdditiveExpression",1440],[6,1441],[0,"%RelationalOperator",1442],[4,1443,1444],[4,878,705,248,878,1411],[6,1287],[7,1287],[3,589,1445],[4,798,1446],[0,"%RegularExpressionNonTerminator",943],[4,327,1433],[4,607,1447,610],[4,802,1433],[0,"%PropertyName",1448],[4,804,878,1437,878,52,878,54,878,55,878,921,878,57],[4,805,878,1437,878,52,878,1449,878,54,878,55,878,921,878,57],[4,1450,1451],[4,878,1452,878,1424],[3,810,811,232,234,1453,1037],[0,"%RelationalExpressionNoIn",1454],[6,1455],[4,815,1429],[0,"%SignedInteger",1456],[6,1457],[3,1019,1045,1314],[0,"%PropertySetParameterList",919],[0,"%MultiplicativeExpression",1458],[6,1459],[0,"%ShiftOperator",821],[0,"%INSTANCEOF",1460],[4,1393,1461],[4,878,1395,878,1443],[4,824,1430],[0,"%RegularExpressionClassChar",1462],[4,1463,1464],[4,878,1465,878,1450],[4,371,977],[6,1466],[3,1467,1418],[0,"%UnaryExpression",1468],[6,1469],[0,"%AdditiveOperator",837],[4,878,1470,878,1393],[4,839,1433],[3,1471,1472,1473,1474,1475,1476,1477,1478,1479,1480],[4,878,1481,878,1463],[0,"%RelationalOperatorNoIn",1482],[0,"%PostfixExpression",1483],[4,1484,878,1463],[4,1485,878,1463],[4,1486,878,1463],[4,858,878,1463],[4,859,878,1463],[4,510,878,1463],[4,514,878,1463],[4,860,878,1463],[4,861,878,1463],[0,"%MultiplicativeOperator",862],[3,810,811,232,234,1453],[4,1095,1487],[0,"%DELETE",1488],[0,"%VOID",1489],[0,"%TYPEOF",1490],[8,1491],[4,370,977],[4,375,977],[4,374,977],[4,960,875]],"nameToUID":{"start":1,"_":3,"SourceElements":6,"WhiteSpace":9,"LineTerminator":10,"Comment":11,"SourceElement":12,"MultiLineComment":19,"SingleLineComment":20,"Statement":21,"FunctionDeclaration":22,"Block":32,"VariableStatement":33,"EmptyStatement":34,"ExpressionStatement":35,"IfStatement":36,"IterationStatement":37,"ContinueStatement":38,"BreakStatement":39,"ReturnStatement":40,"WithStatement":41,"LabelledStatement":42,"SwitchStatement":43,"ThrowStatement":44,"TryStatement":45,"DebuggerStatement":46,"FunctionExpression":47,"ImportStatement":48,"ClassDeclarationStatement":49,"FUNCTION":50,"Identifier":51,"FunctionBody":56,"SingleLineCommentChar":59,"FormalParameterList":80,"VAR":85,"VariableDeclaration":86,"EOS":88,"Expression":90,"IF":91,"DoWhileStatement":93,"WhileStatement":94,"ForStatement":95,"ForInStatement":96,"EachStatement":97,"CONTINUE":98,"__":99,"BREAK":101,"RETURN":102,"WITH":104,"SWITCH":106,"CaseBlock":107,"THROW":108,"TRY":109,"DEBUGGER":111,"ClassBody":118,"IdentifierName":123,"StatementList":126,"SemicolonInsertionEOS":143,"Finally":153,"LocalFilePath":155,"StandardFilePath":156,"IdentifierPart":160,"AssignmentExpression":172,"ELSE":175,"DO":176,"WHILE":177,"FOR":178,"ForInFirstExpression":181,"IN":182,"Catch":195,"StringLiteral":199,"SuperclassDeclaration":201,"CategoryDeclaration":202,"ClassElements":204,"ReservedWord":206,"IdentifierStart":207,"LineTerminatorSequence":212,"EOF":214,"ForFirstExpression":221,"SingleLineMultiLineComment":224,"CaseClauses":226,"DefaultClause":227,"FINALLY":230,"UnicodeCombiningMark":239,"UnicodeDigit":240,"UnicodeConnectorPunctuation":241,"ZWNJ":242,"ZWJ":243,"ConditionalExpression":252,"LeftHandSideExpression":258,"CATCH":264,"CompoundIvarDeclaration":269,"ClassElement":270,"Keyword":277,"FutureReservedWord":278,"NullLiteral":279,"BooleanLiteral":280,"UnicodeLetter":281,"AssignmentOperator":289,"ExpressionNoIn":291,"VariableDeclarationNoIn":294,"CaseClause":296,"DEFAULT":298,"NULL":324,"UnicodeEscapeSequence":328,"LogicalOrExpression":331,"VariableDeclarationListNoIn":334,"CallExpression":335,"NewExpression":336,"DoubleStringCharacter":345,"SingleStringCharacter":346,"IvarType":348,"IvarDeclaration":349,"ClassMethodDeclaration":351,"InstanceMethodDeclaration":352,"TRUE":407,"FALSE":408,"AssignmentExpressionNoIn":442,"CASE":448,"HexDigit":490,"LogicalAndExpression":491,"MemberExpression":497,"Arguments":498,"LineContinuation":505,"IvarTypeElement":507,"MethodSelector":512,"ConditionalExpressionNoIn":521,"NEW":526,"EscapeSequence":528,"Accessors":533,"BitwiseOrExpression":536,"MethodType":551,"UnarySelector":553,"LogicalOrExpressionNoIn":556,"PrimaryExpression":558,"MessageExpression":559,"ArgumentList":562,"BracketedAccessor":563,"DotAccessor":564,"CharacterEscapeSequence":566,"HexEscapeSequence":568,"KeywordSelector":575,"Selector":577,"BitwiseXOrExpression":578,"LogicalAndExpressionNoIn":600,"THIS":602,"Literal":603,"ArrayLiteral":604,"ObjectLiteral":605,"SelectorCall":609,"SingleEscapeCharacter":612,"NonEscapeCharacter":613,"DecimalDigit":614,"ACTION":617,"KeywordDeclarator":620,"BitwiseAndExpression":623,"SUPER":632,"BitwiseOrExpressionNoIn":644,"NumericLiteral":646,"RegularExpressionLiteral":647,"SelectorLiteral":648,"ElementList":649,"AccessorsConfiguration":654,"EqualityExpression":660,"KeywordSelectorCall":670,"EscapeCharacter":672,"BitwiseXOrExpressionNoIn":680,"RegularExpressionBody":685,"RegularExpressionFlags":686,"SelectorLiteralContents":688,"PropertyNameAndValueList":692,"IvarPropertyName":697,"IvarGetterName":698,"IvarSetterName":699,"RelationalExpression":703,"HexIntegerLiteral":708,"DecimalLiteral":709,"KeywordCall":715,"BitwiseAndExpressionNoIn":722,"RegularExpressionFirstChar":726,"PropertyAssignment":730,"ShiftExpression":738,"EqualityOperator":740,"RegularExpressionChar":748,"EqualityExpressionNoIn":758,"DecimalIntegerLiteral":762,"ExponentPart":763,"RegularExpressionBackslashSequence":765,"RegularExpressionClass":766,"PropertyGetter":769,"PropertySetter":770,"AdditiveExpression":771,"RelationalOperator":773,"RegularExpressionNonTerminator":785,"PropertyName":789,"RelationalExpressionNoIn":795,"SignedInteger":799,"PropertySetParameterList":806,"MultiplicativeExpression":807,"ShiftOperator":809,"INSTANCEOF":812,"RegularExpressionClassChar":817,"UnaryExpression":826,"AdditiveOperator":828,"RelationalOperatorNoIn":838,"PostfixExpression":840,"MultiplicativeOperator":850,"DELETE":855,"VOID":856,"TYPEOF":857,"%start":876,"%_":878,"%SourceElements":881,"%WhiteSpace":884,"%LineTerminator":885,"%Comment":886,"%SourceElement":887,"%MultiLineComment":892,"%SingleLineComment":893,"%Statement":894,"%FunctionDeclaration":895,"%Block":900,"%VariableStatement":901,"%EmptyStatement":902,"%ExpressionStatement":903,"%IfStatement":904,"%IterationStatement":905,"%ContinueStatement":906,"%BreakStatement":907,"%ReturnStatement":908,"%WithStatement":909,"%LabelledStatement":910,"%SwitchStatement":911,"%ThrowStatement":912,"%TryStatement":913,"%DebuggerStatement":914,"%FunctionExpression":915,"%ImportStatement":916,"%ClassDeclarationStatement":917,"%FUNCTION":918,"%Identifier":919,"%FunctionBody":921,"%SingleLineCommentChar":922,"%FormalParameterList":942,"%BadBlock":945,"%VAR":946,"%VariableDeclaration":947,"%EOS":949,"%Expression":951,"%IF":952,"%DoWhileStatement":954,"%WhileStatement":955,"%ForStatement":956,"%ForInStatement":957,"%EachStatement":958,"%CONTINUE":959,"%__":960,"%BREAK":962,"%RETURN":963,"%WITH":965,"%SWITCH":966,"%CaseBlock":967,"%THROW":968,"%TRY":969,"%DEBUGGER":971,"%ClassBody":976,"%BadIdentifier":979,"%SemicolonInsertionEOS":1000,"%Finally":1010,"%LocalFilePath":1012,"%StandardFilePath":1013,"%IdentifierPart":1017,"%IdentifierName":1019,"%StatementList":1022,"%AssignmentExpression":1028,"%ELSE":1030,"%DO":1031,"%WHILE":1032,"%FOR":1033,"%ForInFirstExpression":1036,"%IN":1037,"%Catch":1042,"%StringLiteral":1045,"%SuperclassDeclaration":1047,"%CategoryDeclaration":1048,"%ClassElements":1050,"%ReservedWordIdentifier":1054,"%DigitIdentifier":1055,"%LineTerminatorSequence":1059,"%EOF":1060,"%ForFirstExpression":1067,"%SingleLineMultiLineComment":1070,"%CaseClauses":1072,"%DefaultClause":1073,"%FINALLY":1076,"%IdentifierStart":1082,"%UnicodeCombiningMark":1083,"%UnicodeDigit":1084,"%UnicodeConnectorPunctuation":1085,"%ZWNJ":1086,"%ZWJ":1087,"%ReservedWord":1088,"%ConditionalExpression":1093,"%LeftHandSideExpression":1095,"%CATCH":1100,"%CompoundIvarDeclaration":1104,"%ClassElement":1105,"%AssignmentOperator":1111,"%ExpressionNoIn":1113,"%VariableDeclarationNoIn":1116,"%CaseClause":1118,"%DEFAULT":1120,"%UnicodeLetter":1129,"%Keyword":1131,"%FutureReservedWord":1132,"%NullLiteral":1133,"%BooleanLiteral":1134,"%LogicalOrExpression":1135,"%VariableDeclarationListNoIn":1138,"%CallExpression":1139,"%NewExpression":1140,"%DoubleStringCharacter":1148,"%SingleStringCharacter":1149,"%IvarType":1150,"%IvarDeclaration":1151,"%ClassMethodDeclaration":1153,"%InstanceMethodDeclaration":1154,"%UnicodeEscapeSequence":1155,"%NULL":1156,"%AssignmentExpressionNoIn":1160,"%CASE":1166,"%TRUE":1176,"%FALSE":1177,"%LogicalAndExpression":1178,"%MemberExpression":1183,"%Arguments":1184,"%LineContinuation":1191,"%IvarTypeElement":1193,"%MethodSelector":1197,"%HexDigit":1198,"%ConditionalExpressionNoIn":1204,"%NEW":1209,"%EscapeSequence":1211,"%Accessors":1216,"%BitwiseOrExpression":1219,"%MethodType":1233,"%UnarySelector":1235,"%LogicalOrExpressionNoIn":1238,"%PrimaryExpression":1240,"%MessageExpression":1241,"%ArgumentList":1244,"%BracketedAccessor":1245,"%DotAccessor":1246,"%CharacterEscapeSequence":1247,"%HexEscapeSequence":1249,"%KeywordSelector":1253,"%Selector":1255,"%BitwiseXOrExpression":1256,"%LogicalAndExpressionNoIn":1276,"%THIS":1278,"%Literal":1279,"%ArrayLiteral":1280,"%ObjectLiteral":1281,"%SelectorCall":1284,"%SingleEscapeCharacter":1285,"%NonEscapeCharacter":1286,"%DecimalDigit":1287,"%ACTION":1289,"%KeywordDeclarator":1292,"%BitwiseAndExpression":1294,"%SUPER":1302,"%BitwiseOrExpressionNoIn":1312,"%NumericLiteral":1314,"%RegularExpressionLiteral":1315,"%SelectorLiteral":1316,"%ElementList":1317,"%AccessorsConfiguration":1322,"%EqualityExpression":1328,"%KeywordSelectorCall":1337,"%EscapeCharacter":1339,"%BitwiseXOrExpressionNoIn":1345,"%RegularExpressionBody":1349,"%RegularExpressionFlags":1350,"%SelectorLiteralContents":1351,"%PropertyNameAndValueList":1355,"%IvarPropertyName":1359,"%IvarGetterName":1360,"%IvarSetterName":1361,"%RelationalExpression":1362,"%HexIntegerLiteral":1366,"%DecimalLiteral":1367,"%KeywordCall":1373,"%BitwiseAndExpressionNoIn":1380,"%RegularExpressionFirstChar":1384,"%PropertyAssignment":1388,"%ShiftExpression":1393,"%EqualityOperator":1395,"%RegularExpressionChar":1402,"%EqualityExpressionNoIn":1411,"%DecimalIntegerLiteral":1415,"%ExponentPart":1416,"%RegularExpressionBackslashSequence":1418,"%RegularExpressionClass":1419,"%PropertyGetter":1422,"%PropertySetter":1423,"%AdditiveExpression":1424,"%RelationalOperator":1426,"%RegularExpressionNonTerminator":1433,"%PropertyName":1437,"%RelationalExpressionNoIn":1443,"%SignedInteger":1446,"%PropertySetParameterList":1449,"%MultiplicativeExpression":1450,"%ShiftOperator":1452,"%INSTANCEOF":1453,"%RegularExpressionClassChar":1457,"%UnaryExpression":1463,"%AdditiveOperator":1465,"%RelationalOperatorNoIn":1470,"%PostfixExpression":1471,"%MultiplicativeOperator":1481,"%DELETE":1484,"%VOID":1485,"%TYPEOF":1486}}; - - -//function Parser(/*String | CompiledGrammar*/ aGrammar) -/*{ - if (typeof aGrammar.valueOf() === "string") - this.compiledGrammar = new (require("./compiledgrammar"))(aGrammar); - else - this.compiledGrammar = aGrammar; - - return this; -}*/ - -//exports.Parser = Parser; - -var Parser = function(/*CompiledGrammar*/ aGrammar) -{ - this.compiledGrammar = aGrammar; -} - -//Parser.compiledGrammar = compiledGrammar; - -Parser.prototype.parse = function(input) -{ - return parse(this.compiledGrammar, input); -} - -var NAME = 0, - DOT = 1, - CHARACTER_CLASS = 2, - ORDERED_CHOICE = 3, - SEQUENCE = 4, - STRING_LITERAL = 5, - ZERO_OR_MORE = 6, - ONE_OR_MORE = 7, - OPTIONAL = 8, - NEGATIVE_LOOK_AHEAD = 9, - POSITIVE_LOOK_AHEAD = 10, - ERROR_NAME = 11, - ERROR_CHOICE = 12; - -function parse(aCompiledGrammar, input, name) -{ - var node = new SyntaxNode("#document", input, 0, 0), - table = aCompiledGrammar.table, - nameToUID = aCompiledGrammar.nameToUID; - - name = name || "start"; - - // This is a stupid check. - if (aCompiledGrammar.nameToUID["EOF"] !== undefined) - table[0] = [SEQUENCE, nameToUID[name], nameToUID["EOF"]]; - - if (!evaluate(new context(input, table), node, table, 0)) - { - // This is a stupid check. - if (aCompiledGrammar.nameToUID["EOF"] !== undefined) - table[0] = [SEQUENCE, nameToUID["%" + name], nameToUID["EOF"]]; - - node.children.length = 0; - - evaluate(new context(input, table), node, table, 0); - - node.traverse( - { - traverseTextNodes:false, - enteredNode:function(node) - { - if (node.error) - console.log(node.message() + "\n"); - } - }); - } - - return node; -} - -exports.parse = parse; - -function context(input, table) -{ - this.position = 0; - this.input = input; - this.memos = []; - for (var i=0;i input_length) - { - memos[uid] = false; - return false; - } - - var index = 0; - - for (; index < string_length; ++context.position, ++index) - if (context.input.charCodeAt(context.position) !== string.charCodeAt(index)) - { - context.position -= index; - memos[uid] = false; - return false; - } - -// memos[uid] = string; - if (parent) - parent.children.push(string); - - return true; - case DOT: - if (context.position < input_length) - { - if (parent) - parent.children.push(context.input.charAt(context.position)); - ++context.position; - return true; - } - memos[uid] = false; - return false; - case POSITIVE_LOOK_AHEAD: - case NEGATIVE_LOOK_AHEAD: - var position = context.position, - result = evaluate(context, null, rules, rule[1]) === (type === POSITIVE_LOOK_AHEAD); - context.position = position; - memos[uid] = result; - - return result; - - case ZERO_OR_MORE: - var child, - position = context.position, - childCount = parent && parent.children.length; - - while (evaluate(context, parent, rules, rule[1])) - { - position = context.position, - childCount = parent && parent.children.length; - } - - context.position = position; - if (parent) - parent.children.length = childCount; - - return true; - - case ONE_OR_MORE: - var position = context.position, - childCount = parent && parent.children.length; - if (!evaluate(context, parent, rules, rule[1])) - { - memos[uid] = false; - context.position = position; - if (parent) - parent.children.length = childCount; - return false; - } - position = context.position, - childCount = parent && parent.children.length; - while (evaluate(context, parent, rules, rule[1])) - { - position = context.position; - childCount = parent && parent.children.length; - } - context.position = position; - if (parent) - parent.children.length = childCount; - return true; - - case OPTIONAL: - var position = context.position, - childCount = parent && parent.children.length; - - if (!evaluate(context, parent, rules, rule[1])) - { - context.position = position; - - if (parent) - parent.children.length = childCount; - } - - return true; - } -} - -function SyntaxNode(/*String*/ aName, /*String*/ aSource, /*Number*/ aLocation, /*Number*/ aLength, /*String*/anErrorMessage) -{ - this.name = aName; - this.source = aSource; - this.range = { location:aLocation, length:aLength }; - this.children = []; - - if (anErrorMessage) - this.error = anErrorMessage; -} - -SyntaxNode.prototype.message = function() -{ - var source = this.source, - lineNumber = 1, - index = 0, - start = 0, - length = source.length, - range = this.range; - - for (; index < range.location; ++index) - if (source.charAt(index) === '\n') - { - ++lineNumber; - start = index + 1; - } - - for (; index < length; ++index) - if (source.charAt(index) === '\n') - break; - - var line = source.substring(start, index); - message = line + "\n"; - - message += (new Array(this.range.location - start + 1)).join(" "); - message += (new Array(Math.min(range.length, line.length) + 1)).join("^") + "\n"; - message += "ERROR line " + lineNumber + ": " + this.error; - - return message; -} - -SyntaxNode.prototype.toString = function(/*String*/ spaces) -{ - if (!spaces) - spaces = ""; - - var string = spaces + this.name + " <" + this.innerText() + "> ", - children = this.children, - index = 0, - count = children.length; - - for (; index < count; ++index) - { - var child = children[index]; - - if (typeof child === "string") - string += "\n" + spaces + "\t" + child; - - else - string += "\n" + children[index].toString(spaces + '\t'); - } - - return string; -} - -SyntaxNode.prototype.innerText = function() -{ - var range = this.range; - - return this.source.substr(range.location, range.length); -} - -SyntaxNode.prototype.traverse = function(walker) -{ - if (!walker.enteredNode || walker.enteredNode(this) !== false) - { - var children = this.children, - index = 0, - count = children && children.length; - - for (; index < count; ++index) - { - var child = children[index]; - - if (typeof child !== "string") - child.traverse(walker); - - else if (walker.traversesTextNodes) - { - walker.enteredNode(child); - walker.exitedNode(child); - } - } - } - - if (walker.exitedNode) - walker.exitedNode(this); -} - - -exports.Parser = new Parser(compiledGrammar); - From 8100cdb17f2d9eec721800e15f48e96c8a10592a Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Mon, 7 Jan 2013 23:13:54 +0100 Subject: [PATCH 26/46] Fixed "Can't find variable: ObjJCompiler" error --- Objective-J/Executable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/Executable.js b/Objective-J/Executable.js index 6fd3fd57c..e604ec9cf 100644 --- a/Objective-J/Executable.js +++ b/Objective-J/Executable.js @@ -497,7 +497,7 @@ Executable.fileExecutableSearcherForURL = function(/*CFURL*/ referenceURL) { if (!aStaticResource) { - var compilingFileUrl = ObjJCompiler && ObjJCompiler.currentCompileFile ? ObjJCompiler.currentCompileFile : ObjJAcornCompiler ? ObjJAcornCompiler.currentCompileFile : null; + var compilingFileUrl = ObjJAcornCompiler ? ObjJAcornCompiler.currentCompileFile : null; throw new Error("Could not load file at " + aURL + (compilingFileUrl ? " when compiling " + compilingFileUrl : "")); } From d20fb2039a4492ad2baf1e38e05203e2f90015a6 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 14:34:29 +0100 Subject: [PATCH 27/46] Missed some lines in manual merge --- AppKit/CPWindow/_CPWindow.j | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AppKit/CPWindow/_CPWindow.j b/AppKit/CPWindow/_CPWindow.j index f2362b8ba..2b5778267 100644 --- a/AppKit/CPWindow/_CPWindow.j +++ b/AppKit/CPWindow/_CPWindow.j @@ -29,6 +29,9 @@ @import "CPPlatformWindow.j" @import "CPResponder.j" @import "CPScreen.j" +#if PLATFORM(BROWSER) +@import "CPPlatformWindow+DOM.j" +#endif /* From c755dc3ed97532a2ce34cdb1c6ff9e407b9764a5 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 17:00:54 +0100 Subject: [PATCH 28/46] Added some more detailed error messages in parser --- Objective-J/acorn.js | 71 ++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index dffd4c9bc..ecb45a35f 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -1080,11 +1080,11 @@ if (!exports.acorn) { } // Expect a token of a given type. If found, consume it, otherwise, - // raise an unexpected token error. + // raise with errorMessage or an unexpected token error. - function expect(type) { + function expect(type, errorMessage) { if (tokType === type) next(); - else unexpected(); + else errorMessage ? raise(tokStart, errorMessage) : unexpected(); } // Raise an unexpected token error. @@ -1184,7 +1184,7 @@ if (!exports.acorn) { labels.push(loopLabel); node.body = parseStatement(); labels.pop(); - expect(_while); + expect(_while, "Expected 'while' at end of do statement"); node.test = parseParenExpression(); semicolon(); return finishNode(node, "DoWhileStatement"); @@ -1200,7 +1200,7 @@ if (!exports.acorn) { case _for: next(); labels.push(loopLabel); - expect(_parenL); + expect(_parenL, "Expected '(' after 'for'"); if (tokType === _semi) return parseFor(node, null); if (tokType === _var) { var init = startNode(); @@ -1241,7 +1241,7 @@ if (!exports.acorn) { next(); node.discriminant = parseParenExpression(); node.cases = []; - expect(_braceL); + expect(_braceL, "Expected '{' in switch statement"); labels.push(switchLabel); // Statements under must be grouped (by label) in SwitchCase @@ -1260,7 +1260,7 @@ if (!exports.acorn) { if (sawDefault) raise(lastStart, "Multiple default clauses"); sawDefault = true; cur.test = null; } - expect(_colon); + expect(_colon, "Expected ':' after case clause"); } else { if (!cur) unexpected(); cur.consequent.push(parseStatement()); @@ -1286,11 +1286,11 @@ if (!exports.acorn) { while (tokType === _catch) { var clause = startNode(); next(); - expect(_parenL); + expect(_parenL, "Expected '(' after 'catch'"); clause.param = parseIdent(); if (strict && isStrictBadIdWord(clause.param.name)) raise(clause.param.start, "Binding " + clause.param.name + " in strict mode"); - expect(_parenR); + expect(_parenR, "Expected closing ')' after catch"); clause.guard = null; clause.body = parseBlock(); node.handlers.push(finishNode(clause, "CatchClause")); @@ -1337,7 +1337,7 @@ if (!exports.acorn) { node.superclassname = parseIdent(true); else if (eat(_parenL)) { node.categoryname = parseIdent(true); - expect(_parenR); + expect(_parenR, "Expected closing ')' after category name"); } if (eat(_braceL)) { node.ivardeclarations = []; @@ -1349,6 +1349,7 @@ if (!exports.acorn) { } node.body = []; while(!eat(_end)) { + if (tokType === _eof) raise(tokPos, "Expected '@end' after '@implementation'"); node.body.push(parseClassElement()); } } @@ -1430,12 +1431,12 @@ if (!exports.acorn) { switch(config.name) { case "property": case "getter": - expect(_eq); + expect(_eq, "Expected '=' after 'getter' accessor attribute"); decl.accessors[config.name] = parseIdent(true); break; case "setter": - expect(_eq); + expect(_eq, "Expected '=' after 'setter' accessor attribute"); var setter = parseIdent(true); decl.accessors[config.name] = setter; if (eat(_colon)) @@ -1454,7 +1455,7 @@ if (!exports.acorn) { } if (!eat(_comma)) break; } - expect(_parenR); + expect(_parenR, "Expected closing ')' after accessor attributes"); } } } @@ -1476,7 +1477,7 @@ if (!exports.acorn) { element.action = true; if (!eat(_parenR)) { element.returntype = parseObjectiveJType(); - expect(_parenR); + expect(_parenR, "Expected closing ')' after method return type"); } } // Now we parse the selector @@ -1491,17 +1492,17 @@ if (!exports.acorn) { if (first && tokType !== _colon) break; } else selectors.push(null); - expect(_colon); + expect(_colon, "Expected ':' in selector"); var argument = {}; args.push(argument); if (eat(_parenL)) { argument.type = parseObjectiveJType(); - expect(_parenR); + expect(_parenR, "Expected closing ')' after method argument type"); } argument.identifier = parseIdent(false); if (tokType === _braceL || eat(_semi)) break; if (eat(_comma)) { - expect(_dotdotdot); + expect(_dotdotdot, "Expected '...' after ',' in method declaration"); element.parameters = true; break; } @@ -1524,9 +1525,9 @@ if (!exports.acorn) { // parentheses around their expression. function parseParenExpression() { - expect(_parenL); + expect(_parenL, "Expected '(' before expression"); var val = parseExpression(); - expect(_parenR); + expect(_parenR, "Expected closing ')' after expression"); return val; } @@ -1537,7 +1538,7 @@ if (!exports.acorn) { function parseBlock(allowStrict) { var node = startNode(), first = true, strict = false, oldStrict; node.body = []; - expect(_braceL); + expect(_braceL, "Expected '{' before block"); while (!eat(_braceR)) { var stmt = parseStatement(); node.body.push(stmt); @@ -1557,11 +1558,11 @@ if (!exports.acorn) { function parseFor(node, init) { node.init = init; - expect(_semi); + expect(_semi, "Expected ';' in for statement"); node.test = tokType === _semi ? null : parseExpression(); - expect(_semi); + expect(_semi, "Expected ';' in for statement"); node.update = tokType === _parenR ? null : parseExpression(); - expect(_parenR); + expect(_parenR, "Expected closing ')' in for statement"); node.body = parseStatement(); labels.pop(); return finishNode(node, "ForStatement"); @@ -1572,7 +1573,7 @@ if (!exports.acorn) { function parseForIn(node, init) { node.left = init; node.right = parseExpression(); - expect(_parenR); + expect(_parenR, "Expected closing ')' in for statement"); node.body = parseStatement(); labels.pop(); return finishNode(node, "ForInStatement"); @@ -1643,7 +1644,7 @@ if (!exports.acorn) { var node = startNodeFrom(expr); node.test = expr; node.consequent = parseExpression(true); - expect(_colon); + expect(_colon, "Expected ':' in conditional expression"); node.alternate = parseExpression(true, noIn); return finishNode(node, "ConditionalExpression"); } @@ -1732,7 +1733,7 @@ if (!exports.acorn) { node.object = base; node.property = expr; node.computed = true; - expect(_bracketR); + expect(_bracketR, "Expected closing ']' in subscript"); return parseSubscripts(finishNode(node, "MemberExpression"), noCalls); } else if (!noCalls && eat(_parenL)) { var node = startNodeFrom(base); @@ -1778,7 +1779,7 @@ if (!exports.acorn) { } if (options.ranges) val.range = [tokStart1, tokEnd]; - expect(_parenR); + expect(_parenR, "Expected closing ')' in expression"); return val; case _bracketL: @@ -1807,9 +1808,9 @@ if (!exports.acorn) { case _selector: var node = startNode(); next(); - expect(_parenL); + expect(_parenL, "Expected '(' after '@selector'"); parseSelector(node, _parenR); - expect(_parenR); + expect(_parenR, "Expected closing ')' after selector"); return finishNode(node, "SelectorLiteralExpression"); default: @@ -1834,7 +1835,7 @@ if (!exports.acorn) { selectors.push(parseIdent(true).name); if (first && tokType === close) break; } - expect(_colon); + expect(_colon, "Expected ':' in selector"); selectors.push(":"); if (tokType === close) break; first = false; @@ -1857,7 +1858,7 @@ if (!exports.acorn) { } else { selectors.push(null); } - expect(_colon); + expect(_colon, "Expected ':' in selector"); args.push(parseExpression(true)); if (eat(close)) break; @@ -1895,7 +1896,7 @@ if (!exports.acorn) { next(); while (!eat(_braceR)) { if (!first) { - expect(_comma); + expect(_comma, "Expected ',' in object literal"); if (options.allowTrailingCommas && eat(_braceR)) break; } else first = false; @@ -1946,9 +1947,9 @@ if (!exports.acorn) { else node.id = null; node.params = []; var first = true; - expect(_parenL); + expect(_parenL, "Expected '(' before function parameters"); while (!eat(_parenR)) { - if (!first) expect(_comma); else first = false; + if (!first) expect(_comma, "Expected ',' between function parameters"); else first = false; node.params.push(parseIdent()); } @@ -1994,7 +1995,7 @@ if (!exports.acorn) { if (allowEmpty && tokType === _comma && !firstExpr) elts.push(null); else elts.push(firstExpr); } else { - expect(_comma); + expect(_comma, "Expected ',' between expressions"); if (allowTrailingComma && options.allowTrailingCommas && eat(close)) break; if (allowEmpty && tokType === _comma) elts.push(null); else elts.push(parseExpression(true)); From 9f0da2ec41730b7b140d487b50e56cd94e6910e9 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 22:13:36 +0100 Subject: [PATCH 29/46] Fixed spelling error --- Objective-J/acorn.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index ecb45a35f..6561f2d69 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -96,7 +96,7 @@ if (!exports.acorn) { // When `location` is on, you can pass this to record the source // file in every node's `loc` object. sourceFile: null, - // Turn on objj to allow objj systax + // Turn on objj to allow Objective-J syntax objj: true }; From 547f9ff61f04e5789f223a0ebbb60d283fb556f0 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 22:18:19 +0100 Subject: [PATCH 30/46] Merge with latest from Acorn master --- Objective-J/acorn.js | 65 ++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 6561f2d69..3746ed3cc 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -455,13 +455,18 @@ if (!exports.acorn) { return match ? match.index + match[0].length : input.length + 1; } + var line_loc_t = function() { + this.line = tokCurLine; + this.column = tokPos - tokLineStart; + } + function curLineLoc() { while (tokLineStartNext <= tokPos) { ++tokCurLine; tokLineStart = tokLineStartNext; tokLineStartNext = nextLineStart(); } - return {line: tokCurLine, column: tokPos - tokLineStart}; + return new line_loc_t(); } // Reset the token state. Used at the start of a parse. @@ -828,15 +833,17 @@ if (!exports.acorn) { // Read a string value, interpreting backslash-escapes. + var rs_str = []; + function readString(quote) { tokPos++; - var str = []; + rs_str.length = 0; for (;;) { if (tokPos >= inputLen) raise(tokStart, "Unterminated string constant"); var ch = input.charCodeAt(tokPos); if (ch === quote) { ++tokPos; - return finishToken(_string, String.fromCharCode.apply(null, str)); + return finishToken(_string, String.fromCharCode.apply(null, rs_str)); } if (ch === 92) { // '\' ch = input.charCodeAt(++tokPos); @@ -847,28 +854,28 @@ if (!exports.acorn) { ++tokPos; if (octal) { if (strict) raise(tokPos - 2, "Octal literal in strict mode"); - str.push(parseInt(octal, 8)); + rs_str.push(parseInt(octal, 8)); tokPos += octal.length - 1; } else { switch (ch) { - case 110: str.push(10); break; // 'n' -> '\n' - case 114: str.push(13); break; // 'r' -> '\r' - case 120: str.push(readHexChar(2)); break; // 'x' - case 117: str.push(readHexChar(4)); break; // 'u' - case 85: str.push(readHexChar(8)); break; // 'U' - case 116: str.push(9); break; // 't' -> '\t' - case 98: str.push(8); break; // 'b' -> '\b' - case 118: str.push(11); break; // 'v' -> '\u000b' - case 102: str.push(12); break; // 'f' -> '\f' - case 48: str.push(0); break; // 0 -> '\0' + case 110: rs_str.push(10); break; // 'n' -> '\n' + case 114: rs_str.push(13); break; // 'r' -> '\r' + case 120: rs_str.push(readHexChar(2)); break; // 'x' + case 117: rs_str.push(readHexChar(4)); break; // 'u' + case 85: rs_str.push(readHexChar(8)); break; // 'U' + case 116: rs_str.push(9); break; // 't' -> '\t' + case 98: rs_str.push(8); break; // 'b' -> '\b' + case 118: rs_str.push(11); break; // 'v' -> '\u000b' + case 102: rs_str.push(12); break; // 'f' -> '\f' + case 48: rs_str.push(0); break; // 0 -> '\0' case 13: if (input.charCodeAt(tokPos) === 10) ++tokPos; // '\r\n' case 10: break; // ' \n' - default: str.push(ch); break; + default: rs_str.push(ch); break; } } } else { if (ch === 13 || ch === 10 || ch === 8232 || ch === 8329) raise(tokStart, "Unterminated string constant"); - if (ch !== 92) str.push(ch); // '\' // This 'if' seems useless as the same thing is checked above..... - Martin + if (ch !== 92) rs_str.push(ch); // '\' // This 'if' seems useless as the same thing is checked above..... - Martin ++tokPos; } } @@ -984,14 +991,26 @@ if (!exports.acorn) { // Start an AST node, attaching a start offset and optionally a // `commentsBefore` property to it. + var node_t = function(s) { + this.type = null; + this.start = tokStart; + this.end = null; + }; + + var node_loc_t = function(s) { + this.start = tokStartLoc; + this.end = null; + if (sourceFile !== null) this.source = sourceFile; + }; + function startNode() { - var node = {type: null, start: tokStart, end: null}; + var node = new node_t(); if (options.trackComments && tokCommentsBefore) { node.commentsBefore = tokCommentsBefore; tokCommentsBefore = null; } if (options.locations) - node.loc = {start: tokStartLoc, end: null, source: sourceFile}; + node.loc = new node_loc_t(); if (options.ranges) node.range = [tokStart, 0]; return node; @@ -1003,13 +1022,16 @@ if (!exports.acorn) { // already been parsed. function startNodeFrom(other) { - var node = {type: null, start: other.start}; + var node = new node_t(); + node.start = other.start; if (other.commentsBefore) { node.commentsBefore = other.commentsBefore; other.commentsBefore = null; } - if (options.locations) - node.loc = {start: other.loc.start, end: null, source: other.loc.source}; + if (options.locations) { + node.loc = new node_loc_t(); + node.loc.start = other.loc.start; + } if (options.ranges) node.range = [other.range[0], 0]; @@ -1764,6 +1786,7 @@ if (!exports.acorn) { case _null: case _true: case _false: var node = startNode(); node.value = tokType.atomValue; + node.raw = tokType.keyword next(); return finishNode(node, "Literal"); From 79d2ac05666e0429ca76d5debca130d89c053167 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 22:19:55 +0100 Subject: [PATCH 31/46] Fixed some comments and removed unwanted spaces --- Objective-J/acorn.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 3746ed3cc..86e556f7f 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -178,7 +178,8 @@ if (!exports.acorn) { var tokAfterImport; // This is the tokenizer's state for Objective-J. 'nodeMessageSendObjectExpression' - // is used to store the expression that is already parsed when + // is used to store the expression that is already parsed when a subscript was + // not really a subscript var nodeMessageSendObjectExpression; @@ -628,7 +629,7 @@ if (!exports.acorn) { if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2); return finishOp(code === 61 ? _eq : _prefix, 1); } - + function readToken_at(code) { // '@' var next = input.charCodeAt(++tokPos); if (next === 34 || next === 39) // Read string if "'" or '"' @@ -1512,7 +1513,7 @@ if (!exports.acorn) { if (tokType !== _colon) { selectors.push(parseIdent(true)); if (first && tokType !== _colon) break; - } else + } else selectors.push(null); expect(_colon, "Expected ':' in selector"); var argument = {}; @@ -1539,7 +1540,7 @@ if (!exports.acorn) { element.body = parseBlock(true); inFunction = oldInFunc; labels = oldLabels; return finishNode(element, "MethodDeclarationStatement"); - } else + } else return parseStatement(); } From 957b34d1697887ae03e369ee679cd3c68d5c5d8e Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Tue, 8 Jan 2013 22:23:34 +0100 Subject: [PATCH 32/46] Added the option trackSpaces to attach spacesBefore and spacesAfter properties to AST nodes. --- Objective-J/acorn.js | 62 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 86e556f7f..4d1859a96 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -73,6 +73,13 @@ if (!exports.acorn) { // after and before it), but never twice in the before (or after) // array of different nodes. trackComments: false, + // When `trackSpaces` is turned on, the parser will attach + // `spacesBefore` and `spacesAfter` properties to AST nodes + // holding arrays of strings. The same spaces may appear in both + // a `spacesBefore` and `spacesAfter` array (of the nodes + // after and before it), but never twice in the before (or after) + // array of different nodes. + trackSpaces: false, // When `locations` is on, `loc` properties holding objects with // `start` and `end` properties in `{line, column}` form (with // line being 1-based and column 0-based) will be attached to the @@ -151,6 +158,11 @@ if (!exports.acorn) { var tokCommentsBefore, tokCommentsAfter; + // These are used to hold arrays of spaces when + // `options.trackSpaces` is true. + + var tokSpacesBefore, tokSpacesAfter; + // Interal state for the tokenizer. To distinguish between division // operators and regular expressions, it remembers whether the last // token was one that is allowed to be followed by an expression. @@ -158,7 +170,7 @@ if (!exports.acorn) { // division operator. See the `parseStatement` function for a // caveat.) - var tokRegexpAllowed, tokComments; + var tokRegexpAllowed, tokComments, tokSpaces; // When `options.locations` is true, these are used to keep // track of the current line, and know when a new line has been @@ -478,11 +490,12 @@ if (!exports.acorn) { tokLineStartNext = nextLineStart(); tokRegexpAllowed = true; tokComments = null; + tokSpaces = null; skipSpace(); } // Called at the end of every token. Sets `tokEnd`, `tokVal`, - // `tokCommentsAfter`, and `tokRegexpAllowed`, and skips the space + // `tokCommentsAfter`, `tokSpacesAfter`, and `tokRegexpAllowed`, and skips the space // after the token, so that the next one's `tokStart` will point at // the right position. @@ -493,12 +506,14 @@ if (!exports.acorn) { skipSpace(); tokVal = val; tokCommentsAfter = tokComments; + tokSpacesAfter = tokSpaces; tokRegexpAllowed = type.beforeExpr; tokAfterImport = type.afterImport; } function skipBlockComment() { var end = input.indexOf("*/", tokPos += 2); + tokSpaces = null; if (end === -1) raise(tokPos - 2, "Unterminated comment"); if (options.trackComments) (tokComments || (tokComments = [])).push(input.slice(tokPos, end)); @@ -508,6 +523,7 @@ if (!exports.acorn) { function skipLineComment(skipCharacters) { var start = tokPos; var ch = input.charCodeAt(tokPos+=skipCharacters); + tokSpaces = null; while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) { ++tokPos; ch = input.charCodeAt(tokPos); @@ -516,12 +532,24 @@ if (!exports.acorn) { (tokComments || (tokComments = [])).push(input.slice(start, tokPos)); } + function skipWhiteSpaces() { + var start = tokPos; + var ch = input.charCodeAt(++tokPos); + while ((ch < 14 && ch > 8) || ch === 32 || ch === 160 || (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch)))) // 9 - 13, ' ', '\xa0' .... + ch = input.charCodeAt(++tokPos); + if (options.trackSpaces) + (tokSpaces || (tokSpaces = [])).push(input.slice(start, tokPos)); + } + // Called at the start of the parse and after every token. Skips // whitespace and comments, and, if `options.trackComments` is on, - // will store all skipped comments in `tokComments`. + // will store all skipped comments in `tokComments`. If + // `options.trackSpaces` is on, will store the last skipped spaces in + // `tokSpaces`. function skipSpace() { tokComments = null; + tokSpaces = null; while (tokPos < inputLen) { var ch = input.charCodeAt(tokPos); if (ch === 47) { // '/' @@ -531,12 +559,8 @@ if (!exports.acorn) { } else if (next === 47) { // '/' skipLineComment(2); } else break; - } else if (ch < 14 && ch > 8) { - ++tokPos; - } else if (ch === 32 || ch === 160) { // ' ', '\xa0' - ++tokPos; - } else if (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) { - ++tokPos; + } else if ((ch < 14 && ch > 8) || ch === 32 || ch === 160 || (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch)))) { // 9 - 13, ' ', '\xa0' .... + skipWhiteSpaces(); } else { break; } @@ -724,6 +748,7 @@ if (!exports.acorn) { tokStart = tokPos; if (options.locations) tokStartLoc = curLineLoc(); tokCommentsBefore = tokComments; + tokSpacesBefore = tokSpaces; if (forceRegexp) return readRegexp(); if (tokPos >= inputLen) return finishToken(_eof); @@ -1010,6 +1035,10 @@ if (!exports.acorn) { node.commentsBefore = tokCommentsBefore; tokCommentsBefore = null; } + if (options.trackSpaces && tokSpacesBefore) { + node.spacesBefore = tokSpacesBefore; + tokSpacesBefore = null; + } if (options.locations) node.loc = new node_loc_t(); if (options.ranges) @@ -1045,7 +1074,8 @@ if (!exports.acorn) { // We keep track of the last node that we finished, in order // 'bubble' `commentsAfter` properties up to the biggest node. I.e. // in '`1 + 1 // foo', the comment should be attached to the binary - // operator node, not the second literal node. + // operator node, not the second literal node. The same is done on + // `spacesAfter` var lastFinishedNode; @@ -1061,6 +1091,18 @@ if (!exports.acorn) { node.commentsAfter = lastFinishedNode.commentsAfter; lastFinishedNode.commentsAfter = null; } + if (!options.trackSpaces) + lastFinishedNode = node; + } + if (options.trackSpaces) { + if (tokSpacesAfter) { + node.spacesAfter = tokSpacesAfter; + tokSpacesAfter = null; + } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && + lastFinishedNode.spacesAfter) { + node.spacesAfter = lastFinishedNode.spacesAfter; + lastFinishedNode.spacesAfter = null; + } lastFinishedNode = node; } if (options.locations) From 0a573f9da10aed9675875d37c9364629c9bdcd0f Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 09:29:43 +0100 Subject: [PATCH 33/46] Removed unused 6th parameter --- Objective-J/CommonJS/lib/objective-j.js | 2 +- Objective-J/CommonJS/lib/objective-j/jake/bundletask.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j.js b/Objective-J/CommonJS/lib/objective-j.js index 6e4658155..254a96c16 100644 --- a/Objective-J/CommonJS/lib/objective-j.js +++ b/Objective-J/CommonJS/lib/objective-j.js @@ -94,7 +94,7 @@ exports.run = function(args) var arg0 = argv.shift(); var mainFilePath = FILE.canonical(arg0); - exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print, window); + exports.make_narwhal_factory(mainFilePath)(require, { }, module, system, print); if (typeof main === "function") main([arg0].concat(argv)); diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 45021f9c4..80193a8d9 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -880,7 +880,7 @@ BundleTask.prototype.defineSourceTasks = function() basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length); require("objective-j").setCurrentCompilerFlags(environmentCompilerFlags); - require("objective-j").make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print, window); + require("objective-j").make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print); TERM.stream.write("Compiling [\0blue(" + anEnvironment + "\0)] \0purple(" + aFilename + "\0)").flush(); var otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilename] ? otherwayTranslateFilenameToPath[aFilename] : aFilename, From 0dd98b56bcc26773a4e1e3ebd29859e3d045f2f1 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 10:21:16 +0100 Subject: [PATCH 34/46] "self." is only added to instance variables when compiling an instance method --- Objective-J/ObjJAcornCompiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index da456cada..077e748ca 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -692,7 +692,7 @@ MessageSendExpression: function(node, st, c) { st.compiler.lastPos = node.end; }, Identifier: function(node, st, c) { - if (!st.secondMemberExpression) + if (st.currentMethodType() === "-" && !st.secondMemberExpression) { var identifier = node.name, lvar = st.getLvarForCurrentMethod(identifier), From df78df59080f1d26529e056a6387fc1e29e87804 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 10:37:33 +0100 Subject: [PATCH 35/46] Fixed class method that access isa property --- Foundation/CPObject.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/CPObject.j b/Foundation/CPObject.j index 583638f32..2df6acce8 100644 --- a/Foundation/CPObject.j +++ b/Foundation/CPObject.j @@ -292,7 +292,7 @@ CPLog(@"Got some class: %@", inst); + (CPString)description { - return class_getName(isa); + return class_getName(self.isa); } // Sending Messages From 4fb8fa1311a1f383e9f9e6c957090056936a9154 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 14:03:38 +0100 Subject: [PATCH 36/46] Code clean up --- .../CommonJS/lib/objective-j/jake/bundletask.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index 80193a8d9..dd3a32ba6 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -791,9 +791,9 @@ BundleTask.prototype.defineStaticTask = function() fileStream.close(); // Make sure all classes are removed and all FileExecutables are removed. - require("objective-j").Executable.resetCachedFileExecutableSearchers(); - require("objective-j").StaticResource.resetRootResources(); - require("objective-j").FileExecutable.resetFileExecutables(); + ObjectiveJ.Executable.resetCachedFileExecutableSearchers(); + ObjectiveJ.StaticResource.resetRootResources(); + ObjectiveJ.FileExecutable.resetFileExecutables(); objj_resetRegisterClasses(); }); @@ -803,9 +803,6 @@ BundleTask.prototype.defineStaticTask = function() BundleTask.prototype.defineSourceTasks = function() { - // Use new compiler - //require("objective-j").ObjJCompiler.setCurrentUsedVersion("acorn"); - //require("objective-j").ObjJCompiler.setCurrentUsedVersion("objj_compiler2"); var sources = this.sources(); if (!sources) @@ -879,13 +876,13 @@ BundleTask.prototype.defineSourceTasks = function() absolutePath = FILE.absolute(theTranslatedFilename), basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length); - require("objective-j").setCurrentCompilerFlags(environmentCompilerFlags); - require("objective-j").make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print); + ObjectiveJ.setCurrentCompilerFlags(environmentCompilerFlags); + ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, e, module, system, print); TERM.stream.write("Compiling [\0blue(" + anEnvironment + "\0)] \0purple(" + aFilename + "\0)").flush(); var otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilename] ? otherwayTranslateFilenameToPath[aFilename] : aFilename, translatedFilename = translateFilenameToPath[aFilename] ? translateFilenameToPath[aFilename] : aFilename, - executer = new require("objective-j").FileExecutable(otherwayTranslatedFilename); + executer = new ObjectiveJ.FileExecutable(otherwayTranslatedFilename); var compiled = executer.toMarkedString(); } From 1dfc77a4ba532d1917b6f2d466f8275a42e35e44 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 14:12:58 +0100 Subject: [PATCH 37/46] Fixed objjc to use new acorn based compiler --- .../CommonJS/lib/objective-j/compiler.js | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j/compiler.js b/Objective-J/CommonJS/lib/objective-j/compiler.js index f7b15a8a1..b0ed29d2e 100644 --- a/Objective-J/CommonJS/lib/objective-j/compiler.js +++ b/Objective-J/CommonJS/lib/objective-j/compiler.js @@ -1,13 +1,14 @@ var FILE = require("file"), OS = require("os"), - ObjectiveJ = require("objective-j"); + ObjectiveJ = require("objective-j"), + JAKE = require("jake"); require("objective-j/rhino/regexp-rhino-patch"); -ObjectiveJ.Preprocessor.Flags.Preprocess = 1 << 10; -ObjectiveJ.Preprocessor.Flags.Compress = 1 << 11; -ObjectiveJ.Preprocessor.Flags.CheckSyntax = 1 << 12; +ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess = 1 << 10; +ObjectiveJ.ObjJAcornCompiler.Flags.Compress = 1 << 11; +ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax = 1 << 12; var compressors = { ss : { id : "minify/shrinksafe" } @@ -36,16 +37,15 @@ function compressor(code) function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavascript) { - var shouldObjjPreprocess = objjcFlags & ObjectiveJ.Preprocessor.Flags.Preprocess, - shouldCheckSyntax = objjcFlags & ObjectiveJ.Preprocessor.Flags.CheckSyntax, - shouldCompress = objjcFlags & ObjectiveJ.Preprocessor.Flags.Compress, + var shouldObjjPreprocess = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess, + shouldCheckSyntax = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax, + shouldCompress = objjcFlags & ObjectiveJ.ObjJAcornCompiler.Flags.Compress, fileContents = "", executable, code; - if (OS.popen("which gcc").stdout.read().length === 0) + if (!shouldObjjPreprocess && OS.popen("which gcc").stdout.read().length === 0) fileContents = FILE.read(aFilePath, { charset:"UTF-8" }); - else { // GCC preprocess the file. @@ -54,30 +54,38 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc while (chunk = gcc.stdout.read()) fileContents += chunk; - } - if (!shouldObjjPreprocess) return fileContents; + } // Preprocess contents into fragments. // FIXME: should calculate relative path, etc. try { - executable = ObjectiveJ.preprocess(fileContents, FILE.basename(aFilePath), objjcFlags); + var sources = new JAKE.FileList("**/*.j"), + translateFilenameToPath = {}, + otherwayTranslateFilenameToPath = {}; + + // Create a filename to filename path dictionary. (For example: CPArray.j -> CPArray/CPArray.j) + sources.forEach(function(/*String*/ aFilename) + { + translateFilenameToPath[FILE.basename(aFilename)] = aFilename; + otherwayTranslateFilenameToPath[aFilename] = FILE.basename(aFilename); + }, this); + + var translatedFilename = translateFilenameToPath[aFilePath] ? translateFilenameToPath[aFilePath] : aFilePath, + otherwayTranslatedFilename = otherwayTranslateFilenameToPath[aFilePath] ? otherwayTranslateFilenameToPath[aFilePath] : aFilePath, + theTranslatedFilename = otherwayTranslatedFilename ? otherwayTranslatedFilename : translatedFilename, + absolutePath = FILE.absolute(theTranslatedFilename), + basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length); + + ObjectiveJ.setCurrentCompilerFlags(objjcFlags); + ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, {}, module, system, print); + + executable = new ObjectiveJ.FileExecutable(FILE.basename(aFilePath)); } catch (anException) - {print(anException); - var lines = fileContents.split("\n"), - PAD = 3, - lineNumber = anException.lineNumber || anException.line, - errorInfo = "Syntax error in " + aFilePath + - " on preprocessed line number " + lineNumber + "\n\n" + - "\t" + lines.slice(Math.max(0, lineNumber - 1 - PAD), lineNumber + PAD).join("\n\t"); - - print(errorInfo); - - throw errorInfo; - } + {} if (shouldCompress) { @@ -100,7 +108,7 @@ function resolveFlags(args) count = args.length, gccFlags = [], - objjcFlags = ObjectiveJ.Preprocessor.Flags.Preprocess | ObjectiveJ.Preprocessor.Flags.CheckSyntax; + objjcFlags = ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess | ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax; for (; index < count; ++index) { @@ -128,19 +136,19 @@ function resolveFlags(args) } else if (argument.indexOf("-E") === 0) - objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.Preprocess; + objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.Preprocess; else if (argument.indexOf("-S") === 0) - objjcFlags &= ~ObjectiveJ.Preprocessor.Flags.CheckSyntax; + objjcFlags &= ~ObjectiveJ.ObjJAcornCompiler.Flags.CheckSyntax; else if (argument.indexOf("-T") === 0) - objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeTypeSignatures; + objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures; else if (argument.indexOf("-g") === 0) - objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeDebugSymbols; + objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeDebugSymbols; else if (argument.indexOf("-O") === 0) - objjcFlags |= ObjectiveJ.Preprocessor.Flags.Compress; + objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.Compress; else filePaths.push(argument); @@ -191,7 +199,7 @@ exports.main = function(args) if (argv[0] === "-T" || argv[0] === "--includeTypeSignatures") { - objjcFlags |= ObjectiveJ.Preprocessor.Flags.IncludeTypeSignatures; + objjcFlags |= ObjectiveJ.ObjJAcornCompiler.Flags.IncludeTypeSignatures; argv.shift(); continue; } From 89da16afeceb2306b62c841fd8c7571a01ae6a4f Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Wed, 9 Jan 2013 14:58:22 +0100 Subject: [PATCH 38/46] Fixed objjc to output compiled source not the input source --- .../CommonJS/lib/objective-j/compiler.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Objective-J/CommonJS/lib/objective-j/compiler.js b/Objective-J/CommonJS/lib/objective-j/compiler.js index b0ed29d2e..49b32b878 100644 --- a/Objective-J/CommonJS/lib/objective-j/compiler.js +++ b/Objective-J/CommonJS/lib/objective-j/compiler.js @@ -44,17 +44,20 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc executable, code; - if (!shouldObjjPreprocess && OS.popen("which gcc").stdout.read().length === 0) - fileContents = FILE.read(aFilePath, { charset:"UTF-8" }); - else + if (!shouldObjjPreprocess) { - // GCC preprocess the file. - var gcc = OS.popen("gcc -E -x c -P " + (gccFlags ? gccFlags.join(" ") : "") + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), - chunk = ""; + if (OS.popen("which gcc").stdout.read().length === 0) + fileContents = FILE.read(aFilePath, { charset:"UTF-8" }); + else + { + // GCC preprocess the file. + var gcc = OS.popen("gcc -E -x c -P " + (gccFlags ? gccFlags.join(" ") : "") + " " + OS.enquote(aFilePath), { charset:"UTF-8" }), + chunk = ""; - while (chunk = gcc.stdout.read()) - fileContents += chunk; + while (chunk = gcc.stdout.read()) + fileContents += chunk; + } return fileContents; } From c192f3b47beddf044e8af3ab7d73f6292b4fc2aa Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 10 Jan 2013 11:21:45 +0100 Subject: [PATCH 39/46] Fix to make the Cappuccino framework compile with rhino --- Objective-J/CommonJS/lib/objective-j/compiler.js | 13 +++++++++++++ .../CommonJS/lib/objective-j/jake/bundletask.js | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j/compiler.js b/Objective-J/CommonJS/lib/objective-j/compiler.js index 49b32b878..173fe0977 100644 --- a/Objective-J/CommonJS/lib/objective-j/compiler.js +++ b/Objective-J/CommonJS/lib/objective-j/compiler.js @@ -82,10 +82,23 @@ function compileWithResolvedFlags(aFilePath, objjcFlags, gccFlags, asPlainJavasc absolutePath = FILE.absolute(theTranslatedFilename), basePath = absolutePath.substring(0, absolutePath.length - theTranslatedFilename.length); + // This ugly fix to make Cappuccino compile with rhino can be removed when the compiler is not loading classes into the runtime + var rhinoUglyFix = false; + if (system.engine === "rhino") + { + if (typeof document == "undefined") { + document = { createElement: function(x) { return { innerText: ""}}}; + rhinoUglyFix = true; + } + } + ObjectiveJ.setCurrentCompilerFlags(objjcFlags); ObjectiveJ.make_narwhal_factory(absolutePath, basePath, translateFilenameToPath)(require, {}, module, system, print); executable = new ObjectiveJ.FileExecutable(FILE.basename(aFilePath)); + + if (rhinoUglyFix) + delete document; } catch (anException) {} diff --git a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js index dd3a32ba6..34e7c4c5b 100644 --- a/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js +++ b/Objective-J/CommonJS/lib/objective-j/jake/bundletask.js @@ -861,7 +861,17 @@ BundleTask.prototype.defineSourceTasks = function() filedir (compiledEnvironmentSource, [aFilename], function() { - var compile + // This ugly fix to make Cappuccino compile with rhino can be removed when the compiler is not loading classes into the runtime + var rhinoUglyFix = false; + if (system.engine === "rhino") + { + if (typeof document == "undefined") { + document = { createElement: function(x) { return { innerText: ""}}}; + rhinoUglyFix = true; + } + } + + var compile; // if this file doesn't exist or isn't a .j file, don't preprocess it. if (FILE.extension(aFilename) !== ".j") { @@ -887,6 +897,9 @@ BundleTask.prototype.defineSourceTasks = function() var compiled = executer.toMarkedString(); } + if (rhinoUglyFix) + delete document; + TERM.stream.print(Array(Math.round(compiled.length / 1024) + 3).join(".")); FILE.write(compiledEnvironmentSource, compiled, { charset:"UTF-8" }); }); From 7c71cd1f80b5cd88e656ea1d9afcbd3254cfd9bc Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Thu, 10 Jan 2013 19:30:34 +0100 Subject: [PATCH 40/46] The new compiler takes care of hoisted variables --- Objective-J/ObjJAcornCompiler.js | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 077e748ca..01c77a53c 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -79,6 +79,17 @@ Scope.prototype.currentMethodType = function() return this.methodType ? this.methodType : this.prev ? this.prev.currentMethodType() : null; } +Scope.prototype.copyAddedSelfToIvarsToParent = function() +{ + if (this.prev && this.addedSelfToIvars) for (var key in this.addedSelfToIvars) + { + var addedSelfToIvar = this.addedSelfToIvars[key], + scopeAddedSelfToIvar = (this.prev.addedSelfToIvars || (this.prev.addedSelfToIvars = Object.create(null)))[key] || (this.prev.addedSelfToIvars[key] = []); + + scopeAddedSelfToIvar.push.apply(scopeAddedSelfToIvar, addedSelfToIvar); // Append at end in parent scope + } +} + var currentCompilerFlags = ""; var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned*/ flags, /*unsigned*/ pass) @@ -359,6 +370,7 @@ Function: function(node, scope, c) { scope.compiler.lastPos = node.id.end; } c(node.body, inner, "ScopeBody"); + inner.copyAddedSelfToIvarsToParent(); }, TryStatement: function(node, scope, c) { c(node.block, scope, "Statement"); @@ -366,14 +378,28 @@ TryStatement: function(node, scope, c) { var handler = node.handlers[i], inner = new Scope(scope); inner.vars[handler.param.name] = {type: "catch clause", node: handler.param}; c(handler.body, inner, "ScopeBody"); + inner.copyAddedSelfToIvarsToParent(); } if (node.finalizer) c(node.finalizer, scope, "Statement"); }, VariableDeclaration: function(node, scope, c) { for (var i = 0; i < node.declarations.length; ++i) { - var decl = node.declarations[i]; - scope.vars[decl.id.name] = {type: "var", node: decl.id}; + var decl = node.declarations[i], + identifier = decl.id.name; + scope.vars[identifier] = {type: "var", node: decl.id}; if (decl.init) c(decl.init, scope, "Expression"); + if (scope.addedSelfToIvars) { + var addedSelfToIvar = scope.addedSelfToIvars[identifier]; + if (addedSelfToIvar) { + var buffer = scope.compiler.jsBuffer.atoms; + for (var i = 0; i < addedSelfToIvar.length; i++) { + var dict = addedSelfToIvar[i]; + buffer[dict.index] = ""; + scope.compiler.addWarning(createMessage("Local declaration of '" + identifier + "' hides instance variable", dict.node, scope.compiler.source)); + } + scope.addedSelfToIvars[identifier] = []; + } + } } }, MemberExpression: function(node, st, c) { @@ -711,6 +737,9 @@ Identifier: function(node, st, c) { CONCAT(compiler.jsBuffer, compiler.source.substring(compiler.lastPos, nodeStart)); compiler.lastPos = nodeStart; } while (compiler.source.substr(nodeStart++, 1) === "(") + // Save the index in where the "self." string is stored and the node. + // These will be used if we find a variable declaration that is hoisting this identifier. + ((st.addedSelfToIvars || (st.addedSelfToIvars = Object.create(null)))[identifier] || (st.addedSelfToIvars[identifier] = [])).push({node: node, index: compiler.jsBuffer.atoms.length}); CONCAT(compiler.jsBuffer, "self."); } } From f076b05e7ea13b503a04798ae4d44fbf5714d332 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 11 Jan 2013 08:06:51 +0100 Subject: [PATCH 41/46] =?UTF-8?q?More=20information:=20Shows=20that=20the?= =?UTF-8?q?=20new=20compiler=20is=20used=20when=20doing=20"objjc=20--help"?= =?UTF-8?q?.=20New=20output:=20"Usage=20(objjc=202.0):=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Objective-J/CommonJS/lib/objective-j/compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objective-J/CommonJS/lib/objective-j/compiler.js b/Objective-J/CommonJS/lib/objective-j/compiler.js index 173fe0977..2c7d582b9 100644 --- a/Objective-J/CommonJS/lib/objective-j/compiler.js +++ b/Objective-J/CommonJS/lib/objective-j/compiler.js @@ -222,7 +222,7 @@ exports.main = function(args) if (argv[0] === "--help" || argv[0].substr(0, 1) == '-') { - print("Usage: " + args[0] + " [options] [--] file..."); + print("Usage (objjc 2.0): " + args[0] + " [options] [--] file..."); print(" -p, --print print the output directly to stdout"); print(" --unmarked don't tag the output with @STATIC header"); print(""); From 3e93e180f163b7bec1fff6ca452a2ea799e5a8a7 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 11 Jan 2013 20:36:12 +0100 Subject: [PATCH 42/46] Turn off test case that don't apply to the new compiler --- .../Preprocessor/BehaviorTests/IvarTest.j | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j b/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j index fe4d770b5..40ca2c958 100644 --- a/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j +++ b/Tests/Objective-J/Preprocessor/BehaviorTests/IvarTest.j @@ -85,23 +85,27 @@ [self assert:5 equals:testClass.ivar1]; } -- (void)testWithStatementInMethod +// I'm turning this test off as we move to the new compiler. +// We have to figure out how this should work. - Martin +/*- (void)testWithStatementInMethod { [self assert:nil equals:testClass.ivar1]; [testClass setIvar1DespiteAWithStatement:5]; [self assert:5 equals:testClass.ivar1]; [testClass doNothingToIvar1BecauseOfWithStatement:10]; [self assert:5 equals:testClass.ivar1]; -} +}*/ -- (void)testEvalInMethod +// I'm turning this test off as we move to the new compiler. +// We have to figure out how this should work. - Martin +/*- (void)testEvalInMethod { [self assert:nil equals:testClass.ivar1]; [testClass setIvar1UsingEval:5]; [self assert:5 equals:testClass.ivar1]; [testClass doNothingToIvar1UsingEval:10]; [self assert:5 equals:testClass.ivar1]; -} +}*/ - (void)testIvarShadowing { From 3dc6a30c4c6a95f6f1676e8842bfdf1135087adf Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 11 Jan 2013 20:36:19 +0100 Subject: [PATCH 43/46] Code clean up --- Objective-J/ObjJAcornCompiler.js | 63 +++++--------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/Objective-J/ObjJAcornCompiler.js b/Objective-J/ObjJAcornCompiler.js index 01c77a53c..18bd412d5 100644 --- a/Objective-J/ObjJAcornCompiler.js +++ b/Objective-J/ObjJAcornCompiler.js @@ -56,7 +56,7 @@ Scope.prototype.getIvarForCurrentClass = function(/* String */ ivarName) return null; } -Scope.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) +Scope.prototype.getLvar = function(/* String */ lvarName) { if (this.vars) { @@ -69,7 +69,7 @@ Scope.prototype.getLvarForCurrentMethod = function(/* String */ lvarName) // Stop at the method declaration if (prev && !this.methodtype) - return prev.getLvarForCurrentMethod(lvarName); + return prev.getLvar(lvarName); return null; } @@ -102,11 +102,6 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* this.cmBuffer = null; this.warnings = []; - //console.log("Start Parse: " + aURL); - var start = new Date().getTime(); -#ifdef BROWSER - //console.time("Parse with Acorn - " + aURL); -#endif try { this.tokens = exports.acorn.parse(aString); } @@ -122,38 +117,12 @@ var ObjJAcornCompiler = function(/*String*/ aString, /*CFURL*/ aURL, /*unsigned* } throw e; } - var end = new Date().getTime(); - var time = (end - start) / 1000; - //print("Parse with Acorn: " + aURL + " in " + time + " seconds"); -#ifdef BROWSER - //console.timeEnd("Parse with Acorn - " + aURL); -#endif + this.dependencies = []; this.flags = flags | ObjJAcornCompiler.Flags.IncludeDebugSymbols; this.classDefs = Object.create(null); this.lastPos = 0; - //var start = new Date().getTime(); -#ifdef BROWSER - //console.time("Compile pass " + pass + " - " + aURL); -#endif - try { - compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); - } - catch (e) { - #ifdef BROWSER - //console.log("Error: " + e + ", file content: " + aString); - #else - //print("Error: " + e + ", file content: " + aString); - #endif - throw e; - } - //var end = new Date().getTime(); - //var time = (end - start) / 1000; - //print("Compile pass 1: " + aURL + " in " + time + " seconds"); -#ifdef BROWSER - //console.timeEnd("Compile pass " + pass + " - " + aURL); -#endif -// console.log("JS: " + this.jsBuffer); + compile(this.tokens, new Scope(null ,{ compiler: this }), pass === 2 ? pass2 : pass1); } exports.ObjJAcornCompiler = ObjJAcornCompiler; @@ -181,19 +150,7 @@ ObjJAcornCompiler.prototype.compilePass2 = function() this.pass = 2; this.jsBuffer = new StringBuffer(); this.warnings = []; - //console.log("Start Compile2: " + this.URL); - //var start = new Date().getTime(); -#ifdef BROWSER - //console.time("Compile pass 2" + this.pass + " - " + this.URL); -#endif compile(this.tokens, new Scope(null ,{ compiler: this }), pass2); - //var end = new Date().getTime(); - //var time = (end - start) / 1000; - //print("Compile pass 2: " + this.URL + " in " + time + " seconds"); -#ifdef BROWSER - //console.timeEnd("Compile pass 2" + this.pass + " - " + this.URL); -#endif - //print("Compiled: \n" + this.jsBuffer.toString()); for (var i = 0; i < this.warnings.length; i++) { @@ -308,9 +265,8 @@ ObjJAcornCompiler.prototype.JSBuffer = function() ObjJAcornCompiler.prototype.prettifyMessage = function(/* Message */ aMessage, /* String */ messageType) { - var line = this.source.substring(aMessage.lineStart, aMessage.lineEnd); - var message = "\n" + line; - //print("e: " + e + ", e.lineStart: " + e.lineStart + ", e.lineEnd: " + e.lineEnd + ", e.column: " + e.column); + var line = this.source.substring(aMessage.lineStart, aMessage.lineEnd), + message = "\n" + line; message += (new Array(aMessage.column + 1)).join(" "); message += (new Array(Math.min(1, line.length) + 1)).join("^") + "\n"; @@ -329,6 +285,7 @@ ObjJAcornCompiler.prototype.error_message = function(errorMessage, astNode) function createMessage(/* String */ aMessage, /* SpiderMonkey AST node */ node, /* String */ code) { var message = exports.acorn.getLineInfo(code, node.start); + message.message = aMessage; return message; @@ -655,7 +612,7 @@ MethodDeclarationStatement: function(node, st, c) { CONCAT(st.compiler.jsBuffer, st.compiler.source.substring(st.compiler.lastPos, node.body.end)); CONCAT(st.compiler.jsBuffer, "\n"); - if (st.compiler.flags & ObjJAcornCompiler.Flags.IncludeDebugSymbols) //flags.IncludeTypeSignatures) + if (st.compiler.flags & ObjJAcornCompiler.Flags.IncludeDebugSymbols) CONCAT(st.compiler.jsBuffer, ","+JSON.stringify(types)); CONCAT(st.compiler.jsBuffer, ")"); st.compiler.jsBuffer = saveJSBuffer; @@ -702,7 +659,7 @@ MessageSendExpression: function(node, st, c) { st.compiler.lastPos = argument.end; } - // TODO: Move this 'if' wtih body up inside the node.argument 'if' + // TODO: Move this 'if' with body up inside the node.argument 'if' if (node.parameters) for (var i = 0; i < node.parameters.length; ++i) { var parameter = node.parameters[i]; @@ -721,7 +678,7 @@ Identifier: function(node, st, c) { if (st.currentMethodType() === "-" && !st.secondMemberExpression) { var identifier = node.name, - lvar = st.getLvarForCurrentMethod(identifier), + lvar = st.getLvar(identifier), ivar = st.compiler.getIvarForClass(identifier, st); if (ivar) From 85481225a3151da3908fee74945ae41acdb87139 Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Sat, 12 Jan 2013 16:47:44 +0700 Subject: [PATCH 44/46] Use a better error message for missing semicolons, trailing whitespace elimination --- Objective-J/acorn.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 4d1859a96..320f7743a 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -613,14 +613,14 @@ if (!exports.acorn) { function readToken_caret() { // '^' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_assign, 2); - return finishOp(_bin4, 1); + return finishOp(_bin4, 1); } function readToken_plus_min(code) { // '+-' var next = input.charCodeAt(tokPos+1); if (next === code) return finishOp(_incdec, 2); if (next === 61) return finishOp(_assign, 2); - return finishOp(_plusmin, 1); + return finishOp(_plusmin, 1); } function readToken_lt_gt(code) { // '<>' @@ -647,7 +647,7 @@ if (!exports.acorn) { size = input.charCodeAt(tokPos+2) === 61 ? 3 : 2; return finishOp(_bin7, size); } - + function readToken_eq_excl(code) { // '=!' var next = input.charCodeAt(tokPos+1); if (next === 61) return finishOp(_bin6, input.charCodeAt(tokPos+2) === 61 ? 3 : 2); @@ -756,7 +756,7 @@ if (!exports.acorn) { // Identifier or keyword. '\uXXXX' sequences are allowed in // identifiers, so '\' also dispatches to that. if (isIdentifierStart(code) || code === 92 /* '\' */) return readWord(); - + var tok = getTokenFromCode(code); if(tok === false) { @@ -765,7 +765,7 @@ if (!exports.acorn) { var ch = String.fromCharCode(code); if (ch === "\\" || nonASCIIidentifierStart.test(ch)) return readWord(); raise(tokPos, "Unexpected character '" + ch + "'"); - } + } return tok; } @@ -831,7 +831,7 @@ if (!exports.acorn) { } // Read an integer, octal integer, or floating-point number. - + function readNumber(ch) { var start = tokPos, isFloat = ch === "."; if (!isFloat && readInt(10) == null) raise(start, "Invalid number"); @@ -995,7 +995,7 @@ if (!exports.acorn) { // ### Parser utilities // Continue to the next token. - + function next() { lastStart = tokStart; lastEnd = tokEnd; @@ -1141,7 +1141,7 @@ if (!exports.acorn) { // pretend that there is a semicolon at this position. function semicolon() { - if (!eat(_semi) && !canInsertSemicolon()) unexpected(); + if (!eat(_semi) && !canInsertSemicolon()) raise(lastEnd, "Expected a semicolon"); } // Expect a token of a given type. If found, consume it, otherwise, @@ -1297,7 +1297,7 @@ if (!exports.acorn) { // In `return` (and `break`/`continue`), the keywords with // optional arguments, we eagerly look for a semicolon or the // possibility to insert one. - + if (eat(_semi) || canInsertSemicolon()) node.argument = null; else { node.argument = parseExpression(); semicolon(); } return finishNode(node, "ReturnStatement"); @@ -1312,7 +1312,7 @@ if (!exports.acorn) { // Statements under must be grouped (by label) in SwitchCase // nodes. `cur` is used to keep the node that we are currently // adding statements to. - + for (var cur, sawDefault; tokType != _braceR;) { if (tokType === _case || tokType === _default) { var isCase = tokType === _case; @@ -1942,7 +1942,7 @@ if (!exports.acorn) { // New's precedence is slightly tricky. It must allow its argument // to be a `[]` or dot subscript expression, but not a call — at - // least, not without wrapping it in parentheses. Thus, it uses the + // least, not without wrapping it in parentheses. Thus, it uses the function parseNew() { var node = startNode(); From a652fdf8d2590d51863aec01c4b4bba138334c0e Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sun, 13 Jan 2013 21:28:03 +0100 Subject: [PATCH 45/46] Fix for: Track comments will take the comment after the next token instead of the current. Also do "delete" of property instead of setting it to null for cleaner AST tree. --- Objective-J/acorn.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 320f7743a..8c0a2ee07 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -156,7 +156,7 @@ if (!exports.acorn) { // These are used to hold arrays of comments when // `options.trackComments` is true. - var tokCommentsBefore, tokCommentsAfter; + var tokCommentsBefore, tokCommentsAfter, lastTokCommentsAfter; // These are used to hold arrays of spaces when // `options.trackSpaces` is true. @@ -505,6 +505,7 @@ if (!exports.acorn) { tokType = type; skipSpace(); tokVal = val; + lastTokCommentsAfter = tokCommentsAfter; tokCommentsAfter = tokComments; tokSpacesAfter = tokSpaces; tokRegexpAllowed = type.beforeExpr; @@ -1056,7 +1057,7 @@ if (!exports.acorn) { node.start = other.start; if (other.commentsBefore) { node.commentsBefore = other.commentsBefore; - other.commentsBefore = null; + delete other.commentsBefore; } if (options.locations) { node.loc = new node_loc_t(); @@ -1083,13 +1084,13 @@ if (!exports.acorn) { node.type = type; node.end = lastEnd; if (options.trackComments) { - if (tokCommentsAfter) { - node.commentsAfter = tokCommentsAfter; + if (lastTokCommentsAfter) { + node.commentsAfter = lastTokCommentsAfter; tokCommentsAfter = null; } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && lastFinishedNode.commentsAfter) { node.commentsAfter = lastFinishedNode.commentsAfter; - lastFinishedNode.commentsAfter = null; + delete lastFinishedNode.commentsAfter; } if (!options.trackSpaces) lastFinishedNode = node; From 77d66fa0c99e0d480425cfc80dc8c9515d58dbc5 Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Sun, 13 Jan 2013 21:28:40 +0100 Subject: [PATCH 46/46] Fix for: Track spaces will take the spaces after the next token instead of the current. Also do "delete" of property instead of setting it to null for cleaner AST tree. --- Objective-J/acorn.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Objective-J/acorn.js b/Objective-J/acorn.js index 8c0a2ee07..3362fc397 100644 --- a/Objective-J/acorn.js +++ b/Objective-J/acorn.js @@ -161,7 +161,7 @@ if (!exports.acorn) { // These are used to hold arrays of spaces when // `options.trackSpaces` is true. - var tokSpacesBefore, tokSpacesAfter; + var tokSpacesBefore, tokSpacesAfter, lastTokSpacesAfter; // Interal state for the tokenizer. To distinguish between division // operators and regular expressions, it remembers whether the last @@ -506,6 +506,7 @@ if (!exports.acorn) { skipSpace(); tokVal = val; lastTokCommentsAfter = tokCommentsAfter; + lastTokSpacesAfter = tokSpacesAfter; tokCommentsAfter = tokComments; tokSpacesAfter = tokSpaces; tokRegexpAllowed = type.beforeExpr; @@ -514,7 +515,6 @@ if (!exports.acorn) { function skipBlockComment() { var end = input.indexOf("*/", tokPos += 2); - tokSpaces = null; if (end === -1) raise(tokPos - 2, "Unterminated comment"); if (options.trackComments) (tokComments || (tokComments = [])).push(input.slice(tokPos, end)); @@ -524,7 +524,6 @@ if (!exports.acorn) { function skipLineComment(skipCharacters) { var start = tokPos; var ch = input.charCodeAt(tokPos+=skipCharacters); - tokSpaces = null; while (tokPos < inputLen && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8329) { ++tokPos; ch = input.charCodeAt(tokPos); @@ -539,6 +538,7 @@ if (!exports.acorn) { while ((ch < 14 && ch > 8) || ch === 32 || ch === 160 || (ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch)))) // 9 - 13, ' ', '\xa0' .... ch = input.charCodeAt(++tokPos); if (options.trackSpaces) + //tokSpaces = input.slice(start, tokPos); (tokSpaces || (tokSpaces = [])).push(input.slice(start, tokPos)); } @@ -1059,6 +1059,10 @@ if (!exports.acorn) { node.commentsBefore = other.commentsBefore; delete other.commentsBefore; } + if (other.spacesBefore) { + node.spacesBefore = other.spacesBefore; + delete other.spacesBefore; + } if (options.locations) { node.loc = new node_loc_t(); node.loc.start = other.loc.start; @@ -1096,13 +1100,13 @@ if (!exports.acorn) { lastFinishedNode = node; } if (options.trackSpaces) { - if (tokSpacesAfter) { - node.spacesAfter = tokSpacesAfter; - tokSpacesAfter = null; + if (lastTokSpacesAfter) { + node.spacesAfter = lastTokSpacesAfter; + lastTokSpacesAfter = null; } else if (lastFinishedNode && lastFinishedNode.end === lastEnd && lastFinishedNode.spacesAfter) { node.spacesAfter = lastFinishedNode.spacesAfter; - lastFinishedNode.spacesAfter = null; + delete lastFinishedNode.spacesAfter; } lastFinishedNode = node; }