public TypeDefineNode(DeltinScriptParser.Type_defineContext context, BuildAstVisitor visitor) : base(new Location(visitor.file, Range.GetRange(context))) { if (context.STRUCT() != null) { TypeKind = TypeKind.Struct; } else if (context.CLASS() != null) { TypeKind = TypeKind.Class; } else { throw new Exception(); } Name = context.name.Text; DefinedVars = new InclassDefineNode[context.inclass_define().Length]; for (int i = 0; i < DefinedVars.Length; i++) { DefinedVars[i] = (InclassDefineNode)visitor.VisitInclass_define(context.inclass_define(i)); } Constructors = new ConstructorNode[context.constructor().Length]; for (int i = 0; i < Constructors.Length; i++) { Constructors[i] = (ConstructorNode)visitor.VisitConstructor(context.constructor(i)); } Methods = new UserMethodNode[context.user_method().Length]; for (int i = 0; i < Methods.Length; i++) { Methods[i] = (UserMethodNode)visitor.VisitUser_method(context.user_method(i)); } }
public DefinedType(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Type_defineContext typeContext) : base(typeContext.name.Text) { this.typeContext = typeContext; this.parseInfo = parseInfo; if (parseInfo.TranslateInfo.Types.IsCodeType(Name)) { parseInfo.Script.Diagnostics.Error($"A type with the name '{Name}' already exists.", DocRange.GetRange(typeContext.name)); } DefinedAt = new LanguageServer.Location(parseInfo.Script.Uri, DocRange.GetRange(typeContext.name)); parseInfo.TranslateInfo.GetComponent <SymbolLinkComponent>().AddSymbolLink(this, DefinedAt, true); }
public DefinedType(ParseInfo parseInfo, Scope scope, DeltinScriptParser.Type_defineContext typeContext, List <IApplyBlock> applyMethods) : base(typeContext.name.Text) { this.translateInfo = parseInfo.TranslateInfo; if (translateInfo.IsCodeType(Name)) { parseInfo.Script.Diagnostics.Error($"A type with the name '{Name}' already exists.", DocRange.GetRange(typeContext.name)); } DefinedAt = new LanguageServer.Location(parseInfo.Script.Uri, DocRange.GetRange(typeContext.name)); translateInfo.AddSymbolLink(this, DefinedAt); if (typeContext.CLASS() != null) { TypeKind = TypeKind.Class; TypeKindString = "class"; } else if (typeContext.STRUCT() != null) { TypeKind = TypeKind.Struct; TypeKindString = "struct"; } else { throw new NotImplementedException(); } staticScope = translateInfo.GlobalScope.Child(TypeKindString + " " + Name); objectScope = staticScope.Child(TypeKindString + " " + Name); // Get the variables defined in the type. foreach (var definedVariable in typeContext.define()) { Var newVar = Var.CreateVarFromContext(VariableDefineType.InClass, parseInfo, definedVariable); newVar.Finalize(UseScope(newVar.Static)); if (!newVar.Static) { objectVariables.Add(newVar); } } // Todo: Static methods/macros. foreach (var definedMethod in typeContext.define_method()) { var newMethod = new DefinedMethod(parseInfo, UseScope(false), definedMethod); applyMethods.Add(newMethod); } foreach (var macroContext in typeContext.define_macro()) { DeltinScript.GetMacro(parseInfo, UseScope(false), macroContext, applyMethods); } // 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, this, typeContext.constructor(i)); applyMethods.Add((DefinedConstructor)Constructors[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) }; } }
public override Node VisitType_define(DeltinScriptParser.Type_defineContext context) { return(new TypeDefineNode(context, this)); }