Skip to content

Use a separate field on a node to specify parser context flags. #1261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Nov 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f0b7315
Use a separate field on a node to specify parser context flags.
CyrusNajmabadi Nov 25, 2014
14f90b8
Update fidelity to match names.
CyrusNajmabadi Nov 25, 2014
8a61566
Extract context flags into their own enum.
CyrusNajmabadi Nov 25, 2014
726de4b
Add the context mutation operators.
CyrusNajmabadi Nov 25, 2014
7e1a62a
Add support for parsing generator functions and yield expressions.
CyrusNajmabadi Nov 25, 2014
78cd1b5
Parser tests for generators and yield expressions.
CyrusNajmabadi Nov 25, 2014
2f075a1
Fix parsing of function expression names.
CyrusNajmabadi Nov 25, 2014
d11eabc
Add test baselines.
CyrusNajmabadi Nov 25, 2014
3b253e9
Add an _es6 suffix to prevent name collisions.
CyrusNajmabadi Nov 25, 2014
d2aa688
Don't store both boolean context flags and a unified flags value.
CyrusNajmabadi Nov 25, 2014
1bf3ba8
Initialize enum in a way that makes it clearer that it is a Flags-enum.
CyrusNajmabadi Nov 25, 2014
5309171
Rename methods as per CR feedback.
CyrusNajmabadi Nov 25, 2014
ed2cd99
An asterisk is not a legal start of an enum member.
CyrusNajmabadi Nov 25, 2014
dac0a91
Don't use underscores in names.
CyrusNajmabadi Nov 25, 2014
bdaccf6
Rename parser context flags.
CyrusNajmabadi Nov 25, 2014
626e90e
Mark generator functions with an appropriate nodeflag.
CyrusNajmabadi Nov 25, 2014
8bbc409
Simplify fidelity implementation of context flags.
CyrusNajmabadi Nov 25, 2014
ce2e7fc
Have a node flag to indicate if a yield expression has a *.
CyrusNajmabadi Nov 25, 2014
dc6886c
Add clarifying comments.
CyrusNajmabadi Nov 25, 2014
3597f4f
Improve comments for both parsers and bring more in sync.
CyrusNajmabadi Nov 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/compiler/diagnosticInformationMap.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ module ts {
Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@
"category": "Error",
"code": 1162
},
"'yield' expression must be contained_within a generator declaration.": {
"category": "Error",
"code": 1163
},

"Duplicate identifier '{0}'.": {
"category": "Error",
Expand Down
449 changes: 365 additions & 84 deletions src/compiler/parser.ts

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ module ts {
ConditionalExpression,
TemplateExpression,
TemplateSpan,
YieldExpression,
OmittedExpression,
// Element
Block,
Expand Down Expand Up @@ -269,22 +270,30 @@ module ts {
DeclarationFile = 0x00000400, // Node is a .d.ts file
Let = 0x00000800, // Variable declaration
Const = 0x00001000, // Variable declaration

// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
// checking if the node can be reused in incremental settings.
ParsedInStrictModeContext = 0x00002000,
ParsedInDisallowInContext = 0x00004000,

OctalLiteral = 0x00008000,
OctalLiteral = 0x00002000,
Generator = 0x00004000,
YieldStar = 0x00008000,

Modifier = Export | Ambient | Public | Private | Protected | Static,
AccessibilityModifier = Public | Private | Protected,
BlockScoped = Let | Const
}

export const enum ParserContextFlags {
// Set if this node was parsed in strict mode. Used for grammar error checks, as well as
// checking if the node can be reused in incremental settings.
StrictMode = 1 << 0,
DisallowIn = 1 << 1,
Yield = 1 << 2,
GeneratorParameter = 1 << 3,
}

export interface Node extends TextRange {
kind: SyntaxKind;
flags: NodeFlags;
// Specific context the parser was in when this node was created. Normally undefined.
// Only set when the parser was in some interesting context (like async/yield).
parserContextFlags?: ParserContextFlags;
id?: number; // Unique id (used to look up NodeLinks)
parent?: Node; // Parent node (initialized by binding)
symbol?: Symbol; // Symbol declared by node (initialized by binding)
Expand Down Expand Up @@ -431,6 +440,10 @@ module ts {
operator: SyntaxKind;
operand: Expression;
}

export interface YieldExpression extends Expression {
expression: Expression;
}

export interface BinaryExpression extends Expression {
left: Expression;
Expand Down
31 changes: 13 additions & 18 deletions src/services/syntax/constants.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
///<reference path='references.ts' />

module TypeScript {
export const enum ParserContextFlags {
StrictMode = 1 << 0,
DisallowIn = 1 << 1,
Yield = 1 << 2,
GeneratorParameter = 1 << 3,

Mask = 0xF
}

export enum SyntaxNodeConstants {
None = 0,

// Masks that we use to place information about a node into a single int. The first bit tells
// us if we've computed the data for a node.
//
// The second bit tells us if the node is incrementally reusable if it does not
// containe any skipped tokens, zero width tokens, regex tokens in it ("/", "/=" or "/.../"),
// and contains no tokens that were parser generated.
//
// The next bit lets us know if the nodes was parsed in a strict context or node. A node can
// only be used by the incremental parser if it is parsed in the same strict context as before.
// last masks off the part of the int
//
// The first four bit of the flags are used to store parser context flags.
// The width of the node is stored in the remainder of the int. This allows us up to 128MB
// for a node by using all 27 bits. However, in the common case, we'll use less than 27 bits
// for the width. Thus, the info will be stored in a single int in chakra.
DataComputed = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
IncrementallyUnusableMask = 0x00000002, // 0000 0000 0000 0000 0000 0000 0000 0010
ParsedInStrictModeContext = 0x00000004, // 0000 0000 0000 0000 0000 0000 0000 0100
ParsedInDisallowInContext = 0x00000008, // 0000 0000 0000 0000 0000 0000 0000 1000
ParsedInYieldContext = 0x00000010, // 0000 0000 0000 0000 0000 0000 0001 0000
ParsedInGeneratorParameterContext = 0x00000020, // 0000 0000 0000 0000 0000 0000 0010 0000
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
DataComputed = 1 << 4, // 0000 0000 0000 0000 0000 0000 0001 0000
IncrementallyUnusableMask = 1 << 5, // 0000 0000 0000 0000 0000 0000 0010 0000
FullWidthShift = 1 << 6, // 1111 1111 1111 1111 1111 1111 1100 0000
}
}
Loading