PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/2.0/Source/Orcas/LanguageService/Scopes/SpecialScopes.cs

#
C# | 120 lines | 77 code | 18 blank | 25 comment | 0 complexity | a823524a0813913432c0f22ecfe2382a MD5 | raw file
Possible License(s): CPL-1.0, GPL-2.0, CC-BY-SA-3.0, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. /*
  2. Copyright (c) 2008 Jakub Misek
  3. The use and distribution terms for this software are contained in the file named License.txt,
  4. which can be found in the root of the Phalanger distribution. By using this software
  5. in any fashion, you are agreeing to be bound by the terms of this license.
  6. You must not remove this notice from this software.
  7. */
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Text;
  11. using Microsoft.VisualStudio;
  12. using Microsoft.VisualStudio.Package;
  13. using Microsoft.VisualStudio.TextManager.Interop;
  14. using System.Collections;
  15. using System.Reflection;
  16. using PHP.Core;
  17. using PHP.Core.AST;
  18. using PHP.Core.Reflection;
  19. using PHP.VisualStudio.PhalangerLanguageService.Declarations;
  20. namespace PHP.VisualStudio.PhalangerLanguageService.Scopes
  21. {
  22. /// <summary>
  23. /// Specials (native) methods and variables not defined elsewhere.
  24. /// </summary>
  25. /// <remarks>
  26. /// This code scope is included by all the other scopes through the special namespace name. So the declarations here are visible everywhere.
  27. /// </remarks>
  28. public class SpecialScope : ScopeInfo
  29. {
  30. private readonly ProjectDeclarations projectdeclarations;
  31. public SpecialScope(ProjectDeclarations projectdeclarations)
  32. : base(null, new TextSpan())
  33. {
  34. this.projectdeclarations = projectdeclarations;
  35. }
  36. /// <summary>
  37. /// Create the special namespaces (Library) scope and
  38. /// places special (PHP native) keywords and functions into this scope.
  39. /// </summary>
  40. protected override void InitScope()
  41. {
  42. ScopeInfo scope = InitNamespaceDecl(Namespaces.Library);
  43. // PHP native functions
  44. scope.AddDeclaration(new SpecialFunctionDecl(
  45. "echo", "Output one or more strings.",
  46. new FunctionParamInfo[] {
  47. new FunctionParamInfo("arg1", "string", "String to be printed.", new PHP.Core.Parsers.Position()),
  48. new FunctionParamInfo("...", "string", "String to be printed.", new PHP.Core.Parsers.Position(), true)
  49. },
  50. false));
  51. scope.AddDeclaration(new SpecialFunctionDecl("print", "Output a string.", new FunctionParamInfo[] { new FunctionParamInfo("arg", "string", "String to be printed.", new PHP.Core.Parsers.Position()) }, true));
  52. scope.AddDeclaration(new SpecialFunctionDecl("new", "Create new object instance of the specified type.", new FunctionParamInfo[] { new FunctionParamInfo("object", "string", "Object to be created.", new PHP.Core.Parsers.Position()) }, false));
  53. scope.AddDeclaration(new SpecialFunctionDecl("clone", null, new FunctionParamInfo[] { new FunctionParamInfo("variable", "string", "Object to be cloned.", new PHP.Core.Parsers.Position()) }, false));
  54. scope.AddDeclaration(new SpecialFunctionDecl("include", "The include() statement includes and evaluates the specified file.", new FunctionParamInfo[] { new FunctionParamInfo("file_name", "string", "File to be included.", new PHP.Core.Parsers.Position()) }, false));
  55. scope.AddDeclaration(new SpecialFunctionDecl("include_once", "Includes and evaluates the specified file.\nIf the code from a file has already been included, it will not be included again.", new FunctionParamInfo[] { new FunctionParamInfo("file_name", "string", "File to be included.", new PHP.Core.Parsers.Position()) }, false));
  56. scope.AddDeclaration(new SpecialFunctionDecl("require", "The require() statement includes and evaluates the specified file.", new FunctionParamInfo[] { new FunctionParamInfo("file_name", "string", "File to be included.", new PHP.Core.Parsers.Position()) }, false));
  57. scope.AddDeclaration(new SpecialFunctionDecl("require_once", "Includes and evaluates the specified file.\nIf the code from a file has already been included, it will not be included again.", new FunctionParamInfo[] { new FunctionParamInfo("file_name", "string", "File to be included.", new PHP.Core.Parsers.Position()) }, false));
  58. scope.AddDeclaration(new SpecialFunctionDecl("return", null, new FunctionParamInfo[] { new FunctionParamInfo("value", "mixed", "Return value.", new PHP.Core.Parsers.Position(), true) }, false));
  59. scope.AddDeclaration(new SpecialFunctionDecl("global", "Use variables from global scope in local scope.",
  60. new FunctionParamInfo[] {
  61. new FunctionParamInfo("var1", "identifier", "Variable to be used from global scope.", new PHP.Core.Parsers.Position()),
  62. new FunctionParamInfo("...", "identifiers", "Variable to be used from global scope.", new PHP.Core.Parsers.Position(), true)
  63. }, false));
  64. scope.AddDeclaration(new SpecialFunctionDecl("isset", "Determine whether a variable is set.",
  65. new FunctionParamInfo[] {
  66. new FunctionParamInfo("var", "mixed", "The variable to be checked.", new PHP.Core.Parsers.Position()),
  67. new FunctionParamInfo("...", "mixed", "Another variable.", new PHP.Core.Parsers.Position(), true)
  68. }, true));
  69. scope.AddDeclaration(new SpecialFunctionDecl("unset", "unset() destroys the specified variables.",
  70. new FunctionParamInfo[] {
  71. new FunctionParamInfo("var", "mixed", "The variable to be checked.", new PHP.Core.Parsers.Position()),
  72. new FunctionParamInfo("...", "mixed", "Another variable.", new PHP.Core.Parsers.Position(), true)
  73. }, true));
  74. scope.AddDeclaration(new SpecialFunctionDecl("empty", "Determine whether a variable is considered to be empty.",
  75. new FunctionParamInfo[] {
  76. new FunctionParamInfo("var", "mixed", "Variable to be checked.", new PHP.Core.Parsers.Position())
  77. }, true));
  78. // PHP operators
  79. scope.AddDeclaration(new SpecialKeywordDecl("instanceof", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  80. scope.AddDeclaration(new SpecialKeywordDecl("and", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  81. scope.AddDeclaration(new SpecialKeywordDecl("or", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  82. scope.AddDeclaration(new SpecialKeywordDecl("xor", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  83. // keywords
  84. scope.AddDeclaration(new SpecialKeywordDecl("true", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  85. scope.AddDeclaration(new SpecialKeywordDecl("false", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  86. scope.AddDeclaration(new SpecialKeywordDecl("null", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  87. scope.AddDeclaration(new SpecialKeywordDecl("import", "Imports specified namespaces.", DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  88. scope.AddDeclaration(new SpecialKeywordDecl("namespace", null, DeclarationInfo.DeclarationUsages.ThisScope | DeclarationInfo.DeclarationUsages.AllChildScopes, null));
  89. // int, string, array, ...
  90. scope.AddDeclaration(new ClassAliasDecl("int", string.Format("System{0}Int32", QualifiedName.Separator), projectdeclarations));
  91. scope.AddDeclaration(new ClassAliasDecl("string", string.Format("System{0}String", QualifiedName.Separator), projectdeclarations));
  92. scope.AddDeclaration(new SpecialFunctionDecl("array", null,
  93. new FunctionParamInfo[] {
  94. new FunctionParamInfo("item", "mixed", "Items,", new PHP.Core.Parsers.Position(), true)
  95. }, true));
  96. }
  97. }
  98. }