Beispiel #1
0
  private void init(
      Name identifier,
      ModelAttribute[] attributes,
      Modifiers modifiers,
      Type type,
      Value initialValue,
      boolean enumeration) {
    if (delegate == null)
      delegate =
          new SimpleField(modifiers, type, identifier, attributes, initialValue, null, getPath());

    if (enumeration) {
      if (initialValue == null) setLabel(identifier.toIdentifier());
      else setLabel(identifier.toIdentifier() + " : " + initialValue.toLabel());
    } else {
      if (type != null && type.asFunctionType() != null) {
        setLabel(type.toLabel(identifier.toIdentifier(), Type.Label.SMALL));
      } else {
        if (type != null)
          setLabel(identifier.toIdentifier() + " : " + type.toLabel(null, Type.Label.SMALL));
        else setLabel(identifier.toIdentifier());
      }
    }

    setAttributes(attributes);
    setTags(getFieldTags(modifiers, type, enumeration));
    getTags().add(Tag.IDENTIFIABLE);
    setContent(new LabelContent(getLabel(), new Icon(getTags(), attributes), getPath()));
  }
Beispiel #2
0
  public static final String fieldId(Name name, Type type) {
    if (name == null && type == null)
      throw new NullPointerException("either name or type must not be null");

    if (name == null) return "-" + type.id(false);

    if (type == null) return name.toIdentifier();

    return name.toIdentifier() + "-" + type.id(false);
  }
  @Override
  public void check(
      AnalyzeStack stack, DeclarationSpecifierList specifiers, InitDeclarator declaration) {
    if (specifiers == null) return;

    Type type = specifiers.resolveType();
    if (type != null) type = declaration.resolveType(type, stack);

    if (type != null || type.asFunctionType() != null) {
      // a forward declaration of an event or command function
      specifiers.checkModifiers(
          stack,
          new int[] {Modifiers.COMMAND | Modifiers.EVENT | Modifiers.TYPEDEF},
          Modifiers.ALL_TYPE_QUALIFIER | Modifiers.INLINE | Modifiers.ASYNC,
          Modifiers.TASK
              | Modifiers.DEFAULT
              | Modifiers.NORACE
              | Modifiers.AUTO
              | Modifiers.REGISTER,
          null,
          new FunctionMessanger(true, declaration.resolveName()));
    }
  }
Beispiel #4
0
  /**
   * Gets the {@link Tag}s which describe a field with <code>type</code>.
   *
   * @param modifiers the modifiers applied, can be <code>null</code>
   * @param type the type whose tags are required
   * @param enumeration whether the field is specified within an enumeration
   * @return the tags
   */
  public static TagSet getFieldTags(Modifiers modifiers, Type type, boolean enumeration) {
    TagSet tags = new TagSet();
    tags.add(Tag.NO_BASE_EXPANSION);

    if (modifiers != null) {
      if (modifiers.isCommand()) tags.add(Tag.COMMAND);
      if (modifiers.isEvent()) tags.add(Tag.EVENT);
      if (modifiers.isAsync()) tags.add(Tag.ASYNC);
      if (modifiers.isTask()) tags.add(Tag.TASK);
    }

    if (enumeration) {
      tags.add(NesC12ASTModel.ENUMERATION_CONSTANT);
    } else {
      if (type != null && type.asFunctionType() != null) {
        tags.add(Tag.FUNCTION);
      } else {
        tags.add(NesC12ASTModel.FIELD);
      }
    }
    return tags;
  }