//----------------------------------------------------------- public void Visit(VarDef node) { if (level > 0) { Visit((dynamic)node[0]); } }
public void Visit(VarDef node) { foreach (var n in node[0]) { var variableName = n.AnchorToken.Lexeme; if (insideFunction) { if (currentNamespaceTable.Contains(variableName)) { throw new SemanticError("Duplicated variable: " + variableName, n.AnchorToken); } currentNamespaceTable.Add(variableName); } else { if (firstPass) { if (Global_Symbol_Table.Contains(variableName)) { throw new SemanticError("Duplicated variable: " + variableName, n.AnchorToken); } else { Global_Symbol_Table.Add(variableName); } } } VisitChildren(n); } }
public void IgnoreBecauseNotExist(VarDef variable) { IgnoredBecauseNotExist++; if (!IgnoreNotExistNames.TryAdd(variable, 1)) { IgnoreNotExistNames[variable] += 1; } }
public void IgnorebecauseMemReadDelay(VarDef variable) { IgnoredBecauseMemReadDelay++; if (!IgnoreMemReadDelayNames.TryAdd(variable, 1)) { IgnoreMemReadDelayNames[variable] += 1; } }
public Node VarDef() { var n = new VarDef() { AnchorToken = Expect(TokenCategory.VAR) }; n.Add(IdList()); Expect(TokenCategory.SEMICOLON); return(n); }
public void Visit(VarDef varDef) { if (_prev is CloseDelimiter) { _sb.AppendLine(); } AddIndentation(); _sb.Append("var "); _prev = varDef; }
public void AddVarUsage(string varname, long line) { varname = varname.Trim(); if (!funcDefs[currentFunc].varsUsage.ContainsKey(varname)) { VarDef vd = new VarDef(); vd.name = varname; vd.line = line; funcDefs[currentFunc].varsUsage.Add(varname, vd); } }
//<vardef>// public Node VarDef() { var result = new Node(); result = new VarDef() { AnchorToken = Expect(TokenCategory.VAR) }; result.Add(VarList()); Expect(TokenCategory.SEMICOLON);//------------------------------------------------- return(result); }
public override Null Visit(VarDef node) { if (node.value != null) { if (node.info.inExternal) { log.ErrorStmtNotAllowed(node.location, "initialized variable", "inside an external block"); } else if (node.info.classDef == null && node.info.funcDef == null) { log.ErrorStmtNotAllowed(node.location, "initialized variable", "at module scope"); } } base.Visit(node); return null; }
public override Null Visit(VarDef node) { // Define the variable node.symbol = new Symbol { kind = SymbolKind.Variable, isStatic = false, def = node, type = new ErrorType() }; scope.Define(node.symbol); base.Visit(node); return null; }
public void AddVariable(VarDef variable) { List <VarDef> varDefs; SpanString spanStr = new SpanString(variable.ID); if (IDToVariable.TryGetValue(spanStr, out var currDefs)) { varDefs = currDefs; } else { varDefs = new List <VarDef>(); IDToVariable.Add(spanStr, varDefs); } varDefs.Add(variable); }
public Node VarDef() { var varToken = Expect(TokenCategory.VAR); var varList = VarList(); Expect(TokenCategory.SEMICOLON); var result = new VarDef() { varList }; result.AnchorToken = varToken; return(result); }
/// <summary> /// Generates a variable declaration expression with the specified name and type. /// E.g. "var foo string". /// </summary> /// <param name="varName">The name of the variable.</param> /// <param name="typeName">The type name of the variable.</param> /// <returns>The root node in this declaration AST.</returns> public static Node Generate(string varName, string typeName) { if (string.IsNullOrWhiteSpace(varName)) { throw new ArgumentException(nameof(varName)); } if (string.IsNullOrWhiteSpace(typeName)) { throw new ArgumentException(nameof(typeName)); } var varDef = new VarDef(); varDef.AddChild(new Identifier(varName)); varDef.AddChild(new TypeName(typeName)); return(varDef); }
//<vardef>// public string Visit(VarDef node, int i) { //Visit((dynamic) node[0], i); // The code for the local variable declarations is // generated directly from the symbol table, not from // the AST nodes. //GLOBALS var sb = new StringBuilder(); foreach (var entry in table) { sb.Append(String.Format( "\t\t.field public static {0} '{1}'\n", myType, entry.Key) ); } return(sb.ToString()); }
public string Visit(VarDef node) { var result = ""; if (insideFunction) { foreach (var n in node[0]) { result = result + Line(Indent() + ".locals init (int32 '" + n.AnchorToken.Lexeme + "')"); localVariables.Add(n.AnchorToken.Lexeme); } } else { foreach (var n in node[0]) { result = result + Line(Indent() + ".field public static int32 '" + n.AnchorToken.Lexeme + "'"); globalVariables.Add(n.AnchorToken.Lexeme); } } return(result); }
public override Null Visit(VarDef node) { if (node.value == null) { Type type = node.type.computedType.InstanceType(); if (type.IsBool()) { node.value = new BoolExpr { value = false, computedType = type, location = node.location }; } else if (type.IsInt()) { node.value = new IntExpr { value = 0, computedType = type, location = node.location }; } else if (type.IsFloat()) { node.value = new FloatExpr { value = 0, computedType = type, location = node.location }; } else if (type.IsString()) { node.value = new StringExpr { value = "", computedType = type, location = node.location }; } else { node.value = new CastExpr { value = new NullExpr { computedType = new NullType(), location = node.location }, target = new TypeExpr { type = type, computedType = new MetaType { instanceType = type } }, computedType = type }; } } return null; }
public void IgnoreBecauseUnknown(VarDef variable) { IgnoredBecauseUnknown++; }
//----------------------------------------------------------- public void Visit(VarDef node) { Visit((dynamic)node[0]); }
public override Null Visit(VarDef node) { base.Visit(node); HandleAssignment(node.symbol, node.value); return null; }
internal static IDeclCmd?VisitDeclCmd(VCDLexer lexer, IDToVarDef idToVariable, Stack <Scope> scopes) { ReadOnlySpan <byte> declWord = lexer.NextWord(); Span <char> chars = stackalloc char[declWord.Length]; declWord.CopyToCharArray(chars); ReadOnlySpan <byte> endToken = new byte[] { (byte)'$', (byte)'e', (byte)'n', (byte)'d' }; ReadOnlySpan <byte> dollarSign = new byte[] { (byte)'$' }; if (chars.SequenceEqual("$comment")) { string text = lexer.NextUntil(endToken).ToCharString(); lexer.ExpectNextWord(endToken); return(new Comment(text)); } else if (chars.SequenceEqual("$date")) { string text = lexer.NextUntil(endToken).ToCharString(); lexer.ExpectNextWord(endToken); return(new Date(text)); } else if (chars.SequenceEqual("$scope")) { ScopeType type = VisitScopeType(lexer); string id = lexer.NextWord().ToCharString(); Scope scope = new Scope(type, id); scopes.Push(scope); lexer.ExpectNextWord(endToken); return(scope); } else if (chars.SequenceEqual("$timescale")) { int scale = VisitTimeNumber(lexer); TimeUnit unit = VisitTimeUnit(lexer); lexer.ExpectNextWord(endToken); return(new TimeScale(scale, unit)); } else if (chars.SequenceEqual("$upscope")) { scopes.Pop(); lexer.ExpectNextWord(endToken); return(new UpScope()); } else if (chars.SequenceEqual("$var")) { VarType type = VisitVarType(lexer); int size = VisitSize(lexer); string id = lexer.NextWord().ToCharString(); string reference = lexer.NextWord().ToCharString(); VarDef variable = new VarDef(type, size, id, reference, scopes.Reverse().ToArray()); idToVariable.AddVariable(variable); //Skip this stuff because it's not currently supported char nextChar = lexer.PeekNextChar(); if (nextChar == '[') { ReadOnlySpan <byte> endBracket = new byte[] { (byte)']' }; lexer.NextUntil(endBracket); lexer.SkipChar(); } lexer.ExpectNextWord(endToken); return(variable); } else if (chars.SequenceEqual("$version")) { string versionTxt = lexer.NextUntil(dollarSign).ToCharString(); string systemTaskString = string.Empty; ReadOnlySpan <byte> systemTask = lexer.PeekNextWord().Span; if (systemTask.StartsWith(dollarSign) && !systemTask.SequenceEqual(endToken)) { lexer.SkipWord(systemTask); systemTaskString = systemTask.ToCharString(); } lexer.ExpectNextWord(endToken); return(new Version(versionTxt, systemTaskString)); } else if (chars.SequenceEqual("$enddefinitions")) { lexer.ExpectNextWord(endToken); return(null); } else { throw new Exception($"Invalid declaration command: {declWord.ToCharString()}\nBuffer: {lexer.BufferToString()}"); } }
public string Visit(VarDef node) { return(VisitChildren(node)); }
public override Null Visit(VarDef node) { base.Visit(node); node.symbol.type = GetInstanceType(node.type, false); return null; }
//----------------------------------------------------------- //<vardef>// public void Visit(VarDef node, int i) { Visit((dynamic)node[0], i); }
public override Null Visit(VarDef node) { // Make sure the variable is defined (it will already be defined if it's // a global variable but not if it's a local variable) if (node.symbol == null) { node.symbol = new Symbol { kind = SymbolKind.Variable, isStatic = false, def = node, type = new ErrorType() }; scope.Define(node.symbol); } if (node.type is VarExpr && node.value != null) { // Handle type inference node.value.Accept(this); if (node.value.computedType is NullType || node.value.computedType is VoidType) { log.ErrorNotUseableType(node.location, new MetaType { instanceType = node.value.computedType }); node.symbol.type = new ErrorType(); } else { node.symbol.type = node.value.computedType; } } else { // Handle normal variable declaration node.type.Accept(this); if (!node.type.computedType.IsInstantiatableType()) { log.ErrorNotUseableType(node.type.location, node.type.computedType); } else { node.symbol.type = node.type.computedType.InstanceType(); if (node.value != null) { // Provide the variable type as the context to resolve the value type context = new Context { targetType = node.symbol.type }; node.value.Accept(this); if (!node.value.computedType.EqualsType(node.symbol.type)) { if (node.value.computedType.CanImplicitlyConvertTo(node.symbol.type)) { node.value = InsertCast(node.value, node.symbol.type); } else { log.ErrorTypeMismatch(node.location, node.symbol.type, node.value.computedType); } } } } } return null; }
//----------------------------------------------------------- //<vardef>// public void Visit(VarDef node) { //Already visited in first run }