public override void VisitFunctionDecl(FunctionDecl decl, VisitKind visitKind) { if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version)) { PlainCDeprecatedFunctions [decl.QualifiedName] = version; } }
public SourceFunctionSymbol(SourceFileSymbol file, FunctionDecl syntax) { Contract.ThrowIfNull(file); _file = file; _syntax = syntax; }
/// <inheritdoc /> public void DeclareGlobal(FunctionDecl declaration, FileInfo declaringScript) { var function = CreateFunction(declaration, declaringScript); _statistics.Report(Statistic.DeclaredFunctions); declareGlobal(function); }
public override void VisitFunctionDecl(FunctionDecl x) { using (new ScopeHelper(this, x)) { base.VisitFunctionDecl(x); } }
public bool EnterInvocationExpr(InvocationExpressionSyntax invocationExpr, WaddleContext ctx) { if (_functions.ContainsKey(invocationExpr.Identifier) == false) { throw new SemanticErrorException($"function {invocationExpr.Identifier} is not defined"); } FunctionDecl functionDecl = _functions[invocationExpr.Identifier] !; var parameters = functionDecl.Parameters; var arguments = invocationExpr.Arguments.ToArray(); if (parameters.Count != arguments.Length) { throw new SemanticErrorException($"function {invocationExpr.Identifier} has {functionDecl.Parameters.Count} parameters, {invocationExpr.Arguments.Count()} arguments where given."); } // check that for all parameters: IsAssignableFrom(param.Type, arg.Type) for (int i = 0; i < parameters.Count; i++) { var parameter = parameters[i]; var exprType = arguments[i].Accept(TypeVisitor); if (parameter.Type != exprType) { throw new SemanticErrorException($"Parameter {parameter} requires type {parameter.Type}, but type {exprType} was given."); } } return(true); }
private static FunctionDeclarationExpression ToFunctionDeclarationExpression(FunctionDecl e) { return(new FunctionDeclarationExpression( ToNameOfFunction(e.Name), ToDeclarationSignature(e.Signature), Parse(e.Body) )); }
public override void VisitFunctionDecl(FunctionDecl x) { if (x.IsConditional) { Add(x); } // ignored }
public SourceFunctionSymbol(SourceFileSymbol file, FunctionDecl syntax) { Contract.ThrowIfNull(file); _file = file; _syntax = syntax; _params = BuildParameters(syntax.Signature, syntax.PHPDoc).AsImmutable(); }
public override void VisitFunctionDecl(FunctionDecl x) { VisitSpecificElementProlog(); SerializeToken(nameof(x.Name), x.Name.ToString(), x.Name.Span); base.VisitFunctionDecl(x); }
public override void VisitFunctionDecl(FunctionDecl x) { if (x == _routine) { _statementContext = VariableKind.LocalVariable; base.VisitFunctionDecl(x); } }
public SourceFunctionSymbol(SourceFileSymbol file, FunctionDecl syntax) { Contract.ThrowIfNull(file); _file = file; _syntax = syntax; _params = BuildParameters(syntax.Signature, syntax.PHPDoc).AsImmutable(); }
/// <summary> /// Visit a function declaration /// </summary> private void VisitFunctionDecl(FunctionDecl funDecl, TraversalData traversalData) { var desc = MatchHook(traversalData.GetQualifiedType(funDecl)); if (desc != null) { m_bir.Hooks.Add(CreateHook(funDecl, desc, traversalData)); } }
/// <summary> /// Constructs a confrolflow graph. This method should be used only for testing with purpose of testing. /// </summary> /// <param name="globalCode">Globalcode needed for drawing</param> /// <param name="function">function to construct controlflow graph</param> /// <param name="file">Information about source file</param> private ControlFlowGraph(GlobalCode globalCode, FunctionDecl function, FileInfo file) { File = file; this.globalCode = globalCode; this.visitor = new CFGVisitor(this); start = visitor.MakeFunctionCFG(function, function.Body); PostProcess(visitor); }
/// <inheritdoc /> public override void VisitFunctionDecl(FunctionDecl x) { if (isInsideSubroutine) { occurrenceNodes.Enqueue(x); } VisitSubroutineExpr <FunctionDecl>(base.VisitFunctionDecl, x); }
public override void VisitFunctionDecl(FunctionDecl x) { var routine = new SourceFunctionSymbol(_currentFile, x); x.SetProperty(routine); // remember bound function symbol _currentFile.AddFunction(routine); // base.VisitFunctionDecl(x); }
public void CompileFunctionDecl(FunctionDecl fnDecl) { if (fnDecl.Attributes != null && fnDecl.Attributes.Length > 0) { DumpAttributesList(fnDecl.Attributes, true); } textWriter.Write("function {0}", SafeName(fnDecl.Name)); DumpFunction(fnDecl.Function); }
public void VisitFunctionDecl(FunctionDecl node) { _symbols.Define(new FunctionSymbol(node.Name, node)); EnterScope(node); foreach (var arg in node.Args) { _symbols.Define(new FormalArgumentSymbol(arg)); } Visit(node.Body); ExitScope(); }
private void ValidateEntryPointFunction(FunctionDecl function) { if (function.Type != TypeSymbol.Integer && function.Type is not null) { throw new SemanticErrorException("Main must return either void or int"); } if (function.Parameters.Count != 0) { throw new SemanticErrorException("Main signature mismatch"); } }
/// <summary> /// Visit function parameters and function body. /// </summary> /// <param name="x"></param> virtual public void VisitFunctionDecl(FunctionDecl x) { VisitElement(x.PHPDoc); // function parameters VisitList(x.Signature.FormalParams); // function return type VisitElement(x.ReturnType); // function body VisitElement(x.Body); }
public override void VisitFunctionDecl(FunctionDecl x) { var bound = _binder.BindWholeStatement(x).SingleBoundElement(); if (x.IsConditional) { _current.Add(bound); } else { AddUnconditionalDeclaration(bound); } }
public void Visit(FunctionDecl funcDecl) { var oldRet = _foundReturn; _foundReturn = false; funcDecl.Body.Accept(this); Raise <ReturnCheckException> .If(!_foundReturn && funcDecl.ReturnTypeName != "void"); if (!_foundReturn && funcDecl.ReturnTypeName == "void") { funcDecl.RequiresExplicitReturn = true; } _foundReturn = oldRet; }
/// <summary> /// Add global function to the interface with global functions /// </summary> public override void VisitFunctionDecl(FunctionDecl x) { var cmt = x.PHPDoc; if (cmt == null) { return; } if (cmt.Access == Reflection.PhpMemberAttributes.Public) { currentModule.Globals = true; currentModule.GlobalClass.Members.Add(GenerateFunctionCode(cmt, x.Function.Name.Value)); } }
void CheckFunctionDecl(FunctionDecl func) { Assert.IsTrue(func.Span.Contains(func.Name.Span)); Assert.IsTrue(func.Span.Contains(func.HeadingSpan)); Assert.IsTrue(func.Span.Contains(func.ParametersSpan)); Assert.IsTrue(func.Span.Contains(func.Body.Span)); Assert.IsTrue(func.HeadingSpan.Contains(func.Name.Span)); Assert.IsTrue(func.HeadingSpan.Contains(func.ParametersSpan)); Assert.IsTrue(func.HeadingSpan.End <= func.Body.Span.Start); Assert.IsTrue(func.Name.Span.End <= func.ParametersSpan.Start); foreach (var param in func.Signature.FormalParams) { Assert.IsTrue(param.Span.Contains(param.Name.Span)); } }
public void Visit(FunctionDecl funcDecl) { const MethodAttributes funcAttr = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig; MethodDefinition func; if (funcDecl.Name == "$Main") { func = _main; } else { func = new MethodDefinition(funcDecl.Name, funcAttr, funcDecl.ReturnType.Reference); _userFunctions.Methods.Add(func); funcDecl.Reference = func; } foreach (var p in funcDecl.Params) { const ParameterAttributes paramAttr = ParameterAttributes.None; var paramDef = new ParameterDefinition(p.Name, paramAttr, p.Type.Reference); func.Parameters.Add(paramDef); p.Reference = paramDef; } var oldBody = _body; var oldInstructions = _instructions; _body = func.Body; _instructions = _body.Instructions; foreach (var @var in funcDecl.Variables) { var varDef = new VariableDefinition(@var.Name, @var.Type.Reference); _body.Variables.Add(varDef); @var.Reference = varDef; } funcDecl.Body.Accept(this); if (funcDecl.RequiresExplicitReturn) { _instructions.Add(Instruction.Create(OpCodes.Ret)); } _body = oldBody; _instructions = oldInstructions; }
public override void VisitFunctionDecl(FunctionDecl x) { var routine = new SourceFunctionSymbol(_currentFile, x); x.SetProperty(routine); // remember bound function symbol _currentFile.AddFunction(routine); if (!x.IsConditional) { _tables._functions.Add(routine.QualifiedName, routine); } // base.VisitFunctionDecl(x); }
private void TryNotifyConstructorFound(CXXRecordDecl caller, FunctionDecl constructor) { // If no body, error out (= delete) if (constructor.IsInvalidDecl || constructor.Body == null) { return; } // TODO: Friend containers? if (constructor.Access != CX_CXXAccessSpecifier.CX_CXXPublic) { return; } CtorFound?.Invoke(null, constructor.Parameters.ToList()); }
public override void VisitFunctionDecl(FunctionDecl x) { var routine = new SourceFunctionSymbol(_currentFile, x); x.SetProperty(routine); // remember bound function symbol _currentFile.AddFunction(routine); if (!x.IsConditional) { _tables._functions.Add(routine.QualifiedName, routine); } // base.VisitFunctionDecl(x); }
public override void VisitFunctionDecl(FunctionDecl decl, VisitKind visitKind) { if (visitKind != VisitKind.Enter) { return; } // skip macros : we generally implement them but their name is lost (so no matching is possible) if (!decl.IsExternC) { return; } var name = decl.Name; // do not consider _* or __* as public API that should be bound if (name [0] == '_') { return; } var framework = Helpers.GetFramework(decl); if (framework == null) { return; } // check availability macros to see if the API is available on the OS and not deprecated if (!decl.IsAvailable()) { return; } if (!dllimports.ContainsKey(name)) { // if we find functions without matching DllImport then we report them // but don't report deprecated functions if (!decl.IsDeprecated()) { Log.On(framework).Add($"!missing-pinvoke! {name} is not bound"); } return; } dllimports.Remove(name); }
override public void VisitFunctionDecl(FunctionDecl x) { _serializer.StartSerialize(typeof(FunctionDecl).Name, SerializeSpan(x.Span), new NodeObj("Name", x.Name.Name.Value), new NodeObj("IsConditional", x.IsConditional.ToString())); SerializePHPDoc(x.PHPDoc); _serializer.StartSerialize("FormalParams"); // function parameters foreach (FormalParam p in x.Signature.FormalParams) { VisitElement(p); } _serializer.EndSerialize(); SerializeOptionalProperty("Body", x.Body); SerializeOptionalProperty("ReturnType", x.ReturnType); _serializer.EndSerialize(); }
public void Visit(FunctionDecl funcDecl) { Indent(); _sb.AppendFormat("{0} {1}(", funcDecl.ReturnType, funcDecl.Name); if (funcDecl.Params.Count > 0) { var i = 0; FunctionDecl.ParamInfo p; for (; i < funcDecl.Params.Count - 1; ++i) { p = funcDecl.Params[i]; _sb.AppendFormat("{0} {1},", p.Type, p.Name); } p = funcDecl.Params[i]; _sb.AppendFormat("{0} {1}", p.Type, p.Name); } _sb.Append(")\r\n"); funcDecl.Body.Accept(this); }
void LoadFunc(MethodReference funcDef) { Raise <TypeCheckException> .If(_funcDecls.ContainsKey(funcDef.Name)); var funcRef = Module.Import(funcDef); var funcDecl = new FunctionDecl(); funcDecl.Name = funcRef.Name; funcDecl.ReturnType = GetType(funcRef.ReturnType.Name); funcDecl.ReturnTypeName = funcDecl.ReturnType.Name; funcDecl.Reference = funcRef; foreach (var p in funcDef.Parameters) { var paramType = GetType(p.ParameterType.Name); var paramInfo = funcDecl.AddParam(p.Name, paramType.Name); paramInfo.Type = paramType; paramInfo.Reference = p; } _funcDecls.Add(funcDef.Name, funcDecl); }
/// <inheritdoc /> public override void VisitFunctionDecl(FunctionDecl x) { // The function can be declared inside other function or method body // In that case, traversing the tree of the inside function is not necessary if (!isInsideFunction) { var previousValue = isInsideFunction; try { isInsideFunction = true; currentReferences.Clear(); base.VisitFunctionDecl(x); } finally { isInsideFunction = previousValue; } } }
public void Visit(FunctionDecl funcDecl) { const MethodAttributes funcAttr = MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig; MethodDefinition func; if (funcDecl.Name == "$Main") { func = _main; } else { func = new MethodDefinition(funcDecl.Name, funcAttr, funcDecl.ReturnType.Reference); _userFunctions.Methods.Add(func); funcDecl.Reference = func; } foreach (var p in funcDecl.Params) { const ParameterAttributes paramAttr = ParameterAttributes.None; var paramDef = new ParameterDefinition(p.Name, paramAttr, p.Type.Reference); func.Parameters.Add(paramDef); p.Reference = paramDef; } var oldBody = _body; var oldInstructions = _instructions; _body = func.Body; _instructions = _body.Instructions; foreach (var @var in funcDecl.Variables) { var varDef = new VariableDefinition(@var.Name, @var.Type.Reference); _body.Variables.Add(varDef); @var.Reference = varDef; } funcDecl.Body.Accept(this); if (funcDecl.RequiresExplicitReturn) { _instructions.Add(Instruction.Create(OpCodes.Ret)); } _body = oldBody; _instructions = oldInstructions; }
public void Visit(FunctionDecl funcDecl) { Raise<TypeCheckException>.If(_funcDecls.ContainsKey(funcDecl.Name), "Function with existing name!"); funcDecl.ReturnType = GetType(funcDecl.ReturnTypeName); var previousStaticEnv = _staticEnv; _staticEnv = new StaticEnv(new OutmostStaticEnv()); foreach (var p in funcDecl.Params) { p.Type = GetType(p.TypeName); Raise<TypeCheckException>.IfAreSame(p.Type, _voidType, "Struct fields cannot be void"); var vInfo = new StaticEnvBase.VarInfo(p.Name, p.Type, StaticEnvBase.Kind.Param, p); _staticEnv.SetVariable(p.Name, vInfo); } _funcDecls.Add(funcDecl.Name, funcDecl); // Must be put here to allow recursion... var prevFunc = _currFunc; _currFunc = funcDecl; funcDecl.Body.Accept(this); _currFunc = prevFunc; _staticEnv = previousStaticEnv; }
void LoadFunc(MethodReference funcDef) { Raise<TypeCheckException>.If(_funcDecls.ContainsKey(funcDef.Name)); var funcRef = Module.Import(funcDef); var funcDecl = new FunctionDecl(); funcDecl.Name = funcRef.Name; funcDecl.ReturnType = GetType(funcRef.ReturnType.Name); funcDecl.ReturnTypeName = funcDecl.ReturnType.Name; funcDecl.Reference = funcRef; foreach (var p in funcDef.Parameters) { var paramType = GetType(p.ParameterType.Name); var paramInfo = funcDecl.AddParam(p.Name, paramType.Name); paramInfo.Type = paramType; paramInfo.Reference = p; } _funcDecls.Add(funcDef.Name, funcDecl); }
private void PreProcessFuncDecl(Notation notation, Notation.Record rec) { Qname qname = (Qname)rec.Arg0; XmlQualifiedName identity = QNameParser.Parse(qname.Name, _context.NamespaceManager, _context.nameTable); string ns = identity.Namespace; if (ns == String.Empty) { if (_context.DefaultFunctionNS == null) ns = XmlReservedNs.NsXQueryFunc; else ns = _context.DefaultFunctionNS; } if (ns == String.Empty || ns == XmlReservedNs.NsXml || ns == XmlReservedNs.NsXQueryFunc || ns == XmlReservedNs.NsXs || ns == XmlReservedNs.NsXsi) throw new XQueryException(Properties.Resources.XQST0045, identity.Name, identity.Namespace); object f = ATOM.Create(ns, new string[] { identity.Name }, false); FunctionParameter[] parameters = ProcessParamList(notation, rec.args[1]); if (_context.FunctionTable.IsRegistered(f, parameters.Length)) throw new XQueryException(Properties.Resources.XQST0034, identity.Name, identity.Namespace); XQuerySequenceType[] parameterTypes = new XQuerySequenceType[parameters.Length]; for (int k = 0; k < parameters.Length; k++) parameterTypes[k] = parameters[k].type; FunctionDecl decl = new FunctionDecl(f, identity, parameters); if (rec.args.Length > 3) { decl.returnType = new XQuerySequenceType(ProcessTypeDecl(notation, rec.Arg2)); if (rec.args[3] == null) // external throw new NotImplementedException(); else _context.FunctionTable.Register(f, _context, parameterTypes, decl.returnType); } else { if (rec.args[2] == null) // external throw new NotImplementedException(); else decl.returnType = XQuerySequenceType.Item; _context.FunctionTable.Register(f, _context, parameterTypes, decl.returnType); } _fdecl.Add(rec.sym, decl); }
public void Visit(FunctionDecl funcDecl) { Indent(); _sb.AppendFormat("{0} {1}(", funcDecl.ReturnType, funcDecl.Name); if (funcDecl.Params.Count > 0) { var i = 0; FunctionDecl.ParamInfo p; for (; i < funcDecl.Params.Count - 1; ++i) { p = funcDecl.Params[i]; _sb.AppendFormat("{0} {1},", p.Type, p.Name); } p = funcDecl.Params[i]; _sb.AppendFormat("{0} {1}", p.Type, p.Name); } _sb.Append(")\r\n"); funcDecl.Body.Accept(this); }
public void Visit(FunctionDecl funcDecl) { var oldRet = _foundReturn; _foundReturn = false; funcDecl.Body.Accept(this); Raise<ReturnCheckException>.If(!_foundReturn && funcDecl.ReturnTypeName != "void"); if (!_foundReturn && funcDecl.ReturnTypeName == "void") { funcDecl.RequiresExplicitReturn = true; } _foundReturn = oldRet; }