public override ASTNode VisitParameterDecl([NotNull] DaedalusParser.ParameterDeclContext context) { NodeLocation location = GetLocation(context); NameNode typeNameNode = new NameNode(GetLocation(context.dataType()), context.dataType().GetText()); NameNode nameNode = new NameNode(GetLocation(context.nameNode()), context.nameNode().GetText()); if (context.arraySize() != null) { var arraySize = (ExpressionNode)VisitArraySize(context.arraySize()); ParameterArrayDeclarationNode parameterArrayDeclarationNode = new ParameterArrayDeclarationNode(location, typeNameNode, nameNode, arraySize); _arrayDeclarationNodes.Add(parameterArrayDeclarationNode); return(parameterArrayDeclarationNode); } return(new ParameterDeclarationNode(location, typeNameNode, nameNode)); }
public override void EnterParameterDecl(DaedalusParser.ParameterDeclContext context) { BaseExecBlockContext baseExecBlock = _assemblyBuilder.ExecBlocks.Last(); string execBlockName = baseExecBlock.GetSymbol().Name; string parameterLocalName = context.nameNode().GetText(); string parameterName = $"{execBlockName}.{parameterLocalName}"; int parentIndex = DatSymbol.NULL_INDEX; string parameterTypeName = context.typeReference().GetText(); DatSymbolType?parameterType = DatSymbolTypeFromString(parameterTypeName); if (parameterType is DatSymbolType.Class) { parameterType = DatSymbolType.Instance; var parentSymbol = _assemblyBuilder.ResolveSymbol(parameterTypeName); parentIndex = parentSymbol.Index; } DatSymbol symbol; var location = GetLocation(context); var arraySizeContext = context.arraySize(); if (arraySizeContext != null) { if (!uint.TryParse(arraySizeContext.GetText(), out var arrIndex)) { var constSymbol = _assemblyBuilder.ResolveSymbol(arraySizeContext.GetText()); if (constSymbol.Flags != DatSymbolFlag.Const || constSymbol.Type != DatSymbolType.Int) { throw new Exception($"Expected integer constant: {arraySizeContext.GetText()}"); } arrIndex = (uint)(int)constSymbol.Content[0]; } symbol = SymbolBuilder.BuildArrOfVariables(parameterName, parameterType.Value, arrIndex, location); } else { if (_assemblyBuilder.IsCurrentlyParsingExternals) { symbol = SymbolBuilder.BuildExternalParameter(parameterName, parameterType.Value, location, parentIndex); } else { symbol = SymbolBuilder.BuildParameter(parameterName, parameterType.Value, location, parentIndex); } } _assemblyBuilder.AddSymbol(symbol); }