public bool IdenticalSignature(OperatorDeclaration other) { if (this.ReturnType == null && other.ReturnType != null) return false; else if (other.ReturnType == null) return false; return this.OperatorKeyword == other.OperatorKeyword && this.ReturnType.Name.ToLower() == other.ReturnType.Name.ToLower(); }
public OperatorDeclaration GetOperator(OperatorDeclaration sig) { if (sig.Type == ASTNodeType.InfixOperator) return Operators.First(opdecl => opdecl.Value.Type == ASTNodeType.InfixOperator && sig.IdenticalSignature((opdecl.Value as InOpDeclaration))).Value; else if (sig.Type == ASTNodeType.PrefixOperator) return Operators.First(opdecl => opdecl.Value.Type == ASTNodeType.PrefixOperator && sig.IdenticalSignature((opdecl.Value as PreOpDeclaration))).Value; else if (sig.Type == ASTNodeType.PostfixOperator) return Operators.First(opdecl => opdecl.Value.Type == ASTNodeType.PostfixOperator && sig.IdenticalSignature((opdecl.Value as PostOpDeclaration))).Value; return null; }
public bool IdenticalSignature(OperatorDeclaration other) { if (this.ReturnType == null && other.ReturnType != null) { return(false); } else if (other.ReturnType == null) { return(false); } return(this.OperatorKeyword == other.OperatorKeyword && this.ReturnType.Name.ToLower() == other.ReturnType.Name.ToLower()); }
public bool IdenticalSignature(OperatorDeclaration other) { if (this.ReturnType == null && other.ReturnType != null) { return(false); } else if (other.ReturnType == null) { return(false); } return(this.OperatorKeyword == other.OperatorKeyword && string.Equals(this.ReturnType?.Name, other.ReturnType.Name, StringComparison.Ordinal)); }
public bool VisitNode(OperatorDeclaration node) { ASTNode returnType = null; if (node.ReturnType != null) { if (!Symbols.TryGetSymbol(node.ReturnType.Name, out returnType, NodeUtils.GetOuterClassScope(node))) { return Error("No type named '" + node.ReturnType.Name + "' exists in this scope!", node.ReturnType.StartPos, node.ReturnType.EndPos); } else if (!typeof(VariableType).IsAssignableFrom(returnType.GetType())) { return Error("Invalid return type, must be a class/struct/enum/primitive.", node.ReturnType.StartPos, node.ReturnType.EndPos); } } Symbols.PushScope(node.OperatorKeyword); if (node.Type == ASTNodeType.InfixOperator) { var op = node as InOpDeclaration; op.LeftOperand.Outer = node; Success = Success && op.LeftOperand.AcceptVisitor(this); op.RightOperand.Outer = node; Success = Success && op.RightOperand.AcceptVisitor(this); } else if (node.Type == ASTNodeType.PrefixOperator) { var op = node as PreOpDeclaration; op.Operand.Outer = node; Success = Success && op.Operand.AcceptVisitor(this); } else if (node.Type == ASTNodeType.PostfixOperator) { var op = node as PostOpDeclaration; op.Operand.Outer = node; Success = Success && op.Operand.AcceptVisitor(this); } Symbols.PopScope(); if (Success == false) return Error("Error in operator parameters.", node.StartPos, node.EndPos); if (Symbols.OperatorSignatureExists(node)) return Error("An operator with identical signature to '" + node.OperatorKeyword + "' already exists!", node.StartPos, node.EndPos); Symbols.AddOperator(node); return Success; }
public bool VisitNode(OperatorDeclaration node) { // [specifiers] function [returntype] functionname ( [parameter declarations] ) body_or_semicolon Write(""); if (node.Specifiers.Count > 0) Append("{0} ", String.Join(" ", node.Specifiers.Select(x => x.Value))); if (node.Type == ASTNodeType.InfixOperator) { var inOp = node as InOpDeclaration; Append("operator({0}) {1}{2}( ", inOp.Precedence, (node.ReturnType != null ? node.ReturnType.Name + " " : ""), node.OperatorKeyword); inOp.LeftOperand.AcceptVisitor(this); Append(", "); inOp.RightOperand.AcceptVisitor(this); } else if (node.Type == ASTNodeType.PrefixOperator) { var preOp = node as PreOpDeclaration; Append("preoperator {0}{1}( ", (node.ReturnType != null ? node.ReturnType.Name + " " : ""), node.OperatorKeyword); preOp.Operand.AcceptVisitor(this); } else if (node.Type == ASTNodeType.PostfixOperator) { var postOp = node as PostOpDeclaration; Append("postoperator {0}{1}( ", (node.ReturnType != null ? node.ReturnType.Name + " " : ""), node.OperatorKeyword); postOp.Operand.AcceptVisitor(this); } Append(" )"); if (node.Body.Statements != null) { Write("{0}", "{"); NestingLevel++; foreach (Variable v in node.Locals) v.AcceptVisitor(this); node.Body.AcceptVisitor(this); NestingLevel--; Write("{0}", "}"); } else Append(";"); return true; }
public void AddOperator(OperatorDeclaration op) { Operators.Add(op.OperatorKeyword.ToLower(), op); }
public bool OperatorSignatureExists(OperatorDeclaration sig) { if (sig.Type == ASTNodeType.InfixOperator) return Operators.Any(opdecl => opdecl.Value.Type == ASTNodeType.InfixOperator && sig.IdenticalSignature((opdecl.Value as InOpDeclaration))); else if (sig.Type == ASTNodeType.PrefixOperator) return Operators.Any(opdecl => opdecl.Value.Type == ASTNodeType.PrefixOperator && sig.IdenticalSignature((opdecl.Value as PreOpDeclaration))); else if (sig.Type == ASTNodeType.PostfixOperator) return Operators.Any(opdecl => opdecl.Value.Type == ASTNodeType.PostfixOperator && sig.IdenticalSignature((opdecl.Value as PostOpDeclaration))); return false; }