public MethodDescription(AMethodDecl method) { Parser parser = new Parser(method); Start = parser.Start; End = parser.End; ReturnType = parser.ReturnType; Name = parser.Name; Formals = parser.Formals; Locals = parser.Locals; if (method.Parent() != null) method.Parent().RemoveChild(method); IsDelegate = method.GetDelegate() != null; //if (!IsDelegate) Decl = method; IsStatic = method.GetStatic() != null; Visibility = method.GetVisibilityModifier(); realType = (PType)method.GetReturnType().Clone(); Position = TextPoint.FromCompilerCoords(method.GetName()); }
public override void OutAMethodDecl(AMethodDecl node) { //If void return is missing, insert it. if (node.GetReturnType() is AVoidType && node.GetBlock() != null) { AABlock block = (AABlock)node.GetBlock(); bool insertReturn = false; while (true) { if (block.GetStatements().Count == 0) { insertReturn = true; break; } PStm lastStm = (PStm)block.GetStatements()[block.GetStatements().Count - 1]; if (lastStm is AVoidReturnStm) break; if (lastStm is ABlockStm) { block = (AABlock)((ABlockStm)block.GetStatements()[block.GetStatements().Count - 1]).GetBlock(); continue; } insertReturn = true; break; } if (insertReturn) { block.GetStatements().Add(new AVoidReturnStm(new TReturn("return", block.GetToken().Line, block.GetToken().Pos))); } } //Check if delegate is valid if (node.GetDelegate() != null) { if (node.GetBlock() != null) errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText195"))); if (node.GetInline() != null) errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText196"))); if (node.GetTrigger() != null) errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText197"))); if (node.GetStatic() != null) errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText198"))); if (node.GetNative() != null) errors.Add(new ErrorCollection.Error(node.GetDelegate(), currentSourceFile, LocRM.GetString("ErrorText199"))); } //If it's protected, it must be in a struct if (!Util.HasAncestor<AStructDecl>(node)) { if (node.GetVisibilityModifier() is AProtectedVisibilityModifier) errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText200"))); } base.OutAMethodDecl(node); }
public override void CaseAMethodDecl(AMethodDecl node) { InAMethodDecl(node); if (node.GetBlock() != null) { node.GetBlock().Apply(this); } { Object[] temp = new Object[node.GetFormals().Count]; node.GetFormals().CopyTo(temp, 0); for (int i = temp.Length - 1; i >= 0; i--) { ((PLocalDecl)temp[i]).Apply(this); } } if (node.GetName() != null) { node.GetName().Apply(this); } if (node.GetReturnType() != null) { node.GetReturnType().Apply(this); } if (node.GetDelegate() != null) { node.GetDelegate().Apply(this); } if (node.GetInline() != null) { node.GetInline().Apply(this); } if (node.GetNative() != null) { node.GetNative().Apply(this); } if (node.GetStatic() != null) { node.GetStatic().Apply(this); } if (node.GetTrigger() != null) { node.GetTrigger().Apply(this); } if (node.GetVisibilityModifier() != null) { node.GetVisibilityModifier().Apply(this); } OutAMethodDecl(node); }
public override void OutAMethodDecl(AMethodDecl node) { if (node.GetTrigger() != null) { bool validSignature = IsBoolType(node.GetReturnType()); validSignature &= node.GetFormals().Count == 2; foreach (AALocalDecl formal in node.GetFormals()) { validSignature &= IsBoolType(formal.GetType()); validSignature &= formal.GetRef() == null && formal.GetOut() == null; } if (!validSignature) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText156"))); } } //Check that all code paths return a value if (!(node.GetReturnType() is AVoidType)) { CheckReturns returnChecker = new CheckReturns(); node.GetBlock().Apply(returnChecker); if (!returnChecker.Returned) { errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText157"))); } } //If the return type or the type of any formals is a private struct, and the method is a public context, give an error { AStructDecl pStruct = Util.GetAncestor<AStructDecl>(node); //Is public context if (pStruct == null && node.GetVisibilityModifier() is APublicVisibilityModifier || pStruct != null && pStruct.GetVisibilityModifier() is APublicVisibilityModifier && !(node.GetVisibilityModifier() is APrivateVisibilityModifier)) { PType type = node.GetReturnType(); int i = 0; FindPrivateTypes finder = new FindPrivateTypes(data); while (true) { type.Apply(finder); if (i == node.GetFormals().Count) break; AALocalDecl formal = (AALocalDecl) node.GetFormals()[i]; type = formal.GetType(); i++; } if (finder.PrivateTypes.Count > 0) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); List<PDecl> usedDecls = new List<PDecl>(); foreach (ANamedType namedType in finder.PrivateTypes) { if (data.StructTypeLinks.ContainsKey(namedType)) { AStructDecl decl = data.StructTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText64"))); } else if (data.DelegateTypeLinks.ContainsKey(namedType)) { AMethodDecl decl = data.DelegateTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText154"))); } } errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText155"), false, subErrors.ToArray())); } } } base.OutAMethodDecl(node); }