Exemple #1
0
  /**
   * Search local scope
   *
   * @param name the id to resolve
   * @param types constraints on the types of Declarations that will match
   * @see Clc.Analysis.Cpp_LFlags
   */
  protected DeclarationSet searchLocalScope(String name, int types) {

    DeclarationSet matches = scope.get(name);

    if (matches == null) {

      d.msg(Debug.COMPILE, name + " has no matches in local scope");

      matches = new DeclarationSetMulti();
    }

    if (types != Cpp_LFlags.ANY && !matches.isEmpty()) {

      // whittle down results according to flags

      d.msg(Debug.COMPILE, name + " has match(es), whittling down result for types " + types);

      DeclarationSetMulti realMatches = new DeclarationSetMulti();

      for (Enumeration e = matches.elements(); e.hasMoreElements(); ) {

        Declaration decl = (Declaration) e.nextElement();

        if (decl.getCategory().intersects(types)) {

          realMatches.addElement(decl);
        }
      }

      matches = realMatches;
    }

    return matches;
  }
Exemple #2
0
  /**
   * Adds the <code>Declaration</code> to this scope
   *
   * <p>Sets the <code>Declaration's</code> enclosing block to be this scope <br>
   * the fully qualified name will be constructed also.
   *
   * @param decl the declaration to add
   */
  public void addDeclaration(Declaration decl) {

    super.addDeclaration(decl);

    // determine and assign the fqn of the declaration

    decl.setName(fqnToHere(decl.getUnqualifiedName()));
  }
Exemple #3
0
  public void moveContents(ScopeHolder fromSH) {

    if (fromSH == null) return;

    // update the fully qualified id of each declaration

    for (Enumeration decls = fromSH.elements(); decls.hasMoreElements(); ) {

      Declaration decl = (Declaration) decls.nextElement();

      ScopedName new_fqn = this.fqnToHere(decl.getUnqualifiedName());

      d.msg(
          Debug.COMPILE,
          "parameter fqn was " + decl.getName().getName() + ", is now " + new_fqn.getName());

      decl.setName(new_fqn);
    }

    // rest of move procedure

    super.moveContents(fromSH);
  }
  protected void setUp() {
    //                d.on ();

    // Create a time manager to synchronize back tracking
    BTTimeManager timeMan = new BTTimeManager();

    // Create the symbol table
    rt_symtab = new RT_Symbol_Table(timeMan);

    // Create a virtual machine state .
    vms =
        new VMState(
            timeMan, boStatic, toStatic, boHeap, toHeap, boStack, toStack, boScratch, toScratch,
            rt_symtab);

    Cpp_StatementManager sm = new Cpp_StatementManager();
    if (dm == null) dm = new Cpp_DeclarationManager(cem, sm, vms);

    // Prepare the VMState
    vms.setProperty("ASTUtilities", new Cpp_ASTUtilities());
    vms.setProperty("DatumUtilities", new DatumUtilities());

    // create the expression for 5
    five = new ConstInt(ctyInt, "5", 5);

    // create the expression for 1
    one = new ConstInt(ctyInt, "1", 1);

    // create the expression for x
    String xid = "x";
    x_sn = new Cpp_ScopedName(xid);
    x = new ExpId(new TyRef(tyInt), xid, x_sn);

    // create the expression for 5.0
    ffive = new ConstFloat(ctyFloat, "5.0", 5.0);

    // create the expression for 1.0
    fone = new ConstFloat(ctyFloat, "1.0", 1.0);

    // create the expression for y
    String yid = "y";
    y_sn = new Cpp_ScopedName(yid);
    y = new ExpId(new TyRef(tyFloat), yid, y_sn);

    tyPointer = new TyPointer();
    tyPointer.addToEnd(tyInt);
    // create the expression for p
    String pid = "p";
    p = new ExpId(new TyRef(tyPointer), pid, new Cpp_ScopedName(pid));

    tyArray = new TyArray();
    tyArray.addToEnd(tyInt);
    // create the expression for a
    String aid = "a";
    a = new ExpId(new TyRef(tyArray), aid, new Cpp_ScopedName(aid));

    String idC = "C";
    sn_C = new Cpp_ScopedName(idC);
    tyClass = new TyClass(idC, sn_C, null);
    // create the expression for c
    String cid = "c";
    c_sn = new Cpp_ScopedName(cid);
    c = new ExpId(new TyRef(tyClass), cid, c_sn);

    String bid = "b";
    b = new ExpId(new TyRef(tyBool), bid, new Cpp_ScopedName(bid));

    _true = new ConstInt(tyBool, "true", 1);

    // create a string constant
    str_const = (ConstStr) Literals.make_string_const("\"blah\"", vms);
    // array of char
    tyArrayChar = new TyArray();
    tyArrayChar.addToEnd(tyChar);
    // create the expression for a
    String acid = "ac";
    ac = new ExpId(new TyRef(tyArrayChar), acid, new Cpp_ScopedName(acid));

    // reference to int
    tyRefInt = new TyRef(tyInt);

    // create the id expression for rint
    String riid = "ri";
    r_sn = new Cpp_ScopedName(riid);
    rint = new ExpId(new TyRef(tyRefInt), riid, r_sn);

    // constant reference to int
    ctyRefInt = new TyRef(ctyInt);
    ctyRefInt.setAttributes(Cpp_Specifiers.CVQ_CONST);

    // create the id expression for rint
    String criid = "cri";
    crint = new ExpId(new TyRef(ctyRefInt), criid, new Cpp_ScopedName(criid));

    // function taking no parameters and returning int
    tyFun = new TyFun(new Vector(), false);
    tyFun.addToEnd(tyInt);

    // create the following scope and declaration space
    // int x;
    // int &r;
    // int foo ();
    // class C {
    // 	float y;
    // 	int bar ();
    // };
    // C c;
    // C *pc;

    Cpp_SpecifierSet sps = new Cpp_SpecifierSet();
    NodeList nl = new NodeList();
    Declaration decl;

    // int x
    decl = new Declaration(VARIABLE_LF, x_sn, null, sps, tyInt);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyInt));
    st.addDeclaration(decl);

    // int &r
    decl = new Declaration(VARIABLE_LF, r_sn, null, sps, tyRefInt);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyRefInt));
    st.addDeclaration(decl);

    // int foo ()
    foo_sn = new Cpp_ScopedName("foo");
    st.addDefiningDeclaration(foo_sn, REG_FN_LF, tyFun);

    // class C
    ClassHead chc = new ClassHead(ClassHead.CLASS, sn_C, new Vector());
    Declaration c_decl = st.addDefiningDeclaration(chc);

    st.enterScope(c_decl);

    // float y
    decl = new Declaration(VARIABLE_LF, y_sn, null, sps, tyFloat);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyFloat));
    st.addDeclaration(decl);

    // int bar ()
    bar_sn = new Cpp_ScopedName("bar");
    st.addDefiningDeclaration(bar_sn, MEM_FN_LF, tyFun);

    st.exitScope();

    // C c
    decl = new Declaration(VARIABLE_LF, c_sn, null, sps, tyClass);
    decl.setDefinition(c_decl);
    decl.getCategory().set(dm.type_extractor.categorizeClass(decl));
    st.addDeclaration(decl);

    tyPointerClass = new TyPointer();
    tyPointerClass.addToEnd(tyClass);
    // C *pc
    String pcid = "pc";
    pc_sn = new Cpp_ScopedName(pcid);
    pc = new ExpId(new TyRef(tyPointer), pcid, pc_sn);
    decl = new Declaration(VARIABLE_LF, pc_sn, null, sps, tyPointerClass);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyPointerClass));
    st.addDeclaration(decl);
  }