public FunctionDef(LatteParser.FunctionDefContext context) { Type = context.type(); Id = context.ID().GetText(); Block = new Block(context.block()); var arg = context.arg(); if (arg == null) { Args = new List <Arg>(); } else { var idType = arg.ID().Zip(arg.type(), (id, type) => (id, type)); Args = idType.Select(x => new Arg(x.type, x.id.GetText())).ToList(); } }
public override void EnterProgram(LatteParser.ProgramContext context) { _environment.AddPredefinedFunctions(); context.topDef().ToList().ForEach(topDef => { var id = topDef switch { LatteParser.FunctionDefContext fDef => fDef.ID().GetText(), LatteParser.ClassDefContext cDef => cDef.ID()[0].GetText() }; if (_environment.NameToFunctionDef.ContainsKey(id) || _environment.NameToClassDef.ContainsKey(id)) { _errorState.AddErrorMessage(new ErrorMessage( topDef.start.Line, ErrorMessages.FuncOrClassAlreadyDefined(id))); } if (topDef is LatteParser.ClassDefContext classDef) { CheckClassDef(classDef); } FrontendEnvironment.Instance.AddTopDef(topDef); }); _environment.NameToClassDef.Values.ToList().ForEach(classDef => { if (classDef.ParentId != null && !_environment.NameToClassDef.ContainsKey(classDef.ParentId)) { _errorState.AddErrorMessage( new ErrorMessage(ErrorMessages.ParentNorDefinedException(classDef.Id, classDef.ParentId))); } }); }
public override void ExitFunctionDef(LatteParser.FunctionDefContext context) { _environment.RestorePreviousVarEnv(); }
public override void EnterFunctionDef(LatteParser.FunctionDefContext context) { EnterFunctionDef(new FunctionDef(context), context.start.Line, context.block(), context.arg()); }