Exemple #1
0
/**
 * Attempt to read an atom constructor type node at a certain offset.
 *
 * @param  hatFile The file to read the node from.
 * @param  offset  The offset where the start of the node should be.
 * @return A node construct containing the read values.
 */
node* readAtomConstructor(FILE *hatFile, unsigned long offset)
{
    int  argIndex;
    char tag;
    node *newNode = (node *)malloc(sizeof(node));
    
    newNode->nodeType = AtomConstructor;
    newNode->offset = offset;
    
    setFilePos(hatFile, offset);
    tag = readByte(hatFile);
    newNode->params.atomConstructor.module = readPointer(hatFile);
    newNode->params.atomConstructor.filePos = readPosition(hatFile);
    readPosition(hatFile);  /* skip position end */
    newNode->params.atomConstructor.fix = readFixPri(hatFile);
    newNode->params.atomConstructor.arity = readArity(hatFile);
    newNode->params.atomConstructor.name = readString(hatFile);
    if (newNode->params.atomConstructor.hasFields = hasFields(tag))
    {
        newNode->params.atomConstructor.args = (unsigned long *)malloc(newNode->params.atomConstructor.arity * sizeof(unsigned long));
        for (argIndex = 0; argIndex < newNode->params.atomConstructor.arity; argIndex++)
        {
            newNode->params.atomConstructor.args[argIndex] = readPointer(hatFile);
        }
    }
    
    return newNode;
}
void HeaderParser::run(
    const clang::ast_matchers::MatchFinder::MatchResult& result) {
  // Parse structs, unions, and class declarations
  const clang::RecordDecl* rd = result.Nodes.getNodeAs<clang::RecordDecl>("rd");
  if (rd) {
    try {
      file_->addStruct(std::make_unique<ThriftStruct>(*rd));
    } catch (const std::exception& e) {
      // TODO(borisb): this case should generate thrift comments calling for
      // manual code that needs to be written.
    }
    return;
  }
  // Parse enum declarations
  const clang::EnumDecl* ed = result.Nodes.getNodeAs<clang::EnumDecl>("ed");
  if (ed) {
    file_->addEnum(std::make_unique<ThriftEnum>(*ed));
    return;
  }
  // Parse function declarations
  const clang::FunctionDecl* fd =
      result.Nodes.getNodeAs<clang::FunctionDecl>("fd");
  if (fd) {
    try {
      auto tm = std::make_unique<ThriftMethod>(*fd);
      auto ts = std::make_unique<ThriftStruct>(*fd);
      if (ts->hasFields()) {
        tm->resultTypeName = ts->name;
        file_->addStruct(std::move(ts));
      }
      file_->addMethod(std::move(tm));
    } catch (const std::exception& e) {
      // TODO(borisb): this case should generate thrift comments calling for
      // manual code that needs to be written.
    }
    return;
  }
}