public override void ResolveElements() { if (elementsResolved) { return; } // Get the type being extended. if (typeContext.TERNARY_ELSE() != null) { // If there is no type name, error. if (typeContext.extends == null) { parseInfo.Script.Diagnostics.Error("Expected type name.", DocRange.GetRange(typeContext.TERNARY_ELSE())); } else { // Get the type being inherited. CodeType inheriting = parseInfo.TranslateInfo.GetCodeType(typeContext.extends.Text, parseInfo.Script.Diagnostics, DocRange.GetRange(typeContext.extends)); // GetCodeType will return null if the type is not found. if (inheriting != null) { inheriting.Call(parseInfo.Script, DocRange.GetRange(typeContext.extends)); Inherit(inheriting, parseInfo.Script.Diagnostics, DocRange.GetRange(typeContext.extends)); (Extends as ClassType)?.ResolveElements(); } } } base.ResolveElements(); // Give DefinedMethod and GetMacro a scope to use in case of the static attribute. foreach (var definedMethod in typeContext.define_method()) { var newMethod = new DefinedMethod(parseInfo, operationalScope, staticScope, definedMethod, this); // Copy to serving scopes. if (newMethod.Static) { staticScope.CopyMethod(newMethod); } else { serveObjectScope.CopyMethod(newMethod); } } // Get the macros. foreach (var macroContext in typeContext.define_macro()) { var newMacro = DeltinScript.GetMacro(parseInfo, operationalScope, staticScope, macroContext); // Copy to serving scopes. if (newMacro is IMethod asMethod) { if (newMacro.Static) { staticScope.CopyMethod(asMethod); } else { serveObjectScope.CopyMethod(asMethod); } } else { if (newMacro.Static) { staticScope.CopyVariable(newMacro); } else { serveObjectScope.CopyVariable(newMacro); } } } // Get the variables defined in the type. foreach (var definedVariable in typeContext.define()) { Var newVar = new ClassVariable(operationalScope, staticScope, new DefineContextHandler(parseInfo, definedVariable)); // Copy to serving scopes. if (!newVar.Static) { ObjectVariables.Add(new ObjectVariable(newVar)); serveObjectScope.CopyVariable(newVar); } // Add to static scope. else { staticVariables.Add(newVar); staticScope.CopyVariable(newVar); operationalScope.CopyVariable(newVar); } } // Get the constructors. if (typeContext.constructor().Length > 0) { Constructors = new Constructor[typeContext.constructor().Length]; for (int i = 0; i < Constructors.Length; i++) { Constructors[i] = new DefinedConstructor(parseInfo, operationalScope, this, typeContext.constructor(i)); } } else { // If there are no constructors, create a default constructor. Constructors = new Constructor[] { new Constructor(this, new Location(parseInfo.Script.Uri, DocRange.GetRange(typeContext.name)), AccessLevel.Public) }; } // If the extend token exists, add completion that only contains all extendable classes. if (typeContext.TERNARY_ELSE() != null) { parseInfo.Script.AddCompletionRange(new CompletionRange( // Get the completion items of all types. parseInfo.TranslateInfo.types .Where(t => t is ClassType ct && ct.CanBeExtended) .Select(t => t.GetCompletion()) .ToArray(), // Get the completion range. DocRange.GetRange(typeContext.TERNARY_ELSE(), parseInfo.Script.NextToken(typeContext.TERNARY_ELSE())), // This completion takes priority. CompletionRangeKind.ClearRest )); } parseInfo.Script.AddCodeLensRange(new ReferenceCodeLensRange(this, parseInfo, CodeLensSourceType.Type, DefinedAt.range)); }
public CodeParameter(string name, CodeType type, ExpressionOrWorkshopValue defaultValue) { Name = name; Type = type; DefaultValue = defaultValue; }
public CodeParameter(string name, string documentation, CodeType type) { Name = name; Type = type; Documentation = documentation; }
public ParseInfo SetExpectingLambda(CodeType sourceType) => new ParseInfo(this)
public CodeParameter(string name, CodeType type) { Name = name; Type = type; }
public AssignmentOperation(AssignmentOperator op, CodeType valueType, Action <AssignmentOperationInfo> action) { Operator = op; ValueType = valueType; _action = action; }
public ArrayType(CodeType arrayOfType) : base(arrayOfType.Name + "[]") { ArrayOfType = arrayOfType; }
public AssignmentOperation(AssignmentOperator op, CodeType valueType) { Operator = op; ValueType = valueType; _action = DefaultActionFromOperator(op); }
public HookVar(string name, CodeType type, Action <IExpression> setHook) { Name = name; CodeType = type; SetHook = setHook; }
public IVariableInstance GetDefaultInstance(CodeType definedIn) => this;
public IVariableInstance GetInstance(CodeType definedIn, InstanceAnonymousTypeLinker genericsLinker) => this;
public DefinedMethod(ParseInfo parseInfo, Scope objectScope, Scope staticScope, DeltinScriptParser.Define_methodContext context, CodeType containingType) : base(parseInfo, context.name.Text, new Location(parseInfo.Script.Uri, DocRange.GetRange(context.name))) { this.context = context; Attributes.ContainingType = containingType; DocRange nameRange = DocRange.GetRange(context.name); // Get the attributes. MethodAttributeAppender attributeResult = new MethodAttributeAppender(Attributes); MethodAttributesGetter attributeGetter = new MethodAttributesGetter(context, attributeResult); attributeGetter.GetAttributes(parseInfo.Script.Diagnostics); // Copy attribute results Static = attributeResult.Static; IsSubroutine = attributeResult.IsSubroutine; SubroutineName = attributeResult.SubroutineName; AccessLevel = attributeResult.AccessLevel; // Setup scope. SetupScope(Static ? staticScope : objectScope); methodScope.MethodContainer = true; BlockScope = methodScope.Child(); // Get the type. if (context.VOID() == null) { DoesReturnValue = true; ReturnType = CodeType.GetCodeTypeFromContext(parseInfo, context.code_type()); } // Setup the parameters and parse the block. if (!IsSubroutine) { SetupParameters(context.setParameters(), false); } else { subroutineDefaultGlobal = context.PLAYER() == null; Attributes.Parallelable = true; parseInfo.TranslateInfo.AddSubroutine(this); // Subroutines should not have parameters. SetupParameters(context.setParameters(), true); } // Override attribute. if (Attributes.Override) { IMethod overriding = objectScope.GetMethodOverload(this); // No method with the name and parameters found. if (overriding == null) { parseInfo.Script.Diagnostics.Error("Could not find a method to override.", nameRange); } else if (!overriding.Attributes.IsOverrideable) { parseInfo.Script.Diagnostics.Error("The specified method is not marked as virtual.", nameRange); } else { overriding.Attributes.AddOverride(this); } if (overriding != null && overriding.DefinedAt != null) { // Make the override keyword go to the base method. parseInfo.Script.AddDefinitionLink( attributeGetter.ObtainedAttributes.First(at => at.Type == MethodAttributeType.Override).Range, overriding.DefinedAt ); if (!Attributes.Recursive) { Attributes.Recursive = overriding.Attributes.Recursive; } } } if (Attributes.IsOverrideable && AccessLevel == AccessLevel.Private) { parseInfo.Script.Diagnostics.Error("A method marked as virtual or abstract must have the protection level 'public' or 'protected'.", nameRange); } // Syntax error if the block is missing. if (context.block() == null) { parseInfo.Script.Diagnostics.Error("Expected block.", nameRange); } // Add to the scope. Check for conflicts if the method is not overriding. containingScope.AddMethod(this, parseInfo.Script.Diagnostics, nameRange, !Attributes.Override); // Add the hover info. parseInfo.Script.AddHover(DocRange.GetRange(context.name), GetLabel(true)); if (Attributes.IsOverrideable) { parseInfo.Script.AddCodeLensRange(new ImplementsCodeLensRange(this, parseInfo.Script, CodeLensSourceType.Function, nameRange)); } parseInfo.TranslateInfo.ApplyBlock(this); }