Example #1
0
 public TypeParameterConstraintNode(AtomicNameNode typeParameter, ParseNodeList typeConstraints,
                                    bool hasConstructorConstraint)
     : base(ParseNodeType.ConstraintClause, typeParameter.Token)
 {
     this.typeParameter            = typeParameter;
     this.typeConstraints          = typeConstraints;
     this.hasConstructorConstraint = hasConstructorConstraint;
 }
Example #2
0
 public SwitchSectionNode(Token token,
                          ParseNodeList labels,
                          ParseNodeList statements)
     : base(ParseNodeType.SwitchSection, token)
 {
     Labels     = GetParentedNodeList(labels);
     Statements = GetParentedNodeList(statements);
 }
Example #3
0
 public ConstantFieldDeclarationNode(Token token,
                                     ParseNodeList attributes,
                                     Modifiers modifiers,
                                     ParseNode type,
                                     ParseNodeList initializers)
     : base(ParseNodeType.ConstFieldDeclaration, token, attributes, modifiers, type, initializers, false)
 {
 }
Example #4
0
 public SwitchNode(Token token,
                   ParseNode condition,
                   ParseNodeList cases)
     : base(ParseNodeType.Switch, token)
 {
     Condition = GetParentedNode(condition);
     Cases     = GetParentedNodeList(cases);
 }
Example #5
0
 public FieldDeclarationNode(Token token,
                             ParseNodeList attributes,
                             Modifiers modifiers,
                             ParseNode type,
                             ParseNodeList initializers,
                             bool isFixed)
     : this(ParseNodeType.FieldDeclaration, token, attributes, modifiers, type, initializers, isFixed)
 {
 }
Example #6
0
 public NamespaceNode(Token token, string name,
                      ParseNodeList usingClauses,
                      ParseNodeList members)
     : base(ParseNodeType.Namespace, token)
 {
     Name         = name;
     UsingClauses = GetParentedNodeList(usingClauses);
     Members      = GetParentedNodeList(members);
 }
Example #7
0
 public DestructorDeclarationNode(Token token,
                                  ParseNodeList attributes,
                                  Modifiers modifiers,
                                  AtomicNameNode name,
                                  BlockStatementNode body)
     : base(ParseNodeType.DestructorDeclaration, token, attributes, modifiers, /* return type */ null, name,
            new ParseNodeList(), body)
 {
 }
Example #8
0
 public TryNode(Token token,
                ParseNode body,
                ParseNodeList catchClauses,
                ParseNode finallyClause)
     : base(ParseNodeType.Try, token)
 {
     Body          = GetParentedNode(body);
     CatchClauses  = GetParentedNodeList(catchClauses);
     FinallyClause = GetParentedNode(finallyClause);
 }
Example #9
0
        internal static string GetNodeTransformName(this ParseNodeList parseNodeList)
        {
            string dsharpMemberName = parseNodeList?.GetAttributeValue(DSharpStringResources.DSHARP_MEMBER_NAME_ATTRIBUTE);

            if (!string.IsNullOrEmpty(dsharpMemberName))
            {
                return(DSharpStringResources.ScriptExportMember(dsharpMemberName));
            }

            return(parseNodeList?.GetAttributeValue(DSharpStringResources.SCRIPT_ALIAS_ATTRIBUTE));
        }
Example #10
0
 public NamespaceNode(Token token, NameNode nameNode,
                      ParseNodeList externAliases,
                      ParseNodeList usingClauses,
                      ParseNodeList members)
     : base(ParseNodeType.Namespace, token)
 {
     Name = nameNode.Name;
     this.externAliases = GetParentedNodeList(externAliases);
     UsingClauses       = GetParentedNodeList(usingClauses);
     Members            = GetParentedNodeList(members);
 }
Example #11
0
 public AccessorNode(Token token,
                     ParseNodeList attributes,
                     AtomicNameNode name,
                     BlockStatementNode body,
                     Modifiers modifiers)
     : base(ParseNodeType.AccessorDeclaration, token)
 {
     this.name       = (AtomicNameNode)GetParentedNode(name);
     Implementation  = (BlockStatementNode)GetParentedNode(body);
     this.attributes = GetParentedNodeList(attributes);
     Modifiers       = modifiers;
 }
Example #12
0
 public CompilationUnitNode(Token token,
                            ParseNodeList externAliases,
                            ParseNodeList usingClauses,
                            ParseNodeList attributes,
                            ParseNodeList members)
     : base(ParseNodeType.CompilationUnit, token)
 {
     this.externAliases = GetParentedNodeList(externAliases);
     UsingClauses       = GetParentedNodeList(usingClauses);
     Attributes         = GetParentedNodeList(attributes);
     Members            = GetParentedNodeList(GetNamespaces(members));
 }
Example #13
0
 public OperatorDeclarationNode(Token token,
                                ParseNodeList attributes,
                                Modifiers modifiers,
                                TokenType operatorNodeType,
                                ParseNode returnType,
                                ParseNodeList formals,
                                BlockStatementNode body)
     : base(ParseNodeType.OperatorDeclaration, token, attributes, modifiers, returnType, /* name */ null,
            formals, body)
 {
     OperatorTokenType = operatorNodeType;
 }
Example #14
0
 public IndexerDeclarationNode(Token token,
                               ParseNodeList attributes,
                               Modifiers modifiers,
                               ParseNode type,
                               NameNode interfaceType,
                               ParseNodeList parameters,
                               AccessorNode get,
                               AccessorNode set)
     : base(ParseNodeType.IndexerDeclaration, token, attributes, modifiers, type, interfaceType, get, set)
 {
     Parameters = GetParentedNodeList(parameters);
 }
Example #15
0
        private string GetAttributeValue(ParseNodeList attributes, string attributeName)
        {
            AttributeNode node = AttributeNode.FindAttribute(attributes, attributeName);

            if (node != null)
            {
                Debug.Assert(node.Arguments[0] is LiteralNode);
                Debug.Assert(((LiteralNode)node.Arguments[0]).Value is string);

                return((string)((LiteralNode)node.Arguments[0]).Value);
            }
            return(null);
        }
Example #16
0
 public PropertyDeclarationNode(Token token,
                                ParseNodeList attributes,
                                Modifiers modifiers,
                                ParseNode type,
                                NameNode interfaceType,
                                AtomicNameNode name,
                                AccessorNode getOrRemove,
                                AccessorNode setOrAdd)
     : this(ParseNodeType.PropertyDeclaration, token, attributes, modifiers, type, interfaceType, getOrRemove,
            setOrAdd)
 {
     NameNode = (AtomicNameNode)GetParentedNode(name);
 }
Example #17
0
        internal static string GetAttributeValue(this ParseNodeList parseNodeList, string attributeName)
        {
            AttributeNode node = AttributeNode.FindAttribute(parseNodeList, attributeName);

            if (node != null && node.Arguments.Count != 0 && node.Arguments[0].NodeType == ParseNodeType.Literal)
            {
                Debug.Assert(((LiteralNode)node.Arguments[0]).Value is string);

                return((string)((LiteralNode)node.Arguments[0]).Value);
            }

            return(null);
        }
Example #18
0
 public CustomTypeNode(Token token, TokenType type,
                       ParseNodeList attributes,
                       Modifiers modifiers,
                       AtomicNameNode name,
                       ParseNodeList typeParameters,
                       ParseNodeList baseTypes,
                       ParseNodeList constraintClauses,
                       ParseNodeList members)
     : base(ParseNodeType.Type, token, type, attributes, modifiers, name, typeParameters, constraintClauses)
 {
     BaseTypes = GetParentedNodeList(baseTypes);
     Members   = GetParentedNodeList(members);
 }
Example #19
0
 protected FieldDeclarationNode(ParseNodeType nodeType, Token token,
                                ParseNodeList attributes,
                                Modifiers modifiers,
                                ParseNode type,
                                ParseNodeList initializers,
                                bool isFixed)
     : base(nodeType, token)
 {
     Attributes   = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
     Modifiers    = modifiers;
     Type         = GetParentedNode(type);
     Initializers = GetParentedNodeList(initializers);
     IsFixed      = isFixed;
 }
Example #20
0
 public ConstructorDeclarationNode(Token token,
                                   ParseNodeList attributes,
                                   Modifiers modifiers,
                                   AtomicNameNode name,
                                   ParseNodeList formals,
                                   bool callBase,
                                   ParseNode baseArguments,
                                   BlockStatementNode body)
     : base(ParseNodeType.ConstructorDeclaration, token, attributes, modifiers, /* return type */ null, name,
            formals, body)
 {
     CallBase      = callBase;
     BaseArguments = GetParentedNode(baseArguments);
 }
Example #21
0
 public DelegateTypeNode(Token token,
                         ParseNodeList attributes,
                         Modifiers modifiers,
                         ParseNode returnType,
                         AtomicNameNode name,
                         ParseNodeList typeParameters,
                         ParseNodeList parameters,
                         ParseNodeList constraintClauses)
     : base(ParseNodeType.Delegate, token, TokenType.Delegate, attributes, modifiers, name, typeParameters,
            constraintClauses)
 {
     ReturnType = GetParentedNode(returnType);
     Parameters = GetParentedNodeList(parameters);
 }
Example #22
0
 public UserTypeNode(ParseNodeType type, Token token, TokenType tokenType,
                     ParseNodeList attributes,
                     Modifiers modifiers,
                     AtomicNameNode name,
                     ParseNodeList typeParameters,
                     ParseNodeList constraintClauses)
     : base(type, token)
 {
     Type                   = tokenType;
     Attributes             = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
     Modifiers              = modifiers;
     nameNode               = name;
     this.typeParameters    = GetParentedNodeList(typeParameters);
     this.constraintClauses = GetParentedNodeList(constraintClauses);
 }
Example #23
0
 private string GetAssemblyScriptName(ParseNodeList compilationUnits)
 {
     foreach (CompilationUnitNode compilationUnit in compilationUnits)
     {
         foreach (AttributeBlockNode attribBlock in compilationUnit.Attributes)
         {
             string scriptName = GetAttributeValue(attribBlock.Attributes, "ScriptAssembly");
             if (scriptName != null)
             {
                 return(scriptName);
             }
         }
     }
     return(null);
 }
Example #24
0
 private string GetAssemblyScriptPrefix(ParseNodeList compilationUnits)
 {
     foreach (CompilationUnitNode compilationUnit in compilationUnits)
     {
         foreach (AttributeBlockNode attribBlock in compilationUnit.Attributes)
         {
             string scriptPrefix = GetAttributeValue(attribBlock.Attributes, "ScriptQualifier");
             if (scriptPrefix != null)
             {
                 return(scriptPrefix);
             }
         }
     }
     return(null);
 }
Example #25
0
 public ParameterNode(
     Token token,
     ParseNodeList attributes,
     ParameterFlags flags,
     ParseNode type,
     AtomicNameNode name,
     bool isExtensionMethodTarget = false)
     : base(ParseNodeType.FormalParameter, token)
 {
     Attributes = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
     Flags      = flags;
     IsExtensionMethodTarget = isExtensionMethodTarget;
     Type      = GetParentedNode(type);
     this.name = (AtomicNameNode)GetParentedNode(name);
 }
Example #26
0
 public MethodDeclarationNode(Token token,
                              ParseNodeList attributes,
                              Modifiers modifiers,
                              ParseNode returnType,
                              NameNode interfaceType,
                              AtomicNameNode name,
                              ParseNodeList typeParameters,
                              ParseNodeList formals,
                              ParseNodeList constraints,
                              BlockStatementNode body)
     : this(ParseNodeType.MethodDeclaration, token, attributes, modifiers, returnType, name, formals, body)
 {
     this.interfaceType  = (NameNode)GetParentedNode(interfaceType);
     this.typeParameters = GetParentedNodeList(typeParameters);
     this.constraints    = GetParentedNodeList(constraints);
 }
Example #27
0
 protected PropertyDeclarationNode(ParseNodeType nodeType, Token token,
                                   ParseNodeList attributes,
                                   Modifiers modifiers,
                                   ParseNode type,
                                   NameNode interfaceType,
                                   AccessorNode getOrRemove,
                                   AccessorNode setOrAdd)
     : base(nodeType, token)
 {
     Attributes         = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
     Modifiers          = modifiers;
     Type               = GetParentedNode(type);
     this.interfaceType = (NameNode)GetParentedNode(interfaceType);
     GetAccessor        = (AccessorNode)GetParentedNode(getOrRemove);
     SetAccessor        = (AccessorNode)GetParentedNode(setOrAdd);
 }
Example #28
0
 protected MethodDeclarationNode(ParseNodeType nodeType, Token token,
                                 ParseNodeList attributes,
                                 Modifiers modifiers,
                                 ParseNode returnType,
                                 AtomicNameNode name,
                                 ParseNodeList formals,
                                 BlockStatementNode body)
     : base(nodeType, token)
 {
     Attributes     = GetParentedNodeList(AttributeNode.GetAttributeList(attributes));
     Modifiers      = modifiers;
     Type           = GetParentedNode(returnType);
     this.name      = (AtomicNameNode)GetParentedNode(name);
     Parameters     = GetParentedNodeList(formals);
     Implementation = (BlockStatementNode)GetParentedNode(body);
 }
Example #29
0
        bool IParseNodeValidator.Validate(ParseNode node, CompilerOptions options, IErrorHandler errorHandler)
        {
            NamespaceNode namespaceNode = (NamespaceNode)node;

            bool valid = true;

            foreach (ParseNode childNode in namespaceNode.Members)
            {
                if (childNode is NamespaceNode)
                {
                    errorHandler.ReportError("Nested namespaces are not supported.",
                                             childNode.Token.Location);
                    valid = false;
                }
            }

            if (namespaceNode.Name.Equals("System") ||
                namespaceNode.Name.StartsWith("System."))
            {
                // Usage of the System namespace is limited to imported types.

                foreach (ParseNode childNode in namespaceNode.Members)
                {
                    bool allowed = false;

                    if (childNode is UserTypeNode)
                    {
                        ParseNodeList attributes = ((UserTypeNode)childNode).Attributes;
                        if (AttributeNode.FindAttribute(attributes, "ScriptImport") != null ||
                            (AttributeNode.FindAttribute(attributes, "ScriptAllowSystemNamespace") != null))
                        {
                            allowed = true;
                        }
                    }

                    if (allowed == false)
                    {
                        errorHandler.ReportError("Only types marked as Imported are allowed within the System namespace.",
                                                 namespaceNode.Token.Location);
                        valid = false;
                        break;
                    }
                }
            }

            return(valid);
        }
Example #30
0
        internal void IncludeCompilationUnitUsingClauses()
        {
            CompilationUnitNode compilationUnit = (CompilationUnitNode)Parent;

            if (compilationUnit.UsingClauses.Count != 0)
            {
                ParseNodeList mergedUsings = new ParseNodeList();
                mergedUsings.Append(compilationUnit.UsingClauses);

                if (UsingClauses.Count != 0)
                {
                    mergedUsings.Append(UsingClauses);
                }

                UsingClauses = GetParentedNodeList(mergedUsings);
            }
        }