/src/org/ooc/frontend/model/FuncType.java

http://github.com/nddrylliog/ooc · Java · 76 lines · 58 code · 17 blank · 1 comment · 4 complexity · d21514506e9c371d329476f41e67f6d5 MD5 · raw file

  1. package org.ooc.frontend.model;
  2. import java.io.IOException;
  3. import org.ooc.frontend.Visitor;
  4. import org.ooc.frontend.model.tokens.Token;
  5. import org.ooc.middle.hobgoblins.Resolver;
  6. public class FuncType extends Type {
  7. private FunctionDecl decl;
  8. private FuncType(Token startToken) {
  9. super("Func", startToken);
  10. }
  11. public FuncType(Token startToken, FunctionDecl decl) {
  12. this(startToken);
  13. this.decl = decl;
  14. for(TypeParam typeParam: decl.getTypeParams().values()) {
  15. typeParams.add(new VariableAccess(typeParam.getName(), typeParam.startToken));
  16. }
  17. setRef(decl);
  18. }
  19. public FuncType(Token startToken, NodeList<Access> typeParams) {
  20. this(startToken);
  21. decl = new FunctionDecl("<function pointer>", "", false, false, false, true, startToken, null);
  22. decl.setFromPointer(true);
  23. if(typeParams != null) {
  24. typeParams.addAll(typeParams);
  25. for(Access typeParam: typeParams) {
  26. String name = ((VariableAccess) typeParam).getName();
  27. decl.getTypeParams().put(name, new TypeParam(name, typeParam.startToken));
  28. }
  29. }
  30. setRef(decl);
  31. }
  32. public FunctionDecl getDecl() {
  33. return decl;
  34. }
  35. @Override
  36. public Response resolve(NodeList<Node> stack, Resolver res, boolean fatal) {
  37. // hah nothing to worry about =)
  38. return Response.OK;
  39. }
  40. @Override
  41. public void acceptChildren(Visitor visitor) throws IOException {
  42. super.acceptChildren(visitor);
  43. decl.accept(visitor);
  44. }
  45. @Override
  46. public boolean hasChildren() {
  47. return true;
  48. }
  49. @Override
  50. public Type clone() {
  51. FuncType copy = new FuncType(startToken, typeParams);
  52. copy.decl = decl;
  53. return copy;
  54. }
  55. @Override
  56. public String toString() {
  57. return "FuncType|"+super.toString();
  58. }
  59. }