private void CheckParamsNameConflicts(SLangGrammarParser.ThisHeaderContext thisHeader, SLangGrammarParser.RoutineArgListContext argList) { if (thisHeader != null) { var token = thisHeader.Id().Symbol; moduleItem.CheckCommonNamesConflicts(token.Text, token.Line, token.Column); } foreach (var arg in argList.routineArg()) { var token = arg.Id().Symbol; moduleItem.CheckCommonNamesConflicts(token.Text, token.Line, token.Column); } }
private void InitializeRoutineStates(SLangGrammarParser.ThisHeaderContext context, IToken symbol) { currentType = context != null?Visit(context.customType()) as SlangCustomType : null; if (currentType != null) { currentRoutine = Table.FindClass(currentType).Methods[symbol.Text]; } else { currentRoutine = moduleItem.Routines[symbol.Text]; checkDefinitions[symbol.Text] = true; } }
private void InitRoutines(SLangGrammarParser.ThisHeaderContext thisHeader, string routineName) { if (thisHeader != null) { currentType = GetCustomTypeContext(thisHeader.customType()); } if (currentType != null) { currentRoutine = source.FindClass(currentType).Methods[routineName]; } else { currentRoutine = currentModule.Routines[routineName]; } }
/// <summary> /// Exit a parse tree produced by <see cref="SLangGrammarParser.thisHeader"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitThisHeader([NotNull] SLangGrammarParser.ThisHeaderContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="SLangGrammarParser.thisHeader"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitThisHeader([NotNull] SLangGrammarParser.ThisHeaderContext context) { return(VisitChildren(context)); }
public override object VisitThisHeader([NotNull] SLangGrammarParser.ThisHeaderContext context) => Visit(context.customType());
private void ValidateContext(SLangGrammarParser.ThisHeaderContext thisHeader, ITerminalNode id, SLangGrammarParser.ImportHeadContext importHead, ITerminalNode accessModifier, ITerminalNode abstractToken, ITerminalNode overrideToken, SLangGrammarParser.RoutineArgListContext routineArgList, SLangGrammarParser.TypeNameContext typeName, SLangGrammarParser.StatementSeqContext statementSeq) { var isMethod = thisHeader != null; var symbol = id.Symbol; string nameOfThis = string.Empty; if (isMethod) { nameOfThis = thisHeader.Id().GetText(); ThrowIfReservedWord(nameOfThis, ModuleData.File, thisHeader.Id().Symbol); if (importHead != null) { ThrowImportHeaderMethodsException(ModuleData.File, id); } } var name = id.GetText(); ThrowIfReservedWord(name, ModuleData.File, symbol); var args = Visit(routineArgList) as List <RoutineArgNameTableItem>; ImportHeader header = null; if (importHead != null) { header = Visit(importHead) as ImportHeader; } SlangType returnType = typeName != null?Visit(typeName) as SlangType : null; var modifier = GetModifierByName(accessModifier.GetText()); var isAbstract = abstractToken != null; var isOverride = overrideToken != null; if (!isMethod && (isAbstract || isOverride)) { ThrowRoutinesAbstractOverrideException(ModuleData.File, abstractToken ?? overrideToken); } if (header != null && statementSeq.statement().Length != 0) { ThrowImportHeaderException(ModuleData.File, id); } if (isMethod) { if (Visit(thisHeader) is SlangCustomType methodTypeIdent && methodTypeIdent.ModuleName != ModuleData.Name) { ThrowModuleFromOtherClassModuleException(id, ModuleData.File); } if (isAbstract) { ThrowIfAbstractMethodPrivate(modifier, ModuleData.File, id); } if ((args ?? throw new InvalidOperationException(nameof(args))).Any(a => a.Name == nameOfThis)) { ThrowConfictsThisException(thisHeader.Id(), ModuleData.File); } var classData = Visit(thisHeader) as SlangCustomType; var foundClass = Table.FindClass(classData); if (foundClass.Methods.ContainsKey(name)) { ThrowMethodSignatureExistsException(classData, id, ModuleData.File); } if (isAbstract && statementSeq.statement().Length != 0) { ThrowAbstractEmptyException(id, ModuleData.File); } var method = new MethodNameTableItem { AccessModifier = modifier, Column = symbol.Column, Header = header, IsAbstract = isAbstract, IsOverride = isOverride, Line = symbol.Line, Name = name, NameOfThis = nameOfThis, Params = args, ReturnType = returnType }; if (modifier == AccessModifier.Public) { CheckLevelAccessForMethods(method, id, classData); } foundClass.CheckRoutineConflicts(moduleItem.ModuleData, method); foundClass.Methods.Add(method.Name, method); } else { if (moduleItem.Routines.ContainsKey(name)) { ThrowRoutineExistsException(id, ModuleData.File); } var routine = new RoutineNameTableItem { AccessModifier = modifier, Column = symbol.Column, Line = symbol.Line, Header = header, Name = name, Params = args, ReturnType = returnType }; if (modifier == AccessModifier.Public) { CheckLevelAccessForRoutines(routine, id, name); } moduleItem.CheckCommonNamesConflicts(routine.Name, routine.Line, routine.Column); moduleItem.Routines.Add(routine.Name, routine); } }