public CodeGenAnalyser(ISyntaxTreeNode astRoot, bool optimize) { _astRoot = astRoot; _currentLocalIdx = 0; _previousVarKind = VariableDeclaration.Kind.Class; _optimize = optimize; }
public void VisitUnknown(ISyntaxTreeNode node) { if (UnknownVisitor != null) { UnknownVisitor.Visit(node); } }
public void AddDebugSymbol(int address, ISyntaxTreeNode associatedNode) { Symbol range; _nodeToTokenMap.TryGetValue(associatedNode, out range); _addressToTokenMap[address] = range; }
private void VisitPostOrder(ISyntaxTreeNode node) { if (_postOrderVisitor != null) { node.AcceptSyntaxTreeVisitor(_postOrderVisitor); } }
public void ReplaceNode(ISyntaxTreeNode oldNode, ISyntaxTreeNode newNode) { if (_scopes.TryGetValue(oldNode, out NodeScopeInfo info)) { _scopes[newNode] = info; } }
public void SetScope(ISyntaxTreeNode node, Scope scope) { NodeScopeInfo info = new NodeScopeInfo { Scope = scope, DeclarationIndex = scope.Variables.Count }; _scopes[node] = info; }
private void AddAssigmentTypeMismatchError(IType lhsType, IType rhsType, ISyntaxTreeNode node) { string message = "Type mismatch between assignment operator.\n" + $" LHS: {lhsType.Represent()}\n" + $" RHS: {rhsType.Represent()}"; _errors.AddError(message, node); }
public NodeScopeInfo GetScope(ISyntaxTreeNode node) { if (!_scopes.TryGetValue(node, out NodeScopeInfo scope)) { throw new ArgumentException("No scope associated with this node", nameof(node)); } return(scope); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as ArrayExpression; if (other == null) { return(false); } return(this.Elements.StructurallyEquals(other.Elements)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as Query; if (other == null) { return(false); } return(this.Expression.StructurallyEquals(other.Expression)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as BooleanLiteralExpression; if (other == null) { return(false); } return(this.Value == other.Value); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as ParenthesisExpression; if (other == null) { return(false); } return(Expression.StructurallyEquals(other.Expression)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as ArrayAccessExpression; if (other == null) { return(false); } return(this.Indices.StructurallyEquals(other.Indices)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as UnaryOperationExpression; if (other == null) { return(false); } return(this.Operator == other.Operator && this.Expression.StructurallyEquals(other.Expression)); }
/// <summary> /// Deep equals for this syntax node. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as FunctionCallExpression; if (other == null) { return(false); } return(this.ThisExpression.StructurallyEquals(other.ThisExpression) && this.Parameters.StructurallyEquals(other.Parameters)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as MemberExpression; if (other == null) { return(false); } return(this.ThisExpression.StructurallyEquals(other.ThisExpression) && this.MemberName == other.MemberName); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as CastExpression; if (other == null) { return(false); } return(this.CastTypeName == other.CastTypeName && this.Expression.StructurallyEquals(other.Expression)); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as VariableExpression; if (other == null) { return(false); } return(other.Identifier == this.Identifier); }
/// <summary> /// Deep equals. /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { var other = node as ConditionalExpression; if (other == null) { return(false); } return(this.Condition.StructurallyEquals(other.Condition) && this.Then.StructurallyEquals(other.Then) && this.Else.StructurallyEquals(other.Else)); }
public void VisitTypeSpecifier(TypeSpecifierParseNode node) { IType?type = _typeManager.GetType(node.Name, node.PointerMode); if (type == null) { _errors.AddError($"Undefined type name \"{node.Name}\"", node); return; } NewNode = new TypeSpecifierNode(type); ShouldReplace = true; }
internal Metadata SetCurrentDebugLocation(ISyntaxTreeNode node, bool forceDbgInfo = false) { if (_genContext.DebugInfo || forceDbgInfo) { _genContext.TryGetNodeSymbol(node, out Symbol range); Metadata location = _genContext.Context.CreateDebugLocation(range.LLVMLine, _genContext.ColumnInfo ? range.LLVMColumn : 0, _lexicalScope, Metadata.Null); _builder.SetCurrentDebugLocation(location); return(location); } return(Metadata.Null); }
public TreeNodeViewModel(ISyntaxTreeNode node) { var moduleNode = node as CodeModule; _node = node; Icon = SetIcon(); AttributeVisibility = Visibility.Collapsed; if (node is AttributeNode) { AttributeValue = (node as AttributeNode).Value; AttributeVisibility = Visibility.Visible; } }
/// <summary> /// A private helper method to help check the declaration state of a property. /// </summary> /// <param name="node">Node.</param> /// <param name="property">Property.</param> /// <param name="declarationExpected">If set to <c>true</c> declaration expected.</param> private void checkPropertyDeclared(ISyntaxTreeNode node, IProperty property, bool declarationExpected) { if (declarationExpected) { if (!property.Declared) { // if the declaration was expected, report an error about an uninitialized variable analyzer.notifyError(new UninitializedVariableError(node)); } } else { if (property.Declared) { // if the declaration was not expected, report an error about a repeated declaration of a variable analyzer.notifyError(new DeclarationError(node)); } } }
public void Visit(AssignmentParseNode node) { IAddressableNode?assignableNode = node.LHS as IAddressableNode; if (assignableNode == null || !assignableNode.IsAddressable()) { _errors.AddError("Left hand side of assignment is not assignable.", node); return; } _shouldReplace = true; _newNode = new AssignmentNode(assignableNode, node.RHS); // TODO: Need more automated symbol association for new nodes. Symbol originalSymbol; _semanticModule.SymbolMap.TryGetValue(node, out originalSymbol); _semanticModule.SymbolMap[_newNode] = originalSymbol; }
public override string ToString() { if (Value is null) { return($"Entry point:\r\n{string.Join("\r\n", Nodes)}"); } var parents = 0; ISyntaxTreeNode currNode = this; while (currNode.Parent != null) { parents++; currNode = currNode.Parent; } var tab = new string('\t', parents); return($"{tab}{Value.Type}: {Value.Value}\r\n{string.Join("\r\n", Nodes)}"); }
public void Visit(AccessParseNode node) { IType type = _expressionTypeManager.GetExpressionType(node.Lhs); if (!(type is StructType structType)) { _errors.AddError($"Type '{type.Represent()}' has no accessible members.", node); return; } DeclarationNode?declaration = structType.Struct.Members.Find(decl => decl.Name == node.Rhs.Name); if (declaration == null) { _errors.AddError($"No such member {node.Rhs.Name} in struct {structType.Struct.Name}.", node.Rhs); return; } NewNode = new AccessNode(node.Lhs, declaration); ShouldReplace = true; }
public void Visit(IdentifierParseNode node) { ShouldReplace = true; NodeScopeInfo nodeScopeInfo = _scopeManager.GetScope(node); DeclarationNode?decl = nodeScopeInfo.Scope.FindNearestDeclaration(node.Name, nodeScopeInfo.DeclarationIndex); if (decl != null) { NewNode = UpdateSymbolMap(new VariableNode(decl), node); return; } if (_semanticModule.EnumInfo.TryGetValue(node.Name, out EnumDeclarationInfo identifierInfo)) { NewNode = UpdateSymbolMap(new EnumValueNode(identifierInfo.Declaration), node); return; } ShouldReplace = false; _errors.AddError($"Undeclared identifier {node.Name}", node); }
private void AssertLifetime(IType?lhsType, Scope?lhs, Scope?rhs, ISyntaxTreeNode context) { if (lhsType is IPointerType rhsPointerType) { if (rhsPointerType.Mode != PointerMode.Borrowed) { return; } } else { return; } if (lhs == null || rhs == null) { return; } if (lhs.Outlives(rhs)) { _errors.AddError("Incompatible lifetime.", context); } }
public void Visit(FunctionCallParseNode node) { IdentifierParseNode?identifier = node.LHS as IdentifierParseNode; if (identifier == null) { _errors.AddError("LHS of function call operator is not an identifier.", node); return; } ShouldReplace = true; FunctionCallNode?resultNode = null; if (!_semanticModule.Functions.TryGetValue(identifier.Name, out FunctionDefinitionNode function)) { _errors.AddError("Undefined function " + identifier.Name, node); } else if (function.Parameters.Length != node.Arguments.Count) { _errors.AddError($"Expected {function.Parameters.Length} argument(s), got {node.Arguments.Count}", node); return; } else { resultNode = new FunctionCallNode(function, node.Arguments); } if (resultNode == null) { resultNode = MakeFakeFunctionCall(identifier); } UpdateSymbolMap(resultNode, node); NewNode = resultNode; }
/// <summary> /// Deep equals /// </summary> /// <param name="node"></param> /// <returns></returns> public bool StructurallyEquals(ISyntaxTreeNode node) { return(node as NullExpression != null); }
public UninitializedVariableError(ISyntaxTreeNode node) : base(ErrorConstants.UNINITIALIZED_VARIABLE_ERROR_MESSAGE, node) { }
private void HandleExpressionOrStatementNode(ISyntaxTreeNode node) { node.Scope = CurrentScope; }
public void VisitUnknown(ISyntaxTreeNode node) { Print("(Unknown Syntax Tree Node)"); }
public ModuleNode(ISyntaxTreeNode header, IEnumerable<ISyntaxTreeNode> declarations, IEnumerable<ISyntaxTreeNode> members) : base(SyntaxTreeNodeType.ModuleNode, header.Nodes.OfType<AttributeNode>().FirstOrDefault(node => node.NodeName == "VB_Name").Value) { var nodes = header.Nodes.Concat(declarations).Concat(members); foreach (var node in nodes) { Nodes.Add(node); } }