• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0.
2// See LICENSE.txt in the project root for complete license information.
3
4///<reference path='typescript.ts' />
5
6module TypeScript {
7
8    export function hasFlag(val: number, flag: number) {
9        return (val & flag) != 0;
10    }
11
12    export enum ErrorRecoverySet {
13        None = 0,
14        Comma = 1, // Comma
15        SColon = 1 << 1, // SColon
16        Asg = 1 << 2, // Asg
17        BinOp = 1 << 3, // Lsh, Rsh, Rs2, Le, Ge, INSTANCEOF, EQ, NE, Eqv, NEqv, LogAnd, LogOr, AsgMul, AsgDiv
18        // AsgMod, AsgAdd, AsgSub, AsgLsh, AsgRsh, AsgRs2, AsgAnd, AsgXor, AsgOr, QMark, Mult, Div,
19        // Pct, GT, LT, And, Xor, Or
20        RBrack = 1 << 4, // RBrack
21        RCurly = 1 << 5, // RCurly
22        RParen = 1 << 6, // RParen
23        Dot = 1 << 7, // Dot
24        Colon = 1 << 8, // Colon
25        PrimType = 1 << 9, // number, string, boolean
26        AddOp = 1 << 10, // Add, Sub
27        LCurly = 1 << 11, // LCurly
28        PreOp = 1 << 12, // Tilde, Bang, Inc, Dec
29        RegExp = 1 << 13, // RegExp
30        LParen = 1 << 14, // LParen
31        LBrack = 1 << 15, // LBrack
32        Scope = 1 << 16, // Scope
33        In = 1 << 17, // IN
34        SCase = 1 << 18, // CASE, DEFAULT
35        Else = 1 << 19, // ELSE
36        Catch = 1 << 20, // CATCH, FINALLY
37        Var = 1 << 21, //
38        Stmt = 1 << 22, // BREAK, RETURN, THROW, DEBUGGER, FOR, SWITCH, DO, IF, TRY, WITH
39        While = 1 << 23, // WHILE
40        ID = 1 << 24, // ID
41        Prefix = 1 << 25, // VOID, DELETE, TYPEOF, AWAIT
42        Literal = 1 << 26, // IntCon, FltCon, StrCon
43        RLit = 1 << 27, // THIS, TRUE, FALSE, NULL
44        Func = 1 << 28, // FUNCTION
45        EOF = 1 << 29, // EOF
46
47        // REVIEW: Name this something clearer.
48        TypeScriptS = 1 << 30, // PROPERTY, PRIVATE, STATIC, INTERFACE, CLASS, MODULE, EXPORT, IMPORT
49        ExprStart = SColon | AddOp | LCurly | PreOp | RegExp | LParen | LBrack | ID | Prefix | RLit | Func | Literal,
50        StmtStart = ExprStart | SColon | Var | Stmt | While | TypeScriptS,
51        Postfix = Dot | LParen | LBrack,
52    }
53
54    export enum AllowedElements {
55        None = 0,
56        ModuleDeclarations = 1 << 2,
57        ClassDeclarations = 1 << 3,
58        InterfaceDeclarations = 1 << 4,
59        AmbientDeclarations = 1 << 10,
60        Properties = 1 << 11,
61
62        Global = ModuleDeclarations | ClassDeclarations | InterfaceDeclarations | AmbientDeclarations,
63        QuickParse = Global | Properties,
64    }
65
66    export enum Modifiers {
67        None = 0,
68        Private = 1,
69        Public = 1 << 1,
70        Readonly = 1 << 2,
71        Ambient = 1 << 3,
72        Exported = 1 << 4,
73        Getter = 1 << 5,
74        Setter = 1 << 6,
75        Static = 1 << 7,
76    }
77
78    export enum ASTFlags {
79        None = 0,
80        ExplicitSemicolon = 1, // statment terminated by an explicit semicolon
81        AutomaticSemicolon = 1 << 1, // statment terminated by an automatic semicolon
82        Writeable = 1 << 2,  // node is lhs that can be modified
83        Error = 1 << 3, // node has an error
84        DotLHSPartial = 1 << 4, // node is the lhs of an incomplete dot expr at cursor
85        DotLHS = 1 << 5, // node is the lhs of a dot expr
86        IsStatement = 1 << 6, // node is a statement
87        StrictMode = 1 << 7, // node is in the strict mode environment
88        PossibleOptionalParameter = 1 << 8,
89        ClassBaseConstructorCall = 1 << 9,
90        OptionalName = 1 << 10,
91        // REVIEW: This flag is to mark lambda nodes to note that the LParen of an expression has already been matched in the lambda header.
92        //         The flag is used to communicate this piece of information to the calling parseTerm, which intern will remove it.
93        //         Once we have a better way to associate information with nodes, this flag should not be used.
94        SkipNextRParen = 1 << 11,
95    }
96
97    export enum DeclFlags {
98        None = 0,
99        Exported = 1,
100        Private = 1 << 1,
101        Public = 1 << 2,
102        Ambient = 1 << 3,
103        Static = 1 << 4,
104        LocalStatic = 1 << 5,
105        GetAccessor = 1 << 6,
106        SetAccessor = 1 << 7,
107    }
108
109    export enum ModuleFlags {
110        None = 0,
111        Exported = 1,
112        Private = 1 << 1,
113        Public = 1 << 2,
114        Ambient = 1 << 3,
115        Static = 1 << 4,
116        LocalStatic = 1 << 5,
117        GetAccessor = 1 << 6,
118        SetAccessor = 1 << 7,
119        IsEnum = 1 << 8,
120        ShouldEmitModuleDecl = 1 << 9,
121        IsWholeFile = 1 << 10,
122        IsDynamic = 1 << 11,
123        MustCaptureThis = 1 << 12,
124    }
125
126    export enum SymbolFlags {
127        None = 0,
128        Exported = 1,
129        Private = 1 << 1,
130        Public = 1 << 2,
131        Ambient = 1 << 3,
132        Static = 1 << 4,
133        LocalStatic = 1 << 5,
134        GetAccessor = 1 << 6,
135        SetAccessor = 1 << 7,
136        Property = 1 << 8,
137        Readonly = 1 << 9,
138        ModuleMember = 1 << 10,
139        InterfaceMember = 1 << 11,
140        ClassMember = 1 << 12,
141        BuiltIn = 1 << 13,
142        TypeSetDuringScopeAssignment = 1 << 14,
143        Constant = 1 << 15,
144        Optional = 1 << 16,
145        RecursivelyReferenced = 1 << 17,
146        Bound = 1 << 18,
147        CompilerGenerated = 1 << 19,
148    }
149
150    export enum VarFlags {
151        None = 0,
152        Exported = 1,
153        Private = 1 << 1,
154        Public = 1 << 2,
155        Ambient = 1 << 3,
156        Static = 1 << 4,
157        LocalStatic = 1 << 5,
158        GetAccessor = 1 << 6,
159        SetAccessor = 1 << 7,
160        AutoInit = 1 << 8,
161        Property = 1 << 9,
162        Readonly = 1 << 10,
163        Class = 1 << 11,
164        ClassProperty = 1 << 12,
165        ClassBodyProperty = 1 << 13,
166        ClassConstructorProperty = 1 << 14,
167        ClassSuperMustBeFirstCallInConstructor = 1 << 15,
168        Constant = 1 << 16,
169        MustCaptureThis = 1 << 17,
170    }
171
172    export enum FncFlags {
173        None = 0,
174        Exported = 1,
175        Private = 1 << 1,
176        Public = 1 << 2,
177        Ambient = 1 << 3,
178        Static = 1 << 4,
179        LocalStatic = 1 << 5,
180        GetAccessor = 1 << 6,
181        SetAccessor = 1 << 7,
182        Definition = 1 << 8,
183        Signature = 1 << 9,
184        Method = 1 << 10,
185        HasReturnExpression = 1 << 11,
186        CallMember = 1 << 12,
187        ConstructMember = 1 << 13,
188        HasSelfReference = 1 << 14,
189        IsFatArrowFunction = 1 << 15,
190        IndexerMember = 1 << 16,
191        IsFunctionExpression = 1 << 17,
192        ClassMethod = 1 << 18,
193        ClassPropertyMethodExported = 1 << 19,
194    }
195
196    export enum SignatureFlags {
197        None = 0,
198        IsIndexer = 1,
199        IsStringIndexer = 1 << 1,
200        IsNumberIndexer = 1 << 2,
201    }
202
203    export function ToDeclFlags(fncFlags: FncFlags) : DeclFlags;
204    export function ToDeclFlags(varFlags: VarFlags) : DeclFlags;
205    export function ToDeclFlags(symFlags: SymbolFlags): DeclFlags;
206    export function ToDeclFlags(moduleFlags: ModuleFlags): DeclFlags;
207    export function ToDeclFlags(fncOrVarOrSymbolOrModuleFlags: any) {
208        return <DeclFlags>fncOrVarOrSymbolOrModuleFlags;
209    }
210
211    export enum TypeFlags {
212        None = 0,
213        HasImplementation = 1,
214        HasSelfReference = 1 << 1,
215        MergeResult = 1 << 2,
216        IsEnum = 1 << 3,
217        BuildingName = 1 << 4,
218        HasBaseType = 1 << 5,
219        HasBaseTypeOfObject = 1 << 6,
220        IsClass = 1 << 7,
221    }
222
223    export enum TypeRelationshipFlags {
224        SuccessfulComparison = 0,
225        SourceIsNullTargetIsVoidOrUndefined = 1,
226        RequiredPropertyIsMissing = 1 << 1,
227        IncompatibleSignatures = 1 << 2,
228        SourceSignatureHasTooManyParameters = 3,
229        IncompatibleReturnTypes = 1 << 4,
230        IncompatiblePropertyTypes = 1 << 5,
231        IncompatibleParameterTypes = 1 << 6,
232    }
233
234    export enum CodeGenTarget {
235        ES3 = 0,
236        ES5 = 1,
237    }
238
239    export enum ModuleGenTarget {
240        Synchronous = 0,
241        Asynchronous = 1,
242        Local = 1 << 1,
243    }
244
245    // Compiler defaults to generating ES5-compliant code for
246    //  - getters and setters
247    export var codeGenTarget: CodeGenTarget = CodeGenTarget.ES3;
248
249    export var moduleGenTarget: ModuleGenTarget = ModuleGenTarget.Synchronous;
250
251    export var optimizeModuleCodeGen = true;
252
253    export function flagsToString(e, flags: number): string {
254        var builder = "";
255        for (var i = 1; i < (1 << 31) ; i = i << 1) {
256            if ((flags & i) != 0) {
257                for (var k in e) {
258                    if (e[k] == i) {
259                        if (builder.length > 0) {
260                            builder += "|";
261                        }
262                        builder += k;
263                        break;
264                    }
265                }
266            }
267        }
268        return builder;
269    }
270
271}